use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ActionScriptBuilderService method addFieldsBinding.
private String addFieldsBinding(String target, List<ActionBuilderLine> lines, int level) {
StringBuilder stb = new StringBuilder();
lines.sort((l1, l2) -> {
if (l1.getDummy() && !l2.getDummy()) {
return -1;
}
if (!l1.getDummy() && l2.getDummy()) {
return 1;
}
return 0;
});
for (ActionBuilderLine line : lines) {
String name = line.getName();
String value = line.getValue();
if (value != null && value.contains(".sum(")) {
value = getSum(value, line.getFilter());
}
if (line.getDummy()) {
stb.append(format("_$." + name + " = " + value + ";", level));
continue;
}
MetaJsonField jsonField = line.getMetaJsonField();
MetaField metaField = line.getMetaField();
if (jsonField != null && (jsonField.getTargetJsonModel() != null || jsonField.getTargetModel() != null)) {
value = addRelationalBinding(line, target, true);
} else if (metaField != null && metaField.getRelationship() != null) {
value = addRelationalBinding(line, target, false);
}
if (value != null && metaField != null && metaField.getTypeName().equals(BigDecimal.class.getSimpleName())) {
value = "new BigDecimal(" + value + ")";
}
String condition = line.getConditionText();
if (condition != null) {
stb.append(format("if(" + condition + "){" + target + "." + name + " = " + value + ";}", level));
} else {
stb.append(format(target + "." + name + " = " + value + ";", level));
}
}
return stb.toString();
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ActionScriptBuilderService method getTargetModel.
private String getTargetModel(ActionBuilderLine line) {
MetaJsonField jsonField = line.getMetaJsonField();
String targetModel = "";
if (jsonField != null && jsonField.getTargetModel() != null) {
targetModel = jsonField.getTargetModel();
}
MetaField field = line.getMetaField();
if (field != null && field.getTypeName() != null) {
targetModel = field.getTypeName();
}
return targetModel;
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ActionScriptBuilderService method getSourceModel.
private String getSourceModel(ActionBuilderLine line) {
MetaJsonField jsonField = line.getValueJson();
String sourceModel = null;
Object targetObject = null;
try {
if (jsonField != null && jsonField.getTargetModel() != null) {
if (line.getValue() != null && !line.getValue().contentEquals("$." + jsonField.getName())) {
targetObject = filterSqlService.parseJsonField(jsonField, line.getValue().replace("$.", ""), null, null);
} else {
sourceModel = jsonField.getTargetModel();
}
}
MetaField field = line.getValueField();
if (field != null && field.getTypeName() != null) {
if (line.getValue() != null && !line.getValue().contentEquals("$." + field.getName())) {
targetObject = filterSqlService.parseMetaField(field, line.getValue().replace("$.", ""), null, null, false);
} else {
sourceModel = field.getTypeName();
}
}
} catch (AxelorException e) {
TraceBackService.trace(e);
}
if (sourceModel == null && line.getValue() != null && line.getValue().equals("$")) {
sourceModel = getRootSourceModel(line);
}
if (sourceModel == null && line.getValue() != null && line.getValue().equals("$$")) {
sourceModel = getRootSourceModel(line);
}
if (targetObject != null) {
if (targetObject instanceof MetaJsonField) {
sourceModel = ((MetaJsonField) targetObject).getTargetModel();
} else if (targetObject instanceof MetaField) {
sourceModel = ((MetaField) targetObject).getTypeName();
}
}
return sourceModel;
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ValidatorService method createCustomButton.
@Transactional(rollbackOn = { Exception.class })
public void createCustomButton(String modelName, String targetModelName, int sequence) {
String simpleModelName = StringUtils.substringAfterLast(targetModelName, ".");
String fieldName = Inflector.getInstance().camelize(simpleModelName, true) + "Set";
String buttonName = "show" + fieldName + "Btn";
if (metaJsonFieldRepo.all().filter("self.name = ?1 AND self.type = ?2 AND self.model = ?3", buttonName, "button", modelName).count() > 0) {
return;
}
MetaJsonField jsonField = new MetaJsonField();
jsonField.setName(buttonName);
jsonField.setType("button");
jsonField.setTitle("Show " + Inflector.getInstance().titleize(simpleModelName));
jsonField.setSequence(sequence);
jsonField.setModel(modelName);
jsonField.setModelField("attrs");
jsonField.setOnClick("action-file-tab-method-show-record,close");
jsonField.setWidgetAttrs("{\"colSpan\": \"4\"}");
jsonField.setShowIf(fieldName + " != null && $record.advancedImport.statusSelect > 0");
metaJsonFieldRepo.save(jsonField);
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ChartRecordViewServiceImpl method getSelectionFieldValue.
protected Object getSelectionFieldValue(ChartBuilder chartBuilder, Object titleParam, Boolean isForGroup) throws AxelorException {
Object value = null;
String selection = null;
Class<?> targetType = String.class;
Boolean isJson = chartBuilder.getIsJson() || (isForGroup ? chartBuilder.getIsJsonGroupOn() : chartBuilder.getIsJsonAggregateOn());
MetaField target = chartBuilder.getGroupOn();
MetaJsonField jsonField = chartBuilder.getGroupOnJson();
if (!isForGroup) {
target = chartBuilder.getAggregateOn();
jsonField = chartBuilder.getAggregateOnJson();
}
if (isJson && ObjectUtils.notEmpty(jsonField.getSelection()) && (Integer.class.getSimpleName().toLowerCase().equals(jsonField.getType()) || String.class.getSimpleName().toLowerCase().equals(jsonField.getType()))) {
selection = jsonField.getSelection();
if (Integer.class.getSimpleName().toLowerCase().equals(jsonField.getType())) {
targetType = Integer.class;
}
} else {
try {
Mapper mapper = Mapper.of(Class.forName(chartBuilder.getModel()));
Property p = mapper.getProperty(target.getName());
if (ObjectUtils.notEmpty(p.getSelection())) {
selection = p.getSelection();
targetType = p.getJavaType();
}
} catch (ClassNotFoundException e) {
throw new AxelorException(e, TraceBackRepository.CATEGORY_INCONSISTENCY);
}
}
if (ObjectUtils.isEmpty(selection)) {
return value;
}
List<Option> selectionList = MetaStore.getSelectionList(selection);
for (Option option : selectionList) {
if (option.getLocalizedTitle().equals(titleParam)) {
return ConvertUtils.convert(option.getValue(), targetType);
}
}
return value;
}
Aggregations