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;
}
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;
}
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();
}
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);
}
}
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);
}
}
Aggregations