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