Search in sources :

Example 26 with ValidationMessageException

use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryAdjustmentReasonsValidator method validateReason.

private void validateReason(StockEventDto event, UUID reasonId) {
    if (reasonId == null) {
        throw new ValidationMessageException(new Message(ERROR_PHYSICAL_INVENTORY_DISCREPANCY_REASON_NOT_PROVIDED));
    }
    UUID facilityType = getFacilityType(event);
    UUID programId = event.getProgramId();
    if (!isReasonValid(programId, facilityType, reasonId)) {
        throwException(programId, facilityType, reasonId);
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) UUID(java.util.UUID)

Example 27 with ValidationMessageException

use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.

the class ActiveStockCardsValidator method checkAllStockCardsCovered.

private void checkAllStockCardsCovered(StockEventDto stockEventDto) {
    List<OrderableLotIdentity> coveredIdentities = stockEventDto.getLineItems().stream().map(OrderableLotIdentity::identityOf).collect(toList());
    boolean anyMissing = stockCardRepository.getIdentitiesBy(stockEventDto.getProgramId(), stockEventDto.getFacilityId()).stream().anyMatch(identity -> !coveredIdentities.contains(identity));
    if (anyMissing) {
        throw new ValidationMessageException(new Message(ERROR_PHYSICAL_INVENTORY_NOT_INCLUDE_ACTIVE_STOCK_CARD));
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)

Example 28 with ValidationMessageException

use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseServiceTest method shouldThrowValidationExceptionWhenProgramAndFacilityTypeNotFound.

@Test(expected = ValidationMessageException.class)
public void shouldThrowValidationExceptionWhenProgramAndFacilityTypeNotFound() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    doThrow(new ValidationMessageException("errorKey")).when(programFacilityTypeExistenceService).checkProgramAndFacilityTypeExist(programId, facilityTypeId);
    // when
    validSourceService.findSources(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 29 with ValidationMessageException

use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplateServiceTest method shouldNotSaveTemplateWithNonExistingProgramAndFacilityType.

@Test(expected = ValidationMessageException.class)
public void shouldNotSaveTemplateWithNonExistingProgramAndFacilityType() {
    // given: program and facility can not be found in ref data service
    doThrow(new ValidationMessageException("errorKey")).when(programFacilityTypeExistenceService).checkProgramAndFacilityTypeExist(any(UUID.class), any(UUID.class));
    StockCardTemplateDto templateDto = createTemplateDto();
    // when
    stockCardTemplateService.saveOrUpdate(templateDto);
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) UUID(java.util.UUID) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 30 with ValidationMessageException

use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.

the class StockEventValidationsServiceTest method shouldNotRunNextValidatorIfPreviousValidatorFailed.

@Test
public void shouldNotRunNextValidatorIfPreviousValidatorFailed() throws Exception {
    // given
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
    doThrow(new ValidationMessageException(new Message("some error"))).when(validator1).validate(stockEventDto);
    // when:
    try {
        stockEventValidationsService.validate(stockEventDto);
    } catch (ValidationMessageException ex) {
        // then:
        verify(validator1, times(1)).validate(stockEventDto);
        verify(validator2, never()).validate(stockEventDto);
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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