use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class FilterController method updateTargetField.
public void updateTargetField(ActionRequest request, ActionResponse response) {
Filter filter = request.getContext().asType(Filter.class);
MetaField metaField = filter.getMetaField();
MetaJsonField metaJson = filter.getMetaJsonField();
Boolean isJson = filter.getIsJson() != null ? filter.getIsJson() : false;
if (!isJson && metaField != null) {
String type = metaField.getRelationship() != null ? metaField.getRelationship() : metaField.getTypeName();
response.setValue("targetType", type);
response.setValue("targetField", metaField.getName());
response.setValue("targetTitle", metaField.getLabel() != null && !metaField.getLabel().isEmpty() ? metaField.getLabel() : metaField.getName());
} else if ((isJson || !isJson) && metaJson != null) {
response.setValue("targetType", Inflector.getInstance().camelize(metaJson.getType()));
response.setValue("targetField", metaJson.getName());
} else {
response.setValue("targetField", null);
response.setValue("targetType", null);
}
response.setValue("operator", null);
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class MetaJsonFieldController method trackJsonField.
public void trackJsonField(ActionRequest request, ActionResponse response) {
MetaJsonField metaJsonField = request.getContext().asType(MetaJsonField.class);
MetaJsonField jsonField = Beans.get(MetaJsonFieldRepo.class).all().filter("self.name = ?1 AND self.model = ?2", metaJsonField.getName(), metaJsonField.getModel()).fetchOne();
if (jsonField != null) {
return;
}
Beans.get(StudioMetaService.class).trackJsonField(metaJsonField);
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ConfiguratorCreatorServiceImpl method completeSelection.
/**
* Fill {@link MetaJsonField#selection} searching in java class code.
*
* @param metaField a meta field.
* @param newField a meta json field.
*/
protected void completeSelection(MetaField metaField, MetaJsonField newField) {
try {
Field correspondingField = Class.forName(metaField.getMetaModel().getPackageName() + "." + metaField.getMetaModel().getName()).getDeclaredField(metaField.getName());
Widget widget = correspondingField.getAnnotation(Widget.class);
if (widget == null) {
return;
}
String selection = widget.selection();
if (!Strings.isNullOrEmpty(selection)) {
newField.setSelection(selection);
}
} catch (ClassNotFoundException | NoSuchFieldException e) {
TraceBackService.trace(e);
}
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ConfiguratorCreatorServiceImpl method addIfMissing.
/**
* Add the {@link ConfiguratorFormula} in {@link ConfiguratorCreator#indicators} if the formula is
* not represented by an existing indicator.
*
* @param formula
* @param creator
*/
protected void addIfMissing(ConfiguratorFormula formula, ConfiguratorCreator creator) throws AxelorException {
MetaField formulaMetaField = formula.getMetaField();
List<MetaJsonField> fields = Optional.ofNullable(creator.getIndicators()).orElse(Collections.emptyList());
for (MetaJsonField field : fields) {
if (field.getName().equals(formulaMetaField.getName() + "_" + creator.getId())) {
return;
}
}
String metaModelName = formulaMetaField.getMetaModel().getName();
MetaJsonField newField = new MetaJsonField();
newField.setModel(Configurator.class.getName());
newField.setModelField("indicators");
MetaField metaField = Beans.get(MetaFieldRepository.class).all().filter("self.metaModel.name = :metaModelName AND self.name = :name").bind("metaModelName", metaModelName).bind("name", formulaMetaField.getName()).fetchOne();
String typeName;
if (!Strings.isNullOrEmpty(metaField.getRelationship())) {
typeName = metaField.getRelationship();
completeDefaultGridAndForm(metaField, newField);
} else {
typeName = metaField.getTypeName();
}
completeSelection(metaField, newField);
newField.setType(MetaTool.typeToJsonType(typeName));
newField.setName(formulaMetaField.getName() + "_" + creator.getId());
newField.setTitle(formulaMetaField.getLabel());
creator.addIndicator(newField);
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ConfiguratorCreatorImportServiceImpl method fixAttributesName.
@Override
public void fixAttributesName(ConfiguratorCreator creator) throws AxelorException {
List<MetaJsonField> attributes = creator.getAttributes();
if (attributes == null) {
return;
}
for (MetaJsonField attribute : attributes) {
String name = attribute.getName();
if (name != null && name.contains("_")) {
attribute.setName(name.substring(0, name.lastIndexOf('_')) + '_' + creator.getId());
}
updateOtherFieldsInAttribute(creator, attribute);
updateAttributeNameInFormulas(creator, name, attribute.getName());
}
}
Aggregations