This commit is contained in:
2018-11-29 16:05:35 +00:00
parent 7a0ed8928d
commit 0ba9b971ef
3 changed files with 33 additions and 94 deletions

View File

@@ -85,7 +85,8 @@ SERVER
- This object will be replicated repeatedly so it always pays to clean it up more and more - This object will be replicated repeatedly so it always pays to clean it up more and more
- WidgetBiz Put/Patch also share nearly the same process keywords code, so move to common method!! - WidgetBiz Put/Patch also share nearly the same process keywords code, so move to common method!!
- Delete user should delete private datafilters
- Did I code how to handle implications of user delete anywhere yet??
- Stage 2 AFTER POSTED TEST ROUND COMPLETED - Stage 2 AFTER POSTED TEST ROUND COMPLETED

View File

@@ -51,7 +51,7 @@ namespace AyaNova.Api.Controllers
/// Get full DataFilter object /// Get full DataFilter object
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting /// Any (for public filter), owned only for private filter
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns>A single DataFilter</returns> /// <returns>A single DataFilter</returns>
@@ -85,7 +85,7 @@ namespace AyaNova.Api.Controllers
/// Required roles: Any /// Required roles: Any
/// ///
/// </summary> /// </summary>
/// <returns>Paged id/name collection of DataFilters with paging data</returns> /// <returns>List of public or owned data filters for listKey provided</returns>
[HttpGet("PickList", Name = nameof(DataFilterPickList))] [HttpGet("PickList", Name = nameof(DataFilterPickList))]
public async Task<IActionResult> DataFilterPickList([FromQuery] string ListKey) public async Task<IActionResult> DataFilterPickList([FromQuery] string ListKey)
{ {
@@ -108,8 +108,7 @@ namespace AyaNova.Api.Controllers
/// Put (update) DataFilter /// Put (update) DataFilter
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull /// Any (public filter) or owned only (private filter)
/// TechFull (owned only)
/// ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
@@ -189,8 +188,7 @@ namespace AyaNova.Api.Controllers
/// Delete DataFilter /// Delete DataFilter
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull /// Any if public otherwise creator only
/// TechFull (owned only)
/// ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>

View File

@@ -15,7 +15,7 @@ namespace AyaNova.Biz
{ {
internal class DataFilterBiz : BizObject, IJobObject internal class DataFilterBiz : BizObject
{ {
internal DataFilterBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles) internal DataFilterBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles)
@@ -129,26 +129,6 @@ namespace AyaNova.Biz
return ret; return ret;
} }
// //get many (paged)
// internal async Task<ApiPagedResponse<DataFilter>> GetManyAsync(IUrlHelper Url, string routeName, PagingOptions pagingOptions)
// {
// pagingOptions.Offset = pagingOptions.Offset ?? PagingOptions.DefaultOffset;
// pagingOptions.Limit = pagingOptions.Limit ?? PagingOptions.DefaultLimit;
// var items = await ct.DataFilter
// .OrderBy(m => m.Id)
// .Skip(pagingOptions.Offset.Value)
// .Take(pagingOptions.Limit.Value)
// .ToArrayAsync();
// var totalRecordCount = await ct.DataFilter.CountAsync();
// var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, totalRecordCount).PagingLinksObject();
// ApiPagedResponse<DataFilter> pr = new ApiPagedResponse<DataFilter>(items, pageLinks);
// return pr;
// }
//get picklist (NOT PAGED) //get picklist (NOT PAGED)
internal async Task<List<NameIdItem>> GetPickListAsync(string listKey) internal async Task<List<NameIdItem>> GetPickListAsync(string listKey)
@@ -222,9 +202,6 @@ namespace AyaNova.Biz
//Delete search index //Delete search index
Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType); Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType);
//TAGS
TagMapBiz.DeleteAllForObject(new AyaTypeId(BizType, dbObj.Id), ct);
ct.SaveChanges();
return true; return true;
} }
@@ -236,15 +213,6 @@ namespace AyaNova.Biz
//Can save or update? //Can save or update?
private void Validate(DataFilter inObj, bool isNew) private void Validate(DataFilter inObj, bool isNew)
{ {
//run validation and biz rules
if (isNew)
{
//NEW datafilters must be active
if (inObj.Active == null || ((bool)inObj.Active) == false)
{
AddError(ValidationErrorType.InvalidValue, "Active", "New datafilter must be active");
}
}
//OwnerId required //OwnerId required
if (!isNew) if (!isNew)
@@ -253,6 +221,10 @@ namespace AyaNova.Biz
AddError(ValidationErrorType.RequiredPropertyEmpty, "OwnerId"); 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");
//Name required //Name required
if (string.IsNullOrWhiteSpace(inObj.Name)) if (string.IsNullOrWhiteSpace(inObj.Name))
AddError(ValidationErrorType.RequiredPropertyEmpty, "Name"); AddError(ValidationErrorType.RequiredPropertyEmpty, "Name");
@@ -271,25 +243,11 @@ namespace AyaNova.Biz
} }
} }
//Start date AND end date must both be null or both contain values if (string.IsNullOrWhiteSpace(inObj.ListKey))
if (inObj.StartDate == null && inObj.EndDate != null) AddError(ValidationErrorType.RequiredPropertyEmpty, "ListKey");
AddError(ValidationErrorType.RequiredPropertyEmpty, "StartDate");
if (inObj.StartDate != null && inObj.EndDate == null)
AddError(ValidationErrorType.RequiredPropertyEmpty, "EndDate");
//Start date before end date
if (inObj.StartDate != null && inObj.EndDate != null)
if (inObj.StartDate > inObj.EndDate)
AddError(ValidationErrorType.StartDateMustComeBeforeEndDate, "StartDate");
//Enum is valid value
if (!inObj.Roles.IsValid())
{
AddError(ValidationErrorType.InvalidValue, "Roles");
}
if (inObj.ListKey.Length > 255)
AddError(ValidationErrorType.LengthExceeded, "ListKey", "255 max");
return; return;
} }
@@ -298,48 +256,30 @@ namespace AyaNova.Biz
//Can delete? //Can delete?
private void ValidateCanDelete(DataFilter inObj) private void ValidateCanDelete(DataFilter inObj)
{ {
//whatever needs to be check to delete this object //Leaving this off for now
} }
//////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////
//JOB / OPERATIONS // //JOB / OPERATIONS
// // //
public async Task HandleJobAsync(OpsJob job) // public async Task HandleJobAsync(OpsJob job)
{ // {
//Hand off the particular job to the corresponding processing code // //Hand off the particular job to the corresponding processing code
//NOTE: If this code throws an exception the caller (JobsBiz::ProcessJobsAsync) will automatically set the job to failed and log the exeption so // //NOTE: If this code throws an exception the caller (JobsBiz::ProcessJobsAsync) will automatically set the job to failed and log the exeption so
//basically any error condition during job processing should throw up an exception if it can't be handled // //basically any error condition during job processing should throw up an exception if it can't be handled
switch (job.JobType) // switch (job.JobType)
{ // {
case JobType.TestDataFilterJob: // case JobType.TestDataFilterJob:
await ProcessTestJobAsync(job); // await ProcessTestJobAsync(job);
break; // break;
default: // default:
throw new System.ArgumentOutOfRangeException($"DataFilterBiz.HandleJob-> Invalid job type{job.JobType.ToString()}"); // throw new System.ArgumentOutOfRangeException($"DataFilterBiz.HandleJob-> Invalid job type{job.JobType.ToString()}");
} // }
} // }
/// <summary>
/// /// Handle the test job
/// </summary>
/// <param name="job"></param>
private async Task ProcessTestJobAsync(OpsJob job)
{
var sleepTime = 30 * 1000;
//Simulate a long running job here
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Running, ct);
JobsBiz.LogJob(job.GId, $"DataFilterBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct);
//Uncomment this to test if the job prevents other routes from running
//result is NO it doesn't prevent other requests, so we are a-ok for now
await Task.Delay(sleepTime);
JobsBiz.LogJob(job.GId, "DataFilterBiz::ProcessTestJob done sleeping setting job to finished", ct);
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct);
}
//Other job handlers here... //Other job handlers here...