Search in sources :

Example 11 with PhysicalFlow

use of org.finos.waltz.model.physical_flow.PhysicalFlow 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)

Example 12 with PhysicalFlow

use of org.finos.waltz.model.physical_flow.PhysicalFlow in project waltz by khartec.

the class RetireCommandProcessor method retirePhysicalFlow.

private ImmutableCommandResponse<UpdateExecutionStatusCommand> retirePhysicalFlow(UpdateExecutionStatusCommand command, ChangeUnit changeUnit, String 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);
    SetAttributeCommand setAttributeCommand = ImmutableSetAttributeCommand.builder().entityReference(subject.entityReference()).name("entity_lifecycle_status").value(EntityLifecycleStatus.REMOVED.name()).build();
    int i = physicalFlowService.updateAttribute(userName, setAttributeCommand);
    return ImmutableCommandResponse.<UpdateExecutionStatusCommand>builder().entityReference(subject.entityReference()).originalCommand(command).outcome(i == 1 ? CommandOutcome.SUCCESS : CommandOutcome.FAILURE).message("Updated status of physical flow: " + subject + " to " + EntityLifecycleStatus.REMOVED).build();
}
Also used : SetAttributeCommand(org.finos.waltz.model.SetAttributeCommand) ImmutableSetAttributeCommand(org.finos.waltz.model.ImmutableSetAttributeCommand) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow)

Aggregations

PhysicalFlow (org.finos.waltz.model.physical_flow.PhysicalFlow)12 List (java.util.List)5 ChangeUnit (org.finos.waltz.model.change_unit.ChangeUnit)5 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)5 Map (java.util.Map)4 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)4 EntityKind (org.finos.waltz.model.EntityKind)4 PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)4 Collectors.toList (java.util.stream.Collectors.toList)3 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)3 ListUtilities (org.finos.waltz.common.ListUtilities)3 RandomUtilities (org.finos.waltz.common.RandomUtilities)3 PhysicalFlowDao (org.finos.waltz.data.physical_flow.PhysicalFlowDao)3 ChangeAction (org.finos.waltz.model.change_unit.ChangeAction)3 DataType (org.finos.waltz.model.datatype.DataType)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 Timestamp (java.sql.Timestamp)2 LocalDateTime (java.time.LocalDateTime)2 Set (java.util.Set)2