Search in sources :

Example 11 with ValidationMessageException

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

Example 12 with ValidationMessageException

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

Example 13 with ValidationMessageException

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

Example 14 with ValidationMessageException

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()));
    }
}
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 15 with ValidationMessageException

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);
}
Also used : ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)30 Message (org.openlmis.stockmanagement.util.Message)19 UUID (java.util.UUID)10 Test (org.junit.Test)10 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)4 IOException (java.io.IOException)3 UUID.randomUUID (java.util.UUID.randomUUID)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 Set (java.util.Set)2 JRException (net.sf.jasperreports.engine.JRException)2 JasperTemplate (org.openlmis.stockmanagement.domain.JasperTemplate)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)2 PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)2 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Component (org.springframework.stereotype.Component)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2