use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class DmnServiceImpl method mapToMetaModelFields.
private String mapToMetaModelFields(List<String> fields, String modelName, String searchOperator, boolean multiple, String resultVar) throws ClassNotFoundException {
StringBuilder scriptBuilder = new StringBuilder();
Mapper mapper = Mapper.of(EntityHelper.getEntityClass(Class.forName(modelName)));
String varName = Beans.get(WkfCommonService.class).getVarName(modelName);
scriptBuilder.append("def _query = null\n");
for (String field : fields) {
String resultField = resultVar + "?." + field;
String targetField = varName + "." + field;
Property property = mapper.getProperty(field);
if (property == null) {
MetaJsonField jsonField = Beans.get(MetaJsonFieldRepository.class).all().filter("self.model = ?1 and self.name = ?2", modelName, field).fetchOne();
if (jsonField != null) {
addJsonField(searchOperator, multiple, resultVar, scriptBuilder, varName, jsonField);
}
continue;
}
if (property.getTarget() != null) {
addRelationalField(searchOperator, multiple, scriptBuilder, targetField, resultField, property.getTarget().getSimpleName(), property.getTargetName());
} else {
scriptBuilder.append(targetField + " = " + resultField);
}
scriptBuilder.append("\n");
}
return scriptBuilder.toString();
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method addRelationalMetaFieldBind.
private void addRelationalMetaFieldBind(Mapper modelMapper, MetaField field, XMLBind fieldBind) {
Property property = modelMapper.getProperty(field.getName());
if (property.isCollection()) {
fieldBind.setSearch("self." + property.getTargetName() + " in :_" + field.getName());
fieldBind.setExpression(field.getName() + "?.split(';') as List");
} else {
fieldBind.setSearch("self." + property.getTargetName() + " = :_" + field.getName());
}
fieldBind.setUpdate(true);
fieldBind.setCreate(false);
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method getMetaSearchFields.
protected String getMetaSearchFields(Mapper modelMapper, AppDataLoader appDataLoader) throws ClassNotFoundException {
StringBuilder fields = new StringBuilder();
for (MetaField field : appDataLoader.getSearchMetaFieldSet()) {
if (fields.length() != 0) {
fields.append(" AND ");
}
if (field.getRelationship() != null) {
Property property = modelMapper.getProperty(field.getName());
fields.append("self." + field.getName() + "." + property.getTargetName() + " = :_" + field.getName());
} else {
fields.append("self." + field.getName() + " = :_" + field.getName());
}
}
return fields.toString();
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class ReportBuilderService method getNameColumn.
/**
* Get nameColumn for given relational metaField.
*
* @param name Field name
* @param metaField MetaField to check.
* @return Name column of field.
*/
private String getNameColumn(String name, MetaField metaField) {
String refModel = getRefModel(metaField.getTypeName());
try {
Mapper mapper = Mapper.of(Class.forName(refModel));
boolean nameField = false;
boolean codeField = false;
for (Property property : Arrays.asList(mapper.getProperties())) {
if (property.isNameColumn()) {
return name + "." + property.getName();
} else if (property.getName().equals("name")) {
nameField = true;
} else if (property.getName().equals("code")) {
codeField = true;
}
}
if (nameField) {
return name + ".name";
}
if (codeField) {
return name + ".code";
}
return name + "." + "id";
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return name;
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class AdvancedImportServiceImpl method removeSubRecords.
@SuppressWarnings("unchecked")
@Transactional
public void removeSubRecords(Class<? extends Model> klass, JsonContext jsonContext) throws ClassNotFoundException {
for (Property prop : Mapper.of(klass).getProperties()) {
if (prop.getTarget() == null || prop.isCollection()) {
continue;
}
String simpleModelName = StringUtils.substringAfterLast(prop.getTarget().getName(), ".");
String field = inflector.camelize(simpleModelName, true) + "Set";
if (!jsonContext.containsKey(field)) {
continue;
}
List<Object> recList = (List<Object>) jsonContext.get(field);
String ids = recList.stream().map(obj -> {
Map<String, Object> recordMap = Mapper.toMap(EntityHelper.getEntity(obj));
return recordMap.get("id").toString();
}).collect(Collectors.joining(","));
JpaRepository<? extends Model> modelRepo = JpaRepository.of((Class<? extends Model>) Class.forName(prop.getTarget().getName()));
modelRepo.all().filter("self.id IN (" + ids + ")").delete();
}
}
Aggregations