Search in sources :

Example 41 with MetaFile

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;
}
Also used : Path(java.nio.file.Path) Company(com.axelor.apps.base.db.Company) MetaFile(com.axelor.meta.db.MetaFile) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File)

Example 42 with MetaFile

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);
    }
}
Also used : UnitCostCalculationService(com.axelor.apps.production.service.costsheet.UnitCostCalculationService) UnitCostCalculation(com.axelor.apps.production.db.UnitCostCalculation) MetaFile(com.axelor.meta.db.MetaFile) IOException(java.io.IOException) AxelorException(com.axelor.exception.AxelorException) AppProductionService(com.axelor.apps.production.service.app.AppProductionService)

Example 43 with MetaFile

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();
}
Also used : MetaFiles(com.axelor.meta.MetaFiles) Invoice(com.axelor.apps.account.db.Invoice) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) ArrayList(java.util.ArrayList) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile)

Example 44 with MetaFile

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;
}
Also used : DMSFile(com.axelor.dms.db.DMSFile) MetaFile(com.axelor.meta.db.MetaFile)

Example 45 with MetaFile

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);
    }
}
Also used : MetaFiles(com.axelor.meta.MetaFiles) Message(com.axelor.apps.message.db.Message) IExceptionMessage(com.axelor.apps.message.exception.IExceptionMessage) MetaFile(com.axelor.meta.db.MetaFile) Transactional(com.google.inject.persist.Transactional)

Aggregations

MetaFile (com.axelor.meta.db.MetaFile)87 File (java.io.File)50 FileInputStream (java.io.FileInputStream)25 IOException (java.io.IOException)24 AxelorException (com.axelor.exception.AxelorException)21 MetaFiles (com.axelor.meta.MetaFiles)18 Transactional (com.google.inject.persist.Transactional)17 ArrayList (java.util.ArrayList)13 Path (java.nio.file.Path)12 InputStream (java.io.InputStream)10 ZipFile (java.util.zip.ZipFile)9 FileOutputStream (java.io.FileOutputStream)8 MetaFileRepository (com.axelor.meta.db.repo.MetaFileRepository)7 ImportHistory (com.axelor.apps.base.db.ImportHistory)6 DMSFile (com.axelor.dms.db.DMSFile)6 HashMap (java.util.HashMap)6 ZipEntry (java.util.zip.ZipEntry)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 App (com.axelor.apps.base.db.App)3