Search in sources :

Example 1 with DataAdapter

use of com.axelor.data.adapter.DataAdapter 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)

Example 2 with DataAdapter

use of com.axelor.data.adapter.DataAdapter in project axelor-open-suite by axelor.

the class DataImportServiceImpl method createAdapter.

private DataAdapter createAdapter(String typeName, String format) {
    DataAdapter adapter = adapterMap.get(format);
    if (adapter == null) {
        adapter = new DataAdapter(("Adapter" + counter), JavaTimeAdapter.class, "type", typeName, "format", format);
        adapterMap.put(format, adapter);
        counter++;
    }
    return adapter;
}
Also used : JavaTimeAdapter(com.axelor.data.adapter.JavaTimeAdapter) DataAdapter(com.axelor.data.adapter.DataAdapter)

Example 3 with DataAdapter

use of com.axelor.data.adapter.DataAdapter in project axelor-open-suite by axelor.

the class DataImportServiceImpl method getAdapter.

private String getAdapter(String type, String dateFormat) {
    String adapter = null;
    switch(type) {
        case "LocalDate":
            DataAdapter dateAdapter = this.createAdapter("LocalDate", dateFormat);
            adapter = dateAdapter.getName();
            break;
        case "LocalDateTime":
            DataAdapter dateTimeAdapter = this.createAdapter("LocalDateTime", dateFormat);
            adapter = dateTimeAdapter.getName();
            break;
        case "LocalTime":
            DataAdapter timeAdapter = this.createAdapter("LocalTime", dateFormat);
            adapter = timeAdapter.getName();
            break;
        case "ZoneDateTime":
            DataAdapter zonedDateTimeAdapter = this.createAdapter("ZonedDateTime", dateFormat);
            adapter = zonedDateTimeAdapter.getName();
            break;
    }
    return adapter;
}
Also used : DataAdapter(com.axelor.data.adapter.DataAdapter)

Aggregations

DataAdapter (com.axelor.data.adapter.DataAdapter)3 DataReaderService (com.axelor.apps.tool.reader.DataReaderService)1 JavaTimeAdapter (com.axelor.data.adapter.JavaTimeAdapter)1 CSVInput (com.axelor.data.csv.CSVInput)1 MetaFile (com.axelor.meta.db.MetaFile)1