Search in sources :

Example 16 with ValidationMessageException

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);
}
Also used : ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 17 with ValidationMessageException

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());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 18 with ValidationMessageException

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));
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) StockCardLineItemFieldDto(org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto) StockCardFieldDto(org.openlmis.stockmanagement.dto.StockCardFieldDto)

Example 19 with ValidationMessageException

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);
    }
}
Also used : JRException(net.sf.jasperreports.engine.JRException) ByteArrayInputStream(java.io.ByteArrayInputStream) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FileUtils.writeByteArrayToFile(org.apache.commons.io.FileUtils.writeByteArrayToFile) File.createTempFile(java.io.File.createTempFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 20 with ValidationMessageException

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;
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)30 Message (org.openlmis.stockmanagement.util.Message)19 UUID (java.util.UUID)10 Test (org.junit.Test)10 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)4 IOException (java.io.IOException)3 UUID.randomUUID (java.util.UUID.randomUUID)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 Set (java.util.Set)2 JRException (net.sf.jasperreports.engine.JRException)2 JasperTemplate (org.openlmis.stockmanagement.domain.JasperTemplate)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)2 PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)2 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Component (org.springframework.stereotype.Component)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2