Search in sources :

Example 11 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class JasperReportService method getStockCardReportView.

/**
 * Generate stock card report in PDF format.
 *
 * @param stockCardId stock card id
 * @return generated stock card report.
 */
public ModelAndView getStockCardReportView(UUID stockCardId) {
    StockCardDto stockCardDto = stockCardService.findStockCardById(stockCardId);
    if (stockCardDto == null) {
        throw new ResourceNotFoundException(new Message(ERROR_REPORT_ID_NOT_FOUND));
    }
    Collections.reverse(stockCardDto.getLineItems());
    Map<String, Object> params = new HashMap<>();
    params.put("datasource", singletonList(stockCardDto));
    params.put("hasLot", stockCardDto.hasLot());
    return generateReport(CARD_REPORT_URL, params);
}
Also used : Message(org.openlmis.stockmanagement.util.Message) HashMap(java.util.HashMap) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) ResourceNotFoundException(org.openlmis.stockmanagement.exception.ResourceNotFoundException)

Example 12 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class JasperTemplateService method createTemplate.

/**
 * Save report file as ".jasper" in byte array in Template class.
 * If report is not valid throw exception.
 *
 * @param template The template to insert parameters to
 * @param inputStream input stream of the file
 */
private void createTemplate(JasperTemplate template, InputStream inputStream) {
    try {
        JasperReport report = JasperCompileManager.compileReport(inputStream);
        String reportType = report.getProperty("reportType");
        if (reportType != null) {
            template.setType(reportType);
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(bos);
        out.writeObject(report);
        template.setData(bos.toByteArray());
    } catch (JRException ex) {
        throw new ValidationMessageException(ex, new Message(ERROR_REPORTING_FILE_INVALID, ex.getMessage()));
    } catch (IOException ex) {
        throw new ValidationMessageException(ex, new Message(ERROR_IO, ex.getMessage()));
    }
}
Also used : JRException(net.sf.jasperreports.engine.JRException) Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) JasperReport(net.sf.jasperreports.engine.JasperReport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 13 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryService method deletePhysicalInventory.

/**
 * Delete draft.
 *
 * @param id physical inventory id.
 */
public void deletePhysicalInventory(UUID id) {
    PhysicalInventory foundInventory = physicalInventoriesRepository.findOne(id);
    if (foundInventory != null) {
        checkPermission(foundInventory.getProgramId(), foundInventory.getFacilityId());
        if (!foundInventory.getIsDraft()) {
            throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED);
        }
        physicalInventoriesRepository.delete(foundInventory);
    } else {
        throw new ResourceNotFoundException(new Message(ERROR_PHYSICAL_INVENTORY_NOT_FOUND, id));
    }
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) ResourceNotFoundException(org.openlmis.stockmanagement.exception.ResourceNotFoundException)

Example 14 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseService method doAssign.

/**
 * Create a new assignment.
 *
 * @param assignment assignment
 * @param errorKey   error message key
 * @param repository assignment repository
 * @param <T>        assignment type
 * @return created assignment.
 */
protected <T extends SourceDestinationAssignment> ValidSourceDestinationDto doAssign(T assignment, String errorKey, SourceDestinationAssignmentRepository<T> repository) {
    UUID referenceId = assignment.getNode().getReferenceId();
    boolean isRefFacility = facilityRefDataService.exists(referenceId);
    boolean isOrganization = organizationRepository.exists(referenceId);
    if (isRefFacility || isOrganization) {
        assignment.setNode(findOrCreateNode(referenceId, isRefFacility));
        return createAssignmentDto(repository.save(assignment));
    }
    throw new ValidationMessageException(new Message(errorKey));
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) UUID(java.util.UUID)

Example 15 with Message

use of org.openlmis.stockmanagement.util.Message 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)

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