use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class VvmValidator method validate.
/**
* Validates whether the vvm applicables have proper vvm status (if applicable).
* Throws ValidationMessageException if any of items is in invalid state.
* @param vvmApplicables list of items to test
* @param messageKey error message key for exception
* @param ignoreMissingOrderable whether should
*/
public void validate(List<? extends VvmApplicable> vvmApplicables, String messageKey, boolean ignoreMissingOrderable) {
Set<UUID> orderableIds = vvmApplicables.stream().map(VvmApplicable::getOrderableId).collect(Collectors.toSet());
List<OrderableDto> orderables = orderableReferenceDataService.findByIds(orderableIds);
Map<UUID, OrderableDto> groupById = orderables.stream().collect(Collectors.toMap(OrderableDto::getId, orderable -> orderable));
for (VvmApplicable item : vvmApplicables) {
OrderableDto orderable = groupById.get(item.getOrderableId());
if (null == orderable) {
if (ignoreMissingOrderable) {
continue;
} else {
throw new ValidationMessageException(ERROR_EVENT_ORDERABLE_INVALID);
}
}
boolean useVvm = false;
boolean hasVvmStatus = false;
if (orderable.getExtraData() != null) {
useVvm = Boolean.parseBoolean(orderable.getExtraData().get(USE_VVM));
}
if (item.getExtraData() != null) {
hasVvmStatus = item.getExtraData().get(VVM_STATUS) != null;
}
if (!useVvm && hasVvmStatus) {
throw new ValidationMessageException(messageKey);
}
}
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryController method print.
/**
* Print out physical inventory as a PDF file.
*
* @param id The UUID of the stock event to print
* @param format The report format
* @return ResponseEntity with the "#200 OK" HTTP response status and PDF file on success, or
* ResponseEntity containing the error description status.
*/
@GetMapping(value = ID_PATH_VARIABLE, params = "format")
@ResponseBody
public ModelAndView print(@PathVariable("id") UUID id, @RequestParam String format) throws JasperReportViewException {
checkPermission(id);
checkFormat(format.toLowerCase());
JasperTemplate printTemplate = templateService.getByName(PRINT_PI);
if (printTemplate == null) {
throw new ValidationMessageException(new Message(ERROR_REPORTING_TEMPLATE_NOT_FOUND_WITH_NAME, PRINT_PI));
}
JasperReportsMultiFormatView jasperView = jasperReportService.getJasperReportsView(printTemplate);
return new ModelAndView(jasperView, getParams(id, format));
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryValidator method validateDraft.
/**
* Check for physical inventory dto's validity.
* Throws {@link ValidationMessageException} if an error found.
* @param inventory physical inventory to validate.
*/
public void validateDraft(PhysicalInventoryDto inventory, UUID id) {
if (!inventory.getId().equals(id)) {
throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_ID_MISMATCH);
}
PhysicalInventory foundInventory = physicalInventoriesRepository.findOne(id);
if (foundInventory != null && !foundInventory.getIsDraft()) {
throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED);
}
List<PhysicalInventoryLineItemDto> lineItems = inventory.getLineItems();
validateLineItems(lineItems);
vvmValidator.validate(lineItems, ERROR_PHYSICAL_INVENTORY_ORDERABLE_DISABLED_VVM, false);
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryControllerIntegrationTest method shouldReturnBadRequestOnCreateEmptyDraftWhenEntityInvalid.
@Test
public void shouldReturnBadRequestOnCreateEmptyDraftWhenEntityInvalid() {
// given
PhysicalInventoryDto expectedDraft = generateDraft();
when(physicalInventoryService.createNewDraft(expectedDraft)).thenThrow(new ValidationMessageException(ERROR_PROGRAM_ID_MISSING));
// when
restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).body(expectedDraft).when().post(RESOURCE_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 PhysicalInventoryControllerIntegrationTest method shouldReturnBadRequestOnSaveDraftWhenEntityInvalid.
@Test
public void shouldReturnBadRequestOnSaveDraftWhenEntityInvalid() {
// given
UUID physicalInventoryId = UUID.randomUUID();
PhysicalInventoryDto expectedDraft = generatePhysicalInventory();
when(physicalInventoryService.saveDraft(expectedDraft, physicalInventoryId)).thenThrow(new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_LINE_ITEMS_MISSING));
// when
restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).pathParam("id", physicalInventoryId).body(expectedDraft).when().put(ID_URL).then().statusCode(400);
// then
assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
Aggregations