use of com.khartec.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowHarness method main.
public static void main(String[] args) throws ParseException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
LogicalFlowDao dao = ctx.getBean(LogicalFlowDao.class);
ApplicationIdSelectorFactory factory = ctx.getBean(ApplicationIdSelectorFactory.class);
IdSelectionOptions options = IdSelectionOptions.mkOpts(mkRef(EntityKind.ORG_UNIT, 20), HierarchyQueryScope.CHILDREN);
LogicalFlow app2appFlow = dao.findByFlowId(28940);
LogicalFlow app2actorFlow = dao.findByFlowId(28941);
System.out.println("-- App 2 App");
System.out.println(app2appFlow);
System.out.println("-- App 2 Actor");
System.out.println(app2actorFlow);
List<LogicalFlow> flows = dao.findByEntityReference(mkRef(EntityKind.APPLICATION, 22406));
System.out.println("-- flows");
flows.forEach(System.out::println);
}
use of com.khartec.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowService method create.
public PhysicalFlowCreateCommandResponse create(PhysicalFlowCreateCommand command, String username) {
checkNotNull(command, "command cannot be null");
checkNotNull(username, "username cannot be null");
// check we have a logical data flow
LogicalFlow logicalFlow = ensureLogicalDataFlowExists(command.logicalFlowId(), username);
long specId = command.specification().id().orElseGet(() -> physicalSpecificationDao.create(ImmutablePhysicalSpecification.copyOf(command.specification()).withLastUpdatedBy(username).withLastUpdatedAt(nowUtc())));
PhysicalFlow flow = ImmutablePhysicalFlow.builder().specificationId(specId).basisOffset(command.flowAttributes().basisOffset()).frequency(command.flowAttributes().frequency()).transport(command.flowAttributes().transport()).criticality(command.flowAttributes().criticality()).description(mkSafe(command.flowAttributes().description())).logicalFlowId(command.logicalFlowId()).lastUpdatedBy(username).lastUpdatedAt(nowUtc()).build();
// ensure existing not in database
List<PhysicalFlow> byAttributesAndSpecification = physicalFlowDao.findByAttributesAndSpecification(flow);
if (byAttributesAndSpecification.size() > 0) {
return ImmutablePhysicalFlowCreateCommandResponse.builder().originalCommand(command).outcome(CommandOutcome.FAILURE).message("Duplicate with existing flow").entityReference(mkRef(PHYSICAL_FLOW, byAttributesAndSpecification.get(0).id().get())).build();
}
long physicalFlowId = physicalFlowDao.create(flow);
logChange(username, logicalFlow.source(), String.format("Added physical flow (%s) to: %s", command.specification().name(), safeName(logicalFlow.target())), Operation.ADD);
logChange(username, logicalFlow.target(), String.format("Added physical flow (%s) from: %s", command.specification().name(), safeName(logicalFlow.source())), Operation.ADD);
logChange(username, mkRef(PHYSICAL_SPECIFICATION, specId), String.format("Added physical flow (%s) from: %s, to %s", command.specification().name(), safeName(logicalFlow.source()), safeName(logicalFlow.target())), Operation.ADD);
return ImmutablePhysicalFlowCreateCommandResponse.builder().originalCommand(command).outcome(CommandOutcome.SUCCESS).entityReference(mkRef(PHYSICAL_FLOW, physicalFlowId)).build();
}
use of com.khartec.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowService method delete.
public PhysicalFlowDeleteCommandResponse delete(PhysicalFlowDeleteCommand command, String username) {
checkNotNull(command, "command cannot be null");
PhysicalFlow physicalFlow = physicalFlowDao.getById(command.flowId());
LogicalFlow logicalFlow = logicalFlowService.getById(physicalFlow.logicalFlowId());
CommandOutcome commandOutcome = CommandOutcome.SUCCESS;
String responseMessage = null;
boolean isSpecificationUnused = false;
if (physicalFlow == null) {
commandOutcome = CommandOutcome.FAILURE;
responseMessage = "Flow not found";
} else {
int deleteCount = physicalFlowDao.delete(command.flowId());
if (deleteCount == 0) {
commandOutcome = CommandOutcome.FAILURE;
responseMessage = "This flow cannot be deleted as it is being used in a lineage";
} else {
isSpecificationUnused = !physicalSpecificationDao.isUsed(physicalFlow.specificationId());
}
}
// log changes against source and target entities
if (commandOutcome == CommandOutcome.SUCCESS) {
PhysicalSpecification specification = physicalSpecificationDao.getById(physicalFlow.specificationId());
logChange(username, logicalFlow.source(), String.format("Physical flow: %s, from: %s, to: %s removed.", specification.name(), safeName(logicalFlow.source()), safeName(logicalFlow.target())), Operation.REMOVE);
logChange(username, logicalFlow.target(), String.format("Physical flow: %s, from: %s removed.", specification.name(), safeName(logicalFlow.source())), Operation.REMOVE);
logChange(username, logicalFlow.source(), String.format("Physical flow: %s, to: %s removed.", specification.name(), safeName(logicalFlow.target())), Operation.REMOVE);
}
return ImmutablePhysicalFlowDeleteCommandResponse.builder().originalCommand(command).entityReference(mkRef(PHYSICAL_FLOW, command.flowId())).outcome(commandOutcome).message(Optional.ofNullable(responseMessage)).isSpecificationUnused(isSpecificationUnused).build();
}
use of com.khartec.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowDecoratorService method deleteDecorators.
public int[] deleteDecorators(long flowId, Collection<EntityReference> decoratorReferences, String username) {
checkNotNull(decoratorReferences, "decoratorReferences cannot be null");
LogicalFlow flow = logicalFlowDao.findByFlowId(flowId);
int[] deleted = logicalFlowDecoratorDao.deleteDecorators(flowId, decoratorReferences);
dataTypeUsageService.recalculateForApplications(newArrayList(flow.source(), flow.target()));
audit("Removed", decoratorReferences, flow, username);
return deleted;
}
use of com.khartec.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowDecoratorService method addDecorators.
public int[] addDecorators(long flowId, Set<EntityReference> decoratorReferences, String username) {
checkNotNull(decoratorReferences, "decoratorReferences cannot be null");
if (decoratorReferences.isEmpty())
return new int[0];
LogicalFlow flow = logicalFlowDao.findByFlowId(flowId);
boolean requiresRating = flow.source().kind() == APPLICATION && flow.target().kind() == APPLICATION;
Collection<LogicalFlowDecorator> unrated = map(decoratorReferences, ref -> ImmutableLogicalFlowDecorator.builder().rating(AuthoritativenessRating.NO_OPINION).provenance("waltz").dataFlowId(flowId).decoratorEntity(ref).lastUpdatedBy(username).lastUpdatedAt(nowUtc()).build());
Collection decorators = requiresRating ? ratingsCalculator.calculate(unrated) : unrated;
int[] added = logicalFlowDecoratorDao.addDecorators(decorators);
dataTypeUsageService.recalculateForApplications(newArrayList(flow.source(), flow.target()));
audit("Added", decoratorReferences, flow, username);
return added;
}
Aggregations