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);
}
}
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));
}
}
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);
}
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);
}
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);
}
}
Aggregations