Search in sources :

Example 1 with LogicalFlow

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) ApplicationIdSelectorFactory(com.khartec.waltz.data.application.ApplicationIdSelectorFactory) DSLContext(org.jooq.DSLContext) LogicalFlowDao(com.khartec.waltz.data.logical_flow.LogicalFlowDao) IdSelectionOptions(com.khartec.waltz.model.IdSelectionOptions)

Example 2 with LogicalFlow

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();
}
Also used : LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow)

Example 3 with LogicalFlow

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();
}
Also used : CommandOutcome(com.khartec.waltz.model.command.CommandOutcome) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) ImmutablePhysicalSpecification(com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow)

Example 4 with LogicalFlow

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;
}
Also used : LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow)

Example 5 with LogicalFlow

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;
}
Also used : ImmutableLogicalFlowDecorator(com.khartec.waltz.model.data_flow_decorator.ImmutableLogicalFlowDecorator) LogicalFlowDecorator(com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow)

Aggregations

LogicalFlow (com.khartec.waltz.model.logical_flow.LogicalFlow)11 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)5 EntityReference (com.khartec.waltz.model.EntityReference)5 ImmutableLogicalFlow (com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow)4 DSLContext (org.jooq.DSLContext)4 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)4 AuthoritativeSourceDao (com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao)3 EntityKind (com.khartec.waltz.model.EntityKind)3 Application (com.khartec.waltz.model.application.Application)3 ApplicationService (com.khartec.waltz.service.application.ApplicationService)3 LogicalFlowService (com.khartec.waltz.service.logical_flow.LogicalFlowService)3 Collectors.toList (java.util.stream.Collectors.toList)3 ListUtilities.randomPick (com.khartec.waltz.common.ListUtilities.randomPick)2 SetUtilities (com.khartec.waltz.common.SetUtilities)2 IdSelectionOptions (com.khartec.waltz.model.IdSelectionOptions)2 AuthoritativeSource (com.khartec.waltz.model.authoritativesource.AuthoritativeSource)2 ImmutableLogicalFlowDecorator (com.khartec.waltz.model.data_flow_decorator.ImmutableLogicalFlowDecorator)2 LogicalFlowDecorator (com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator)2 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)2 LOGICAL_FLOW (com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW)2