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();
}
Aggregations