use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ImportCompany method importCompany.
public Object importCompany(Object bean, Map<String, Object> values) {
assert bean instanceof Company;
Company company = (Company) bean;
String fileName = (String) values.get("logo_fileName");
if (!StringUtils.isEmpty(fileName)) {
final Path path = (Path) values.get("__path__");
try {
final File image = path.resolve(fileName).toFile();
if (image != null && image.isFile()) {
final MetaFile metaFile = metaFiles.upload(image);
company.setLogo(metaFile);
}
} catch (Exception e) {
LOG.error("Error when importing company : {}", e);
}
}
return company;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class UnitCostCalculationController method exportUnitCostCalc.
public void exportUnitCostCalc(ActionRequest request, ActionResponse response) throws IOException {
try {
UnitCostCalculation unitCostCalculation = request.getContext().asType(UnitCostCalculation.class);
unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculation.getId());
String fileName = unitCostCalculation.getUnitCostCalcSeq() + "-" + Beans.get(AppProductionService.class).getTodayDateTime().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
MetaFile metaFile = Beans.get(UnitCostCalculationService.class).exportUnitCostCalc(unitCostCalculation, fileName);
response.setView(ActionView.define(fileName).add("html", "ws/rest/com.axelor.meta.db.MetaFile/" + metaFile.getId() + "/content/download?v=" + metaFile.getVersion()).map());
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class InvoicingProjectService method generateAnnex.
public void generateAnnex(InvoicingProject invoicingProject) throws AxelorException, IOException {
String title = I18n.get("InvoicingProjectAnnex") + "-" + Beans.get(AppBaseService.class).getTodayDateTime().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDDHHMM));
ReportSettings reportSettings = ReportFactory.createReport(IReport.INVOICING_PROJECT_ANNEX, title).addParam("InvProjectId", invoicingProject.getId()).addParam("Timezone", getTimezone(invoicingProject)).addParam("Locale", ReportSettings.getPrintingLocale(null));
if (invoicingProject.getAttachAnnexToInvoice()) {
List<File> fileList = new ArrayList<>();
MetaFiles metaFiles = Beans.get(MetaFiles.class);
Invoice invoice = invoicingProject.getInvoice();
fileList.add(Beans.get(InvoicePrintServiceImpl.class).print(invoice, null, ReportSettings.FORMAT_PDF, null));
fileList.add(reportSettings.generate().getFile());
MetaFile metaFile = metaFiles.upload(PdfTool.mergePdf(fileList));
metaFile.setFileName(title + ".pdf");
metaFiles.attach(metaFile, null, invoicingProject);
return;
}
reportSettings.toAttach(invoicingProject).generate();
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class TemplateMessageServiceImpl method getMetaFiles.
@Override
public Set<MetaFile> getMetaFiles(Template template, Templates templates, Map<String, Object> templatesContext) throws AxelorException, IOException {
List<DMSFile> metaAttachments = Query.of(DMSFile.class).filter("self.relatedId = ?1 AND self.relatedModel = ?2", template.getId(), EntityHelper.getEntityClass(template).getName()).fetch();
Set<MetaFile> metaFiles = Sets.newHashSet();
for (DMSFile metaAttachment : metaAttachments) {
if (!metaAttachment.getIsDirectory())
metaFiles.add(metaAttachment.getMetaFile());
}
log.debug("Metafile to attach: {}", metaFiles);
return metaFiles;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class MessageServiceImpl method attachMetaFiles.
@Override
@Transactional
public void attachMetaFiles(Message message, Set<MetaFile> metaFiles) {
Preconditions.checkNotNull(message.getId());
if (metaFiles == null || metaFiles.isEmpty()) {
return;
}
log.debug("Add metafiles to object {}:{}", Message.class.getName(), message.getId());
for (MetaFile metaFile : metaFiles) {
Beans.get(MetaFiles.class).attach(metaFile, metaFile.getFileName(), message);
}
}
Aggregations