use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryControllerIntegrationTest method shouldReturnBadRequestWhenInventoryIsSubmitted.
@Test
public void shouldReturnBadRequestWhenInventoryIsSubmitted() {
// given
UUID physicalInventoryId = UUID.randomUUID();
doThrow(new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED)).when(physicalInventoryService).deletePhysicalInventory(physicalInventoryId);
// when
restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).pathParam("id", physicalInventoryId).when().delete(ID_URL).then().statusCode(400);
// then
assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentController method removeReasonAssignment.
/**
* Remove a reason assignment.
*
* @param assignmentId reason assignment id.
* @return No content status.
*/
@RequestMapping(value = "/validReasons/{id}", method = DELETE)
public ResponseEntity removeReasonAssignment(@PathVariable("id") UUID assignmentId) {
LOGGER.debug("Try to remove reason assignment {}", assignmentId);
permissionService.canManageReasons();
if (!reasonAssignmentRepository.exists(assignmentId)) {
throw new ValidationMessageException(new Message(ERROR_REASON_ASSIGNMENT_NOT_FOUND));
}
reasonAssignmentRepository.delete(assignmentId);
return new ResponseEntity<>(null, NO_CONTENT);
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryTemplateController method downloadXmlTemplate.
/**
* Download report template with ".jrxml" format(extension) for Physical Inventory from database.
*
* @param response HttpServletResponse object.
*/
@GetMapping
@ResponseBody
public void downloadXmlTemplate(HttpServletResponse response) throws IOException {
LOGGER.debug("Checking right to view Physical Inventory template");
permissionService.canManageSystemSettings();
JasperTemplate piPrintTemplate = templateService.getByName(PRINT_PI);
if (piPrintTemplate == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Physical Inventory template does not exist.");
} else {
response.setContentType("application/xml");
response.addHeader("Content-Disposition", "attachment; filename=piPrint" + ".jrxml");
File file = templateService.convertJasperToXml(piPrintTemplate);
try (InputStream fis = new FileInputStream(file);
InputStream bis = new BufferedInputStream(fis)) {
IOUtils.copy(bis, response.getOutputStream());
response.flushBuffer();
} catch (IOException ex) {
throw new ValidationMessageException(ex, new Message(ERROR_IO, ex.getMessage()));
}
}
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class ApprovedOrderableValidator method validate.
/**
* Validate if the orderable in stock event is in the approved list.
*
* @param stockEventDto the event to be validated.
*/
public void validate(StockEventDto stockEventDto) {
LOGGER.debug("Validate approved product reference data service");
UUID facility = stockEventDto.getFacilityId();
UUID program = stockEventDto.getProgramId();
// that is other validator's job
if (!stockEventDto.hasLineItems() || facility == null || program == null) {
return;
}
List<UUID> nonApprovedIds = findNonApprovedIds(stockEventDto, stockEventDto.getContext().getAllApprovedProducts());
if (!isEmpty(nonApprovedIds)) {
List<OrderableDto> orderables = orderableReferenceDataService.findByIds(nonApprovedIds);
String codes = orderables.stream().map(OrderableDto::getProductCode).collect(Collectors.joining(", "));
throw new ValidationMessageException(new Message(ERROR_ORDERABLE_NOT_IN_APPROVED_LIST, codes));
}
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class OrderableLotDuplicationValidator method validate.
@Override
public void validate(StockEventDto stockEventDto) {
// duplication is not allow in physical inventory, but is allowed in adjustment
if (!stockEventDto.hasLineItems() || !stockEventDto.isPhysicalInventory()) {
return;
}
Set<OrderableLotIdentity> nonDuplicates = new HashSet<>();
Set<OrderableLotIdentity> duplicates = stockEventDto.getLineItems().stream().map(OrderableLotIdentity::identityOf).filter(lotIdentity -> !nonDuplicates.add(lotIdentity)).collect(toSet());
if (duplicates.size() > 0) {
throw new ValidationMessageException(new Message(ERROR_EVENT_ORDERABLE_LOT_DUPLICATION, duplicates));
}
}
Aggregations