Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: UpdateObject duplicate changes 2022 4 #1860

Merged
merged 3 commits into from Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 28 additions & 21 deletions backend/Origam.Server/Common/ChangeInfo.cs
Expand Up @@ -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<http://www.gnu.org/licenses/>.
*/
#endregion

using System;
using Origam.Rule;

namespace Origam.Server
Expand Down Expand Up @@ -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() != GetType())
{
return false;
}
return Equals((ChangeInfo)obj);
}

public override int GetHashCode()
{
return HashCode.Combine(entity, (int)operation, objectId);
}
}
}
3 changes: 2 additions & 1 deletion backend/Origam.Server/Controller/SessionController.cs
Expand Up @@ -21,6 +21,7 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Threading;
Expand Down Expand Up @@ -172,7 +173,7 @@ public IActionResult UpdateRow([FromBody]UpdateRowData updateData)
return RunWithErrorHandler(() =>
{
SessionStore ss = sessionObjects.SessionManager.GetSession(updateData.SessionFormIdentifier);
IList output = ss.UpdateObject(
IEnumerable<ChangeInfo> output = ss.UpdateObject(
entity: updateData.Entity,
id: updateData.Id,
property: updateData.Property,
Expand Down
4 changes: 2 additions & 2 deletions backend/Origam.Server/ServerCoreUIService.cs
Expand Up @@ -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<ChangeInfo> 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,
Expand Down Expand Up @@ -927,7 +927,7 @@ public ArrayList GetPendingChanges(Guid sessionFormIdentifier)
sessionStore.PendingChanges = null;
return changes ?? new ArrayList();
}
public ArrayList GetChanges(ChangesInput input)
public List<ChangeInfo> GetChanges(ChangesInput input)
{
var sessionStore = sessionManager.GetSession(
input.SessionFormIdentifier);
Expand Down
16 changes: 8 additions & 8 deletions backend/Origam.Server/Session Stores/SaveableSessionStore.cs
Expand Up @@ -197,7 +197,7 @@ internal virtual object Save()
return listOfChanges;
}

public override ArrayList CreateObject(string entity, IDictionary<string, object> values,
public override List<ChangeInfo> CreateObject(string entity, IDictionary<string, object> values,
IDictionary<string, object> parameters, string requestingGrid)
{
if (this.Template == null || !this.Template.Entity.Name.Equals(entity))
Expand Down Expand Up @@ -225,17 +225,17 @@ internal virtual object Save()

DataRow newRow = table.Rows.Find(key);
NewRowToDataList(newRow);
ArrayList listOfChanges = GetChangesByRow(requestingGrid,
List<ChangeInfo> listOfChanges = GetChangesByRow(requestingGrid,
newRow, Operation.Create, this.Data.HasErrors,
this.Data.HasChanges(), true);

return listOfChanges;
}
}

public override ArrayList UpdateObject(string entity, object id, string property, object newValue)
public override IEnumerable<ChangeInfo> UpdateObject(string entity, object id, string property, object newValue)
{
ArrayList result = new ArrayList();
var result = new HashSet<ChangeInfo>();
InitializeFieldDependencies();
DataTable table = GetTable(entity, this.Data);
Guid dsEntityId = (Guid)table.ExtendedProperties["Id"];
Expand All @@ -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<ChangeInfo> changes;
try
{
changes = this.UpdateObject(entity, id, dependentColumnName, null);
Expand All @@ -260,16 +260,16 @@ 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);
}
}
}
}

IList baseChanges = base.UpdateObject(entity, id, property, newValue);
foreach (object o in baseChanges)
IEnumerable<ChangeInfo> baseChanges = base.UpdateObject(entity, id, property, newValue);
foreach (var o in baseChanges)
{
result.Add(o);
}
Expand Down
45 changes: 23 additions & 22 deletions backend/Origam.Server/Session Stores/SessionStore.cs
Expand Up @@ -827,20 +827,20 @@ private static bool IsInColumns(DataColumn searchedColumn, DataColumn[] columns)
return false;
}

