diff --git a/backend/Origam.Server/Common/ChangeInfo.cs b/backend/Origam.Server/Common/ChangeInfo.cs index d9dc9070f6..6111b06c75 100644 --- a/backend/Origam.Server/Common/ChangeInfo.cs +++ b/backend/Origam.Server/Common/ChangeInfo.cs @@ -19,27 +19,7 @@ */ #endregion -#region license -/* -Copyright 2005 - 2021 Advantage Solutions, s. r. o. - -This file is part of ORIGAM. - -ORIGAM is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -ORIGAM is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with ORIGAM. If not, see. -*/ -#endregion - +using System; using Origam.Rule; namespace Origam.Server @@ -155,5 +135,32 @@ public static ChangeInfo CleanDataChangeInfo() ci.Operation = Operation.DeleteAllData; return ci; } + + protected bool Equals(ChangeInfo other) + { + return entity == other.entity && operation == other.operation && Equals(objectId, other.objectId); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != this.GetType()) + { + return false; + } + return Equals((ChangeInfo)obj); + } + + public override int GetHashCode() + { + return HashCode.Combine(entity, (int)operation, objectId); + } } } \ No newline at end of file diff --git a/backend/Origam.Server/Controller/SessionController.cs b/backend/Origam.Server/Controller/SessionController.cs index 290931577e..8753724855 100644 --- a/backend/Origam.Server/Controller/SessionController.cs +++ b/backend/Origam.Server/Controller/SessionController.cs @@ -21,6 +21,7 @@ using System; using System.Collections; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Data; using System.Threading; @@ -172,7 +173,7 @@ public IActionResult UpdateRow([FromBody]UpdateRowData updateData) return RunWithErrorHandler(() => { SessionStore ss = sessionObjects.SessionManager.GetSession(updateData.SessionFormIdentifier); - IList output = ss.UpdateObject( + IEnumerable output = ss.UpdateObject( entity: updateData.Entity, id: updateData.Id, property: updateData.Property, diff --git a/backend/Origam.Server/ServerCoreUIService.cs b/backend/Origam.Server/ServerCoreUIService.cs index ee6e5da3ee..43097325b2 100644 --- a/backend/Origam.Server/ServerCoreUIService.cs +++ b/backend/Origam.Server/ServerCoreUIService.cs @@ -382,7 +382,7 @@ public IList DeleteObject(DeleteObjectInput input) public IList DeleteObjectInOrderedList(DeleteObjectInOrderedListInput input) { SessionStore ss = sessionManager.GetSession(new Guid(input.SessionFormIdentifier)); - ArrayList changes = ss.UpdateObjectBatch(input.Entity, input.OrderProperty, input.UpdatedOrderValues); + List changes = ss.UpdateObjectBatch(input.Entity, input.OrderProperty, input.UpdatedOrderValues); changes.AddRange(ss.DeleteObject(input.Entity, input.Id)); Task.Run(() => SecurityTools.CreateUpdateOrigamOnlineUser( SecurityManager.CurrentPrincipal.Identity.Name, @@ -927,7 +927,7 @@ public ArrayList GetPendingChanges(Guid sessionFormIdentifier) sessionStore.PendingChanges = null; return changes ?? new ArrayList(); } - public ArrayList GetChanges(ChangesInput input) + public List GetChanges(ChangesInput input) { var sessionStore = sessionManager.GetSession( input.SessionFormIdentifier); diff --git a/backend/Origam.Server/Session Stores/SaveableSessionStore.cs b/backend/Origam.Server/Session Stores/SaveableSessionStore.cs index 88fd0160c2..8ab74f0dee 100644 --- a/backend/Origam.Server/Session Stores/SaveableSessionStore.cs +++ b/backend/Origam.Server/Session Stores/SaveableSessionStore.cs @@ -197,7 +197,7 @@ internal virtual object Save() return listOfChanges; } - public override ArrayList CreateObject(string entity, IDictionary values, + public override List CreateObject(string entity, IDictionary values, IDictionary parameters, string requestingGrid) { if (this.Template == null || !this.Template.Entity.Name.Equals(entity)) @@ -225,7 +225,7 @@ internal virtual object Save() DataRow newRow = table.Rows.Find(key); NewRowToDataList(newRow); - ArrayList listOfChanges = GetChangesByRow(requestingGrid, + List listOfChanges = GetChangesByRow(requestingGrid, newRow, Operation.Create, this.Data.HasErrors, this.Data.HasChanges(), true); @@ -233,9 +233,9 @@ internal virtual object Save() } } - public override ArrayList UpdateObject(string entity, object id, string property, object newValue) + public override IEnumerable UpdateObject(string entity, object id, string property, object newValue) { - ArrayList result = new ArrayList(); + var result = new HashSet(); InitializeFieldDependencies(); DataTable table = GetTable(entity, this.Data); Guid dsEntityId = (Guid)table.ExtendedProperties["Id"]; @@ -248,7 +248,7 @@ public override ArrayList UpdateObject(string entity, object id, string property foreach(Guid dependentColumnId in _entityFieldDependencies[dsEntityId][fieldId]) { string dependentColumnName = ColumnNameById(table, dependentColumnId); - IList changes; + IEnumerable changes; try { changes = this.UpdateObject(entity, id, dependentColumnName, null); @@ -260,7 +260,7 @@ public override ArrayList UpdateObject(string entity, object id, string property dependentColumnName, property, entity, e.Message)); } - foreach (object o in changes) + foreach (var o in changes) { result.Add(o); } @@ -268,8 +268,8 @@ public override ArrayList UpdateObject(string entity, object id, string property } } - IList baseChanges = base.UpdateObject(entity, id, property, newValue); - foreach (object o in baseChanges) + IEnumerable baseChanges = base.UpdateObject(entity, id, property, newValue); + foreach (var o in baseChanges) { result.Add(o); } diff --git a/backend/Origam.Server/Session Stores/SessionStore.cs b/backend/Origam.Server/Session Stores/SessionStore.cs index 9a48768e5f..e47ec05669 100644 --- a/backend/Origam.Server/Session Stores/SessionStore.cs +++ b/backend/Origam.Server/Session Stores/SessionStore.cs @@ -827,7 +827,7 @@ private static bool IsInColumns(DataColumn searchedColumn, DataColumn[] columns) return false; } - public ArrayList GetChangesByRow( + public List GetChangesByRow( string requestingGrid, DataRow row, Operation operation, bool hasErrors, bool hasChanges, bool fromTemplate) { @@ -835,12 +835,12 @@ private static bool IsInColumns(DataColumn searchedColumn, DataColumn[] columns) hasErrors, hasChanges, fromTemplate); } - internal ArrayList GetChangesByRow( + internal List GetChangesByRow( string requestingGrid, DataRow row, Operation operation, Hashtable ignoreKeys, bool includeRowStates, bool hasErrors, bool hasChanges, bool fromTemplate) { - ArrayList listOfChanges = new ArrayList(); + var listOfChanges = new List(); DataRow rootRow = DatasetTools.RootRow(row); DatasetTools.CheckRowErrorRecursive(rootRow, null, false); @@ -925,20 +925,20 @@ private static void CloneErrors(DataRow sourceRow, DataRow destinationRow) } } - public ArrayList GetChanges(string entity, object id, Operation operation, bool hasErrors, bool hasChanges) + public List GetChanges(string entity, object id, Operation operation, bool hasErrors, bool hasChanges) { return GetChangesByRow(null, this.GetSessionRow(entity, id), operation, hasErrors, hasChanges, false); } - public ArrayList GetChanges(string entity, object id, Operation operation, Hashtable ignoreKeys, bool includeRowStates, bool hasErrors, bool hasChanges) + public List GetChanges(string entity, object id, Operation operation, Hashtable ignoreKeys, bool includeRowStates, bool hasErrors, bool hasChanges) { return GetChangesByRow(null, this.GetSessionRow(entity, id), operation, ignoreKeys, includeRowStates, hasErrors, hasChanges, false); } - private void GetChangesRecursive(ArrayList changes, string requestingGrid, DataRow row, Operation operation, DataRow changedRow, bool allDetails, Hashtable ignoreKeys, bool includeRowStates) + private void GetChangesRecursive(List changes, string requestingGrid, DataRow row, Operation operation, DataRow changedRow, bool allDetails, Hashtable ignoreKeys, bool includeRowStates) { if (row.RowState != DataRowState.Deleted && row.RowState != DataRowState.Detached) { @@ -1488,7 +1488,7 @@ public bool IsLazyLoadedEntity(string entity) } #region CUD - public virtual ArrayList CreateObject(string entity, IDictionary values, + public virtual List CreateObject(string entity, IDictionary values, IDictionary parameters, string requestingGrid) { lock (_lock) @@ -1585,7 +1585,7 @@ public bool IsLazyLoadedEntity(string entity) NewRowToDataList(newRow); - ArrayList listOfChanges = GetChangesByRow(requestingGrid, + List listOfChanges = GetChangesByRow(requestingGrid, newRow, Operation.Create, this.Data.HasErrors, this.Data.HasChanges(), false); @@ -1593,7 +1593,7 @@ public bool IsLazyLoadedEntity(string entity) } } - public virtual ArrayList UpdateObject(string entity, object id, string property, object newValue) + public virtual IEnumerable UpdateObject(string entity, object id, string property, object newValue) { lock (_lock) { @@ -1618,7 +1618,7 @@ public virtual ArrayList UpdateObject(string entity, object id, string property, { UpdateRowColumn(property, newValue, profile, row); } - ArrayList listOfChanges = GetChangesByRow(null, row, + List listOfChanges = GetChangesByRow(null, row, Operation.Update, this.Data.HasErrors, this.Data.HasChanges(), false); if (!this.Data.HasChanges()) @@ -1748,7 +1748,7 @@ private static void UpdateRowValue(string property, object newValue, DataRow row } } - public virtual ArrayList DeleteObject(string entity, object id) + public virtual List DeleteObject(string entity, object id) { lock(_lock) { @@ -1757,7 +1757,7 @@ public virtual ArrayList DeleteObject(string entity, object id) DataSet dataset = row.Table.DataSet; // get the changes for the deleted row before we actually deleted, because then the row would be inaccessible - ArrayList deletedItems = new ArrayList(); + var deletedItems = new List(); Dictionary> backup = BackupDeletedRows(row); object[] listRowBackup = null; @@ -1800,7 +1800,7 @@ public virtual ArrayList DeleteObject(string entity, object id) // handle rules for the data changes after the row has been deleted this.RuleHandler.OnRowDeleted((DataRow[])parentRows.ToArray(typeof(DataRow)), row, this.XmlData, this.RuleSet, this.RuleEngine); - ArrayList listOfChanges = new ArrayList(); + var listOfChanges = new List(); // get the changes - from root - e.g. recalculated totals after deletion @@ -1831,7 +1831,8 @@ public virtual ArrayList DeleteObject(string entity, object id) table.AcceptChanges(); } // save the data - listOfChanges.AddRange((IList)this.ExecuteAction(SessionStore.ACTION_SAVE)); + var actionResult = ((IList)ExecuteAction(ACTION_SAVE)).ToList(); + listOfChanges.AddRange(actionResult); } return listOfChanges; } @@ -1947,7 +1948,7 @@ private static void BackupChildRows(DataRow parentRow, Dictionary CopyObject(string entity, object originalId, string requestingGrid, ArrayList entities, IDictionary forcedValues) { @@ -2145,7 +2146,7 @@ public virtual ChangeInfo GetRow(string entity, object id) } #endregion - private void AddChildDeletedItems(ArrayList deletedItems, DataRow deletedRow) + private void AddChildDeletedItems(List deletedItems, DataRow deletedRow) { foreach (DataRelation child in deletedRow.Table.ChildRelations) { @@ -2160,9 +2161,9 @@ private void AddChildDeletedItems(ArrayList deletedItems, DataRow deletedRow) #endregion - public ArrayList UpdateObjectBatch(string entity, string property, Hashtable values) + public List UpdateObjectBatch(string entity, string property, Hashtable values) { - ArrayList result = new ArrayList(); + var result = new List(); lock (_lock) { @@ -2175,9 +2176,9 @@ public ArrayList UpdateObjectBatch(string entity, string property, Hashtable val return result; } - public ArrayList UpdateObjectEx(string entity, object id, Hashtable values) + public List UpdateObjectEx(string entity, object id, Hashtable values) { - ArrayList result = new ArrayList(); + var result = new List(); lock (_lock) { @@ -2189,9 +2190,9 @@ public ArrayList UpdateObjectEx(string entity, object id, Hashtable values) return result; } - public ArrayList UpdateObjectBatch(string entity, UpdateData[] updateDataArray) + public List UpdateObjectBatch(string entity, UpdateData[] updateDataArray) { - ArrayList result = new ArrayList(); + var result = new List(); lock (_lock) {