use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ValidatorService method createCustomObjectSet.
@Transactional(rollbackOn = { Exception.class })
public void createCustomObjectSet(String modelName, String targetModelName, int sequence) {
String simpleModelName = StringUtils.substringAfterLast(targetModelName, ".");
String fieldName = Inflector.getInstance().camelize(simpleModelName, true) + "Set";
String viewName = Inflector.getInstance().dasherize(simpleModelName);
if (metaJsonFieldRepo.all().filter("self.type = ?1 AND self.model = ?2 AND self.targetModel = ?3", "many-to-many", modelName, targetModelName).count() > 0) {
return;
}
MetaJsonField jsonField = new MetaJsonField();
jsonField.setName(fieldName);
jsonField.setType("many-to-many");
jsonField.setTitle(Inflector.getInstance().titleize(simpleModelName));
jsonField.setSequence(sequence);
jsonField.setModel(modelName);
jsonField.setModelField("attrs");
jsonField.setTargetModel(targetModelName);
jsonField.setGridView(viewName + "-grid");
jsonField.setFormView(viewName + "-form");
jsonField.setWidgetAttrs("{\"colSpan\": \"12\"}");
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 ChartBuilderService method addSearchField.
/**
* Method set default value for search-fields(parameters). It will add field and expression in
* onNew for chart.
*
* @param fieldName Name of field of search-field.
* @param typeName Type of field.
* @param defaultValue Default value input in chart filter.
* @param modelField It is for relational field. String array with first element as Model name and
* second as its field.
*/
// private void setDefaultValue(String fieldName, String typeName,
// String defaultValue, String[] modelField) {
//
// if (defaultValue == null) {
// return;
// }
//
// RecordField field = new RecordField();
// field.setName(fieldName);
//
// defaultValue = filterCommonService.getTagValue(defaultValue, false);
//
// if (modelField != null) {
// if (typeName.equals("STRING")) {
// defaultValue = "__repo__(" + modelField[0]
// + ").all().filter(\"LOWER(" + modelField[1] + ") LIKE "
// + defaultValue + "\").fetchOne()";
// } else {
// defaultValue = "__repo__(" + modelField[0]
// + ").all().filter(\"" + modelField[1] + " = "
// + defaultValue + "\").fetchOne()";
// }
//
// }
//
// log.debug("Default value: {}", defaultValue);
//
// field.setExpression("eval:" + defaultValue);
//
// onNewFields.add(field);
// }
/**
* It will create onNew action from onNew fields.
*
* @param viewBuilder ViewBuilder use to get model name also used in onNew action name creation.
*/
// private void setOnNewAction(ChartBuilder chartBuilder) {
//
// if (!onNewFields.isEmpty()) {
// onNewAction = new ActionRecord();
// onNewAction.setName("action-" + chartBuilder.getName() + "-default");
// onNewAction.setModel(chartBuilder.getModel());
// onNewAction.setFields(onNewFields);
// }
//
// }
private void addSearchField(List<Filter> filters) throws AxelorException {
if (filters == null) {
return;
}
for (Filter filter : filters) {
if (!filter.getIsParameter()) {
continue;
}
String fieldStr = "param" + filter.getId();
Object object = null;
StringBuilder parent = new StringBuilder("self");
if (filter.getIsJson()) {
object = filterSqlService.parseJsonField(filter.getMetaJsonField(), filter.getTargetField(), null, parent);
} else {
object = filterSqlService.parseMetaField(filter.getMetaField(), filter.getTargetField(), null, parent, true);
}
if (object instanceof MetaField) {
fieldStr = getMetaSearchField(fieldStr, (MetaField) object);
} else {
fieldStr = getJsonSearchField(fieldStr, (MetaJsonField) object);
}
searchFields.add(fieldStr + "\" x-required=\"true\" />");
}
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class FileTabController method showRecord.
public void showRecord(ActionRequest request, ActionResponse response) {
try {
FileTab fileTab = request.getContext().asType(FileTab.class);
fileTab = Beans.get(FileTabRepository.class).find(fileTab.getId());
String btnName = request.getContext().get("_signal").toString();
String fieldName = StringUtils.substringBetween(btnName, "show", "Btn");
MetaJsonField jsonField = Beans.get(MetaJsonFieldRepository.class).all().filter("self.name = ?1 AND self.type = 'many-to-many' AND self.model = ?2 AND self.modelField = 'attrs'", fieldName, fileTab.getClass().getName()).fetchOne();
if (jsonField == null) {
return;
}
String ids = Beans.get(FileTabService.class).getShowRecordIds(fileTab, jsonField.getName());
response.setView(ActionView.define(I18n.get(jsonField.getTitle())).model(jsonField.getTargetModel()).add("grid", jsonField.getGridView()).add("form", jsonField.getFormView()).domain("self.id IN (" + ids + ")").map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ConfiguratorCreatorImportServiceImpl method updateOtherFieldsInAttribute.
/**
* Update the configurator id in other fields of the attribute.
*
* @param creator
* @param attribute attribute to update
*/
protected void updateOtherFieldsInAttribute(ConfiguratorCreator creator, MetaJsonField attribute) {
try {
List<Field> fieldsToUpdate = Arrays.stream(attribute.getClass().getDeclaredFields()).filter(field -> field.getType().equals(String.class)).collect(Collectors.toList());
for (Field field : fieldsToUpdate) {
Mapper mapper = Mapper.of(attribute.getClass());
Method getter = mapper.getGetter(field.getName());
String fieldString = (String) getter.invoke(attribute);
if (fieldString != null && fieldString.contains("_")) {
Method setter = mapper.getSetter(field.getName());
String updatedFieldString = fieldString.substring(0, fieldString.lastIndexOf('_')) + '_' + creator.getId();
setter.invoke(attribute, updatedFieldString);
}
}
} catch (Exception e) {
TraceBackService.trace(e);
}
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class ConfiguratorCreatorServiceImpl method updateIndicators.
@Transactional
public void updateIndicators(ConfiguratorCreator creator) throws AxelorException {
List<MetaJsonField> indicators = Optional.ofNullable(creator.getIndicators()).orElse(Collections.emptyList());
// add missing formulas
List<? extends ConfiguratorFormula> formulas;
if (creator.getGenerateProduct()) {
formulas = creator.getConfiguratorProductFormulaList();
} else {
formulas = creator.getConfiguratorSOLineFormulaList();
}
for (ConfiguratorFormula formula : formulas) {
addIfMissing(formula, creator);
}
// remove formulas
List<MetaJsonField> fieldsToRemove = new ArrayList<>();
for (MetaJsonField indicator : indicators) {
if (isNotInFormulas(indicator, creator, formulas)) {
fieldsToRemove.add(indicator);
}
}
for (MetaJsonField indicatorToRemove : fieldsToRemove) {
creator.removeIndicator(indicatorToRemove);
}
updateIndicatorsAttrs(creator, formulas);
configuratorCreatorRepo.save(creator);
}
Aggregations