Search in sources :

Example 1 with DataConfigLine

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

the class ObjectDataAnonymizeServiceImpl method anonymize.

public void anonymize(ObjectDataConfig objectDataConfig, Long recordId) throws AxelorException {
    try {
        String rootModel = objectDataConfig.getModelSelect();
        for (DataConfigLine line : objectDataConfig.getDataConfigLineList()) {
            String path = line.getTypeSelect() == DataConfigLineRepository.TYPE_PATH ? line.getMetaFieldPath().getName() : line.getPath();
            Class<? extends Model> modelClass = ObjectDataCommonService.findModelClass(line.getMetaModel());
            Query<? extends Model> query = ObjectDataCommonService.createQuery(recordId, line, modelClass);
            List<? extends Model> data = query.fetch();
            Mapper mapper = Mapper.of(modelClass);
            int reset = line.getResetPathSelect();
            if (reset != DataConfigLineRepository.RESET_NONE && line.getTypeSelect() == DataConfigLineRepository.TYPE_PATH) {
                if (reset == DataConfigLineRepository.RESET_DELETE) {
                    deleteLink(mapper, path, data);
                } else {
                    replaceLink(mapper, path, data, rootModel, line.getRecordSelectId());
                }
            }
            deleteFields(line.getToDeleteMetaFieldSet(), mapper, data);
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getMessage());
    }
}
Also used : Mapper(com.axelor.db.mapper.Mapper) AxelorException(com.axelor.exception.AxelorException) DataConfigLine(com.axelor.apps.base.db.DataConfigLine) AxelorException(com.axelor.exception.AxelorException)

Example 2 with DataConfigLine

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

the class ObjectDataExportServiceImpl method createData.

private Map<String, List<String[]>> createData(ObjectDataConfig objectDataConfig, Long recordId, String language) throws ClassNotFoundException {
    Map<String, List<String[]>> data = new HashMap<>();
    for (DataConfigLine line : objectDataConfig.getDataConfigLineList()) {
        MetaModel metaModel = line.getMetaModel();
        logger.debug("Create data for: {}", metaModel.getName());
        Class<? extends Model> modelClass = ObjectDataCommonService.findModelClass(metaModel);
        Query<? extends Model> query = ObjectDataCommonService.createQuery(recordId, line, modelClass);
        ResourceBundle bundle = ObjectDataCommonService.getResourceBundle(language);
        String[][] fieldsData = createFieldsData(line.getToExportMetaFieldSet(), bundle);
        Map<String, String> selectMap = getSelectMap(Mapper.of(modelClass));
        List<String[]> dataList = fetchData(fieldsData, query, selectMap, bundle);
        data.put(line.getTabName(), dataList);
    }
    return data;
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) DataConfigLine(com.axelor.apps.base.db.DataConfigLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ResourceBundle(java.util.ResourceBundle)

Aggregations

DataConfigLine (com.axelor.apps.base.db.DataConfigLine)2 Mapper (com.axelor.db.mapper.Mapper)1 AxelorException (com.axelor.exception.AxelorException)1 MetaModel (com.axelor.meta.db.MetaModel)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1