Search in sources :

Example 1 with ChangeUnit

use of org.finos.waltz.model.change_unit.ChangeUnit in project waltz by khartec.

the class ChangeUnitViewService method findPhysicalFlowChangeUnitsByChangeSetId.

public Set<PhysicalFlowChangeUnitViewItem> findPhysicalFlowChangeUnitsByChangeSetId(long changeSetId) {
    IdSelectionOptions idSelectionOptions = mkOptsForAllLifecycleStates(mkRef(EntityKind.CHANGE_SET, changeSetId), HierarchyQueryScope.EXACT);
    Collection<PhysicalFlow> physicalFlows = physicalFlowService.findBySelector(idSelectionOptions);
    Collection<PhysicalSpecification> physicalSpecs = physicalSpecificationService.findByIds(map(physicalFlows, PhysicalFlow::specificationId));
    // TODO: Move to a logical flow selector based upon change set #5626
    Collection<LogicalFlow> logicalFlows = logicalFlowService.findAllByFlowIds(map(physicalFlows, PhysicalFlow::logicalFlowId));
    List<AssessmentRating> assessmentRatings = assessmentRatingService.findByTargetKindForRelatedSelector(EntityKind.CHANGE_UNIT, idSelectionOptions);
    Map<Long, RatingSchemeItem> ratingSchemeItemsById = indexBy(ratingSchemeService.getAllRatingSchemeItems(), item -> item.id().get());
    Map<Long, PhysicalFlow> physicalFlowsById = indexBy(physicalFlows, flow -> flow.id().get());
    Map<Long, LogicalFlow> logicalFlowsById = indexBy(logicalFlows, flow -> flow.id().get());
    Map<Long, PhysicalSpecification> specsById = indexBy(physicalSpecs, spec -> spec.id().get());
    Map<Long, Collection<AssessmentRating>> assessmentRatingsByEntityId = groupBy(rating -> rating.entityReference().id(), assessmentRatings);
    List<ChangeUnit> changeUnits = changeUnitService.findByChangeSetId(changeSetId);
    return changeUnits.stream().filter(cu -> cu.subjectEntity().kind().equals(EntityKind.PHYSICAL_FLOW)).map(cu -> {
        PhysicalFlow physicalFlow = physicalFlowsById.get(cu.subjectEntity().id());
        PhysicalSpecification spec = specsById.get(physicalFlow.specificationId());
        LogicalFlow logicalFlow = logicalFlowsById.get(physicalFlow.logicalFlowId());
        Long changeUnitId = cu.id().get();
        Collection<AssessmentRating> assessmentRatingsForChangeUnit = assessmentRatingsByEntityId.getOrDefault(changeUnitId, emptySet());
        Set<AssessmentRatingDetail> assessmentRatingDetailForChangeUnit = map(assessmentRatingsForChangeUnit, rating -> mkAssessmentDefinitionDetail(rating, ratingSchemeItemsById.get(rating.ratingId())));
        return ImmutablePhysicalFlowChangeUnitViewItem.builder().changeUnit(cu).physicalSpecification(spec).logicalFlow(logicalFlow).assessments(assessmentRatingDetailForChangeUnit).build();
    }).collect(toSet());
}
Also used : ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) PhysicalFlowChangeUnitViewItem(org.finos.waltz.model.change_unit.PhysicalFlowChangeUnitViewItem) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Autowired(org.springframework.beans.factory.annotation.Autowired) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) AssessmentRatingDetail(org.finos.waltz.model.assessment_rating.AssessmentRatingDetail) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) ImmutablePhysicalFlowChangeUnitViewItem(org.finos.waltz.model.change_unit.ImmutablePhysicalFlowChangeUnitViewItem) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) Service(org.springframework.stereotype.Service) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Map(java.util.Map) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) Collectors.toSet(java.util.stream.Collectors.toSet) IdSelectionOptions.mkOptsForAllLifecycleStates(org.finos.waltz.model.IdSelectionOptions.mkOptsForAllLifecycleStates) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) Collection(java.util.Collection) Set(java.util.Set) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) AssessmentRatingService(org.finos.waltz.service.assessment_rating.AssessmentRatingService) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) ImmutableAssessmentRatingDetail(org.finos.waltz.model.assessment_rating.ImmutableAssessmentRatingDetail) HierarchyQueryScope(org.finos.waltz.model.HierarchyQueryScope) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) Collectors.toSet(java.util.stream.Collectors.toSet) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Collection(java.util.Collection) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 2 with ChangeUnit

