Search in sources :

Example 1 with CommandOutcome

use of com.khartec.waltz.model.command.CommandOutcome 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 2 with CommandOutcome

use of com.khartec.waltz.model.command.CommandOutcome in project waltz by khartec.

the class PhysicalSpecificationService method delete.

public CommandResponse<PhysicalSpecificationDeleteCommand> delete(PhysicalSpecificationDeleteCommand command, String username) {
    checkNotNull(command, "command cannot be null");
    CommandOutcome commandOutcome = CommandOutcome.SUCCESS;
    String responseMessage = null;
    PhysicalSpecification specification = specificationDao.getById(command.specificationId());
    if (specification == null) {
        commandOutcome = CommandOutcome.FAILURE;
        responseMessage = "Specification not found";
    } else {
        int deleteCount = specificationDao.delete(command.specificationId());
        if (deleteCount == 0) {
            commandOutcome = CommandOutcome.FAILURE;
            responseMessage = "This specification cannot be deleted as it is being referenced by one or more physical flows";
        }
    }
    if (commandOutcome == CommandOutcome.SUCCESS) {
        logChange(username, specification.owningEntity(), String.format("Specification: %s removed", specification.name()), Operation.REMOVE);
    }
    return ImmutableCommandResponse.<PhysicalSpecificationDeleteCommand>builder().entityReference(EntityReference.mkRef(EntityKind.PHYSICAL_SPECIFICATION, command.specificationId())).originalCommand(command).outcome(commandOutcome).message(Optional.ofNullable(responseMessage)).build();
}
Also used : CommandOutcome(com.khartec.waltz.model.command.CommandOutcome) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification)

Aggregations

CommandOutcome (com.khartec.waltz.model.command.CommandOutcome)2 PhysicalSpecification (com.khartec.waltz.model.physical_specification.PhysicalSpecification)2 ImmutableLogicalFlow (com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow)1 LogicalFlow (com.khartec.waltz.model.logical_flow.LogicalFlow)1 ImmutablePhysicalSpecification (com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification)1