Search in sources :

Example 6 with DataReaderService

use of com.axelor.apps.tool.reader.DataReaderService in project axelor-open-suite by axelor.

the class DataImportServiceImpl method importData.

@Override
public MetaFile importData(AdvancedImport advancedImport) throws IOException, AxelorException, ClassNotFoundException {
    adapterMap = new HashMap<String, DataAdapter>();
    importContext = new HashMap<String, Object>();
    language = advancedImport.getLanguageSelect();
    dataDir = Files.createTempDir();
    String extension = Files.getFileExtension(advancedImport.getImportFile().getFileName());
    DataReaderService reader = dataReaderFactory.getDataReader(extension);
    reader.initialize(advancedImport.getImportFile(), advancedImport.getFileSeparator());
    List<CSVInput> inputs = this.process(reader, advancedImport);
    if (advancedImport.getAttachment() != null) {
        this.processAttachments(advancedImport.getAttachment());
    }
    MetaFile logFile = this.importData(inputs);
    FileUtils.forceDelete(dataDir);
    return logFile;
}
Also used : DataAdapter(com.axelor.data.adapter.DataAdapter) DataReaderService(com.axelor.apps.tool.reader.DataReaderService) CSVInput(com.axelor.data.csv.CSVInput) MetaFile(com.axelor.meta.db.MetaFile)

Aggregations

DataReaderService (com.axelor.apps.tool.reader.DataReaderService)6 AxelorException (com.axelor.exception.AxelorException)5 AdvancedImport (com.axelor.apps.base.db.AdvancedImport)2 FileField (com.axelor.apps.base.db.FileField)2 FileTab (com.axelor.apps.base.db.FileTab)2 FileFieldRepository (com.axelor.apps.base.db.repo.FileFieldRepository)2 DataReaderFactory (com.axelor.apps.tool.reader.DataReaderFactory)2 Inflector (com.axelor.common.Inflector)2 DataAdapter (com.axelor.data.adapter.DataAdapter)2 CSVInput (com.axelor.data.csv.CSVInput)2 Model (com.axelor.db.Model)2 Mapper (com.axelor.db.mapper.Mapper)2 Property (com.axelor.db.mapper.Property)2 TraceBackService (com.axelor.exception.service.TraceBackService)2 MetaFiles (com.axelor.meta.MetaFiles)2 MetaFile (com.axelor.meta.db.MetaFile)2 Strings (com.google.common.base.Strings)2 Files (com.google.common.io.Files)2 Inject (com.google.inject.Inject)2 File (java.io.File)2