diff --git a/server/AyaNova/biz/PickListBiz.cs b/server/AyaNova/biz/PickListBiz.cs index 0a63dbb2..d1fecf20 100644 --- a/server/AyaNova/biz/PickListBiz.cs +++ b/server/AyaNova/biz/PickListBiz.cs @@ -209,175 +209,61 @@ namespace AyaNova.Biz private void Validate(PickListTemplate inObj) { - //validate that the template is valid, the type is legit etc var TemplateType = (AyaType)inObj.Id; if (!TemplateType.HasAttribute(typeof(CoreBizObjectAttribute))) { - AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "AyaType", "AyaType specified is not a core object type and doesn't support pick list templates"); + AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ayaType", "AyaType specified is not a Core object type and doesn't support pick list templates"); return; } - // //UserId required - // if (!isNew) - // { - // if (inObj.UserId == 0) - // AddError(ApiErrorCode.VALIDATION_REQUIRED, "UserId"); - // } + if (string.IsNullOrWhiteSpace(inObj.Template)) + AddError(ApiErrorCode.VALIDATION_REQUIRED, "Template"); + var PickList = PickListFactory.GetAyaPickList(TemplateType); - // //Name required - // if (string.IsNullOrWhiteSpace(inObj.Name)) - // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name"); + //Filter json must parse + //this is all automated normally so not going to do too much parsing here + //just ensure it's basically there + if (!string.IsNullOrWhiteSpace(inObj.Template)) + { + try + { + var v = JArray.Parse(inObj.Template); + for (int i = 0; i < v.Count; i++) + { + var filterItem = v[i]; + if (filterItem["fld"] == null) + AddError(ApiErrorCode.VALIDATION_REQUIRED, "Template", $"Template array item {i}, object is missing required \"fld\" property "); + else + { + var fld = filterItem["fld"].Value(); + if (string.IsNullOrWhiteSpace(fld)) + AddError(ApiErrorCode.VALIDATION_REQUIRED, "Template", $"Template array item {i}, \"fld\" property is empty and required"); - // //Name must be less than 255 characters - // if (inObj.Name.Length > 255) - // AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max"); + //validate the field name if we can + if (PickList != null) + { - // //If name is otherwise OK, check that name is unique - // if (!PropertyHasErrors("Name")) - // { - // //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false - // if (await ct.DataListView.AnyAsync(m => m.Name == inObj.Name && m.Id != inObj.Id)) - // { - // AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name"); - // } - // } + var TheField = PickList.ColumnDefinitions.SingleOrDefault(x => x.FieldKey.ToLowerInvariant() == fld); - // if (string.IsNullOrWhiteSpace(inObj.ListKey)) - // AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListKey"); + if (TheField == null) + { + AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Template", $"Template array item {i}, fld property value \"{fld}\" is not a valid value for AyaType specified"); + } + } + } - // var DataList = DataListFactory.GetAyaDataList(inObj.ListKey); + } + } + catch (Newtonsoft.Json.JsonReaderException ex) + { + AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Template", "Template is not valid JSON string: " + ex.Message); - // if (DataList == null) - // { - // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListKey", $"ListKey \"{inObj.ListKey}\" DataListKey is not valid"); - // } - - - - // if (inObj.ListKey.Length > 255) - // AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "ListKey", "255 max"); - - // //Filter json must parse - // //this is all automated normally so not going to do too much parsing here - // //just ensure it's basically there - // if (!string.IsNullOrWhiteSpace(inObj.ListView)) - // { - // try - // { - // var v = JArray.Parse(inObj.ListView); - // for (int i = 0; i < v.Count; i++) - // { - // var filterItem = v[i]; - // if (filterItem["fld"] == null) - // AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListView", $"ListView array item {i}, object is missing required \"fld\" property "); - // else - // { - // var fld = filterItem["fld"].Value(); - // if (string.IsNullOrWhiteSpace(fld)) - // AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListView", $"ListView array item {i}, \"fld\" property is empty and required"); - - // //validate the field name if we can - // if (DataList != null) - // { - - // var TheField = DataList.FieldDefinitions.SingleOrDefault(x => x.FieldKey.ToLowerInvariant() == fld); - - // if (TheField == null) - // { - // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListView", $"ListView array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified"); - // } - - // } - // } - // //This is the old filter validation code but at this point only going to validate that the fields are present and valid as the bare minimum - // // if (filterItem["op"] == null) - // // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing required \"op\" property "); - // // else - // // { - // // var opType = filterItem["op"].Value(); - // // if (!DataListFilterComparisonOperator.Operators.Contains(opType)) - // // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", $"Filter array item {i}, \"op\" property value of \"{opType}\" is not a valid FilterComparisonOperator type"); - // // } - - // // if (filterItem["value"] == null) - // // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property "); - // // else - // // { - // // //check if the value is present, not what it is exactly, just that it's present - // // //value also could contain relative date tokens, not that it checks them anyway but just noting it here - // // if (filterItem["value"].Type == JTokenType.String && string.IsNullOrWhiteSpace(filterItem["value"].Value())) - // // AddError(ApiErrorCode.VALIDATION_REQUIRED, "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(ApiErrorCode.VALIDATION_REQUIRED, "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(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListView", "ListView is not valid JSON string: " + ex.Message); - - // } - // } - - - // // //VALIDATE SORT - // // //Filter json must parse - // // if (!string.IsNullOrWhiteSpace(inObj.Sort)) - // // { - // // try - // // { - // // var v = JArray.Parse(inObj.Sort); - // // for (int i = 0; i < v.Count; i++) - // // { - // // var sortItem = v[i]; - // // if (sortItem["fld"] == null) - // // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, object is missing required \"fld\" property "); - // // else - // // { - // // var fld = sortItem["fld"].Value(); - // // if (string.IsNullOrWhiteSpace(fld)) - // // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, \"fld\" property is empty and required"); - - // // //validate the field name if we can - // // if (DataList != null) - // // { - - // // if (!DataList.FieldDefinitions.Exists(x => x.FieldKey.ToLowerInvariant() == fld && x.IsFilterable)) - // // { - // // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", $"Sort array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified"); - // // } - - // // } - // // } - // // if (sortItem["dir"] == null) - // // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, object is missing required \"dir\" sort direction property "); - // // else - // // { - // // var sortDir = sortItem["dir"].Value(); - // // if (sortDir != "+" && sortDir != "-") - // // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", $"Sort array item {i}, \"dir\" property value of \"{sortDir}\" is not a valid sort direction value, must be \"+\" or \"-\" only"); - // // } - // // //NOTE: value of nothing, null or empty is a valid value so no checking for it here - // // } - // // } - // // catch (Newtonsoft.Json.JsonReaderException ex) - // // { - // // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", "Sort is not valid JSON string: " + ex.Message); - - // // } - // // } - - - - return; + } + } }