Search in sources :

Example 36 with AbstractNode

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

the class IdRequestParameterGraphDataSource method getData.

@Override
public Iterable<GraphObject> getData(final RenderContext renderContext, final DOMNode referenceNode) throws FrameworkException {
    final SecurityContext securityContext = renderContext.getSecurityContext();
    if (securityContext != null && securityContext.getRequest() != null) {
        String nodeId = securityContext.getRequest().getParameter(parameterName);
        if (nodeId != null) {
            AbstractNode node = (AbstractNode) StructrApp.getInstance(securityContext).getNodeById(nodeId);
            if (node != null) {
                List<GraphObject> graphData = new LinkedList<>();
                graphData.add(node);
                return graphData;
            }
        }
    }
    return null;
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) SecurityContext(org.structr.common.SecurityContext) GraphObject(org.structr.core.GraphObject) LinkedList(java.util.LinkedList)

Example 37 with AbstractNode

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

the class AbstractPrimitiveProperty method setProperty.

@Override
public Object setProperty(final SecurityContext securityContext, final GraphObject obj, final T value) throws FrameworkException {
    final PropertyConverter converter = databaseConverter(securityContext, PropertyMap.unwrap(obj));
    Object convertedValue = value;
    if (converter != null) {
        convertedValue = converter.convert(value);
    }
    // use transformators from property
    for (final String fqcn : transformators) {
        // first test, use caching here later..
        final Transformer transformator = getTransformator(fqcn);
        if (transformator != null) {
            convertedValue = transformator.setProperty(PropertyMap.unwrap(obj), this, convertedValue);
        }
    }
    final PropertyContainer propertyContainer = obj.getPropertyContainer();
    if (propertyContainer != null) {
        if (!TransactionCommand.inTransaction()) {
            throw new NotInTransactionException("setProperty outside of transaction");
        }
        boolean internalSystemPropertiesUnlocked = (obj instanceof CreationContainer);
        // collect modified properties
        if (obj instanceof AbstractNode) {
            if (!unvalidated) {
                TransactionCommand.nodeModified(securityContext.getCachedUser(), (AbstractNode) obj, AbstractPrimitiveProperty.this, propertyContainer.hasProperty(dbName()) ? propertyContainer.getProperty(dbName()) : null, value);
            }
            internalSystemPropertiesUnlocked = ((AbstractNode) obj).internalSystemPropertiesUnlocked;
        } else if (obj instanceof AbstractRelationship) {
            if (!unvalidated) {
                TransactionCommand.relationshipModified(securityContext.getCachedUser(), (AbstractRelationship) obj, AbstractPrimitiveProperty.this, propertyContainer.hasProperty(dbName()) ? propertyContainer.getProperty(dbName()) : null, value);
            }
            internalSystemPropertiesUnlocked = ((AbstractRelationship) obj).internalSystemPropertiesUnlocked;
        }
        // catch all sorts of errors and wrap them in a FrameworkException
        try {
            // save space
            if (convertedValue == null) {
                propertyContainer.removeProperty(dbName());
            } else {
                if (!isSystemInternal() || internalSystemPropertiesUnlocked) {
                    propertyContainer.setProperty(dbName(), convertedValue);
                } else {
                    logger.warn("Tried to set internal system property {} to {}. Action was denied.", new Object[] { dbName(), convertedValue });
                }
            }
            updateAccessInformation(securityContext, propertyContainer);
        } catch (final RetryException rex) {
            // don't catch RetryException here
            throw rex;
        } catch (Throwable t) {
            // throw FrameworkException with the given cause
            final FrameworkException fex = new FrameworkException(500, "Unable to set property " + jsonName() + " on entity with ID " + obj.getUuid() + ": " + t.toString());
            fex.initCause(t);
            throw fex;
        }
        if (isIndexed()) {
            // work
            if (!isPassivelyIndexed()) {
                index(obj, convertedValue);
            }
        }
    }
    return null;
}
Also used : PropertyContainer(org.structr.api.graph.PropertyContainer) Transformer(org.structr.schema.Transformer) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) AbstractRelationship(org.structr.core.entity.AbstractRelationship) CreationContainer(org.structr.core.graph.CreationContainer) RetryException(org.structr.api.RetryException) NotInTransactionException(org.structr.api.NotInTransactionException) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject)

Example 38 with AbstractNode

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

the class AggregatorProperty method getProperty.

