Search in sources :

Example 1 with FECImport

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);
    }
}
Also used : FECImport(com.axelor.apps.account.db.FECImport) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 2 with FECImport

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

FECImport (com.axelor.apps.account.db.FECImport)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ImportConfiguration (com.axelor.apps.base.db.ImportConfiguration)1 ImportHistory (com.axelor.apps.base.db.ImportHistory)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1