Search in sources :

Example 26 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class StartNode method getSearchAttribute.

@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, S 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;
    if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {
        if (exactMatch) {
            switch(occur) {
                case REQUIRED:
                    if (!alreadyAdded) {
                        // the first result is the basis of all subsequent intersections
                        intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
                        // the next additions are intersected with this one
                        alreadyAdded = true;
                    } else {
                        intersectionResult.retainAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
                    }
                    break;
                case OPTIONAL:
                    intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
                    break;
                case FORBIDDEN:
                    break;
            }
        } else {
            intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
        }
        attr.setResult(intersectionResult);
    } else {
        // value in the given field
        return new EmptySearchAttribute(this, null);
    }
    return attr;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SourceSearchAttribute(org.structr.core.graph.search.SourceSearchAttribute) EmptySearchAttribute(org.structr.core.graph.search.EmptySearchAttribute) GraphObject(org.structr.core.GraphObject)

Example 27 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class StartNodes method getSearchAttribute.

@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, List<S> 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;
    if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {
        if (exactMatch) {
            for (NodeInterface node : searchValue) {
                switch(occur) {
                    case REQUIRED:
                        if (!alreadyAdded) {
                            // the first result is the basis of all subsequent intersections
                            intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                            // the next additions are intersected with this one
                            alreadyAdded = true;
                        } else {
                            intersectionResult.retainAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                        }
                        break;
                    case OPTIONAL:
                        intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                        break;
                    case FORBIDDEN:
                        break;
                }
            }
        } else {
            // loose search behaves differently, all results must be combined
            for (NodeInterface node : searchValue) {
                intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
            }
        }
        attr.setResult(intersectionResult);
    } else {
        // value in the given field
        return new EmptySearchAttribute(this, null);
    }
    return attr;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SourceSearchAttribute(org.structr.core.graph.search.SourceSearchAttribute) EmptySearchAttribute(org.structr.core.graph.search.EmptySearchAttribute) GraphObject(org.structr.core.GraphObject) NodeInterface(org.structr.core.graph.NodeInterface)

Example 28 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class AllExpression method evaluate.

@Override
public Object evaluate(final ActionContext ctx, final GraphObject entity) throws FrameworkException, UnlicensedException {
    if (listExpression == null) {
        return ERROR_MESSAGE_ALL;
    }
    final Object listSource = listExpression.evaluate(ctx, entity);
    if (listSource != null && listSource instanceof List) {
        final List source = (List) listSource;
        final Object oldDataValue = ctx.getConstant("data");
        for (Object obj : source) {
            ctx.setConstant("data", obj);
            final Object resultObject = allExpression.evaluate(ctx, entity);
            if (resultObject != null) {
                if (resultObject instanceof Boolean) {
                    if (!(Boolean) resultObject) {
                        return false;
                    }
                } else {
                    if (!Boolean.valueOf(resultObject.toString())) {
                        return false;
                    }
                }
            }
        }
        ctx.setConstant("data", oldDataValue);
    }
    return true;
}
Also used : GraphObject(org.structr.core.GraphObject) List(java.util.List)

Example 29 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class AnyExpression method evaluate.

@Override
public Object evaluate(final ActionContext ctx, final GraphObject entity) throws FrameworkException, UnlicensedException {
    if (listExpression == null) {
        return ERROR_MESSAGE_ANY;
    }
    final Object listSource = listExpression.evaluate(ctx, entity);
    if (listSource != null && listSource instanceof List) {
        final List source = (List) listSource;
        final Object oldDataValue = ctx.getConstant("data");
        for (Object obj : source) {
            ctx.setConstant("data", obj);
            final Object resultObject = anyExpression.evaluate(ctx, entity);
            if (resultObject != null) {
                if (resultObject instanceof Boolean) {
                    if ((Boolean) resultObject) {
                        return true;
                    }
                } else {
                    if (Boolean.valueOf(resultObject.toString())) {
                        return true;
                    }
                }
            }
        }
        ctx.setConstant("data", oldDataValue);
    }
    return false;
}
Also used : GraphObject(org.structr.core.GraphObject) List(java.util.List)

Example 30 with GraphObject

use of org.structr.core.GraphObject in project structr by structr.

the class AutoStringProperty method index.

@Override
public void index(GraphObject entity, Object value) {
    Object indexValue = value;
    if (indexValue == null) {
        indexValue = createValue(entity);
        if (indexValue != null) {
            try {
                entity.setProperty(this, (String) indexValue);
            } catch (FrameworkException fex) {
                logger.warn("Unable to set value {} on entity {}: {}", new Object[] { indexValue, entity, fex.getMessage() });
            }
        }
    }
    super.index(entity, indexValue);
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) GraphObject(org.structr.core.GraphObject)

Aggregations

GraphObject (org.structr.core.GraphObject)151 FrameworkException (org.structr.common.error.FrameworkException)58 PropertyKey (org.structr.core.property.PropertyKey)39 LinkedList (java.util.LinkedList)35 SecurityContext (org.structr.common.SecurityContext)25 App (org.structr.core.app.App)25 StructrApp (org.structr.core.app.StructrApp)24 Tx (org.structr.core.graph.Tx)23 List (java.util.List)22 PropertyConverter (org.structr.core.converter.PropertyConverter)22 AbstractNode (org.structr.core.entity.AbstractNode)18 GraphObjectMap (org.structr.core.GraphObjectMap)17 NodeInterface (org.structr.core.graph.NodeInterface)17 LinkedHashSet (java.util.LinkedHashSet)15 PropertyMap (org.structr.core.property.PropertyMap)13 Map (java.util.Map)12 RestMethodResult (org.structr.rest.RestMethodResult)11 ConfigurationProvider (org.structr.schema.ConfigurationProvider)10 Result (org.structr.core.Result)9 ArrayList (java.util.ArrayList)8