Search in sources :

Example 1 with AttributeChange

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();
}
Also used : CommandResponse(org.finos.waltz.model.command.CommandResponse) ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) CommandOutcome(org.finos.waltz.model.command.CommandOutcome) AttributeChangeCommandProcessor(org.finos.waltz.service.change_unit.AttributeChangeCommandProcessor) Autowired(org.springframework.beans.factory.annotation.Autowired) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ChangeUnitCommandProcessor(org.finos.waltz.service.change_unit.ChangeUnitCommandProcessor) Collectors.toMap(java.util.stream.Collectors.toMap) ImmutableCommandResponse(org.finos.waltz.model.command.ImmutableCommandResponse) AttributeChange(org.finos.waltz.model.attribute_change.AttributeChange) UpdateExecutionStatusCommand(org.finos.waltz.model.change_unit.UpdateExecutionStatusCommand) Service(org.springframework.stereotype.Service) ChangeAction(org.finos.waltz.model.change_unit.ChangeAction) Map(java.util.Map) AttributeChangeService(org.finos.waltz.service.attribute_change.AttributeChangeService) AttributeChange(org.finos.waltz.model.attribute_change.AttributeChange) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow)

Example 2 with AttributeChange

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();
}
Also used : ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) AttributeChangeCommandProcessor(org.finos.waltz.service.change_unit.AttributeChangeCommandProcessor) EntityKind(org.finos.waltz.model.EntityKind) SetUtilities.minus(org.finos.waltz.common.SetUtilities.minus) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) DataTypeDecoratorService(org.finos.waltz.service.data_type.DataTypeDecoratorService) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) AttributeChange(org.finos.waltz.model.attribute_change.AttributeChange) Service(org.springframework.stereotype.Service) SetUtilities(org.finos.waltz.common.SetUtilities) EntityReference(org.finos.waltz.model.EntityReference) Collectors.toSet(java.util.stream.Collectors.toSet) EntityReference(org.finos.waltz.model.EntityReference) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow)

Aggregations

List (java.util.List)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)2 Checks.checkTrue (org.finos.waltz.common.Checks.checkTrue)2 AttributeChange (org.finos.waltz.model.attribute_change.AttributeChange)2 ChangeUnit (org.finos.waltz.model.change_unit.ChangeUnit)2 PhysicalFlow (org.finos.waltz.model.physical_flow.PhysicalFlow)2 AttributeChangeCommandProcessor (org.finos.waltz.service.change_unit.AttributeChangeCommandProcessor)2 PhysicalFlowService (org.finos.waltz.service.physical_flow.PhysicalFlowService)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 SetUtilities (org.finos.waltz.common.SetUtilities)1 SetUtilities.minus (org.finos.waltz.common.SetUtilities.minus)1 EntityKind (org.finos.waltz.model.EntityKind)1