Search in sources :

Example 6 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class SecurityContext method removeForbiddenNodes.

public void removeForbiddenNodes(List<? extends GraphObject> nodes, final boolean includeDeletedAndHidden, final boolean publicOnly) {
    boolean readableByUser = false;
    for (Iterator<? extends GraphObject> it = nodes.iterator(); it.hasNext(); ) {
        GraphObject obj = it.next();
        if (obj instanceof AbstractNode) {
            AbstractNode n = (AbstractNode) obj;
            readableByUser = n.isGranted(Permission.read, this);
            if (!(readableByUser && (includeDeletedAndHidden || !n.isDeleted()) && (n.isVisibleToPublicUsers() || !publicOnly))) {
                it.remove();
            }
        }
    }
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) GraphObject(org.structr.core.GraphObject)

Example 7 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class EntityNotionProperty method getSearchAttribute.

@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, T searchValue, boolean exactMatch, final Query query) {
    final Predicate<GraphObject> predicate = query != null ? query.toPredicate() : null;
    final SourceSearchAttribute attr = new SourceSearchAttribute(occur);
    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded = false;
    try {
        if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {
            final App app = StructrApp.getInstance(securityContext);
            final PropertyKey key = notion.getPrimaryPropertyKey();
            final PropertyConverter inputConverter = key != null ? key.inputConverter(securityContext) : null;
            // transform search values using input convert of notion property
            final Object transformedValue = inputConverter != null ? inputConverter.convert(searchValue) : searchValue;
            if (exactMatch) {
                Result<AbstractNode> result = app.nodeQuery(entityProperty.relatedType()).and(key, transformedValue).getResult();
                for (AbstractNode node : result.getResults()) {
                    switch(occur) {
                        case REQUIRED:
                            if (!alreadyAdded) {
                                // the first result is the basis of all subsequent intersections
                                intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                                // the next additions are intersected with this one
                                alreadyAdded = true;
                            } else {
                                intersectionResult.retainAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                            }
                            break;
                        case OPTIONAL:
                            intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                            break;
                        case FORBIDDEN:
                            break;
                    }
                }
            } else {
                Result<AbstractNode> result = app.nodeQuery(entityProperty.relatedType()).and(key, transformedValue, false).getResult();
                // loose search behaves differently, all results must be combined
                for (AbstractNode node : result.getResults()) {
                    intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                }
            }
            attr.setResult(intersectionResult);
        } else {
            // value in the given field
            return new EmptySearchAttribute(this, null);
        }
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    return attr;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) FrameworkException(org.structr.common.error.FrameworkException) SourceSearchAttribute(org.structr.core.graph.search.SourceSearchAttribute) AbstractNode(org.structr.core.entity.AbstractNode) EmptySearchAttribute(org.structr.core.graph.search.EmptySearchAttribute) GraphObject(org.structr.core.GraphObject) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject)

Example 8 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class CypherQueryProperty method getProperty.

@Override
public List<GraphObject> getProperty(SecurityContext securityContext, GraphObject obj, boolean applyConverter, Predicate<GraphObject> predicate) {
    if (obj instanceof AbstractNode) {
        try {
            final String query = Scripting.replaceVariables(new ActionContext(securityContext), obj, this.format);
            final Map<String, Object> parameters = new LinkedHashMap<>();
            parameters.put("id", obj.getUuid());
            parameters.put("type", obj.getType());
            return StructrApp.getInstance(securityContext).command(CypherQueryCommand.class).execute(query, parameters);
        } catch (Throwable t) {
            logger.warn("", t);
        }
    }
    return null;
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) GraphObject(org.structr.core.GraphObject) ActionContext(org.structr.schema.action.ActionContext) CypherQueryCommand(org.structr.core.graph.CypherQueryCommand) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class CMISAclService method getAcl.

@Override
public Acl getAcl(final String repositoryId, final String objectId, final Boolean onlyBasicPermissions, final ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        final AbstractNode node = app.get(AbstractNode.class, objectId);
        if (node != null) {
            return CMISObjectWrapper.wrap(node, null, false);
        }
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) AbstractNode(org.structr.core.entity.AbstractNode)

Example 10 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class CMISObjectService method getObject.

@Override
public ObjectData getObject(final String repositoryId, final String objectId, final String propertyFilter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePolicyIds, final Boolean includeAcl, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    try (final Tx tx = app.tx()) {
        final AbstractNode obj = app.get(AbstractNode.class, objectId);
        if (obj != null) {
            final ObjectData data = CMISObjectWrapper.wrap(obj, propertyFilter, includeAllowableActions);
            tx.success();
            return data;
        }
    } catch (Throwable t) {
        logger.warn("", t);
    }
    throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) AbstractNode(org.structr.core.entity.AbstractNode) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData)

Aggregations

AbstractNode (org.structr.core.entity.AbstractNode)62 FrameworkException (org.structr.common.error.FrameworkException)31 Tx (org.structr.core.graph.Tx)20 App (org.structr.core.app.App)18 StructrApp (org.structr.core.app.StructrApp)18 GraphObject (org.structr.core.GraphObject)17 SecurityContext (org.structr.common.SecurityContext)16 PropertyMap (org.structr.core.property.PropertyMap)12 Result (org.structr.core.Result)10 Test (org.junit.Test)9 AbstractRelationship (org.structr.core.entity.AbstractRelationship)9 LinkedList (java.util.LinkedList)8 TestOne (org.structr.core.entity.TestOne)8 DatabaseService (org.structr.api.DatabaseService)7 NodeInterface (org.structr.core.graph.NodeInterface)7 PropertyKey (org.structr.core.property.PropertyKey)7 Principal (org.structr.core.entity.Principal)6 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 DOMNode (org.structr.web.entity.dom.DOMNode)5 LinkedHashSet (java.util.LinkedHashSet)4