public virtual string AddData(Registration reg) { if (reg.jsonSchema == null) { throw new DataSetException(this.datasetId, ApiResponseStatus.DatasetJsonSchemaMissing); } var addDataResult = base.AddData(reg, reg.datasetId, reg.createdBy); DataSet.CachedDatasets.Delete(reg.datasetId); //check orderList if (reg.orderList?.Length > 0) { //get mapping var ds = CachedDatasets.Get(addDataResult); var txtProps = ds.GetTextMappingList(); var allProps = ds.GetMappingList(); if (allProps.Count() > 0) //0=mapping not available , (no record in db) { bool changedOrderList = false; //find missing and remove it List <int> toRemove = new List <int>(); for (int i = 0; i < reg.orderList.GetLength(0); i++) { string oProp = reg.orderList[i, 1] .Replace(DataSearchResult.OrderAsc, "") .Replace(DataSearchResult.OrderDesc, "") .Replace(DataSearchResult.OrderAscUrl, "") .Replace(DataSearchResult.OrderDescUrl, "") .Trim(); if (allProps.Contains(oProp) == false) { //neni na seznamu properties, pridej do seznamu k smazani toRemove.Add(i); } } if (toRemove.Count > 0) { foreach (var i in toRemove.OrderByDescending(n => n)) { reg.orderList = HlidacStatu.Util.ArrayTools.TrimArray <string>(i, null, reg.orderList); changedOrderList = true; } } for (int i = 0; i < reg.orderList.GetLength(0); i++) { string oProp = reg.orderList[i, 1] .Replace(DataSearchResult.OrderAsc, "") .Replace(DataSearchResult.OrderAscUrl, "") .Replace(DataSearchResult.OrderDesc, "") .Replace(DataSearchResult.OrderDescUrl, "") .Trim(); if (txtProps.Contains(oProp)) { //pridej keyword na konec reg.orderList[i, 1] = reg.orderList[i, 1].Replace(oProp, oProp + ".keyword"); changedOrderList = true; } } if (changedOrderList) { addDataResult = base.AddData(reg, reg.datasetId, reg.createdBy); } } } DataSet.CachedDatasets.Set(reg.datasetId, null); return(addDataResult); }
public virtual string AddData(Registration reg, string user, bool skipallowWriteAccess = false) { if (reg.jsonSchema == null) { throw new DataSetException(this.datasetId, ApiResponseStatus.DatasetJsonSchemaMissing); } Registration oldReg = null; oldReg = DataSet.CachedDatasets.Get(reg.datasetId)?.Registration(); if (oldReg == null) { Audit.Add <Registration>(Audit.Operations.Create, user, reg, null); } else { Audit.Add <Registration>(Audit.Operations.Update, user, reg, oldReg); } var addDataResult = base.AddData(reg, reg.datasetId, reg.createdBy, validateSchema: false, skipallowWriteAccess: true); DataSet.CachedDatasets.Delete(reg.datasetId); //check orderList if (reg.orderList?.Length > 0) { //get mapping var ds = CachedDatasets.Get(addDataResult); var txtProps = ds.GetTextMappingList(); var allProps = ds.GetMappingList(); if (allProps.Where(m => !DataSet.DefaultDatasetProperties.Keys.Contains(m)).Count() > 0) //0=mapping not available , (no record in db) { bool changedOrderList = false; //find missing and remove it List <int> toRemove = new List <int>(); for (int i = 0; i < reg.orderList.GetLength(0); i++) { string oProp = reg.orderList[i, 1] .Replace(DataSearchResult.OrderAsc, "") .Replace(DataSearchResult.OrderDesc, "") .Replace(DataSearchResult.OrderAscUrl, "") .Replace(DataSearchResult.OrderDescUrl, "") .Trim(); if (oProp.EndsWith(".keyword")) { oProp = System.Text.RegularExpressions.Regex.Replace(oProp, "\\.keyword$", ""); } if (allProps.Contains(oProp) == false) { //neni na seznamu properties, pridej do seznamu k smazani toRemove.Add(i); } } if (toRemove.Count > 0) { foreach (var i in toRemove.OrderByDescending(n => n)) { reg.orderList = Devmasters.Collections.ArrayExt.TrimArray <string>(i, null, reg.orderList); changedOrderList = true; } } for (int i = 0; i < reg.orderList.GetLength(0); i++) { string oProp = reg.orderList[i, 1] .Replace(DataSearchResult.OrderAsc, "") .Replace(DataSearchResult.OrderAscUrl, "") .Replace(DataSearchResult.OrderDesc, "") .Replace(DataSearchResult.OrderDescUrl, "") .Trim(); if (txtProps.Contains(oProp)) { //pridej keyword na konec reg.orderList[i, 1] = reg.orderList[i, 1].Replace(oProp, oProp + ".keyword"); changedOrderList = true; } } if (changedOrderList) { addDataResult = base.AddData(reg, reg.datasetId, reg.createdBy); } } } DataSet.CachedDatasets.Set(reg.datasetId, null); return(addDataResult); }