use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class ApprovedOrderableValidator method validate.
/**
* Validate if the orderable in stock event is in the approved list.
*
* @param stockEventDto the event to be validated.
*/
public void validate(StockEventDto stockEventDto) {
LOGGER.debug("Validate approved product reference data service");
UUID facility = stockEventDto.getFacilityId();
UUID program = stockEventDto.getProgramId();
// that is other validator's job
if (!stockEventDto.hasLineItems() || facility == null || program == null) {
return;
}
List<UUID> nonApprovedIds = findNonApprovedIds(stockEventDto, stockEventDto.getContext().getAllApprovedProducts());
if (!isEmpty(nonApprovedIds)) {
List<OrderableDto> orderables = orderableReferenceDataService.findByIds(nonApprovedIds);
String codes = orderables.stream().map(OrderableDto::getProductCode).collect(Collectors.joining(", "));
throw new ValidationMessageException(new Message(ERROR_ORDERABLE_NOT_IN_APPROVED_LIST, codes));
}
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class OrderableLotDuplicationValidator method validate.
@Override
public void validate(StockEventDto stockEventDto) {
// duplication is not allow in physical inventory, but is allowed in adjustment
if (!stockEventDto.hasLineItems() || !stockEventDto.isPhysicalInventory()) {
return;
}
Set<OrderableLotIdentity> nonDuplicates = new HashSet<>();
Set<OrderableLotIdentity> duplicates = stockEventDto.getLineItems().stream().map(OrderableLotIdentity::identityOf).filter(lotIdentity -> !nonDuplicates.add(lotIdentity)).collect(toSet());
if (duplicates.size() > 0) {
throw new ValidationMessageException(new Message(ERROR_EVENT_ORDERABLE_LOT_DUPLICATION, duplicates));
}
}
use of org.openlmis.stockmanagement.util.Message 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.util.Message 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.util.Message 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