use of com.axelor.meta.db.MetaField 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);
}
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class AdvancedExportController method metaFieldDomain.
public void metaFieldDomain(ActionRequest request, ActionResponse response) throws ClassNotFoundException {
AdvancedExportLine adv = request.getContext().asType(AdvancedExportLine.class);
MetaModel metaModel = Beans.get(MetaModelRepository.class).findByName(adv.getCurrentDomain());
List<MetaField> metaFields = metaModel.getMetaFields();
List<Long> metaFieldList = new ArrayList<>();
if (metaFields != null) {
Class<?> klass = Class.forName(metaModel.getFullName());
Mapper mapper = Mapper.of(klass);
for (MetaField field : metaFields) {
if (!mapper.getProperty(field.getName()).isTransient()) {
metaFieldList.add(field.getId());
}
}
}
metaFieldList.add(0L);
response.setAttr("metaField", "domain", "self.id in (" + Joiner.on(",").join(metaFieldList) + ")");
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class AdvancedExportController method fillTitle.
public void fillTitle(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
MetaField metaField = (MetaField) context.get("metaField");
if (metaField != null) {
if (Strings.isNullOrEmpty(metaField.getLabel())) {
inflector = Inflector.getInstance();
response.setValue("title", I18n.get(this.getFieldTitle(inflector, metaField.getName())));
} else {
response.setValue("title", I18n.get(metaField.getLabel()));
}
} else {
response.setValue("title", null);
}
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class AdvancedExportController method fillTargetField.
public void fillTargetField(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
MetaField metaField = (MetaField) context.get("metaField");
if (metaField != null) {
String targetField = "";
if (context.get("targetField") == null) {
targetField = metaField.getName();
} else {
targetField = context.get("targetField").toString();
targetField += "." + metaField.getName();
}
response.setValue("targetField", targetField);
if (metaField.getRelationship() != null) {
response.setValue("currentDomain", metaField.getTypeName());
response.setValue("metaField", null);
} else {
response.setAttr("metaField", "readonly", true);
response.setAttr("validateFieldSelectionBtn", "readonly", true);
response.setAttr("$viewerMessage", "hidden", false);
response.setAttr("$isValidate", "value", true);
}
}
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class ConfiguratorCreatorServiceImpl method completeFormula.
/**
* Complete the given configurator formula with correct metafields.
*
* @param configuratorFormula a configurator formula.
* @param name the meta field name.
* @param metaFieldType the name of the model owning the meta field.
*/
protected void completeFormula(ConfiguratorFormula configuratorFormula, String name, String metaFieldType) {
configuratorFormula.setShowOnConfigurator(true);
configuratorFormula.setFormula("");
Long modelId = JPA.all(MetaModel.class).filter("self.name = ?", metaFieldType).fetchOne().getId();
MetaField metaField = JPA.all(MetaField.class).filter("self.name = ? AND self.metaModel.id = ?", name, modelId).fetchOne();
configuratorFormula.setMetaField(metaField);
}
Aggregations