Search in sources :

Example 1 with MetaFiles

use of com.axelor.meta.MetaFiles in project axelor-open-suite by axelor.

the class PrintServiceImpl method attachMetaFiles.

@Override
public void attachMetaFiles(Print print, Set<MetaFile> metaFiles) {
    Preconditions.checkNotNull(print.getId());
    if (metaFiles == null || metaFiles.isEmpty()) {
        return;
    }
    LOG.debug("Add metafiles to object {} : {}", Print.class.getName(), print.getId());
    for (MetaFile metaFile : metaFiles) {
        Beans.get(MetaFiles.class).attach(metaFile, metaFile.getFileName(), print);
    }
}
Also used : Print(com.axelor.apps.base.db.Print) MetaFiles(com.axelor.meta.MetaFiles) MetaFile(com.axelor.meta.db.MetaFile)

Example 2 with MetaFiles

use of com.axelor.meta.MetaFiles in project axelor-open-suite by axelor.

the class BatchEmploymentContractExport method employmentContractExportSilae.

@Transactional(rollbackOn = { Exception.class })
public MetaFile employmentContractExportSilae(List<EmploymentContract> employmentContractList) throws IOException {
    List<String[]> list = new ArrayList<>();
    for (EmploymentContract employmentContract : employmentContractList) {
        Beans.get(EmploymentContractService.class).employmentContractExportSilae(employmentContract, list);
        total++;
        incrementDone();
    }
    File tempFile = MetaFiles.createTempFile(Beans.get(EmploymentContractService.class).employmentContractExportName(), ".csv").toFile();
    String[] headers = Beans.get(EmploymentContractService.class).employmentContractExportHeaders();
    CsvTool.csvWriter(tempFile.getParent(), tempFile.getName(), ';', headers, list);
    MetaFiles metaFiles = Beans.get(MetaFiles.class);
    MetaFile metaFile = metaFiles.upload(tempFile);
    tempFile.delete();
    return metaFile;
}
Also used : EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) EmploymentContractService(com.axelor.apps.hr.service.EmploymentContractService) MetaFiles(com.axelor.meta.MetaFiles) ArrayList(java.util.ArrayList) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) Transactional(com.google.inject.persist.Transactional)

Example 3 with MetaFiles

use of com.axelor.meta.MetaFiles in project axelor-open-suite by axelor.

the class BankOrderServiceImpl method generateFile.

