use of org.openlmis.stockmanagement.util.Message 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.util.Message 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.util.Message 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.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class ReasonConfigurationOptionsControllerIntegrationTest method shouldThrow403.
private void shouldThrow403(String api) throws Exception {
// given
doThrow(new PermissionMessageException(new Message("some error"))).when(permissionService).canManageReasons();
// when
ResultActions resultActions = mvc.perform(get(api).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE));
// then
resultActions.andExpect(status().isForbidden());
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class StockCardControllerIntegrationTest method shouldReturn403WhenUserDoesNotHavePermissionToViewCardSummaries.
@Test
public void shouldReturn403WhenUserDoesNotHavePermissionToViewCardSummaries() throws Exception {
// given
UUID programId = UUID.randomUUID();
UUID facilityId = UUID.randomUUID();
doThrow(new PermissionMessageException(new Message("no permission"))).when(permissionService).canViewStockCard(programId, facilityId);
// when
ResultActions resultActions = mvc.perform(get(API_STOCK_CARD_SUMMARIES).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).param("program", programId.toString()).param("facility", facilityId.toString()));
// then
resultActions.andExpect(status().isForbidden());
}
Aggregations