Search in sources :

Example 1 with ImportHistory

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

the class ImportCityServiceImpl method importCityData.

/**
 * Imports city data
 *
 * @param configXmlFile
 * @param dataCsvFile
 * @return
 */
protected ImportHistory importCityData(File configXmlFile, File dataCsvFile) {
    ImportHistory importHistory = null;
    try {
        ImportConfiguration importConfiguration = new ImportConfiguration();
        importConfiguration.setBindMetaFile(metaFiles.upload(configXmlFile));
        importConfiguration.setDataMetaFile(metaFiles.upload(dataCsvFile));
        importHistory = factoryImporter.createImporter(importConfiguration).run();
    } catch (Exception e) {
        TraceBackService.trace(e);
        printWriter.append(e.getLocalizedMessage() + " at " + e.getStackTrace()[0] + "\n");
    }
    return importHistory;
}
Also used : ImportConfiguration(com.axelor.apps.base.db.ImportConfiguration) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ImportHistory(com.axelor.apps.base.db.ImportHistory)

Example 2 with ImportHistory

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

the class ImportCityServiceImpl method importFromGeonamesManualConfig.

/**
 * Imports cities from a custom Geonames file. This is useful for the countries not present in the
 * predefined list.
 *
 * @param map
 * @param typeSelect
 * @return
 */
public Map<String, Object> importFromGeonamesManualConfig(Map<String, Object> map, String typeSelect) {
    List<ImportHistory> importHistoryList = new ArrayList<>();
    Map<String, Object> importCityMap = new HashMap<>();
    try {
        File tempDir = Files.createTempDir();
        errorFile = new File(tempDir.getAbsolutePath(), "Error-File.txt");
        printWriter = new PrintWriter(errorFile);
        if (map != null) {
            MetaFile dataFile = metaFileRepo.find(Long.parseLong(map.get("id").toString()));
            importHistoryList.add(this.importCity(typeSelect + "-dump", dataFile));
        }
    } catch (Exception e) {
        printWriter.append(e.getLocalizedMessage() + " at " + e.getStackTrace()[0] + "\n");
    }
    printWriter.close();
    importCityMap.put("importHistoryList", importHistoryList);
    importCityMap.put("errorFile", this.getMetaFile(errorFile));
    return importCityMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetaFile(com.axelor.meta.db.MetaFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ImportHistory(com.axelor.apps.base.db.ImportHistory) PrintWriter(java.io.PrintWriter)

Example 3 with ImportHistory

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

the class ImportDemoDataServiceImpl method importFileData.

private MetaFile importFileData(File dataFile, File configFile, String dataFileName, String configFileName) throws IOException, AxelorException {
    ImportConfiguration config = new ImportConfiguration();
    MetaFile configMetaFile = metaFiles.upload(new FileInputStream(configFile), configFileName + ".xml");
    MetaFile dataMetaFile = metaFiles.upload(new FileInputStream(dataFile), dataFileName + ".csv");
    config.setBindMetaFile(configMetaFile);
    config.setDataMetaFile(dataMetaFile);
    config.setTypeSelect("csv");
    ImportHistory importHistory = factoryImporter.createImporter(config).run();
    MetaFiles.getPath(configMetaFile).toFile().delete();
    MetaFiles.getPath(dataMetaFile).toFile().delete();
    return importHistory.getLogMetaFile();
}
Also used : ImportConfiguration(com.axelor.apps.base.db.ImportConfiguration) MetaFile(com.axelor.meta.db.MetaFile) FileInputStream(java.io.FileInputStream) ImportHistory(com.axelor.apps.base.db.ImportHistory)

Example 4 with ImportHistory

use of com.axelor.apps.base.db.ImportHistory 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 5 with ImportHistory

use of com.axelor.apps.base.db.ImportHistory 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)

Aggregations

ImportHistory (com.axelor.apps.base.db.ImportHistory)10 MetaFile (com.axelor.meta.db.MetaFile)7 File (java.io.File)7 ZipFile (java.util.zip.ZipFile)5 ImportConfiguration (com.axelor.apps.base.db.ImportConfiguration)4 AxelorException (com.axelor.exception.AxelorException)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 FECImport (com.axelor.apps.account.db.FECImport)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 ImportService (com.axelor.apps.base.service.imports.ImportService)1 FileWriter (java.io.FileWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1