Search in sources :

Example 21 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

the class PropertyConditionGenerator method isCrossDataStoreReference.

protected boolean isCrossDataStoreReference(String property, @Nullable String entityName) {
    if (Strings.isNullOrEmpty(entityName)) {
        return false;
    }
    MetaClass metaClass = metadata.getClass(entityName);
    MetaPropertyPath mpp = metaClass.getPropertyPath(property);
    if (mpp == null) {
        return false;
    }
    return metadataTools.getCrossDataStoreReferenceIdProperty(metaClass.getStore().getName(), mpp.getMetaProperty()) != null;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 22 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

the class PropertyConditionGenerator method getProperty.

protected String getProperty(String property, @Nullable String entityName) {
    if (Strings.isNullOrEmpty(entityName) || !isCrossDataStoreReference(property, entityName)) {
        return property;
    }
    MetaClass metaClass = metadata.getClass(entityName);
    MetaPropertyPath mpp = metaClass.getPropertyPath(property);
    if (mpp == null) {
        return property;
    }
    String referenceIdProperty = metadataTools.getCrossDataStoreReferenceIdProperty(metaClass.getStore().getName(), mpp.getMetaProperty());
    // noinspection ConstantConditions
    return property.lastIndexOf(".") > 0 ? property.substring(0, property.lastIndexOf(".") + 1) + referenceIdProperty : referenceIdProperty;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 23 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

the class SortJpqlGenerator method getUniqueSortExpression.

protected Map<String, Sort.Direction> getUniqueSortExpression(Map<String, Sort.Direction> sortExpressions, MetaClass metaClass, Sort.Direction direction) {
    String pkName = metadataTools.getPrimaryKeyName(metaClass);
    if (pkName != null) {
        MetaProperty idProperty = metaClass.getProperty(pkName);
        if (metadataTools.hasCompositePrimaryKey(metaClass)) {
            Map<String, Sort.Direction> uniqueSortExpressions = new LinkedHashMap<>();
            MetaClass pkMetaClass = idProperty.getRange().asClass();
            for (MetaProperty metaProperty : pkMetaClass.getProperties()) {
                if (metadataTools.isJpa(metaProperty)) {
                    MetaPropertyPath idPropertyPath = metaClass.getPropertyPath(String.format("%s.%s", pkName, metaProperty.getName()));
                    Map<String, Sort.Direction> currentSortExpressions = getPropertySortExpressions(Objects.requireNonNull(idPropertyPath), direction);
                    if (currentSortExpressions.keySet().stream().noneMatch(sortExpressions::containsKey)) {
                        uniqueSortExpressions.putAll(currentSortExpressions);
                    }
                }
            }
            return uniqueSortExpressions;
        } else {
            MetaPropertyPath idPropertyPath = metaClass.getPropertyPath(pkName);
            Map<String, Sort.Direction> uniqueSortExpressions = getPropertySortExpressions(Objects.requireNonNull(idPropertyPath), direction);
            if (uniqueSortExpressions.keySet().stream().noneMatch(sortExpressions::containsKey)) {
                return uniqueSortExpressions;
            }
        }
    }
    return Collections.emptyMap();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 24 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

the class SortJpqlGenerator method getNotPersistentPropertySortExpression.

protected Map<String, Sort.Direction> getNotPersistentPropertySortExpression(MetaPropertyPath metaPropertyPath, Sort.Direction sortDirection) {
    List<String> related = metadataTools.getDependsOnProperties(metaPropertyPath.getMetaProperty());
    MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
    if (!related.isEmpty()) {
        Map<String, Sort.Direction> sortExpressions = new LinkedHashMap<>(related.size());
        for (String item : related) {
            MetaProperty metaProperty = propertyMetaClass.getProperty(item);
            if (metadataTools.isJpa(metaProperty)) {
                List<MetaProperty> metaProperties = Arrays.asList(metaPropertyPath.getMetaProperties());
                metaProperties.set(metaProperties.size() - 1, metaProperty);
                MetaPropertyPath childPropertyPath = new MetaPropertyPath(metaPropertyPath.getMetaClass(), Iterables.toArray(metaProperties, MetaProperty.class));
                sortExpressions.putAll(getPropertySortExpressions(childPropertyPath, sortDirection));
            }
        }
        return sortExpressions;
    }
    return Collections.emptyMap();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 25 with MetaPropertyPath

use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.

the class SortJpqlGenerator method processQuery.

public String processQuery(String entityName, List<String> valueProperties, String queryString, Sort sort) {
    List<Sort.Order> orders = sort.getOrders();
    if (orders.isEmpty()) {
        return queryString;
    }
    Sort.Direction defaultSort = Sort.Direction.ASC;
    Map<String, Sort.Direction> sortExpressions = new LinkedHashMap<>();
    if (entityName != null) {
        MetaClass metaClass = metadata.getClass(entityName);
        for (Sort.Order order : sort.getOrders()) {
            MetaPropertyPath metaPropertyPath = metaClass.getPropertyPath(order.getProperty());
            checkNotNullArgument(metaPropertyPath, "Could not resolve property path '%s' in '%s'", order.getProperty(), metaClass);
            sortExpressions.putAll(getPropertySortExpressions(metaPropertyPath, order.getDirection()));
        }
        if (!sortExpressions.isEmpty()) {
            sortExpressions.putAll(getUniqueSortExpression(sortExpressions, metaClass, defaultSort));
        }
    } else if (valueProperties != null) {
        List<String> selectedExpressions = queryTransformerFactory.parser(queryString).getSelectedExpressionsList();
        for (Sort.Order order : sort.getOrders()) {
            sortExpressions.putAll(getValuePropertySortExpression(order.getProperty(), valueProperties, selectedExpressions, order.getDirection()));
        }
    }
    return transformQuery(queryString, sortExpressions, defaultSort);
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

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