Search in sources :

Example 1 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class RemoveAction method checkRemovePermission.

protected boolean checkRemovePermission() {
    CollectionDatasource ds = target.getDatasource();
    if (ds instanceof PropertyDatasource) {
        PropertyDatasource propertyDatasource = (PropertyDatasource) ds;
        MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass();
        MetaProperty metaProperty = propertyDatasource.getProperty();
        boolean modifyPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
        if (!modifyPermitted) {
            return false;
        }
        if (metaProperty.getRange().getCardinality() != Range.Cardinality.MANY_TO_MANY) {
            boolean deletePermitted = security.isEntityOpPermitted(ds.getMetaClass(), EntityOp.DELETE);
            if (!deletePermitted) {
                return false;
            }
        }
    } else {
        boolean entityOpPermitted = security.isEntityOpPermitted(ds.getMetaClass(), EntityOp.DELETE);
        if (!entityOpPermitted) {
            return false;
        }
    }
    return true;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 2 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class FilterDelegateImpl method setDatasource.

@Override
public void setDatasource(CollectionDatasource datasource) {
    this.datasource = datasource;
    this.dsQueryFilter = datasource.getQueryFilter();
    if (getResultingManualApplyRequired()) {
        // set initial denying condition to get empty datasource before explicit filter applying
        QueryFilter queryFilter = new QueryFilter(new DenyingClause());
        if (dsQueryFilter != null) {
            queryFilter = QueryFilter.merge(dsQueryFilter, queryFilter);
        }
        datasource.setQueryFilter(queryFilter);
    }
    if (datasource instanceof CollectionDatasource.Lazy || datasource instanceof HierarchicalDatasource) {
        setUseMaxResults(false);
    } else if (useMaxResults) {
        initMaxResults();
    }
    if (ftsSwitch != null && !isEntityAvailableForFts()) {
        controlsLayout.remove(ftsSwitch);
    }
}
Also used : QueryFilter(com.haulmont.cuba.core.global.filter.QueryFilter) HierarchicalDatasource(com.haulmont.cuba.gui.data.HierarchicalDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DenyingClause(com.haulmont.cuba.core.global.filter.DenyingClause)

Example 3 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class FilterParserImpl method createCondition.

protected AbstractCondition createCondition(ConditionType type, Element element, Filter filter, String xml) {
    String filterComponentName = filter.getId();
    String messagesPack = filter.getFrame().getMessagesPack();
    CollectionDatasource datasource = filter.getDatasource();
    switch(type) {
        case GROUP:
            return new GroupCondition(element, filterComponentName);
        case PROPERTY:
            return new PropertyCondition(element, messagesPack, filterComponentName, datasource);
        case CUSTOM:
            return new CustomCondition(element, messagesPack, filterComponentName, datasource);
        case RUNTIME_PROPERTY:
            return new DynamicAttributesCondition(element, messagesPack, filterComponentName, datasource);
        case FTS:
            return new FtsCondition(element, messagesPack, filterComponentName, datasource);
        default:
            throw new IllegalStateException("Unknown condition type: " + type + " in " + xml);
    }
}
Also used : CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 4 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class Param method createOptionsDataSource.

protected CollectionDatasource<Entity<Object>, Object> createOptionsDataSource(MetaClass metaClass) {
    CollectionDatasource ds = DsBuilder.create(datasource.getDsContext()).setMetaClass(metaClass).setViewName(entityView).buildCollectionDatasource();
    ds.setRefreshOnComponentValueChange(true);
    ((DatasourceImplementation) ds).initialized();
    if (!StringUtils.isBlank(entityWhere)) {
        QueryTransformer transformer = QueryTransformerFactory.createTransformer("select e from " + metaClass.getName() + " e");
        transformer.addWhere(entityWhere);
        String q = transformer.getResult();
        ds.setQuery(q);
    }
    if (WindowParams.DISABLE_AUTO_REFRESH.getBool(datasource.getDsContext().getFrameContext())) {
        if (ds instanceof CollectionDatasource.Suspendable)
            ((CollectionDatasource.Suspendable) ds).refreshIfNotSuspended();
        else
            ds.refresh();
    }
    return ds;
}
Also used : CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation)

Example 5 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class ConditionDescriptorsTreeBuilder method build.

@Override
public Tree<AbstractConditionDescriptor> build() {
    Messages messages = AppBeans.get(Messages.class);
    String messagesPack = filter.getFrame().getMessagesPack();
    CollectionDatasource datasource = filter.getDatasource();
    Tree<AbstractConditionDescriptor> tree = new Tree<>();
    List<AbstractConditionDescriptor> propertyDescriptors = new ArrayList<>();
    List<AbstractConditionDescriptor> customDescriptors = new ArrayList<>();
    boolean propertiesExplicitlyDefined = false;
    if (filter.getXmlDescriptor() != null) {
        for (Element element : Dom4j.elements(filter.getXmlDescriptor())) {
            AbstractConditionDescriptor conditionDescriptor;
            if ("properties".equals(element.getName())) {
                addMultiplePropertyDescriptors(element, propertyDescriptors, filter);
                propertiesExplicitlyDefined = true;
            } else if ("property".equals(element.getName())) {
                conditionDescriptor = new PropertyConditionDescriptor(element, messagesPack, filterComponentName, datasource);
                propertyDescriptors.add(conditionDescriptor);
                propertiesExplicitlyDefined = true;
            } else if ("custom".equals(element.getName())) {
                conditionDescriptor = new CustomConditionDescriptor(element, messagesPack, filterComponentName, datasource);
                customDescriptors.add(conditionDescriptor);
                propertiesExplicitlyDefined = true;
            } else {
                throw new UnsupportedOperationException("Element not supported: " + element.getName());
            }
        }
    }
    if (!propertiesExplicitlyDefined) {
        addMultiplePropertyDescriptors(".*", "", propertyDescriptors, filter);
    }
    propertyDescriptors.sort(new ConditionDescriptorComparator());
    customDescriptors.sort(new ConditionDescriptorComparator());
    HeaderConditionDescriptor propertyHeaderDescriptor = new HeaderConditionDescriptor("propertyConditions", messages.getMainMessage("filter.addCondition.propertyConditions"), filterComponentName, datasource);
    HeaderConditionDescriptor customHeaderDescriptor = new HeaderConditionDescriptor("customConditions", messages.getMainMessage("filter.addCondition.customConditions"), filterComponentName, datasource);
    Node<AbstractConditionDescriptor> propertyHeaderNode = new Node<>(propertyHeaderDescriptor);
    Node<AbstractConditionDescriptor> customHeaderNode = new Node<>(customHeaderDescriptor);
    int currentDepth = 0;
    for (AbstractConditionDescriptor propertyDescriptor : propertyDescriptors) {
        MetaClass propertyDsMetaClass = propertyDescriptor.getDatasourceMetaClass();
        MetaPropertyPath propertyPath = propertyDsMetaClass.getPropertyPath(propertyDescriptor.getName());
        if (propertyPath == null) {
            log.error("Property path for {} of metaClass {} not found", propertyDescriptor.getName(), propertyDsMetaClass.getName());
            continue;
        }
        MetaProperty metaProperty = propertyPath.getMetaProperty();
        MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
        if (isPropertyAllowed(propertyEnclosingMetaClass, metaProperty) && !excludedProperties.contains(metaProperty.getName())) {
            Node<AbstractConditionDescriptor> node = new Node<>(propertyDescriptor);
            propertyHeaderNode.addChild(node);
            if (currentDepth < hierarchyDepth) {
                recursivelyFillPropertyDescriptors(node, currentDepth);
            }
        }
    }
    for (AbstractConditionDescriptor customDescriptor : customDescriptors) {
        Node<AbstractConditionDescriptor> node = new Node<>(customDescriptor);
        customHeaderNode.addChild(node);
    }
    List<Node<AbstractConditionDescriptor>> rootNodes = new ArrayList<>();
    rootNodes.add(propertyHeaderNode);
    if (!customDescriptors.isEmpty())
        rootNodes.add(customHeaderNode);
    if (!hideCustomConditions && security.isSpecificPermitted(CUSTOM_CONDITIONS_PERMISSION)) {
        rootNodes.add(new Node<>(new CustomConditionCreator(filterComponentName, datasource)));
    }
    if (!hideDynamicAttributes && !dynamicAttributes.getAttributesForMetaClass(datasource.getMetaClass()).isEmpty()) {
        rootNodes.add(new Node<>(new DynamicAttributesConditionCreator(filterComponentName, datasource, "")));
    }
    if (FtsConfigHelper.getEnabled()) {
        rootNodes.add(new Node<>(new FtsConditionDescriptor(filterComponentName, datasource)));
    }
    tree.setRootNodes(rootNodes);
    return tree;
}
Also used : CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Element(org.dom4j.Element) Node(com.haulmont.bali.datastruct.Node) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) Tree(com.haulmont.bali.datastruct.Tree) MetaProperty(com.haulmont.chile.core.model.MetaProperty) MetaClass(com.haulmont.chile.core.model.MetaClass)

Aggregations

CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)67 Datasource (com.haulmont.cuba.gui.data.Datasource)39 UUID (java.util.UUID)24 Group (com.haulmont.cuba.security.entity.Group)23 User (com.haulmont.cuba.security.entity.User)23 ArrayList (java.util.ArrayList)23 Ignore (org.junit.Ignore)23 Test (org.junit.Test)23 Component (com.haulmont.cuba.gui.components.Component)20 List (java.util.List)19 Assert.assertEquals (org.junit.Assert.assertEquals)19 Assert.assertTrue (org.junit.Assert.assertTrue)19 Entity (com.haulmont.cuba.core.entity.Entity)15 MetaClass (com.haulmont.chile.core.model.MetaClass)10 MetaProperty (com.haulmont.chile.core.model.MetaProperty)10 LookupField (com.haulmont.cuba.gui.components.LookupField)8 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)7 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)7 Element (org.dom4j.Element)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7