public async Task <NodeEntry> UpdateComponent([FromRoute] ComponentUpdate nodeBody, [FromQuery] IncludeFieldsQueryParams queryParams) { var nodeEntryBeforeUpdate = await _alfrescoHttpClient.GetNodeInfo(nodeBody.ComponentId); var nodeEntryAfterUpdate = await _nodesService.ComponentUpdate(nodeBody, ImmutableList <Parameter> .Empty.AddQueryParams(queryParams)); try { var documentEntry = await _alfrescoHttpClient.GetNodeInfo(nodeBody?.NodeId); var difference = _alfrescoModelComparer.CompareProperties( nodeEntryBeforeUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), nodeEntryAfterUpdate?.Entry?.Properties?.As <JObject>().ToDictionary()); try { var componentsJson = difference.FirstOrDefault(x => x.Key == SpisumNames.Properties.ComponentVersionJSON); if (componentsJson != null) { difference.Remove(componentsJson); } } catch { } string messageDocument = TransactinoHistoryMessages.GetMessagePropertiesChange(TransactinoHistoryMessages.DocumentComponentUpdateDocument, difference); string messageFile = TransactinoHistoryMessages.GetMessagePropertiesChange(TransactinoHistoryMessages.DocumentComponentUpdateFile, difference); await _auditLogService.Record( documentEntry?.Entry?.Id, SpisumNames.NodeTypes.Component, nodeEntryBeforeUpdate?.GetPid(), NodeTypeCodes.Komponenta, EventCodes.Uprava, nodeEntryBeforeUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), nodeEntryAfterUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), messageDocument); var fileId = await _documentService.GetDocumentFileId(documentEntry?.Entry?.Id); if (fileId != null) { await _auditLogService.Record( fileId, SpisumNames.NodeTypes.Component, nodeEntryBeforeUpdate?.GetPid(), NodeTypeCodes.Komponenta, EventCodes.Uprava, nodeEntryBeforeUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), nodeEntryAfterUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), messageFile); } } catch (Exception ex) { Log.Logger?.Error(ex, "Audit log failed"); } return(nodeEntryAfterUpdate); }
public void CompareProperties_WhenIsCalled_ReturnNestedProperties() { var obj1 = AlfrescoComparerModels.NestedProperties1(); var obj2 = AlfrescoComparerModels.NestedProperties2(); var result = _alfrescoModelComparer.CompareProperties(obj1, obj2); Assert.That(result, Has.Exactly(4).Items); Assert.That(result, Has.Exactly(1).Matches <ObjectDifference>(x => x.Operation == Operations.New)); Assert.That(result, Has.Exactly(2).Matches <ObjectDifference>(x => x.Operation == Operations.Edit)); Assert.That(result, Has.Exactly(1).Matches <ObjectDifference>(x => x.Operation == Operations.Deleted)); Assert.That(result, Has.Exactly(1).Matches <ObjectDifference>(x => x.Key == "ssl:newValue" && x.OldValue == null && x.NewValue.ToString() == "new")); Assert.That(result, Has.Exactly(1).Matches <ObjectDifference>(x => x.Key == "ssl:deletedValue" && x.OldValue.ToString() == "delete" && x.NewValue == null)); Assert.That(result, Has.Exactly(1).Matches <ObjectDifference>(x => x.Key == "ssl:customBool" && Convert.ToBoolean(x.OldValue) && Convert.ToBoolean(x.NewValue) == false)); Assert.That(result, Has.Exactly(1).Matches <ObjectDifference>(x => x.Key == "ssl:nestedValue.displayName" && x.OldValue.ToString() == "martin" && x.NewValue.ToString() == "karel")); }
public async Task Record(string nodeId, string nodeType, string pid, string nodeTypeCode, string eventType, Dictionary <string, object> a, Dictionary <string, object> b, string message = null) { var difference = _alfrescoModelComparer.CompareProperties(a, b); if (!string.IsNullOrWhiteSpace(message)) { await difference.ForEachAsync(async x => { var translation = await _translateService.Translate(x.Key, nodeType, "title"); if (translation != null) { message = message.Replace(x.Key, translation); } // CodeList translation var translationCodeListOldValue = await _translateService.Translate(x.Key, "codelist", x.OldValue?.ToString()); var translationCodeListNewValue = await _translateService.Translate(x.Key, "codelist", x.NewValue?.ToString()); if (translationCodeListOldValue != null) { message = message.Replace(x.OldValue?.ToString(), translationCodeListOldValue); } if (translationCodeListNewValue != null) { message = message.Replace(x.NewValue?.ToString(), translationCodeListNewValue); } }); } await LocalRecord(nodeId, nodeType, pid, nodeTypeCode, eventType, JsonConvert.SerializeObject( difference.Any() ? message != null ? new TransactionHistoryParameters(message, difference) : new TransactionHistoryParameters(difference) : message != null ? new TransactionHistoryParameters(message): null, _jsonSettings)); }