use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class ConfiguratorCreatorServiceImpl method setContextToJsonField.
/**
* Set the context field to a json field. Allows to limit the json field to the configurator
* having the right configurator creator.
*
* @param creator
* @param field
*/
protected void setContextToJsonField(ConfiguratorCreator creator, MetaJsonField field) {
final String fieldName = "configuratorCreator";
final Class<?> modelClass;
final String modelName = field.getModel();
try {
modelClass = Class.forName(modelName);
} catch (ClassNotFoundException e) {
// this should not happen
TraceBackService.trace(e);
return;
}
final Mapper mapper = Mapper.of(modelClass);
final Property property = mapper.getProperty(fieldName);
final String target = property == null ? null : property.getTarget().getName();
final String targetName = property == null ? null : property.getTargetName();
field.setContextField(fieldName);
field.setContextFieldTarget(target);
field.setContextFieldTargetName(targetName);
field.setContextFieldValue(creator.getId().toString());
field.setContextFieldTitle(creator.getName());
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class ObjectDataAnonymizeServiceImpl method getDefaultValues.
private Map<String, Object> getDefaultValues(Mapper mapper, Set<MetaField> fields) {
Map<String, Object> defaultValues = new HashMap<>();
LocalDate defaultDate = LocalDate.of(1900, 01, 01);
for (MetaField field : fields) {
String name = field.getName();
Property property = mapper.getProperty(name);
if (!property.isRequired()) {
defaultValues.put(name, null);
continue;
}
if (property.getTarget() != null) {
continue;
}
switch(field.getTypeName()) {
case "String":
{
defaultValues.put(name, "anonymous");
break;
}
case "BigDecimal":
{
defaultValues.put(name, BigDecimal.ZERO);
break;
}
case "Integer":
{
defaultValues.put(name, Integer.valueOf(0));
break;
}
case "Boolean":
{
defaultValues.put(name, Boolean.FALSE);
break;
}
case "Long":
{
defaultValues.put(name, Long.valueOf(0));
break;
}
case "LocalTime":
{
defaultValues.put(name, LocalTime.MIDNIGHT);
break;
}
case "LocalDateTime":
{
defaultValues.put(name, defaultDate.atStartOfDay());
break;
}
case "ZonedDateTime":
{
defaultValues.put(name, defaultDate.atStartOfDay(ZoneId.systemDefault()));
break;
}
default:
{
break;
}
}
}
return defaultValues;
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class ImportAdvancedImport method importGeneral.
@SuppressWarnings("unchecked")
public Object importGeneral(Object bean, Map<String, Object> values) throws ClassNotFoundException {
if (bean == null) {
return bean;
}
FileTab fileTab = fileTabRepo.find(Long.valueOf(values.get("fileTabId").toString()));
ScriptHelper scriptHelper = new GroovyScriptHelper(new ScriptBindings(values));
List<String> exprs = (List<String>) values.get("ifConditions" + fileTab.getId());
if (!CollectionUtils.isEmpty(exprs)) {
if ((boolean) scriptHelper.eval(String.join(" || ", exprs))) {
return null;
}
}
if (((Model) bean).getId() == null) {
List<Property> propList = this.getProperties(bean);
JPA.save((Model) bean);
this.addJsonObjectRecord(bean, fileTab, fileTab.getMetaModel().getName(), values);
int fieldSeq = 2;
int btnSeq = 3;
for (Property prop : propList) {
validatorService.createCustomObjectSet(fileTab.getClass().getName(), prop.getTarget().getName(), fieldSeq);
validatorService.createCustomButton(fileTab.getClass().getName(), prop.getTarget().getName(), btnSeq);
this.addJsonObjectRecord(prop.get(bean), fileTab, StringUtils.substringAfterLast(prop.getTarget().getName(), "."), values);
fieldSeq++;
btnSeq++;
}
}
final String ACTIONS_TO_APPLY = "actionsToApply" + fileTab.getId();
if (!ObjectUtils.isEmpty(values.get(ACTIONS_TO_APPLY))) {
bean = actionService.apply(values.get(ACTIONS_TO_APPLY).toString(), bean);
}
return bean;
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class WkfCommonServiceImpl method addProperties.
@Override
public Model addProperties(Map<String, String> propertyMap, Model model, ModelElementInstance element) {
Mapper mapper = Mapper.of(EntityHelper.getEntityClass(model));
for (String property : propertyMap.keySet()) {
Object value = element.getAttributeValueNs(BpmnParser.CAMUNDA_BPMN_EXTENSIONS_NS, propertyMap.get(property));
if (value != null && value.equals("undefined")) {
value = null;
}
Property field = mapper.getProperty(property);
if (field.isReference()) {
try {
value = JpaRepository.of((Class<? extends Model>) field.getTarget()).all().filter("self.name = ?1", value).fetchOne();
} catch (Exception e) {
e.printStackTrace();
}
}
mapper.set(model, property, value);
}
return model;
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class DmnServiceImpl method processMetaField.
private Object processMetaField(String fieldName, String subField, Object value, Class<Model> entityClass) throws AxelorException {
Property property = Mapper.of(entityClass).getProperty(fieldName);
if (property == null) {
return processMetaModelJson(fieldName, subField, value, entityClass);
}
String targetModel = property.getTarget().getName();
boolean isCollection = property.isCollection();
boolean isSet = property.getJavaType().isAssignableFrom(Set.class);
return findResult(value, subField, targetModel, isCollection, isSet);
}
Aggregations