use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseService method findExistingNode.
private <T extends SourceDestinationAssignment> Node findExistingNode(T assignment, UUID programId, UUID facilityTypeId) {
programFacilityTypeExistenceService.checkProgramAndFacilityTypeExist(programId, facilityTypeId);
Node node = assignment.getNode();
if (node == null || node.getReferenceId() == null) {
throw new ValidationMessageException(new Message(ERROR_SOURCE_DESTINATION_ASSIGNMENT_ID_MISSING));
}
return nodeRepository.findByReferenceId(node.getReferenceId());
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItem method tryDecrease.
private void tryDecrease(int previousStockOnHand) {
if (previousStockOnHand - quantity < 0) {
throw new ValidationMessageException(new Message(ERROR_EVENT_DEBIT_QUANTITY_EXCEED_SOH, previousStockOnHand, quantity));
}
setStockOnHand(previousStockOnHand - quantity);
LOGGER.debug(previousStockOnHand + " - " + quantity + " = " + getStockOnHand());
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItem method tryIncrease.
private void tryIncrease(int previousStockOnHand) {
try {
// this may exceed max of integer
setStockOnHand(Math.addExact(previousStockOnHand, quantity));
LOGGER.debug(previousStockOnHand + " + " + quantity + " = " + getStockOnHand());
} catch (ArithmeticException ex) {
throw new ValidationMessageException(new Message(ERRRO_EVENT_SOH_EXCEEDS_LIMIT, previousStockOnHand, quantity, ex));
}
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class ProgramFacilityTypeExistenceService method checkProgramAndFacilityTypeExist.
/**
* Check program and facility type existence.
*
* @param programId program id.
* @param facilityTypeId facility type id.
*/
public void checkProgramAndFacilityTypeExist(UUID programId, UUID facilityTypeId) {
ProgramDto programDto = programReferenceDataService.findOne(programId);
FacilityTypeDto facilityTypeDto = facilityTypeReferenceDataService.findOne(facilityTypeId);
if (programDto == null) {
throw new ValidationMessageException(new Message(ERROR_PROGRAM_NOT_FOUND, programId.toString()));
}
if (facilityTypeDto == null) {
throw new ValidationMessageException(new Message(ERROR_FACILITY_TYPE_NOT_FOUND, facilityTypeId.toString()));
}
}
use of org.openlmis.stockmanagement.exception.ValidationMessageException in project openlmis-stockmanagement by OpenLMIS.
the class ProgramFacilityTypeExistenceServiceTest method throwValidationMessageExceptionWhenFacilityTypeNotFound.
@Test(expected = ValidationMessageException.class)
public void throwValidationMessageExceptionWhenFacilityTypeNotFound() throws Exception {
UUID facilityTypeId = randomUUID();
UUID programId = randomUUID();
when(facilityTypeRefDataService.findOne(facilityTypeId)).thenThrow(new ValidationMessageException("errorKey"));
programFacilityTypeExistenceService.checkProgramAndFacilityTypeExist(programId, facilityTypeId);
}
Aggregations