use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class StockCardTemplatesControllerIntegrationTest method throwValidationExceptionWith.
private void throwValidationExceptionWith(String exceptionKey) throws Exception {
// given
Mockito.doThrow(new ValidationMessageException(new Message(exceptionKey, "some id"))).when(stockCardTemplateService).saveOrUpdate(any());
// when
ResultActions resultActions = mvc.perform(post(STOCK_CARD_TEMPLATE_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardTemplate())));
// then
resultActions.andExpect(status().isBadRequest());
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class StockEventsControllerIntegrationTest method shouldReturnBadRequestOnCreateStockEventWhenEntityInvalid.
@Test
public void shouldReturnBadRequestOnCreateStockEventWhenEntityInvalid() {
// given
mockHasPermissions();
mockPassValidation();
StockEventDto stockEvent = generateStockEvent();
when(stockEventProcessor.process(any(StockEventDto.class))).thenThrow(new ValidationMessageException(ERROR_REASON_ASSIGNMENT_NOT_FOUND));
// when
restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).body(stockEvent).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 JasperTemplateService method createTemplate.
/**
* Save report file as ".jasper" in byte array in Template class.
* If report is not valid throw exception.
*
* @param template The template to insert parameters to
* @param inputStream input stream of the file
*/
private void createTemplate(JasperTemplate template, InputStream inputStream) {
try {
JasperReport report = JasperCompileManager.compileReport(inputStream);
String reportType = report.getProperty("reportType");
if (reportType != null) {
template.setType(reportType);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(report);
template.setData(bos.toByteArray());
} catch (JRException ex) {
throw new ValidationMessageException(ex, new Message(ERROR_REPORTING_FILE_INVALID, ex.getMessage()));
} 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 PhysicalInventoryService method deletePhysicalInventory.
/**
* Delete draft.
*
* @param id physical inventory id.
*/
public void deletePhysicalInventory(UUID id) {
PhysicalInventory foundInventory = physicalInventoriesRepository.findOne(id);
if (foundInventory != null) {
checkPermission(foundInventory.getProgramId(), foundInventory.getFacilityId());
if (!foundInventory.getIsDraft()) {
throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED);
}
physicalInventoriesRepository.delete(foundInventory);
} else {
throw new ResourceNotFoundException(new Message(ERROR_PHYSICAL_INVENTORY_NOT_FOUND, id));
}
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseService method doAssign.
/**
* Create a new assignment.
*
* @param assignment assignment
* @param errorKey error message key
* @param repository assignment repository
* @param <T> assignment type
* @return created assignment.
*/
protected <T extends SourceDestinationAssignment> ValidSourceDestinationDto doAssign(T assignment, String errorKey, SourceDestinationAssignmentRepository<T> repository) {
UUID referenceId = assignment.getNode().getReferenceId();
boolean isRefFacility = facilityRefDataService.exists(referenceId);
boolean isOrganization = organizationRepository.exists(referenceId);
if (isRefFacility || isOrganization) {
assignment.setNode(findOrCreateNode(referenceId, isRefFacility));
return createAssignmentDto(repository.save(assignment));
}
throw new ValidationMessageException(new Message(errorKey));
}
Aggregations