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);
}
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()));
}
}
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));
}
}
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));
}
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());
}
Aggregations