Search in sources :

Example 16 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class AdvancedImportServiceImpl method checkSubFields.

private boolean checkSubFields(String[] subFields, int index, Property parentProp, String model) throws AxelorException, ClassNotFoundException {
    boolean isValid = true;
    if (index < subFields.length) {
        if (parentProp.getTarget() != null) {
            Mapper mapper = getMapper(parentProp.getTarget().getName());
            Property childProp = mapper.getProperty(subFields[index]);
            if (childProp == null) {
                throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.ADVANCED_IMPORT_2), subFields[index], parentProp.getName(), model));
            }
            if (childProp.getTarget() != null) {
                if (childProp.getType().name().equals("ONE_TO_MANY")) {
                    isValid = false;
                    return isValid;
                }
                if (index != subFields.length - 1) {
                    isValid = this.checkSubFields(subFields, index + 1, childProp, model);
                } else {
                    throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.ADVANCED_IMPORT_5), subFields[index], model));
                }
            }
        }
    }
    return isValid;
}
Also used : Mapper(com.axelor.db.mapper.Mapper) AxelorException(com.axelor.exception.AxelorException) Property(com.axelor.db.mapper.Property)

Example 17 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class AdvancedImportServiceImpl method setFileTabConfig.

protected void setFileTabConfig(String[] row, FileTab fileTab, int rowIndex) throws AxelorException {
    final String KEY_OBJECT = "object";
    final String KEY_IMPORT_TYPE = "importtype";
    final String KEY_SEARCH_FIELD_SET = "searchfieldset";
    final String KEY_ACTIONS = "actions";
    final String KEY_SEARCH_CALL = "search-call";
    final List<String> KEY_LIST = Arrays.asList(KEY_IMPORT_TYPE, KEY_OBJECT, KEY_SEARCH_FIELD_SET, KEY_ACTIONS, KEY_SEARCH_CALL);
    Map<String, String> tabConfigDataMap = getTabConfigDataMap(row, KEY_LIST);
    MetaModel model = metaModelRepo.findByName(tabConfigDataMap.get(KEY_OBJECT));
    fileTab.setMetaModel(model);
    if (tabConfigDataMap.containsKey(KEY_IMPORT_TYPE)) {
        Integer importType = this.getImportType(null, tabConfigDataMap.get(KEY_IMPORT_TYPE));
        fileTab.setImportType(importType);
        if (importType != FileFieldRepository.IMPORT_TYPE_NEW) {
            if (!tabConfigDataMap.containsKey(KEY_SEARCH_FIELD_SET) && !tabConfigDataMap.containsKey(KEY_SEARCH_CALL)) {
                throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ADVANCED_IMPORT_6), fileTab.getName());
            }
            if (tabConfigDataMap.containsKey(KEY_SEARCH_CALL)) {
                fileTab.setSearchCall(tabConfigDataMap.get(KEY_SEARCH_CALL));
            } else {
                searchFieldList = Arrays.asList(tabConfigDataMap.get(KEY_SEARCH_FIELD_SET).split("\\,"));
            }
        }
    }
    fileTab.setActions(tabConfigDataMap.get(KEY_ACTIONS));
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaModel(com.axelor.meta.db.MetaModel)

Example 18 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class AdvancedImportServiceImpl method applyObject.

private boolean applyObject(String[] row, FileTab fileTab, boolean isConfig, int linesToIgnore, boolean isTabConfig) throws AxelorException {
    int rowIndex = isConfig ? (isTabConfig ? 1 : 0) : 0;
    if (isTabConfig && row[0] != null) {
        rowIndex = 0;
        isTabWithoutConfig = true;
    }
    if (StringUtils.contains(row[rowIndex], "Object") && isConfig) {
        this.setFileTabConfig(row, fileTab, rowIndex);
    } else if ((StringUtils.containsIgnoreCase(row[0], "Object") || (row.length > 1 && StringUtils.contains(row[1], "Object"))) && !isConfig) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ADVANCED_IMPORT_3));
    } else if (isConfig && (!StringUtils.containsIgnoreCase(row[0], "Object") && (row.length > 1 && !StringUtils.contains(row[1], "Object")))) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ADVANCED_IMPORT_4));
    } else if (isConfig) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ADVANCED_IMPORT_NO_OBJECT), fileTab.getName());
    }
    if ((StringUtils.isBlank(row[0]) && (row.length > 1 && StringUtils.isBlank(row[1])) && linesToIgnore == 0)) {
        return false;
    }
    return true;
}
Also used : AxelorException(com.axelor.exception.AxelorException)

Example 19 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class AdvancedExportServiceImpl method getAdvancedExportQuery.

/**
 * This method split and join the all fields/columns which are selected by user and create the
 * query.
 *
 * @param advancedExport
 * @param criteria
 * @return
 * @throws AxelorException
 * @throws ClassNotFoundException
 */
@Override
public Query getAdvancedExportQuery(AdvancedExport advancedExport, List<Long> recordIds) throws AxelorException {
    StringBuilder selectFieldBuilder = new StringBuilder();
    StringBuilder orderByFieldBuilder = new StringBuilder();
    joinFieldSet.clear();
    selectionJoinFieldSet.clear();
    isNormalField = true;
    selectField = "";
    msi = 0;
    mt = 0;
    int col = 0;
    language = Optional.ofNullable(AuthUtils.getUser()).map(User::getLanguage).orElse(null);
    try {
        if (language == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get("Please select a language on user form."));
        }
        for (AdvancedExportLine advancedExportLine : advancedExport.getAdvancedExportLineList()) {
            String[] splitField = advancedExportLine.getTargetField().split("\\.");
            String alias = "Col_" + col;
            createQueryParts(splitField, 0, advancedExport.getMetaModel());
            selectFieldBuilder.append(aliasName + selectField + " AS " + alias + ",");
            if (advancedExportLine.getOrderBy()) {
                orderByFieldBuilder.append(alias + " " + advancedExportLine.getOrderByType() + ",");
            }
            selectField = "";
            aliasName = "";
            col++;
        }
        if (StringUtils.notEmpty(orderByFieldBuilder)) {
            orderByFieldBuilder.append("self.id asc,");
        }
    } catch (ClassNotFoundException e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
    return createQuery(createQueryBuilder(advancedExport, selectFieldBuilder, recordIds, orderByFieldBuilder));
}
Also used : AxelorException(com.axelor.exception.AxelorException) User(com.axelor.auth.db.User) AdvancedExportLine(com.axelor.apps.base.db.AdvancedExportLine)

Example 20 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class ExcelExportGenerator method close.

@Override
public void close() throws AxelorException {
    try {
        FileOutputStream fout = new FileOutputStream(exportFile);
        workbook.write(fout);
        fout.close();
    } catch (IOException e) {
        TraceBackService.trace(e);
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27