@Override
public List<T> getProperty(SecurityContext securityContext, GraphObject currentObject, boolean applyConverter, final Predicate<GraphObject> predicate) {
    if (currentObject != null && currentObject instanceof AbstractNode) {
        NodeInterface sourceNode = (NodeInterface) currentObject;
        List<NodeInterface> nodes = new LinkedList<>();
        // 1. step: add all nodes
        for (Property property : aggregation.getAggregationProperties()) {
            Object obj = sourceNode.getProperty(property);
            if (obj != null && obj instanceof Collection) {
                nodes.addAll((Collection) obj);
            }
        }
        // 2. step: sort nodes according to comparator
        Comparator<NodeInterface> comparator = aggregation.getComparator();
        if (nodes.isEmpty() && comparator != null) {
            Collections.sort(nodes, comparator);
        }
        // 3. step: apply notions depending on type
        List results = new LinkedList();
        try {
            for (NodeInterface node : nodes) {
                Notion notion = aggregation.getNotionForType(node.getClass());
                if (notion != null) {
                    results.add(notion.getAdapterForGetter(securityContext).adapt(node));
                } else {
                    results.add(node);
                }
            }
        } catch (Throwable t) {
            logger.warn("", t);
        }
        return results;
    }
    return Collections.emptyList();
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) Collection(java.util.Collection) Notion(org.structr.core.notion.Notion) GraphObject(org.structr.core.GraphObject) List(java.util.List) LinkedList(java.util.LinkedList) NodeInterface(org.structr.core.graph.NodeInterface) LinkedList(java.util.LinkedList)

Example 39 with AbstractNode

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

the class CollectionNotionProperty method getSearchAttribute.

@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, List<T> searchValues, 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 (searchValues != null && !searchValues.isEmpty()) {
            final PropertyKey key = notion.getPrimaryPropertyKey();
            final PropertyConverter inputConverter = key.inputConverter(securityContext);
            final List<Object> transformedValues = new LinkedList<>();
            boolean allBlank = true;
            // transform search values using input convert of notion property
            for (T searchValue : searchValues) {
                if (inputConverter != null) {
                    transformedValues.add(inputConverter.convert(searchValue));
                } else {
                    transformedValues.add(searchValue);
                }
            }
            // iterate over transformed values
            for (Object searchValue : transformedValues) {
                // check if the list contains non-empty search values
                if (StringUtils.isBlank(searchValue.toString())) {
                    continue;
                } else {
                    allBlank = false;
                }
                final App app = StructrApp.getInstance(securityContext);
                if (exactMatch) {
                    Result<AbstractNode> result = app.nodeQuery(collectionProperty.relatedType()).and(notion.getPrimaryPropertyKey(), searchValue).getResult();
                    for (AbstractNode node : result.getResults()) {
                        switch(occur) {
                            case REQUIRED:
                                if (!alreadyAdded) {
                                    // the first result is the basis of all subsequent intersections
                                    intersectionResult.addAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                                    // the next additions are intersected with this one
                                    alreadyAdded = true;
                                } else {
                                    intersectionResult.retainAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                                }
                                break;
                            case OPTIONAL:
                                intersectionResult.addAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                                break;
                            case FORBIDDEN:
                                break;
                        }
                    }
                } else {
                    Result<AbstractNode> result = app.nodeQuery(collectionProperty.relatedType()).and(notion.getPrimaryPropertyKey(), searchValue, false).getResult();
                    // loose search behaves differently, all results must be combined
                    for (AbstractNode node : result.getResults()) {
                        intersectionResult.addAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                    }
                }
            }
            if (allBlank) {
                // value in the given field
                return new EmptySearchAttribute(this, Collections.emptyList());
            } else {
                attr.setResult(intersectionResult);
            }
        } else {
            // value in the given field
            return new EmptySearchAttribute(this, Collections.emptyList());
        }
    } 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) LinkedList(java.util.LinkedList) PropertyConverter(org.structr.core.converter.PropertyConverter) GraphObject(org.structr.core.GraphObject)

Example 40 with AbstractNode

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

the class HyperRelationProperty method getProperty.

@Override
public List<T> getProperty(SecurityContext securityContext, GraphObject obj, boolean applyConverter, final Predicate<GraphObject> predicate) {
    List<S> connectors = obj.getProperty(step1);
    List<T> endNodes = new LinkedList<>();
    if (connectors != null) {
        for (AbstractNode node : connectors) {
            endNodes.add(node.getProperty(step2));
        }
    }
    return endNodes;
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) LinkedList(java.util.LinkedList)

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