use of org.finos.waltz.model.physical_flow.PhysicalFlow 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());
}
use of org.finos.waltz.model.physical_flow.PhysicalFlow in project waltz by khartec.
the class ActivateCommandProcessor method activatePhysicalFlow.
private ImmutableCommandResponse<UpdateExecutionStatusCommand> activatePhysicalFlow(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 initial change unit status: " + subject);
SetAttributeCommand setAttributeCommand = ImmutableSetAttributeCommand.builder().entityReference(subject.entityReference()).name("entity_lifecycle_status").value(EntityLifecycleStatus.ACTIVE.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.ACTIVE).build();
}
use of org.finos.waltz.model.physical_flow.PhysicalFlow 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.physical_flow.PhysicalFlow 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;
}
use of org.finos.waltz.model.physical_flow.PhysicalFlow in project waltz by khartec.
the class PhysicalFlowParticipantService method writeToAuditLog.
// --- helpers ---
private void writeToAuditLog(String verb, long physicalFlowId, EntityReference participant, String username) {
nameResolver.resolve(participant).ifPresent(p -> {
String msg = format("%s participant: [%s] to physical flow", verb, p.name().orElse("?"));
auditChange(msg, EntityReference.mkRef(PHYSICAL_FLOW, physicalFlowId), username, Operation.ADD);
});
PhysicalFlow physicalFlow = physicalFlowService.getById(physicalFlowId);
if (physicalFlow != null) {
LogicalFlow logicalFlow = logicalFlowService.getById(physicalFlow.logicalFlowId());
PhysicalSpecification specification = physicalSpecificationService.getById(physicalFlow.specificationId());
if (logicalFlow != null && specification != null) {
auditChange(format("%s as a participant to flow: (%s) -[%s]-> (%s)", verb, logicalFlow.source().name().orElse("?"), specification.name(), logicalFlow.target().name().orElse("?")), participant, username, Operation.ADD);
}
}
}
Aggregations