Search in sources :

Example 21 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class GroupDelegate method doGroup.

protected void doGroup() {
    roots = new LinkedList<>();
    parents = new LinkedHashMap<>();
    children = new HashMap<>();
    groupItems = new HashMap<>();
    itemGroups = new HashMap<>();
    final Collection<K> itemIds = datasource.getItemIds();
    for (final K id : itemIds) {
        final T item = datasource.getItem(id);
        GroupInfo<MetaPropertyPath> groupInfo = groupItems(0, null, roots, item, new LinkedMap());
        if (groupInfo == null) {
            throw new IllegalStateException("Item group cannot be NULL");
        }
        List<K> itemsIds = groupItems.computeIfAbsent(groupInfo, k -> new ArrayList<>());
        itemsIds.add(id);
    }
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) LinkedMap(org.apache.commons.collections4.map.LinkedMap)

Example 22 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class GroupDelegate method doGroupSort.

protected void doGroupSort(CollectionDatasource.Sortable.SortInfo<MetaPropertyPath>[] sortInfo) {
    if (hasGroups()) {
        final MetaPropertyPath propertyPath = sortInfo[0].getPropertyPath();
        final boolean asc = CollectionDatasource.Sortable.Order.ASC.equals(sortInfo[0].getOrder());
        final int index = Arrays.asList(groupProperties).indexOf(propertyPath);
        if (index > -1) {
            if (index == 0) {
                // Sort roots
                roots.sort(new GroupInfoComparator(asc));
            } else {
                final Object parentProperty = groupProperties[index - 1];
                for (final Map.Entry<GroupInfo, List<GroupInfo>> entry : children.entrySet()) {
                    Object property = entry.getKey().getProperty();
                    if (property.equals(parentProperty)) {
                        entry.getValue().sort(new GroupInfoComparator(asc));
                    }
                }
            }
        } else {
            final Set<GroupInfo> groups = parents.keySet();
            for (final GroupInfo groupInfo : groups) {
                List<K> items = groupItems.get(groupInfo);
                if (items != null) {
                    items.sort(new EntityByIdComparator<>(propertyPath, datasource, asc));
                }
            }
        }
    }
}
Also used : GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) LinkedMap(org.apache.commons.collections4.map.LinkedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 23 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class RdbmsStore method checkValueQueryPermissions.

protected boolean checkValueQueryPermissions(QueryParser queryParser) {
    if (isAuthorizationRequired()) {
        queryParser.getQueryPaths().stream().filter(path -> !path.isSelectedPath()).forEach(path -> {
            MetaClass metaClass = metadata.getClassNN(path.getEntityName());
            MetaPropertyPath propertyPath = metaClass.getPropertyPath(path.getPropertyPath());
            if (propertyPath == null) {
                throw new IllegalStateException(String.format("query path '%s' is unresolved", path.getFullPath()));
            }
            if (!isEntityAttrViewPermitted(propertyPath)) {
                throw new AccessDeniedException(PermissionType.ENTITY_ATTR, metaClass + "." + path.getFullPath());
            }
        });
        MetaClass metaClass = metadata.getClassNN(queryParser.getEntityName());
        if (!isEntityOpPermitted(metaClass, EntityOp.READ)) {
            log.debug("reading of {} not permitted, returning empty list", metaClass);
            return false;
        }
        if (security.hasInMemoryConstraints(metaClass, ConstraintOperationType.READ, ConstraintOperationType.ALL)) {
            String msg = String.format("%s is not permitted for %s", ConstraintOperationType.READ, metaClass.getName());
            if (serverConfig.getDisableLoadValuesIfConstraints()) {
                throw new RowLevelSecurityException(msg, metaClass.getName(), ConstraintOperationType.READ);
            } else {
                log.debug(msg);
            }
        }
        Set<String> entityNames = queryParser.getAllEntityNames();
        entityNames.remove(metaClass.getName());
        for (String entityName : entityNames) {
            MetaClass entityMetaClass = metadata.getClassNN(entityName);
            if (!isEntityOpPermitted(entityMetaClass, EntityOp.READ)) {
                log.debug("reading of {} not permitted, returning empty list", entityMetaClass);
                return false;
            }
            if (security.hasConstraints(entityMetaClass)) {
                String msg = String.format("%s is not permitted for %s", ConstraintOperationType.READ, entityName);
                if (serverConfig.getDisableLoadValuesIfConstraints()) {
                    throw new RowLevelSecurityException(msg, entityName, ConstraintOperationType.READ);
                } else {
                    log.debug(msg);
                }
            }
        }
    }
    return true;
}
Also used : com.haulmont.cuba.core(com.haulmont.cuba.core) java.util(java.util) PermissionType(com.haulmont.cuba.security.entity.PermissionType) LoggerFactory(org.slf4j.LoggerFactory) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) NoResultException(javax.persistence.NoResultException) ConstraintOperationType(com.haulmont.cuba.security.entity.ConstraintOperationType) MetaClass(com.haulmont.chile.core.model.MetaClass) Scope(org.springframework.context.annotation.Scope) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) StringUtils.isBlank(org.apache.commons.lang.StringUtils.isBlank) AbstractInstance(com.haulmont.chile.core.model.impl.AbstractInstance) com.haulmont.cuba.core.entity(com.haulmont.cuba.core.entity) EntityFetcher(com.haulmont.cuba.core.sys.EntityFetcher) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Collectors(java.util.stream.Collectors) Preconditions(com.haulmont.bali.util.Preconditions) DynamicAttributesManagerAPI(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesManagerAPI) Component(org.springframework.stereotype.Component) EntityOp(com.haulmont.cuba.security.entity.EntityOp) AppContext(com.haulmont.cuba.core.sys.AppContext) EntityAttrAccess(com.haulmont.cuba.security.entity.EntityAttrAccess) QueryResultsManagerAPI(com.haulmont.cuba.core.app.queryresults.QueryResultsManagerAPI) Session(com.haulmont.chile.core.model.Session) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 24 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class AttributeAccessSupport method visitComponent.

