use of com.axelor.apps.stock.service.stockmove.print.ConformityCertificatePrintService in project axelor-open-suite by axelor.
the class StockMoveController method printConformityCertificate.
/**
* Called from stock move form view. Print conformity certificate for the given stock move.
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void printConformityCertificate(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
String fileLink;
String title;
ConformityCertificatePrintService conformityCertificatePrintService = Beans.get(ConformityCertificatePrintService.class);
if (!ObjectUtils.isEmpty(context.get("_ids"))) {
List<Long> ids = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
fileLink = conformityCertificatePrintService.printConformityCertificates(ids);
title = I18n.get("Conformity Certificates");
} else if (context.get("id") != null) {
StockMove stockMove = context.asType(StockMove.class);
title = conformityCertificatePrintService.getFileName(stockMove);
fileLink = conformityCertificatePrintService.printConformityCertificate(stockMove, ReportSettings.FORMAT_PDF);
logger.debug("Printing {}", title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.STOCK_MOVE_PRINT));
}
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations