Skip to content

Commit

Permalink
Merge pull request finos#441 in WALTZ/waltz-gh-staging from WALTZ/wal…
Browse files Browse the repository at this point in the history
…tz-ma:CTCTOWALTZ-1850_audit_enhancement_measurable to waltz-4969_audit_logs_to_add_remove_measurable

* commit 'c3593bbe9c1055333c82272e45ff16631f219aeb':
  CTCTOWALTZ-1853 CTCTOWALTZ-1852 /CTCTOWALTZ-1850 add changelog message in the following actions of editing measurable 1. A peer is added 2. A child is created 3. A peer/child is removed
  CTCTOWALTZ-1853 CTCTOWALTZ-1852 /CTCTOWALTZ-1850 add changelog message in the following actions of editing measurable 1. A peer is added 2. A child is created 3. A peer/child is removed
  • Loading branch information
MarkGuerriero committed Jul 3, 2020
2 parents 4063805 + c3593bb commit 8f60569
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ private <T> boolean updateField(long id, Field<T> field, T value, String userId)
}


public boolean create(Measurable measurable) {
int rc = dsl.insertInto(MEASURABLE)
public Long create(Measurable measurable) {
return dsl.insertInto(MEASURABLE)
.set(MEASURABLE.MEASURABLE_CATEGORY_ID, measurable.categoryId())
.set(MEASURABLE.PARENT_ID, measurable.parentId().orElse(null))
.set(MEASURABLE.EXTERNAL_ID, measurable.externalId().orElse(null))
Expand All @@ -172,9 +172,9 @@ public boolean create(Measurable measurable) {
.set(MEASURABLE.PROVENANCE, "waltz")
.set(MEASURABLE.LAST_UPDATED_BY, measurable.lastUpdatedBy())
.set(MEASURABLE.LAST_UPDATED_AT, Timestamp.valueOf(measurable.lastUpdatedAt()))
.execute();

return rc == 1;
.returning(MEASURABLE.ID)
.fetchOne()
.getId();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ public boolean updateExternalId(long id, String newValue, String userId) {


public boolean create(Measurable measurable, String userId) {
return measurableDao.create(measurable);
Long measurableId = measurableDao.create(measurable);
writeAuditMessage(measurableId, userId, String.format("created new measurable %s", measurable.name()));
return measurableId > 1;
}


Expand Down Expand Up @@ -211,7 +213,7 @@ private String resolveName(long id) {
}


private void writeAuditMessage(Long measurableId, String userId, String msg) {
public void writeAuditMessage(Long measurableId, String userId, String msg) {
changeLogService.write(ImmutableChangeLog.builder()
.severity(Severity.INFORMATION)
.userId(userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -199,8 +200,7 @@ private void previewChildNodeRemovals(ImmutableTaxonomyChangePreview.Builder pre

public TaxonomyChangeCommand apply(TaxonomyChangeCommand cmd, String userId) {
doBasicValidation(cmd);
validatePrimaryMeasurable(measurableService, cmd);

Measurable measurable = validatePrimaryMeasurable(measurableService, cmd);

IdSelectionOptions selectionOptions = mkOpts(cmd.primaryReference(), HierarchyQueryScope.CHILDREN);

Expand All @@ -210,6 +210,12 @@ public TaxonomyChangeCommand apply(TaxonomyChangeCommand cmd, String userId) {
removeMeasurables(selectionOptions);
removeFlowDiagrams(selectionOptions);
removeEntityRelationshipsDiagrams(selectionOptions);

String message = String.format("Measurable %s has been removed", measurable.name());
Optional<Long> measurableId = measurable.parentId().isPresent()
? measurable.parentId()
: measurable.id();
measurableId.ifPresent(id -> measurableService.writeAuditMessage(id, userId, message));

// TODO: entitySvgDiagrams, roadmapScenarios

Expand Down

0 comments on commit 8f60569

Please sign in to comment.