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;
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations