Search in sources :

Example 6 with ImportConfiguration

use of com.axelor.apps.base.db.ImportConfiguration in project axelor-open-suite by axelor.

the class ImportConfigurationController method run.

public void run(ActionRequest request, ActionResponse response) {
    ImportConfiguration importConfiguration = request.getContext().asType(ImportConfiguration.class);
    try {
        ImportHistory importHistory = Beans.get(ImportService.class).run(importConfiguration);
        response.setValue("statusSelect", ImportConfigurationRepository.STATUS_COMPLETED);
        response.setValue("endDateTime", Beans.get(AppBaseService.class).getTodayDateTime().toLocalDateTime());
        response.setAttr("importHistoryList", "value:add", importHistory);
        File readFile = MetaFiles.getPath(importHistory.getLogMetaFile()).toFile();
        response.setNotify(FileUtils.readFileToString(readFile, StandardCharsets.UTF_8).replaceAll("(\r\n|\n\r|\r|\n)", "<br />"));
    } catch (Exception e) {
        response.setValue("statusSelect", ImportConfigurationRepository.STATUS_ERROR);
        TraceBackService.trace(response, e);
    }
}
Also used : ImportService(com.axelor.apps.base.service.imports.ImportService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) ImportConfiguration(com.axelor.apps.base.db.ImportConfiguration) File(java.io.File) ImportHistory(com.axelor.apps.base.db.ImportHistory)

Example 7 with ImportConfiguration

use of com.axelor.apps.base.db.ImportConfiguration in project axelor-open-suite by axelor.

the class FECImportController method runImport.

public void runImport(ActionRequest request, ActionResponse response) {
    try {
        FECImport fecImport = request.getContext().asType(FECImport.class);
        fecImport = Beans.get(FECImportRepository.class).find(fecImport.getId());
        ImportConfiguration importConfig = new ImportConfiguration();
        importConfig.setBindMetaFile(fecImport.getBindMetaFile());
        importConfig.setDataMetaFile(Beans.get(MetaFiles.class).upload(new FileInputStream(MetaFiles.getPath(fecImport.getDataMetaFile()).toFile()), "FEC.csv"));
        ImportHistory importHistory = Beans.get(FactoryImporter.class).createImporter(importConfig).run();
        File readFile = MetaFiles.getPath(importHistory.getLogMetaFile()).toFile();
        response.setNotify(FileUtils.readFileToString(readFile, StandardCharsets.UTF_8).replaceAll("(\r\n|\n\r|\r|\n)", "<br />"));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : FECImport(com.axelor.apps.account.db.FECImport) ImportConfiguration(com.axelor.apps.base.db.ImportConfiguration) File(java.io.File) FileInputStream(java.io.FileInputStream) ImportHistory(com.axelor.apps.base.db.ImportHistory)

Example 8 with ImportConfiguration

use of com.axelor.apps.base.db.ImportConfiguration in project axelor-open-suite by axelor.

the class LeadController method getLeadImportConfig.

public void getLeadImportConfig(ActionRequest request, ActionResponse response) {
    ImportConfiguration leadImportConfig = Beans.get(ImportConfigurationRepository.class).all().filter("self.bindMetaFile.fileName = ?1", ImportLeadConfiguration.IMPORT_LEAD_CONFIG).fetchOne();
    logger.debug("ImportConfig for lead: {}", leadImportConfig);
    if (leadImportConfig == null) {
        response.setFlash(I18n.get(IExceptionMessage.LEAD_4));
    } else {
        response.setView(ActionView.define(I18n.get(IExceptionMessage.LEAD_5)).model("com.axelor.apps.base.db.ImportConfiguration").add("form", "import-configuration-form").param("popup", "reload").param("forceEdit", "true").param("popup-save", "false").param("show-toolbar", "false").context("_showRecord", leadImportConfig.getId().toString()).map());
    }
}
Also used : ImportConfigurationRepository(com.axelor.apps.base.db.repo.ImportConfigurationRepository) ImportConfiguration(com.axelor.apps.base.db.ImportConfiguration)

Example 9 with ImportConfiguration

use of com.axelor.apps.base.db.ImportConfiguration in project axelor-open-suite by axelor.

the class ImportLeadConfiguration method importFiles.

public Object importFiles(Object bean, Map<String, Object> values) {
    assert bean instanceof ImportConfiguration;
    final Path path = (Path) values.get("__path__");
    ImportConfiguration importConfig = (ImportConfiguration) bean;
    try {
        File file = path.resolve(FILES_DIR + File.separator + IMPORT_LEAD_CONFIG).toFile();
        importConfig.setBindMetaFile(metaFiles.upload(file));
        file = path.resolve(FILES_DIR + File.separator + IMPORT_LEAD_CSV).toFile();
        importConfig.setDataMetaFile(metaFiles.upload(file));
    } catch (IOException e) {
        log.debug("Error importing lead import config", e);
        return null;
    }
    return importConfig;
}
Also used : Path(java.nio.file.Path) ImportConfiguration(com.axelor.apps.base.db.ImportConfiguration) IOException(java.io.IOException) File(java.io.File)

Aggregations

ImportConfiguration (com.axelor.apps.base.db.ImportConfiguration)9 ImportHistory (com.axelor.apps.base.db.ImportHistory)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 FECImport (com.axelor.apps.account.db.FECImport)1 ICalendar (com.axelor.apps.base.db.ICalendar)1 ImportConfigurationRepository (com.axelor.apps.base.db.repo.ImportConfigurationRepository)1 ICalendarService (com.axelor.apps.base.ical.ICalendarService)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 ImportService (com.axelor.apps.base.service.imports.ImportService)1 AxelorException (com.axelor.exception.AxelorException)1 MetaFile (com.axelor.meta.db.MetaFile)1 UnknownHostException (java.net.UnknownHostException)1 Path (java.nio.file.Path)1