@Override
public File generateFile(BankOrder bankOrder) throws JAXBException, IOException, AxelorException, DatatypeConfigurationException {
    if (bankOrder.getBankOrderLineList() == null || bankOrder.getBankOrderLineList().isEmpty()) {
        return null;
    }
    bankOrder.setFileGenerationDateTime(LocalDateTime.now());
    BankOrderFileFormat bankOrderFileFormat = bankOrder.getBankOrderFileFormat();
    File file = null;
    switch(bankOrderFileFormat.getOrderFileFormatSelect()) {
        case BankOrderFileFormatRepository.FILE_FORMAT_PAIN_001_001_02_SCT:
            file = new BankOrderFile00100102Service(bankOrder).generateFile();
            break;
        case BankOrderFileFormatRepository.FILE_FORMAT_PAIN_001_001_03_SCT:
            file = new BankOrderFile00100103Service(bankOrder).generateFile();
            break;
        case BankOrderFileFormatRepository.FILE_FORMAT_PAIN_XXX_CFONB320_XCT:
            file = new BankOrderFileAFB320XCTService(bankOrder).generateFile();
            break;
        case BankOrderFileFormatRepository.FILE_FORMAT_PAIN_XXX_CFONB160_ICT:
            file = new BankOrderFileAFB160ICTService(bankOrder).generateFile();
            break;
        case BankOrderFileFormatRepository.FILE_FORMAT_PAIN_008_001_01_SDD:
            file = new BankOrderFile00800101Service(bankOrder, BankOrderFile008Service.SEPA_TYPE_CORE).generateFile();
            break;
        case BankOrderFileFormatRepository.FILE_FORMAT_PAIN_008_001_01_SBB:
            file = new BankOrderFile00800101Service(bankOrder, BankOrderFile008Service.SEPA_TYPE_SBB).generateFile();
            break;
        case BankOrderFileFormatRepository.FILE_FORMAT_PAIN_008_001_02_SDD:
            file = new BankOrderFile00800102Service(bankOrder, BankOrderFile008Service.SEPA_TYPE_CORE).generateFile();
            break;
        case BankOrderFileFormatRepository.FILE_FORMAT_PAIN_008_001_02_SBB:
            file = new BankOrderFile00800102Service(bankOrder, BankOrderFile008Service.SEPA_TYPE_SBB).generateFile();
            break;
        default:
            throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_FILE_UNKNOWN_FORMAT));
    }
    if (file == null) {
        throw new AxelorException(bankOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_ISSUE_DURING_FILE_GENERATION), bankOrder.getBankOrderSeq());
    }
    MetaFiles metaFiles = Beans.get(MetaFiles.class);
    try (InputStream is = new FileInputStream(file)) {
        metaFiles.attach(is, file.getName(), bankOrder);
        bankOrder.setGeneratedMetaFile(metaFiles.upload(file));
    }
    return file;
}
Also used : BankOrderFileAFB320XCTService(com.axelor.apps.bankpayment.service.bankorder.file.transfer.BankOrderFileAFB320XCTService) AxelorException(com.axelor.exception.AxelorException) MetaFiles(com.axelor.meta.MetaFiles) BankOrderFile00100102Service(com.axelor.apps.bankpayment.service.bankorder.file.transfer.BankOrderFile00100102Service) BankOrderFile00100103Service(com.axelor.apps.bankpayment.service.bankorder.file.transfer.BankOrderFile00100103Service) BankOrderFileAFB160ICTService(com.axelor.apps.bankpayment.service.bankorder.file.transfer.BankOrderFileAFB160ICTService) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BankOrderFile00800101Service(com.axelor.apps.bankpayment.service.bankorder.file.directdebit.BankOrderFile00800101Service) BankOrderFile00800102Service(com.axelor.apps.bankpayment.service.bankorder.file.directdebit.BankOrderFile00800102Service) BankOrderFileFormat(com.axelor.apps.bankpayment.db.BankOrderFileFormat) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with MetaFiles

use of com.axelor.meta.MetaFiles 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 5 with MetaFiles

use of com.axelor.meta.MetaFiles 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

MetaFiles (com.axelor.meta.MetaFiles)6 MetaFile (com.axelor.meta.db.MetaFile)5 File (java.io.File)4 ReportSettings (com.axelor.apps.report.engine.ReportSettings)2 AxelorException (com.axelor.exception.AxelorException)2 Transactional (com.google.inject.persist.Transactional)2 ArrayList (java.util.ArrayList)2 Invoice (com.axelor.apps.account.db.Invoice)1 BankOrderFileFormat (com.axelor.apps.bankpayment.db.BankOrderFileFormat)1 BankOrderFile00800101Service (com.axelor.apps.bankpayment.service.bankorder.file.directdebit.BankOrderFile00800101Service)1 BankOrderFile00800102Service (com.axelor.apps.bankpayment.service.bankorder.file.directdebit.BankOrderFile00800102Service)1 BankOrderFile00100102Service (com.axelor.apps.bankpayment.service.bankorder.file.transfer.BankOrderFile00100102Service)1 BankOrderFile00100103Service (com.axelor.apps.bankpayment.service.bankorder.file.transfer.BankOrderFile00100103Service)1 BankOrderFileAFB160ICTService (com.axelor.apps.bankpayment.service.bankorder.file.transfer.BankOrderFileAFB160ICTService)1 BankOrderFileAFB320XCTService (com.axelor.apps.bankpayment.service.bankorder.file.transfer.BankOrderFileAFB320XCTService)1 Print (com.axelor.apps.base.db.Print)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 EmploymentContract (com.axelor.apps.hr.db.EmploymentContract)1 EmploymentContractService (com.axelor.apps.hr.service.EmploymentContractService)1 Message (com.axelor.apps.message.db.Message)1