Search in sources :

Example 16 with Message

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());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException)

Example 17 with Message

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));
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException)

Example 18 with Message

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()));
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) FacilityTypeDto(org.openlmis.stockmanagement.dto.referencedata.FacilityTypeDto)

Example 19 with Message

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());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException)

Example 20 with Message

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());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Aggregations

Message (org.openlmis.stockmanagement.util.Message)35 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)19 Test (org.junit.Test)13 PermissionMessageException (org.openlmis.stockmanagement.exception.PermissionMessageException)13 ResultActions (org.springframework.test.web.servlet.ResultActions)9 UUID (java.util.UUID)8 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)6 StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto)4 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)4 ResourceNotFoundException (org.openlmis.stockmanagement.exception.ResourceNotFoundException)3 IOException (java.io.IOException)2 JasperTemplate (org.openlmis.stockmanagement.domain.JasperTemplate)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)2 StockCardTemplate (org.openlmis.stockmanagement.domain.template.StockCardTemplate)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1