Search in sources :

Example 91 with MetaProperty

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

the class AbstractDataGrid method addColumnInternal.

protected void addColumnInternal(ColumnImpl<E> column, int index) {
    Grid.Column<E, ?> gridColumn = component.addColumn(new EntityValueProvider<>(column.getPropertyPath()));
    columns.put(column.getId(), column);
    columnsOrder.add(index, column);
    final String caption = StringUtils.capitalize(column.getCaption() != null ? column.getCaption() : generateColumnCaption(column));
    column.setCaption(caption);
    if (column.getOwner() == null) {
        column.setOwner(this);
    }
    MetaPropertyPath propertyPath = column.getPropertyPath();
    if (propertyPath != null) {
        MetaProperty metaProperty = propertyPath.getMetaProperty();
        MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
        if (metadataTools.isLob(metaProperty) && !propertyMetaClass.getStore().supportsLobSortingAndFiltering()) {
            column.setSortable(false);
        }
    }
    setupGridColumnProperties(gridColumn, column);
    component.setColumnOrder(getColumnOrder());
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) JmixEnhancedGrid(io.jmix.ui.widget.JmixEnhancedGrid) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 92 with MetaProperty

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

the class EntityStates method checkLoadedWithFetchPlan.

protected void checkLoadedWithFetchPlan(Object entity, FetchPlan fetchPlan, Set visited) {
    if (visited.contains(entity)) {
        return;
    }
    visited.add(entity);
    for (FetchPlanProperty property : fetchPlan.getProperties()) {
        MetaClass metaClass = metadata.getClass(entity);
        MetaProperty metaProperty = metaClass.getProperty(property.getName());
        if (!isLoaded(entity, property.getName())) {
            String errorMessage = String.format("%s.%s is not loaded", entity.getClass().getSimpleName(), property.getName());
            throw new IllegalArgumentException(errorMessage);
        }
        if (metaProperty.getRange().isClass()) {
            FetchPlan propertyFetchPlan = property.getFetchPlan();
            if (propertyFetchPlan != null && metadataTools.isJpa(metaProperty)) {
                Object value = EntityValues.getValue(entity, metaProperty.getName());
                if (value != null) {
                    if (!metaProperty.getRange().getCardinality().isMany()) {
                        checkLoadedWithFetchPlan(value, propertyFetchPlan, visited);
                    } else {
                        @SuppressWarnings("unchecked") Collection collection = (Collection) value;
                        for (Object item : collection) {
                            checkLoadedWithFetchPlan(item, propertyFetchPlan, visited);
                        }
                    }
                }
            }
        }
    }
    // after check we remove item from visited because different subtrees may have different fetch plan for the same instance
    visited.remove(entity);
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) Collection(java.util.Collection) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 93 with MetaProperty

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

the class EntityStates method recursivelyConstructCurrentFetchPlan.

protected void recursivelyConstructCurrentFetchPlan(Entity entity, FetchPlanBuilder builder, HashSet<Object> visited) {
    if (visited.contains(entity))
        return;
    visited.add(entity);
    // Using MetaClass of the fetchPlan helps in the case when the entity is an item of a collection, and the collection
    // can contain instances of different subclasses. So we don't want to add specific properties of subclasses
    // to the resulting fetch plan.
    MetaClass metaClass = metadata.getClass(builder.getEntityClass());
    for (MetaProperty property : metaClass.getProperties()) {
        if (!isLoaded(entity, property.getName()))
            continue;
        if (property.getRange().isClass()) {
            FetchPlanBuilder propertyBuilder = fetchPlans.builder(property.getRange().asClass().getJavaClass());
            // The input object graph can be large, so we use FetchMode.UNDEFINED to avoid huge SQLs with
            // unpredictably high number of joins
            builder.add(property.getName(), propertyBuilder, FetchMode.UNDEFINED);
            if (isLoaded(entity, property.getName())) {
                Object value = EntityValues.getValue(entity, property.getName());
                if (value != null) {
                    if (value instanceof Collection) {
                        for (Object item : ((Collection) value)) {
                            recursivelyConstructCurrentFetchPlan((Entity) item, propertyBuilder, visited);
                        }
                    } else {
                        recursivelyConstructCurrentFetchPlan((Entity) value, propertyBuilder, visited);
                    }
                }
            }
        } else {
            builder.add(property.getName());
        }
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) Collection(java.util.Collection) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 94 with MetaProperty

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

the class Param method loadEntity.

protected Object loadEntity(String id) {
    MetaProperty primaryKey = metadata.getTools().getPrimaryKeyProperty(metadata.getClassNN(javaClass));
    Object objectId = null;
    if (primaryKey != null) {
        try {
            objectId = primaryKey.getRange().asDatatype().parse(id);
        } catch (ParseException e) {
            throw new RuntimeException("Error parsing entity ID", e);
        }
    }
    // noinspection unchecked
    return dataManager.load(javaClass).fetchPlan(FetchPlan.BASE).id(objectId).optional().orElse(null);
}
Also used : ParseException(java.text.ParseException) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 95 with MetaProperty

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

the class AddAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null || target.getDatasource() == null) {
        return false;
    }
    CollectionDatasource ownerDs = target.getDatasource();
    if (ownerDs instanceof PropertyDatasource) {
        PropertyDatasource datasource = (PropertyDatasource) ownerDs;
        MetaClass parentMetaClass = datasource.getMaster().getMetaClass();
        MetaProperty metaProperty = datasource.getProperty();
        boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
        if (!attrPermitted) {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Aggregations

MetaProperty (io.jmix.core.metamodel.model.MetaProperty)267 MetaClass (io.jmix.core.metamodel.model.MetaClass)162 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)53 Nullable (javax.annotation.Nullable)36 Range (io.jmix.core.metamodel.model.Range)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 Collectors (java.util.stream.Collectors)22 java.util (java.util)20 Component (org.springframework.stereotype.Component)18 Entity (io.jmix.core.Entity)17 EntityValues (io.jmix.core.entity.EntityValues)17 io.jmix.core (io.jmix.core)16 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)12 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)10 Metadata (io.jmix.core.Metadata)9 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8