use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class ConfiguratorCreatorServiceImpl method updateIndicatorAttrs.
/**
* Update one indicator attrs in the view, using the corresponding formula. Do nothing if
* indicator and formula do not represent the same field.
*
* @param indicator
* @param formula
*/
protected void updateIndicatorAttrs(ConfiguratorCreator creator, MetaJsonField indicator, ConfiguratorFormula formula) {
int scale = Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice();
String fieldName = indicator.getName();
fieldName = fieldName.substring(0, fieldName.indexOf('_'));
MetaField metaField = formula.getMetaField();
if (!metaField.getName().equals(fieldName)) {
return;
}
if (formula.getShowOnConfigurator()) {
indicator.setHidden(false);
setContextToJsonField(creator, indicator);
} else {
indicator.setHidden(true);
}
if (metaField.getTypeName().equals("BigDecimal")) {
indicator.setPrecision(20);
indicator.setScale(scale);
} else if (!Strings.isNullOrEmpty(metaField.getRelationship())) {
indicator.setTargetModel(Beans.get(MetaModelRepository.class).findByName(metaField.getTypeName()).getFullName());
}
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class ConfiguratorServiceImpl method fetchManyToManyFields.
/**
* Fix relational fields of a product or a sale order line generated from a configurator. This
* method may become useless on a future ADK update.
*
* @param model
*/
protected void fetchManyToManyFields(Model model) throws AxelorException {
// get all many to many fields
List<MetaField> manyToManyFields = metaFieldRepository.all().filter("self.metaModel.name = :name " + "AND self.relationship = 'ManyToMany'").bind("name", model.getClass().getSimpleName()).fetch();
Mapper mapper = Mapper.of(model.getClass());
for (MetaField manyToManyField : manyToManyFields) {
Set<? extends Model> manyToManyValue = (Set<? extends Model>) mapper.get(model, manyToManyField.getName());
fetchManyToManyField(model, manyToManyValue, manyToManyField);
}
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class ConfiguratorServiceImpl method fixRelationalFields.
protected void fixRelationalFields(Model model) throws AxelorException {
// get all many to one fields
List<MetaField> manyToOneFields = metaFieldRepository.all().filter("self.metaModel.name = :name " + "AND self.relationship = 'ManyToOne'").bind("name", model.getClass().getSimpleName()).fetch();
Mapper mapper = Mapper.of(model.getClass());
for (MetaField manyToOneField : manyToOneFields) {
Model manyToOneValue = (Model) mapper.get(model, manyToOneField.getName());
fixRelationalField(model, manyToOneValue, manyToOneField);
}
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class FilterGroovyService method getMetaFieldType.
private String getMetaFieldType(MetaField field, String targetField, boolean isJson) throws AxelorException {
if (targetField == null || !targetField.contains(".")) {
return field.getTypeName();
}
targetField = targetField.substring(targetField.indexOf(".") + 1);
String targetName = targetField.contains(".") ? targetField.substring(0, targetField.indexOf(".")) : targetField;
MetaModel model = metaModelRepo.findByName(field.getTypeName());
if (model == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No model found: %s ", field.getName());
}
MetaField subMeta = filterSqlService.findMetaField(targetName, model.getFullName());
if (subMeta != null) {
return getMetaFieldType(subMeta, targetField, isJson);
} else if (isJson) {
MetaJsonField subJson = filterSqlService.findJsonField(targetName, model.getName());
if (subJson != null) {
return getJsonFieldType(subJson, targetField);
}
}
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No sub field found field: %s model: %s ", targetName, model.getFullName());
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class FilterSqlService method parseJsonField.
public Object parseJsonField(MetaJsonField field, String target, List<String> joins, StringBuilder parent) throws AxelorException {
log.debug("Parse json target: {}", target);
if (target == null || !target.contains(".")) {
if (field.getTargetJsonModel() != null && joins != null) {
target = getDefaultTargetJson(field.getName(), field.getTargetJsonModel())[0];
} else if (field.getTargetModel() != null && joins != null) {
target = getDefaultTarget(field.getName(), field.getTargetModel())[0];
} else {
return field;
}
}
target = target.substring(target.indexOf(".") + 1);
String targetName = target.contains(".") ? target.substring(0, target.indexOf(".")) : target;
if (field.getTargetJsonModel() == null && field.getTargetModel() == null) {
return field;
}
if (field.getTargetJsonModel() != null) {
MetaJsonField subJson = metaJsonFieldRepo.all().filter("self.name = ?1 and self.jsonModel = ?2", targetName, field.getTargetJsonModel()).fetchOne();
if (subJson != null) {
if (joins != null) {
addJoin(field, joins, parent);
}
return parseJsonField(subJson, target, joins, parent);
}
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No sub field found model: %s field %s ", field.getTargetJsonModel().getName(), targetName);
} else {
MetaField subMeta = findMetaField(targetName, field.getTargetModel());
if (subMeta != null) {
if (joins != null) {
addJoin(field, joins, parent);
}
return parseMetaField(subMeta, target, joins, parent, true);
}
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No sub field found model: %s field %s ", field.getTargetModel(), targetName);
}
}
Aggregations