Search in sources :

Example 1 with EntityCollectionPropertyDiff

use of com.haulmont.cuba.core.entity.diff.EntityCollectionPropertyDiff in project cuba by cuba-platform.

the class DiffTreeDatasource method loadPropertyDiff.

protected Node<EntityPropertyDiff> loadPropertyDiff(EntityPropertyDiff propertyDiff) {
    Node<EntityPropertyDiff> diffNode = null;
    if (propertyDiff != null) {
        Security security = AppBeans.get(Security.NAME);
        MetaClass propMetaClass = metadata.getClassNN(propertyDiff.getMetaClassName());
        if (!security.isEntityOpPermitted(propMetaClass, EntityOp.READ) || !security.isEntityAttrPermitted(propMetaClass, propertyDiff.getPropertyName(), EntityAttrAccess.VIEW)) {
            return null;
        }
        diffNode = new Node<>(propertyDiff);
        if (propertyDiff instanceof EntityClassPropertyDiff) {
            EntityClassPropertyDiff classPropertyDiff = (EntityClassPropertyDiff) propertyDiff;
            for (EntityPropertyDiff childPropertyDiff : classPropertyDiff.getPropertyDiffs()) {
                Node<EntityPropertyDiff> childPropDiffNode = loadPropertyDiff(childPropertyDiff);
                if (childPropDiffNode != null)
                    diffNode.addChild(childPropDiffNode);
            }
        } else if (propertyDiff instanceof EntityCollectionPropertyDiff) {
            EntityCollectionPropertyDiff collectionPropertyDiff = (EntityCollectionPropertyDiff) propertyDiff;
            for (EntityPropertyDiff childPropertyDiff : collectionPropertyDiff.getAddedEntities()) {
                Node<EntityPropertyDiff> childPropDiffNode = loadPropertyDiff(childPropertyDiff);
                if (childPropDiffNode != null)
                    diffNode.addChild(childPropDiffNode);
            }
            for (EntityPropertyDiff childPropertyDiff : collectionPropertyDiff.getModifiedEntities()) {
                Node<EntityPropertyDiff> childPropDiffNode = loadPropertyDiff(childPropertyDiff);
                if (childPropDiffNode != null)
                    diffNode.addChild(childPropDiffNode);
            }
            for (EntityPropertyDiff childPropertyDiff : collectionPropertyDiff.getRemovedEntities()) {
                Node<EntityPropertyDiff> childPropDiffNode = loadPropertyDiff(childPropertyDiff);
                if (childPropDiffNode != null)
                    diffNode.addChild(childPropDiffNode);
            }
        }
    }
    return diffNode;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) EntityCollectionPropertyDiff(com.haulmont.cuba.core.entity.diff.EntityCollectionPropertyDiff) EntityClassPropertyDiff(com.haulmont.cuba.core.entity.diff.EntityClassPropertyDiff) Node(com.haulmont.bali.datastruct.Node) Security(com.haulmont.cuba.core.global.Security) EntityPropertyDiff(com.haulmont.cuba.core.entity.diff.EntityPropertyDiff)

Aggregations

Node (com.haulmont.bali.datastruct.Node)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 EntityClassPropertyDiff (com.haulmont.cuba.core.entity.diff.EntityClassPropertyDiff)1 EntityCollectionPropertyDiff (com.haulmont.cuba.core.entity.diff.EntityCollectionPropertyDiff)1 EntityPropertyDiff (com.haulmont.cuba.core.entity.diff.EntityPropertyDiff)1 Security (com.haulmont.cuba.core.global.Security)1