public ArrayList GetChangesByRow(
public List<ChangeInfo> GetChangesByRow(
string requestingGrid, DataRow row, Operation operation,
bool hasErrors, bool hasChanges, bool fromTemplate)
{
return GetChangesByRow(requestingGrid, row, operation, null, true,
hasErrors, hasChanges, fromTemplate);
}

internal ArrayList GetChangesByRow(
internal List<ChangeInfo> 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<ChangeInfo>();
DataRow rootRow = DatasetTools.RootRow(row);
DatasetTools.CheckRowErrorRecursive(rootRow, null, false);

Expand Down Expand Up @@ -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<ChangeInfo> 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<ChangeInfo> 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<ChangeInfo> changes, string requestingGrid, DataRow row, Operation operation, DataRow changedRow, bool allDetails, Hashtable ignoreKeys, bool includeRowStates)
{
if (row.RowState != DataRowState.Deleted && row.RowState != DataRowState.Detached)
{
Expand Down Expand Up @@ -1488,7 +1488,7 @@ public bool IsLazyLoadedEntity(string entity)
}

#region CUD
public virtual ArrayList CreateObject(string entity, IDictionary<string, object> values,
public virtual List<ChangeInfo> CreateObject(string entity, IDictionary<string, object> values,
IDictionary<string, object> parameters, string requestingGrid)
{
lock (_lock)
Expand Down Expand Up @@ -1585,15 +1585,15 @@ public bool IsLazyLoadedEntity(string entity)

NewRowToDataList(newRow);

ArrayList listOfChanges = GetChangesByRow(requestingGrid,
List<ChangeInfo> listOfChanges = GetChangesByRow(requestingGrid,
newRow, Operation.Create, this.Data.HasErrors,
this.Data.HasChanges(), false);

return listOfChanges;
}
}

public virtual ArrayList UpdateObject(string entity, object id, string property, object newValue)
public virtual IEnumerable<ChangeInfo> UpdateObject(string entity, object id, string property, object newValue)
{
lock (_lock)
{
Expand All @@ -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<ChangeInfo> listOfChanges = GetChangesByRow(null, row,
Operation.Update, this.Data.HasErrors,
this.Data.HasChanges(), false);
if (!this.Data.HasChanges())
Expand Down Expand Up @@ -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<ChangeInfo> DeleteObject(string entity, object id)
{
lock(_lock)
{
Expand All @@ -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<ChangeInfo>();
Dictionary<string, List<DeletedRowInfo>> backup = BackupDeletedRows(row);
object[] listRowBackup = null;

Expand Down Expand Up @@ -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<ChangeInfo>();


// get the changes - from root - e.g. recalculated totals after deletion
Expand Down Expand Up @@ -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<ChangeInfo>();
listOfChanges.AddRange(actionResult);
}
return listOfChanges;
}
Expand Down Expand Up @@ -1947,7 +1948,7 @@ private static void BackupChildRows(DataRow parentRow, Dictionary<string, List<D
}
}

public ArrayList CopyObject(string entity, object originalId,
public List<ChangeInfo> CopyObject(string entity, object originalId,
string requestingGrid, ArrayList entities,
IDictionary<string, object> forcedValues)
{
Expand Down Expand Up @@ -2145,7 +2146,7 @@ public virtual ChangeInfo GetRow(string entity, object id)
}
#endregion

private void AddChildDeletedItems(ArrayList deletedItems, DataRow deletedRow)
private void AddChildDeletedItems(List<ChangeInfo> deletedItems, DataRow deletedRow)
{
foreach (DataRelation child in deletedRow.Table.ChildRelations)
{
Expand All @@ -2160,9 +2161,9 @@ private void AddChildDeletedItems(ArrayList deletedItems, DataRow deletedRow)

#endregion

public ArrayList UpdateObjectBatch(string entity, string property, Hashtable values)
public List<ChangeInfo> UpdateObjectBatch(string entity, string property, Hashtable values)
{
ArrayList result = new ArrayList();
var result = new List<ChangeInfo>();

lock (_lock)
{
Expand All @@ -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<ChangeInfo> UpdateObjectEx(string entity, object id, Hashtable values)
{
ArrayList result = new ArrayList();
var result = new List<ChangeInfo>();

lock (_lock)
{
Expand All @@ -2189,9 +2190,9 @@ public ArrayList UpdateObjectEx(string entity, object id, Hashtable values)

return result;
}
public ArrayList UpdateObjectBatch(string entity, UpdateData[] updateDataArray)
public List<ChangeInfo> UpdateObjectBatch(string entity, UpdateData[] updateDataArray)
{
ArrayList result = new ArrayList();
var result = new List<ChangeInfo>();

lock (_lock)
{
Expand Down