Search in sources :

Example 1 with CommandOutcome

use of org.finos.waltz.model.command.CommandOutcome in project waltz by khartec.

the class PhysicalSpecificationService method markRemovedIfUnused.

public CommandResponse<PhysicalSpecificationDeleteCommand> markRemovedIfUnused(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.markRemovedIfUnused(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(org.finos.waltz.model.command.CommandOutcome) ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification)

Aggregations

CommandOutcome (org.finos.waltz.model.command.CommandOutcome)1 ImmutablePhysicalSpecification (org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification)1 PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)1