This commit is contained in:
@@ -32,14 +32,15 @@ namespace AyaNova.Biz
|
||||
DEPRECATED_REUSELATER_15 = 15,
|
||||
DEPRECATED_REUSELATER_16 = 16,
|
||||
FileAttachment = 17,
|
||||
DataFilter = 18
|
||||
DataFilter = 18,
|
||||
FormCustom = 19
|
||||
|
||||
|
||||
//NOTE: New objects added here need to also be added to the following classes:
|
||||
//AyaNova.Biz.BizObjectExistsInDatabase
|
||||
//AyaNova.Biz.BizObjectFactory
|
||||
//AyaNova.Biz.BizRoles
|
||||
//AyaNova.Biz.BizObjectNameFetcher && BizObjectNameFetcherDIRECT
|
||||
//AyaNova.Biz.BizObjectNameFetcherDIRECT
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ namespace AyaNova.Biz
|
||||
return ct.FileAttachment.Any(m => m.Id == id);
|
||||
case AyaType.DataFilter:
|
||||
return ct.DataFilter.Any(m => m.Id == id);
|
||||
case AyaType.FormCustom:
|
||||
return ct.FormCustom.Any(m => m.Id == id);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace AyaNova.Biz
|
||||
case AyaType.User:
|
||||
return new UserBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
case AyaType.Widget:
|
||||
return new WidgetBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
return new WidgetBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
case AyaType.JobOperations:
|
||||
return new JobOperationsBiz(dbcontext, userId, roles);
|
||||
case AyaType.AyaNova7Import:
|
||||
@@ -37,6 +37,8 @@ namespace AyaNova.Biz
|
||||
return new LocaleBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
case AyaType.DataFilter:
|
||||
return new DataFilterBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
case AyaType.FormCustom:
|
||||
return new FormCustomBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.JsonPatch;
|
||||
using EnumsNET;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using AyaNova.Models;
|
||||
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
//Turn a type and ID into a displayable name
|
||||
internal static class BizObjectNameFetcher
|
||||
{
|
||||
|
||||
/*
|
||||
NOT SURE IF I WILL WANT TO USE THIS OR NOT GOING FORWARD SO KEEPING IT IN PLACE BUT NOT USABLE FOR NOW
|
||||
|
||||
*/
|
||||
|
||||
internal static string Name(AyaTypeId tid, AyContext ct = null)
|
||||
{
|
||||
throw new System.NotSupportedException("BizObjectNameFetcher:: Slow version, did you mean to call this one?");
|
||||
//return Name(tid.ObjectType, tid.ObjectId, ct);
|
||||
}
|
||||
|
||||
|
||||
//Returns existance status of object type and id specified in database
|
||||
internal static string Name(AyaType aytype, long id, AyContext ct = null)
|
||||
{
|
||||
throw new System.NotSupportedException("BizObjectNameFetcher:: Slow version, did you mean to call this one?");
|
||||
// //new up a context??
|
||||
// if (ct == null)
|
||||
// {
|
||||
// ct = ServiceProviderProvider.DBContext;
|
||||
// }
|
||||
// switch (aytype)
|
||||
// {
|
||||
// case AyaType.User:
|
||||
// return ct.User.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
|
||||
// case AyaType.Widget:
|
||||
// return ct.Widget.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
|
||||
|
||||
// case AyaType.FileAttachment:
|
||||
// return ct.FileAttachment.AsNoTracking().Where(m => m.Id == id).Select(m => m.DisplayFileName).FirstOrDefault();
|
||||
|
||||
// default:
|
||||
// throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported");
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
}//eoc
|
||||
|
||||
|
||||
}//eons
|
||||
|
||||
@@ -45,6 +45,10 @@ namespace AyaNova.Biz
|
||||
case AyaType.DataFilter:
|
||||
TABLE = "adatafilter";
|
||||
break;
|
||||
case AyaType.FormCustom:
|
||||
TABLE = "aformcustom";
|
||||
COLUMN = "formkey";
|
||||
break;
|
||||
default:
|
||||
throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported");
|
||||
}
|
||||
|
||||
@@ -149,6 +149,17 @@ namespace AyaNova.Biz
|
||||
ReadFullRecord = AuthorizationRoles.AnyRole
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//FORMCUSTOM
|
||||
//
|
||||
roles.Add(AyaType.FormCustom, new BizRoleSet()
|
||||
{
|
||||
//Only BizAdminFull can modify forms
|
||||
Change = AuthorizationRoles.BizAdminFull,
|
||||
EditOwn = AuthorizationRoles.NoRole,
|
||||
ReadFullRecord = AuthorizationRoles.AnyRole
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#endregion all roles init
|
||||
|
||||
|
||||
284
server/AyaNova/biz/FormCustomBiz.cs
Normal file
284
server/AyaNova/biz/FormCustomBiz.cs
Normal file
@@ -0,0 +1,284 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Models;
|
||||
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
|
||||
internal class FormCustomBiz : BizObject
|
||||
{
|
||||
|
||||
internal FormCustomBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
UserId = currentUserId;
|
||||
UserLocaleId = userLocaleId;
|
||||
CurrentUserRoles = UserRoles;
|
||||
BizType = AyaType.FormCustom;
|
||||
}
|
||||
|
||||
internal static FormCustomBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
|
||||
{
|
||||
return new FormCustomBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
}
|
||||
|
||||
//Version for internal use
|
||||
internal static FormCustomBiz GetBizInternal(AyContext ct)
|
||||
{
|
||||
return new FormCustomBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//EXISTS
|
||||
internal async Task<bool> ExistsAsync(long id)
|
||||
{
|
||||
return await ct.FormCustom.AnyAsync(e => e.Id == id);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// GET
|
||||
internal async Task<FormCustom> GetNoLogAsync(long fetchId)
|
||||
{
|
||||
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
|
||||
return await ct.FormCustom.SingleOrDefaultAsync(m => m.Id == fetchId);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CREATE
|
||||
internal async Task<FormCustom> CreateAsync(FormCustom inObj)
|
||||
{
|
||||
Validate(inObj, true);
|
||||
if (HasErrors)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
//do stuff with datafilter
|
||||
FormCustom outObj = inObj;
|
||||
outObj.OwnerId = UserId;
|
||||
|
||||
|
||||
await ct.FormCustom.AddAsync(outObj);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Handle child and associated items:
|
||||
|
||||
//EVENT LOG
|
||||
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
|
||||
//SEARCH INDEXING
|
||||
// Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name);
|
||||
|
||||
return outObj;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CREATE
|
||||
internal FormCustom Create(AyContext TempContext, FormCustom inObj)
|
||||
{
|
||||
Validate(inObj, true);
|
||||
if (HasErrors)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
//do stuff with datafilter
|
||||
FormCustom outObj = inObj;
|
||||
outObj.OwnerId = UserId;
|
||||
|
||||
|
||||
TempContext.FormCustom.Add(outObj);
|
||||
TempContext.SaveChanges();
|
||||
|
||||
//Handle child and associated items:
|
||||
|
||||
//EVENT LOG
|
||||
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext);
|
||||
|
||||
//SEARCH INDEXING
|
||||
// Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name);
|
||||
|
||||
return outObj;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// GET
|
||||
|
||||
//Get one
|
||||
internal async Task<FormCustom> GetAsync(string formKey)
|
||||
{
|
||||
var ret = await ct.FormCustom.SingleOrDefaultAsync(m => m.FormKey == formKey);
|
||||
//Do not log this, it's going to be called a zillion times anyway
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//UPDATE
|
||||
//
|
||||
|
||||
//put
|
||||
internal bool Put(FormCustom dbObj, FormCustom inObj)
|
||||
{
|
||||
//preserve the owner ID if none was specified
|
||||
if (inObj.OwnerId == 0)
|
||||
inObj.OwnerId = dbObj.OwnerId;
|
||||
|
||||
//Replace the db object with the PUT object
|
||||
CopyObject.Copy(inObj, dbObj, "Id");
|
||||
//Set "original" value of concurrency token to input token
|
||||
//this will allow EF to check it out
|
||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
|
||||
|
||||
Validate(dbObj, false);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
|
||||
//Log modification
|
||||
EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
|
||||
//Update keywords
|
||||
// Search.ProcessUpdatedObjectKeywords(UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//NO DELETE, ONLY EDIT
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
|
||||
//Can save or update?
|
||||
private void Validate(FormCustom inObj, bool isNew)
|
||||
{
|
||||
|
||||
//OwnerId required
|
||||
if (!isNew)
|
||||
{
|
||||
if (inObj.OwnerId == 0)
|
||||
AddError(ValidationErrorType.RequiredPropertyEmpty, "OwnerId");
|
||||
}
|
||||
|
||||
// //Owner must be current user, there are no exceptions
|
||||
// if (inObj.OwnerId != UserId)
|
||||
// AddError(ValidationErrorType.InvalidValue, "OwnerId", "OwnerId must be current user Id");
|
||||
|
||||
//FormKey required
|
||||
if (string.IsNullOrWhiteSpace(inObj.FormKey))
|
||||
AddError(ValidationErrorType.RequiredPropertyEmpty, "FormKey");
|
||||
|
||||
//FormKey must be less than 255 characters
|
||||
if (inObj.FormKey.Length > 255)
|
||||
AddError(ValidationErrorType.LengthExceeded, "FormKey", "255 max");
|
||||
|
||||
//If name is otherwise OK, check that name is unique
|
||||
if (!PropertyHasErrors("FormKey"))
|
||||
{
|
||||
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
||||
if (ct.FormCustom.Any(m => m.FormKey == inObj.FormKey && m.Id != inObj.Id))
|
||||
{
|
||||
AddError(ValidationErrorType.NotUnique, "FormKey");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Template json must parse
|
||||
if (!string.IsNullOrWhiteSpace(inObj.Template))
|
||||
{
|
||||
try
|
||||
{
|
||||
var v = JArray.Parse(inObj.Template);
|
||||
//TODO: validate the json
|
||||
// for (int i = 0; i < v.Count; i++)
|
||||
// {
|
||||
// var filterItem = v[i];
|
||||
// if (filterItem["fld"] == null)
|
||||
// AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing required \"fld\" property ");
|
||||
// else
|
||||
// {
|
||||
// var fld = filterItem["fld"].Value<string>();
|
||||
// if (string.IsNullOrWhiteSpace(fld))
|
||||
// AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, \"fld\" property is empty and required");
|
||||
|
||||
// //validate the field name if we can
|
||||
// if (ListValidFilterOptions != null)
|
||||
// {
|
||||
|
||||
// if (!ListValidFilterOptions.Flds.Exists(x => x.Fld == fld))
|
||||
// {
|
||||
// AddError(ValidationErrorType.InvalidValue, "Filter", $"Filter array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified");
|
||||
// }
|
||||
|
||||
// }
|
||||
// }
|
||||
// if (filterItem["op"] == null)
|
||||
// AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing required \"op\" property ");
|
||||
// else
|
||||
// {
|
||||
// var opType = filterItem["op"].Value<string>();
|
||||
// if (!FilterComparisonOperator.Operators.Contains(opType))
|
||||
// AddError(ValidationErrorType.InvalidValue, "Filter", $"Filter array item {i}, \"op\" property value of \"{opType}\" is not a valid FilterComparisonOperator type");
|
||||
// }
|
||||
|
||||
// if (filterItem["value"] == null)
|
||||
// AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ");
|
||||
// else
|
||||
// {
|
||||
// if (filterItem["value"].Type == JTokenType.String && string.IsNullOrWhiteSpace(filterItem["value"].Value<string>()))
|
||||
// AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ");
|
||||
|
||||
// if (filterItem["value"].Type == JTokenType.Array && filterItem["value"].Count() == 0)
|
||||
// AddError(ValidationErrorType.RequiredPropertyEmpty, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ARRAY ");
|
||||
// }
|
||||
|
||||
|
||||
// //NOTE: value of nothing, null or empty is a valid value so no checking for it here
|
||||
// }
|
||||
}
|
||||
catch (Newtonsoft.Json.JsonReaderException ex)
|
||||
{
|
||||
AddError(ValidationErrorType.InvalidValue, "Template", "Template is not valid JSON string: " + ex.Message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// //Can delete?
|
||||
// private void ValidateCanDelete(FormCustom inObj)
|
||||
// {
|
||||
// //Leaving this off for now
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
}//eoc
|
||||
|
||||
|
||||
}//eons
|
||||
|
||||
Reference in New Issue
Block a user