Search in sources :

Example 46 with MetaFile

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

the class CampaignController method sendReminderEmail.

public void sendReminderEmail(ActionRequest request, ActionResponse response) {
    Campaign campaign = request.getContext().asType(Campaign.class);
    try {
        campaign = Beans.get(CampaignRepository.class).find(campaign.getId());
        if (campaign.getInvitedPartnerSet().isEmpty() && campaign.getInvitedPartnerSet().isEmpty()) {
            response.setFlash(I18n.get(IExceptionMessage.REMINDER_EMAIL1));
            return;
        }
        MetaFile logFile = Beans.get(CampaignService.class).sendReminderEmail(campaign);
        if (logFile == null) {
            response.setFlash(I18n.get(IExceptionMessage.EMAIL_SUCCESS));
        } else {
            response.setFlash(I18n.get(IExceptionMessage.EMAIL_ERROR2));
        }
        response.setValue("emailLog", logFile);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : CampaignService(com.axelor.apps.marketing.service.CampaignService) Campaign(com.axelor.apps.marketing.db.Campaign) MetaFile(com.axelor.meta.db.MetaFile)

Example 47 with MetaFile

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

the class CampaignController method sendEmail.

public void sendEmail(ActionRequest request, ActionResponse response) {
    Campaign campaign = request.getContext().asType(Campaign.class);
    try {
        campaign = Beans.get(CampaignRepository.class).find(campaign.getId());
        if (campaign.getLeadSet().isEmpty() && campaign.getPartnerSet().isEmpty()) {
            response.setFlash(I18n.get(IExceptionMessage.EMPTY_TARGET));
            return;
        }
        MetaFile logFile = Beans.get(CampaignService.class).sendEmail(campaign);
        if (logFile == null) {
            response.setFlash(I18n.get(IExceptionMessage.EMAIL_SUCCESS));
        } else {
            response.setFlash(I18n.get(IExceptionMessage.EMAIL_ERROR2));
        }
        response.setValue("emailLog", logFile);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : CampaignService(com.axelor.apps.marketing.service.CampaignService) Campaign(com.axelor.apps.marketing.db.Campaign) MetaFile(com.axelor.meta.db.MetaFile)

Example 48 with MetaFile

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

the class DeclarationOfExchangesExporter method attach.

protected String attach(String path) {
    DMSFile dmsFile;
    try (InputStream is = new FileInputStream(path)) {
        dmsFile = Beans.get(MetaFiles.class).attach(is, getFileName(), declarationOfExchanges);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    MetaFile metaFile = dmsFile.getMetaFile();
    return String.format("ws/rest/com.axelor.meta.db.MetaFile/%d/content/download?v=%d/%s", metaFile.getId(), metaFile.getVersion(), path);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DMSFile(com.axelor.dms.db.DMSFile) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MetaFile(com.axelor.meta.db.MetaFile) FileInputStream(java.io.FileInputStream)

Example 49 with MetaFile

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

the class ExportObserver method onExport.

void onExport(@Observes @Named(RequestEvent.EXPORT) PostRequest event) throws IOException {
    List<GlobalTrackingConfigurationLine> gtcLines = Beans.get(AppBaseService.class).getAppBase().getGlobalTrackingConfigurationLines();
    if (CollectionUtils.isEmpty(gtcLines)) {
        return;
    }
    MetaModel model = Beans.get(MetaModelRepository.class).all().filter("self.fullName = ?", event.getRequest().getBeanClass().getName()).fetchOne();
    if (gtcLines.stream().anyMatch(l -> l.getMetaModel().equals(model) && l.getTrackExport())) {
        @SuppressWarnings("unchecked") final Map<String, Object> data = (Map<String, Object>) event.getResponse().getData();
        if (data == null || data.get("fileName") == null) {
            return;
        }
        final String fileName = (String) data.get("fileName");
        final Path filePath = MetaFiles.findTempFile(fileName);
        MetaFile mf = new MetaFile();
        mf.setFileName(fileName);
        Beans.get(MetaFiles.class).upload(new FileInputStream(filePath.toFile()), mf);
        Beans.get(GlobalTrackingLogService.class).createExportLog(model, mf);
    }
}
Also used : Path(java.nio.file.Path) MetaFiles(com.axelor.meta.MetaFiles) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) FileInputStream(java.io.FileInputStream) MetaModel(com.axelor.meta.db.MetaModel) GlobalTrackingConfigurationLine(com.axelor.apps.base.db.GlobalTrackingConfigurationLine) MetaFile(com.axelor.meta.db.MetaFile) Map(java.util.Map)

Example 50 with MetaFile

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

the class DmsImportWizardController method importDMS.

public void importDMS(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        @SuppressWarnings("unchecked") Map<String, Object> metaFileMap = (Map<String, Object>) request.getContext().get("metaFile");
        MetaFile metaFile = metaFileRepo.find(Long.parseLong(metaFileMap.get("id").toString()));
        dmsImportWizardService.importDMS(metaFile);
        response.setReload(true);
    } catch (AxelorException e) {
        response.setFlash(e.getMessage());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaFile(com.axelor.meta.db.MetaFile) Map(java.util.Map)

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