Search in sources :

Example 96 with MetaPropertyPath

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;
}
Also used : EntityLogAttr(io.jmix.audit.entity.EntityLogAttr) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 97 with MetaPropertyPath

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;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 98 with MetaPropertyPath

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;
    }
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 99 with MetaPropertyPath

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;
            }
        }
    }
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 100 with MetaPropertyPath

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());
        }
    }
}
Also used : JmixTableData(io.jmix.reports.entity.JmixTableData) Element(org.dom4j.Element) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Aggregations

MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)134 MetaClass (io.jmix.core.metamodel.model.MetaClass)68 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)52 Nullable (javax.annotation.Nullable)19 Table (io.jmix.ui.component.Table)15 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)12 MetadataTools (io.jmix.core.MetadataTools)10 Element (org.dom4j.Element)10 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)8 JmixEnhancedTable (io.jmix.ui.widget.JmixEnhancedTable)7 EntityTableItems (io.jmix.ui.component.data.meta.EntityTableItems)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 Range (io.jmix.core.metamodel.model.Range)5 HasValueSource (io.jmix.ui.component.data.HasValueSource)5 ValueSource (io.jmix.ui.component.data.ValueSource)4 AbstractTable (io.jmix.ui.component.impl.AbstractTable)4 TableSettings (io.jmix.ui.settings.component.TableSettings)4