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