Search in sources :

Example 16 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class WkfModelServiceImpl method getMetaModelRecordFilter.

@SuppressWarnings("unchecked")
private Object[] getMetaModelRecordFilter(WkfTaskConfig config, String modelName, User user) {
    MetaModel metaModel = metaModelRepo.findByName(modelName);
    String model = metaModel.getFullName();
    String filter = "self.processInstanceId IN (:processInstanceIds)";
    Class<Model> klass = null;
    try {
        klass = (Class<Model>) Class.forName(model);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    if (user != null) {
        String path = config.getUserPath();
        Property property = Mapper.of(klass).getProperty(path.split("\\.")[0]);
        if (property == null) {
            filter += " AND self.attrs." + path + ".id = '" + user.getId() + "'";
        } else {
            filter += " AND self." + path + ".id = " + user.getId();
        }
    }
    return new Object[] { klass, filter };
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) WkfModel(com.axelor.apps.bpm.db.WkfModel) MetaModel(com.axelor.meta.db.MetaModel) Model(com.axelor.db.Model) Property(com.axelor.db.mapper.Property)

Example 17 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class WkfModelController method showRecord.

@SuppressWarnings("unchecked")
public void showRecord(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        String status = context.get("status").toString();
        String tableName = null;
        String jsonModel = null;
        ActionViewBuilder actionViewBuilder = null;
        if (context.get("metaModel") != null) {
            Long id = Long.parseLong(((Map<String, Object>) context.get("metaModel")).get("id").toString());
            MetaModel metaModel = Beans.get(MetaModelRepository.class).find(id);
            tableName = metaModel.getTableName();
            actionViewBuilder = createActionBuilder(status, metaModel);
        } else if (context.get("metaJsonModel") != null) {
            Long id = Long.parseLong(((Map<String, Object>) context.get("metaJsonModel")).get("id").toString());
            MetaJsonModel metaJsonModel = Beans.get(MetaJsonModelRepository.class).find(id);
            jsonModel = metaJsonModel.getName();
            tableName = MetaJsonRecord.class.getAnnotation(Table.class).name();
            actionViewBuilder = createActionBuilder(status, metaJsonModel);
        }
        List<Long> idList = getRecordIds(context, tableName, jsonModel);
        response.setView(actionViewBuilder.context("ids", !idList.isEmpty() ? idList : 0).map());
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) Table(javax.persistence.Table) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) MetaModel(com.axelor.meta.db.MetaModel) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 18 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class WkfModelController method viewNewRecord.

private ActionViewBuilder viewNewRecord(String modelName, boolean isMetaModel) {
    ActionViewBuilder actionViewBuilder = null;
    if (isMetaModel) {
        MetaModel metaModel = Beans.get(MetaModelRepository.class).findByName(modelName);
        String viewPrefix = Inflector.getInstance().dasherize(metaModel.getName());
        actionViewBuilder = ActionView.define(metaModel.getName()).model(metaModel.getFullName()).add("form", viewPrefix + "-form");
    } else {
        MetaJsonModel metaJsonModel = Beans.get(MetaJsonModelRepository.class).findByName(modelName);
        actionViewBuilder = ActionView.define(metaJsonModel.getTitle()).model(MetaJsonRecord.class.getName()).add("form", metaJsonModel.getFormView().getName()).domain("self.jsonModel = :jsonModel").context("jsonModel", modelName);
    }
    return actionViewBuilder;
}
Also used : MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaModel(com.axelor.meta.db.MetaModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) MetaJsonModelRepository(com.axelor.meta.db.repo.MetaJsonModelRepository) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 19 with MetaModel

use of com.axelor.meta.db.MetaModel 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)

Example 20 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class AdvancedExportController method getModelAllFields.

public void getModelAllFields(ActionRequest request, ActionResponse response) throws ClassNotFoundException {
    AdvancedExport advancedExport = request.getContext().asType(AdvancedExport.class);
    inflector = Inflector.getInstance();
    if (advancedExport.getMetaModel() != null) {
        List<Map<String, Object>> allFieldList = new ArrayList<>();
        MetaModelRepository metaModelRepository = Beans.get(MetaModelRepository.class);
        MetaFieldRepository metaFieldRepository = Beans.get(MetaFieldRepository.class);
        for (MetaField field : advancedExport.getMetaModel().getMetaFields()) {
            Map<String, Object> allFieldMap = new HashMap<>();
            allFieldMap.put("currentDomain", advancedExport.getMetaModel().getName());
            Class<?> modelClass = Class.forName(advancedExport.getMetaModel().getFullName());
            Mapper modelMapper = Mapper.of(modelClass);
            if (modelMapper.getProperty(field.getName()) == null || modelMapper.getProperty(field.getName()).isTransient()) {
                continue;
            }
            if (!Strings.isNullOrEmpty(field.getRelationship())) {
                MetaModel metaModel = metaModelRepository.all().filter("self.name = ?", field.getTypeName()).fetchOne();
                Class<?> klass = Class.forName(metaModel.getFullName());
                Mapper mapper = Mapper.of(klass);
                String fieldName = mapper.getNameField() == null ? "id" : mapper.getNameField().getName();
                MetaField metaField = metaFieldRepository.all().filter("self.name = ?1 AND self.metaModel = ?2", fieldName, metaModel).fetchOne();
                allFieldMap.put("metaField", metaField);
                allFieldMap.put("targetField", field.getName() + "." + metaField.getName());
            } else {
                allFieldMap.put("metaField", field);
                allFieldMap.put("targetField", field.getName());
            }
            if (Strings.isNullOrEmpty(field.getLabel())) {
                allFieldMap.put("title", this.getFieldTitle(inflector, field.getName()));
            } else {
                allFieldMap.put("title", field.getLabel());
            }
            allFieldList.add(allFieldMap);
        }
        response.setAttr("advancedExportLineList", "value", allFieldList);
    }
}
Also used : MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) MetaField(com.axelor.meta.db.MetaField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetaFieldRepository(com.axelor.meta.db.repo.MetaFieldRepository) Mapper(com.axelor.db.mapper.Mapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MetaModel(com.axelor.meta.db.MetaModel) AdvancedExport(com.axelor.apps.base.db.AdvancedExport) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MetaModel (com.axelor.meta.db.MetaModel)41 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)12 AxelorException (com.axelor.exception.AxelorException)9 MetaField (com.axelor.meta.db.MetaField)9 ArrayList (java.util.ArrayList)8 Model (com.axelor.db.Model)7 Mapper (com.axelor.db.mapper.Mapper)6 IOException (java.io.IOException)6 Transactional (com.google.inject.persist.Transactional)5 List (java.util.List)5 App (com.axelor.apps.base.db.App)4 Property (com.axelor.db.mapper.Property)4 MetaJsonModel (com.axelor.meta.db.MetaJsonModel)4 Context (com.axelor.rpc.Context)4 AuditableModel (com.axelor.auth.db.AuditableModel)3 CSVInput (com.axelor.data.csv.CSVInput)3 MetaFile (com.axelor.meta.db.MetaFile)3 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)3 AppFilter (com.axelor.app.internal.AppFilter)2 AdvancedExport (com.axelor.apps.base.db.AdvancedExport)2