use of org.finos.waltz.model.change_unit.ChangeUnit 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 3 with ChangeUnit

use of org.finos.waltz.model.change_unit.ChangeUnit in project waltz by khartec.

the class ChangeUnitGenerator method mkAttributeChanges.

private List<AttributeChangeRecord> mkAttributeChanges(DSLContext dsl, List<PhysicalFlow> physicalFlows) {
    List<ChangeUnit> modifyCUs = dsl.selectFrom(CHANGE_UNIT).where(CHANGE_UNIT.ACTION.eq(ChangeAction.MODIFY.name())).fetch(ChangeUnitDao.TO_DOMAIN_MAPPER);
    List<String> attributes = ListUtilities.asList("criticality", "frequency", "DataType");
    Map<Long, PhysicalFlow> flowsById = MapUtilities.indexBy(f -> f.id().get(), physicalFlows);
    List<AttributeChangeRecord> attributeChanges = modifyCUs.stream().flatMap(cu -> randomlySizedIntStream(1, 2).mapToObj(idx -> randomPick(attributes)).map(attribute -> {
        PhysicalFlow flow = flowsById.get(cu.subjectEntity().id());
        switch(attribute) {
            case "criticality":
                return mkCriticalityChange(dsl, cu, flow, attribute);
            case "frequency":
                return mkFrequencyChange(dsl, cu, flow, attribute);
            case "DataType":
                return mkDataTypeChange(dsl, cu, flow, attribute);
            default:
                throw new UnsupportedOperationException("Attribute change not supported: " + attribute);
        }
    })).collect(toList());
    return attributeChanges;
}
Also used : ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) ChangeUnitRecord(org.finos.waltz.schema.tables.records.ChangeUnitRecord) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) LocalDateTime(java.time.LocalDateTime) PhysicalFlowDao(org.finos.waltz.data.physical_flow.PhysicalFlowDao) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) DataType(org.finos.waltz.model.datatype.DataType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) StringUtilities.joinUsing(org.finos.waltz.common.StringUtilities.joinUsing) CHANGE_SET(org.finos.waltz.schema.tables.ChangeSet.CHANGE_SET) DSLContext(org.jooq.DSLContext) ChangeUnitDao(org.finos.waltz.data.change_unit.ChangeUnitDao) AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord) StringUtilities(org.finos.waltz.common.StringUtilities) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) MapUtilities(org.finos.waltz.common.MapUtilities) Criticality(org.finos.waltz.model.Criticality) Timestamp(java.sql.Timestamp) ExecutionStatus(org.finos.waltz.model.change_unit.ExecutionStatus) CHANGE_UNIT(org.finos.waltz.schema.tables.ChangeUnit.CHANGE_UNIT) ApplicationContext(org.springframework.context.ApplicationContext) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FrequencyKind(org.finos.waltz.model.physical_flow.FrequencyKind) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) ListUtilities(org.finos.waltz.common.ListUtilities) ChangeAction(org.finos.waltz.model.change_unit.ChangeAction) DataTypeDao(org.finos.waltz.data.data_type.DataTypeDao) AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord) ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow)

Example 4 with ChangeUnit

use of org.finos.waltz.model.change_unit.ChangeUnit 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)4 ChangeUnit (org.finos.waltz.model.change_unit.ChangeUnit)4 PhysicalFlow (org.finos.waltz.model.physical_flow.PhysicalFlow)4 Map (java.util.Map)3 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)3 EntityKind (org.finos.waltz.model.EntityKind)3 Set (java.util.Set)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 Checks.checkTrue (org.finos.waltz.common.Checks.checkTrue)2 AttributeChange (org.finos.waltz.model.attribute_change.AttributeChange)2 ChangeAction (org.finos.waltz.model.change_unit.ChangeAction)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 Timestamp (java.sql.Timestamp)1 LocalDateTime (java.time.LocalDateTime)1 Collection (java.util.Collection)1 Collections.emptySet (java.util.Collections.emptySet)1