Search in sources :

Example 6 with AdvancedImport

use of com.axelor.apps.base.db.AdvancedImport in project axelor-open-suite by axelor.

the class AdvancedImportController method resetImport.

public void resetImport(ActionRequest request, ActionResponse response) {
    try {
        AdvancedImport advancedImport = request.getContext().asType(AdvancedImport.class);
        if (advancedImport.getId() != null) {
            advancedImport = Beans.get(AdvancedImportRepository.class).find(advancedImport.getId());
        }
        boolean isReset = Beans.get(AdvancedImportService.class).resetImport(advancedImport);
        if (isReset) {
            response.setFlash(I18n.get(IExceptionMessage.ADVANCED_IMPORT_RESET));
            response.setSignal("refresh-app", true);
        } else {
            response.setFlash(I18n.get(IExceptionMessage.ADVANCED_IMPORT_NO_RESET));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AdvancedImportService(com.axelor.apps.base.service.advanced.imports.AdvancedImportService) AdvancedImport(com.axelor.apps.base.db.AdvancedImport) AxelorException(com.axelor.exception.AxelorException)

Example 7 with AdvancedImport

use of com.axelor.apps.base.db.AdvancedImport in project axelor-open-suite by axelor.

the class AdvancedImportBaseRepository method copy.

@Override
public AdvancedImport copy(AdvancedImport entity, boolean deep) {
    AdvancedImport copy = super.copy(entity, deep);
    copy.setStatusSelect(0);
    copy.setErrorLog(null);
    copy.setImportFile(null);
    return copy;
}
Also used : AdvancedImport(com.axelor.apps.base.db.AdvancedImport)

Example 8 with AdvancedImport

use of com.axelor.apps.base.db.AdvancedImport in project axelor-open-suite by axelor.

the class ValidatorService method validate.

@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public boolean validate(DataReaderService reader, AdvancedImport advancedImport) throws IOException, ClassNotFoundException, AxelorException {
    boolean isLog = false;
    String[] sheets = reader.getSheetNames();
    this.validateTab(sheets, advancedImport);
    boolean isConfig = advancedImport.getIsConfigInFile();
    boolean isTabConfig = advancedImport.getIsFileTabConfigAdded();
    sortFileTabList(advancedImport.getFileTabList());
    for (FileTab fileTab : advancedImport.getFileTabList()) {
        if (!Arrays.stream(sheets).anyMatch(sheet -> sheet.equals(fileTab.getName()))) {
            continue;
        }
        fieldMap = new HashMap<>();
        titleMap = new HashMap<>();
        String sheet = fileTab.getName();
        logService.initialize(sheet);
        this.validateModel(fileTab);
        int tabConfigRowCount = 0;
        int totalLines = reader.getTotalLines(fileTab.getName());
        if (isConfig) {
            String[] objectRow = reader.read(sheet, 0, 0);
            if (isTabConfig) {
                tabConfigRowCount = advancedImportService.getTabConfigRowCount(sheet, reader, totalLines, objectRow);
            }
            this.validateObject(objectRow, fileTab, isTabConfig);
        }
        this.validateSearch(fileTab);
        this.validateObjectRequiredFields(fileTab);
        this.validateFieldAndData(reader, sheet, fileTab, isConfig, isTabConfig, tabConfigRowCount);
        this.validateActions(fileTab);
        if (fileTab.getValidationLog() != null) {
            fileTab.setValidationLog(null);
        }
        if (logService.isLogGenerated()) {
            logService.write();
            logService.close();
            File logFile = logService.getLogFile();
            fileTab.setValidationLog(metaFiles.upload(new FileInputStream(logFile), sheet + "_err.xlsx"));
            logFile.delete();
            isLog = true;
        } else {
            createCustomObjectSet(fileTab.getClass().getName(), fileTab.getMetaModel().getFullName(), 0);
            createCustomButton(fileTab.getClass().getName(), fileTab.getMetaModel().getFullName(), 1);
        }
        fileTabRepo.save(fileTab);
    }
    return isLog;
}
Also used : MetaJsonFieldRepository(com.axelor.meta.db.repo.MetaJsonFieldRepository) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) Property(com.axelor.db.mapper.Property) HashMap(java.util.HashMap) Mapper(com.axelor.db.mapper.Mapper) StringUtils(org.apache.commons.lang3.StringUtils) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) FileField(com.axelor.apps.base.db.FileField) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Files(com.google.common.io.Files) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) LocalTime(java.time.LocalTime) I18n(com.axelor.i18n.I18n) BigInteger(java.math.BigInteger) Inflector(com.axelor.common.Inflector) MetaJsonField(com.axelor.meta.db.MetaJsonField) DataReaderFactory(com.axelor.apps.tool.reader.DataReaderFactory) MetaFiles(com.axelor.meta.MetaFiles) Model(com.axelor.db.Model) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MetaField(com.axelor.meta.db.MetaField) BufferedWriter(java.io.BufferedWriter) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) FileTabRepository(com.axelor.apps.base.db.repo.FileTabRepository) File(java.io.File) DataReaderService(com.axelor.apps.tool.reader.DataReaderService) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) FileFieldRepository(com.axelor.apps.base.db.repo.FileFieldRepository) IExceptionMessage(com.axelor.apps.base.exceptions.IExceptionMessage) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) FileTab(com.axelor.apps.base.db.FileTab) AdvancedImport(com.axelor.apps.base.db.AdvancedImport) FileTab(com.axelor.apps.base.db.FileTab) File(java.io.File) FileInputStream(java.io.FileInputStream) Transactional(com.google.inject.persist.Transactional)

Aggregations

AdvancedImport (com.axelor.apps.base.db.AdvancedImport)8 AxelorException (com.axelor.exception.AxelorException)6 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 AdvancedImportService (com.axelor.apps.base.service.advanced.imports.AdvancedImportService)2 DataReaderFactory (com.axelor.apps.tool.reader.DataReaderFactory)2 DataReaderService (com.axelor.apps.tool.reader.DataReaderService)2 Inflector (com.axelor.common.Inflector)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 FileTabRepository (com.axelor.apps.base.db.repo.FileTabRepository)1 IExceptionMessage (com.axelor.apps.base.exceptions.IExceptionMessage)1