protected void visitComponent(DatasourceComponent component, boolean reset) {
    Datasource datasource = component.getDatasource();
    MetaPropertyPath propertyPath = component.getMetaPropertyPath();
    if (datasource == null || datasource.getState() != Datasource.State.VALID || propertyPath == null || datasource.getItem() == null) {
        return;
    }
    if (reset) {
        component.setVisible(security.isEntityAttrReadPermitted(datasource.getMetaClass(), propertyPath.toString()));
        component.setEditable(security.isEntityAttrUpdatePermitted(datasource.getMetaClass(), propertyPath.toString()));
        if (component instanceof Field) {
            ((Field) component).setRequired(propertyPath.getMetaProperty().isMandatory());
        }
    }
    ComponentState componentState = calculateComponentState(datasource.getItem(), propertyPath);
    if (componentState.hidden) {
        component.setVisible(false);
    }
    if (componentState.readOnly) {
        component.setEditable(false);
    }
    if (component instanceof Field) {
        if (componentState.required && component.isEditable() && component.isVisible()) {
            ((Field) component).setRequired(true);
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Field(com.haulmont.cuba.gui.components.Field) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 25 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class ComponentsHelper method createActionsByMetaAnnotations.

/**
 * INTERNAL.
 * Adds actions specified in {@link Lookup} annotation on entity attribute to the given PickerField.
 */
public static boolean createActionsByMetaAnnotations(PickerField pickerField) {
    MetaPropertyPath mpp = pickerField.getMetaPropertyPath();
    if (mpp == null)
        return false;
    String[] actions = (String[]) AppBeans.get(MetadataTools.class).getMetaAnnotationAttributes(mpp.getMetaProperty().getAnnotations(), Lookup.class).get("actions");
    if (actions != null && actions.length > 0) {
        for (String actionId : actions) {
            for (PickerField.ActionType actionType : PickerField.ActionType.values()) {
                if (actionType.getId().equals(actionId.trim())) {
                    pickerField.addAction(actionType.createAction(pickerField));
                    break;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Aggregations

MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)84 MetaClass (com.haulmont.chile.core.model.MetaClass)34 MetaProperty (com.haulmont.chile.core.model.MetaProperty)27 Element (org.dom4j.Element)16 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)11 Entity (com.haulmont.cuba.core.entity.Entity)9 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)9 Datasource (com.haulmont.cuba.gui.data.Datasource)6 Table (com.haulmont.cuba.gui.components.Table)5 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 Instance (com.haulmont.chile.core.model.Instance)3 Op (com.haulmont.cuba.core.global.filter.Op)3 FocusableTable (com.haulmont.cuba.desktop.sys.vcl.FocusableTable)3 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Formatter (com.haulmont.cuba.gui.components.Formatter)3 Window (com.haulmont.cuba.gui.components.Window)3 CollectionFormatter (com.haulmont.cuba.gui.components.formatters.CollectionFormatter)3 GroupInfo (com.haulmont.cuba.gui.data.GroupInfo)3 java.util (java.util)3