use of org.finos.waltz.model.attribute_change.AttributeChange in project waltz by khartec.
the class ModifyCommandProcessor method modifyPhysicalFlow.
private CommandResponse<UpdateExecutionStatusCommand> modifyPhysicalFlow(UpdateExecutionStatusCommand command, ChangeUnit changeUnit, String userName) {
doBasicValidation(command, changeUnit, userName);
PhysicalFlow subject = physicalFlowService.getById(changeUnit.subjectEntity().id());
checkNotNull(subject, "subject not found: " + changeUnit.subjectEntity());
checkTrue(subject.entityLifecycleStatus().equals(changeUnit.subjectInitialStatus()), "current subject status does not match initial change unit status: " + subject);
// fetch attribute changes
List<AttributeChange> attributeChanges = attributeChangeService.findByChangeUnitId(changeUnit.id().get());
boolean success = attributeChanges.stream().map(a -> processAttributeChange(a, changeUnit, userName)).allMatch(a -> a == true);
return ImmutableCommandResponse.<UpdateExecutionStatusCommand>builder().entityReference(subject.entityReference()).originalCommand(command).outcome(success ? CommandOutcome.SUCCESS : CommandOutcome.FAILURE).message("Modified physical flow: " + subject + " attributes").build();
}
use of org.finos.waltz.model.attribute_change.AttributeChange in project waltz by khartec.
the class DataTypeChangeCommandProcessor method apply.
@Override
public boolean apply(AttributeChange attributeChange, ChangeUnit changeUnit, String userName) {
doBasicValidation(attributeChange, changeUnit, userName);
checkTrue(changeUnit.subjectEntity().kind() == EntityKind.PHYSICAL_FLOW, "Change Subject should be a Physical Flow");
// get physical flow
PhysicalFlow physicalFlow = physicalFlowService.getById(changeUnit.subjectEntity().id());
// update the specs data types
Set<Long> oldValues = readValue(attributeChange.oldValue());
Set<Long> newValues = readValue(attributeChange.newValue());
EntityReference specificationEntityRef = EntityReference.mkRef(EntityKind.PHYSICAL_SPECIFICATION, physicalFlow.specificationId());
Set<Long> existing = dataTypeDecoratorService.findByEntityId(specificationEntityRef).stream().map(a -> a.dataTypeId()).collect(toSet());
Set<Long> toAdd = minus(newValues, oldValues, existing);
Set<Long> toRemove = minus(oldValues, newValues);
int removedCount = dataTypeDecoratorService.removeDataTypeDecorator(userName, specificationEntityRef, toRemove);
int[] addedCount = dataTypeDecoratorService.addDecorators(userName, specificationEntityRef, toAdd);
return removedCount == toRemove.size() && addedCount.length == toAdd.size();
}
Aggregations