use of org.finos.waltz.common.exception.DuplicateKeyException in project waltz by khartec.
the class PhysicalSpecDefinitionEndpoint method register.
@Override
public void register() {
String findForSpecificationPath = WebUtilities.mkPath(BASE_URL, "specification", ":id");
String findBySelectorPath = WebUtilities.mkPath(BASE_URL, "selector");
String createPath = WebUtilities.mkPath(BASE_URL, "specification", ":id");
String updateStatusPath = WebUtilities.mkPath(BASE_URL, "specification", ":id", "status");
String deletePath = WebUtilities.mkPath(BASE_URL, "specification", ":id");
ListRoute<PhysicalSpecDefinition> findForSpecificationRoute = (req, res) -> specDefinitionService.findForSpecification(WebUtilities.getId(req));
ListRoute<PhysicalSpecDefinition> findBySelectorRoute = (req, res) -> specDefinitionService.findBySelector(WebUtilities.readIdSelectionOptionsFromBody(req));
DatumRoute<Long> createRoute = (req, res) -> {
WebUtilities.requireRole(userRoleService, req, SystemRole.LOGICAL_DATA_FLOW_EDITOR);
PhysicalSpecDefinitionChangeCommand physicalSpecDefinitionChangeCommand = WebUtilities.readBody(req, PhysicalSpecDefinitionChangeCommand.class);
long physicalSpecificationId = WebUtilities.getId(req);
Set<String> existingVersions = map(specDefinitionService.findForSpecification(physicalSpecificationId), d -> d.version());
if (existingVersions.contains(physicalSpecDefinitionChangeCommand.version())) {
throw new DuplicateKeyException("Cannot create physical specification definition with version that already exists");
}
return specDefinitionService.create(WebUtilities.getUsername(req), physicalSpecificationId, physicalSpecDefinitionChangeCommand);
};
DatumRoute<Boolean> updateStatusRoute = (req, res) -> {
WebUtilities.requireRole(userRoleService, req, SystemRole.LOGICAL_DATA_FLOW_EDITOR);
return specDefinitionService.updateStatus(WebUtilities.getUsername(req), WebUtilities.getId(req), WebUtilities.readBody(req, ReleaseLifecycleStatusChangeCommand.class));
};
DatumRoute<Integer> deleteRoute = (req, res) -> {
WebUtilities.requireRole(userRoleService, req, SystemRole.LOGICAL_DATA_FLOW_EDITOR);
return specDefinitionService.delete(WebUtilities.getUsername(req), WebUtilities.getId(req));
};
EndpointUtilities.getForList(findForSpecificationPath, findForSpecificationRoute);
EndpointUtilities.postForList(findBySelectorPath, findBySelectorRoute);
EndpointUtilities.postForDatum(createPath, createRoute);
EndpointUtilities.putForDatum(updateStatusPath, updateStatusRoute);
EndpointUtilities.deleteForDatum(deletePath, deleteRoute);
}
Aggregations