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