use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class ProgramFacilityTypeExistenceServiceTest method throwValidationMessageExceptionWhenProgramNotFound.
@Test(expected = ValidationMessageException.class)
public void throwValidationMessageExceptionWhenProgramNotFound() throws Exception {
UUID facilityTypeId = randomUUID();
UUID programId = randomUUID();
when(programRefDataService.findOne(programId)).thenThrow(new ValidationMessageException("errorKey"));
programFacilityTypeExistenceService.checkProgramAndFacilityTypeExist(programId, facilityTypeId);
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class StockEventsControllerrIntegrationTest method shouldReturn400WhenValidationFails.
@Test
public void shouldReturn400WhenValidationFails() throws Exception {
// given
Mockito.doThrow(new ValidationMessageException(new Message(ERROR_EVENT_QUANTITIES_INVALID))).when(stockEventProcessor).process(any());
// when
ResultActions resultActions = mvc.perform(post(CREATE_STOCK_EVENT_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockEventDto())));
// then
resultActions.andExpect(status().isBadRequest());
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class StockCardTemplateService method checkFieldsDuplication.
private void checkFieldsDuplication(StockCardTemplateDto templateDto) {
List<StockCardFieldDto> cardFields = templateDto.getStockCardFields();
long cardFieldCount = cardFields.stream().map(StockCardFieldDto::getName).distinct().count();
List<StockCardLineItemFieldDto> lineItemFields = templateDto.getStockCardLineItemFields();
long lineItemFieldCount = lineItemFields.stream().map(StockCardLineItemFieldDto::getName).distinct().count();
if (cardFieldCount < cardFields.size() || lineItemFieldCount < lineItemFields.size()) {
throw new ValidationMessageException(new Message(ERROR_STOCK_CARD_FIELD_DUPLICATED));
}
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class JasperTemplateService method convertJasperToXml.
/**
* Convert template from ".jasper" format in database to ".jrxml"(extension) format.
*/
public File convertJasperToXml(JasperTemplate template) {
try (InputStream inputStream = new ByteArrayInputStream(template.getData());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
JasperCompileManager.writeReportToXmlStream(inputStream, outputStream);
File xmlReport = createTempFile(template.getName(), ".jrxml");
writeByteArrayToFile(xmlReport, outputStream.toByteArray());
return xmlReport;
} catch (JRException | IOException ex) {
throw new ValidationMessageException(ex, ERROR_REPORTING_CREATION);
}
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class StockCard method shallowCopy.
/**
* Creates a shallow copy of this stock card. Used during recalculation to avoid updates on
* existing stock cards and line items.
*/
public StockCard shallowCopy() {
StockCard clone = new StockCard();
clone.setId(getId());
clone.setLotId(lotId);
clone.setStockOnHand(stockOnHand);
clone.setOrderableId(orderableId);
clone.setProgramId(programId);
clone.setFacilityId(facilityId);
clone.setLineItems(new ArrayList<>());
try {
if (lineItems != null) {
for (StockCardLineItem lineItem : this.getLineItems()) {
clone.getLineItems().add((StockCardLineItem) cloneBean(lineItem));
}
}
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException ex) {
// this here to satisfy checkstyle/pmd and to make sure potential bug is not hidden.
throw new ValidationMessageException(new Message(SERVER_ERROR_SHALLOW_COPY, ex));
}
return clone;
}
Aggregations