use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class EntityLogImpl method createLogAttributes.
protected Set<EntityLogAttr> createLogAttributes(Object entity, Set<String> attributes, @Nullable AttributeChanges changes) {
Set<EntityLogAttr> result = new HashSet<>();
for (String name : attributes) {
EntityLogAttr attr = metadata.create(EntityLogAttr.class);
attr.setName(name);
MetaPropertyPath propertyPath = metadata.getClass(entity).getPropertyPath(name);
MetaProperty metaProperty = propertyPath == null ? null : propertyPath.getMetaProperty();
String value = stringify(EntityValues.getValueEx(entity, name), metaProperty);
attr.setValue(value);
Object valueId = getValueId(EntityValues.getValueEx(entity, name));
if (valueId != null)
attr.setValueId(valueId.toString());
if (changes != null) {
Object oldValue = changes.getOldValue(name);
attr.setOldValue(stringify(oldValue, metaProperty));
Object oldValueId = getValueId(oldValue);
if (oldValueId != null) {
attr.setOldValueId(oldValueId.toString());
}
}
// TODO: enable if @LocalizedValue would be supported
// if (metadata.getClass(entity).getProperty(name) != null) {
// //skip embedded properties
// MessageTools messageTools = AppBeans.get(MessageTools.NAME);
// String mp = messageTools.inferMessagePack(name, entity);
// if (mp != null)
// attr.setMessagesPack(mp);
// }
result.add(attr);
}
return result;
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class EntityDifferenceManagerImpl method getPropertyDiffs.
/**
* Get diffs for entity properties
*
* @param diffFetchPlan FetchPlan
* @param firstEntity First entity
* @param secondEntity Second entity
* @param diffBranch Diff branch
* @return Diff list
*/
private List<EntityPropertyDifferenceModel> getPropertyDiffs(FetchPlan diffFetchPlan, @Nullable Object firstEntity, @Nullable Object secondEntity, Stack<Object> diffBranch) {
List<EntityPropertyDifferenceModel> propertyDiffs = new LinkedList<>();
MetaClass fetchPlanMetaClass = metadata.getSession().getClass(diffFetchPlan.getEntityClass());
MetaClass metaClass = extendedEntities.getEffectiveMetaClass(fetchPlanMetaClass);
Collection<MetaPropertyPath> metaProperties = metadataTools.getFetchPlanPropertyPaths(diffFetchPlan, metaClass);
for (MetaPropertyPath metaPropertyPath : metaProperties) {
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
if (metadataTools.isJpa(metaProperty) && !metadataTools.isSystem(metaProperty)) {
FetchPlanProperty fetchPlanProperty = diffFetchPlan.getProperty(metaProperty.getName());
Object firstValue = firstEntity != null ? EntityValues.getValue(firstEntity, metaPropertyPath.toString()) : null;
Object secondValue = secondEntity != null ? EntityValues.getValue(secondEntity, metaPropertyPath.toString()) : null;
EntityPropertyDifferenceModel diff = getPropertyDifference(firstValue, secondValue, metaProperty, fetchPlanProperty, diffBranch);
if (diff != null)
propertyDiffs.add(diff);
}
}
Comparator<EntityPropertyDifferenceModel> comparator = Comparator.comparing(EntityPropertyDifferenceModel::getName);
Collections.sort(propertyDiffs, comparator);
return propertyDiffs;
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class MessageTools method getPropertyCaption.
/**
* Get localized name of an entity property.
*
* @param metaClass MetaClass containing the property
* @param propertyName property's name
* @param locale locale, if value is null locale of current user is used
* @return localized name
*/
public String getPropertyCaption(MetaClass metaClass, String propertyName, @Nullable Locale locale) {
Class originalClass = extendedEntities.getOriginalClass(metaClass);
Class<?> ownClass = originalClass != null ? originalClass : metaClass.getJavaClass();
String className = ownClass.getSimpleName();
String key = className + "." + propertyName;
String message;
if (locale == null) {
message = messages.getMessage(ownClass, key);
} else {
message = messages.getMessage(ownClass, key, locale);
}
if (!message.equals(key)) {
return message;
}
MetaPropertyPath propertyPath = metadataTools.resolveMetaPropertyPathOrNull(metaClass, propertyName);
if (propertyPath != null) {
return getPropertyCaption(propertyPath.getMetaProperty());
} else {
return message;
}
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class BulkEditorWindow method ensureEmbeddedPropertyCreated.
protected void ensureEmbeddedPropertyCreated(Entity item, String propertyPath) {
if (!StringUtils.contains(propertyPath, ".")) {
return;
}
MetaPropertyPath path = metaClass.getPropertyPath(propertyPath);
if (path != null) {
Object currentItem = item;
for (MetaProperty property : path.getMetaProperties()) {
if (metadataTools.isEmbedded(property)) {
Object currentItemValue = EntityValues.getValue(currentItem, property.getName());
if (currentItemValue == null) {
Object newItem = metadata.create(property.getRange().asClass());
EntityValues.setValue(currentItem, property.getName(), newItem);
currentItem = newItem;
} else {
currentItem = currentItemValue;
}
} else {
break;
}
}
}
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class ShowReportTableScreen method createColumns.
protected void createColumns(KeyValueCollectionContainer collectionContainer, Table table, Set<JmixTableData.ColumnInfo> headers) {
Collection<MetaPropertyPath> paths = metadataTools.getPropertyPaths(collectionContainer.getEntityMetaClass());
for (MetaPropertyPath metaPropertyPath : paths) {
MetaProperty property = metaPropertyPath.getMetaProperty();
if (!property.getRange().getCardinality().isMany() && !metadataTools.isSystem(property)) {
String propertyName = property.getName();
JmixTableData.ColumnInfo columnInfo = getColumnInfo(propertyName, headers);
Element element = DocumentHelper.createElement("column");
Table.Column column = columnInfo.getPosition() == null ? table.addColumn(metaPropertyPath) : table.addColumn(metaPropertyPath, columnInfo.getPosition());
column.setXmlDescriptor(element);
column.setCaption(columnInfo.getCaption());
}
}
}
Aggregations