use of com.axelor.apps.account.db.FECImport in project axelor-open-suite by axelor.
the class FECImportController method setDefault.
public void setDefault(ActionRequest request, ActionResponse response) {
try {
FECImport fecImport = request.getContext().asType(FECImport.class);
fecImport.setUser(AuthUtils.getUser());
File configFile = File.createTempFile("input-config", ".xml");
InputStream bindFileInputStream = this.getClass().getResourceAsStream("/FEC-config/import-FEC-config.xml");
FileOutputStream outputStream = new FileOutputStream(configFile);
IOUtils.copy(bindFileInputStream, outputStream);
fecImport.setBindMetaFile(Beans.get(MetaFiles.class).upload(configFile));
FileUtils.forceDelete(configFile);
response.setValues(fecImport);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.FECImport 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