Search in sources :

Example 21 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class StartNodeGroup method getGroupedProperties.

@Override
public PropertyMap getGroupedProperties(SecurityContext securityContext, GraphObject source) {
    if (source instanceof AbstractRelationship) {
        RelationshipInterface rel = (RelationshipInterface) source;
        NodeInterface startNode = rel.getSourceNode();
        return super.getGroupedProperties(securityContext, startNode);
    }
    return null;
}
Also used : AbstractRelationship(org.structr.core.entity.AbstractRelationship) RelationshipInterface(org.structr.core.graph.RelationshipInterface) NodeInterface(org.structr.core.graph.NodeInterface)

Example 22 with NodeInterface

use of org.structr.core.graph.NodeInterface 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 23 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class GeoTest method createTestRelationships.

protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {
    List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
    final NodeInterface startNode = nodes.get(0);
    final NodeInterface endNode = nodes.get(1);
    try (final Tx tx = app.tx()) {
        List<T> rels = new LinkedList<>();
        for (int i = 0; i < number; i++) {
            rels.add((T) app.create(startNode, endNode, relType));
        }
        tx.success();
        return rels;
    }
}
Also used : Tx(org.structr.core.graph.Tx) GenericNode(org.structr.core.entity.GenericNode) NodeInterface(org.structr.core.graph.NodeInterface) LinkedList(java.util.LinkedList)

Example 24 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class StructrDataFeedsModuleTest method createTestRelationships.

protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {
    List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
    final NodeInterface startNode = nodes.get(0);
    final NodeInterface endNode = nodes.get(1);
    try (final Tx tx = app.tx()) {
        List<T> rels = new LinkedList<>();
        for (int i = 0; i < number; i++) {
            rels.add((T) app.create(startNode, endNode, relType));
        }
        tx.success();
        return rels;
    }
}
Also used : Tx(org.structr.core.graph.Tx) GenericNode(org.structr.core.entity.GenericNode) NodeInterface(org.structr.core.graph.NodeInterface) LinkedList(java.util.LinkedList)

Example 25 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class StructrCsvModuleTest method cleanDatabase.

@After
@Before
public void cleanDatabase() {
    try (final Tx tx = app.tx()) {
        final List<? extends NodeInterface> nodes = app.nodeQuery().getAsList();
        logger.info("Cleaning database: {} nodes", nodes.size());
        for (final NodeInterface node : nodes) {
            app.delete(node);
        }
        // delete remaining nodes without UUIDs etc.
        app.cypher("MATCH (n)-[r]-(m) DELETE n, r, m", Collections.emptyMap());
        tx.success();
    } catch (FrameworkException fex) {
        logger.error("Exception while trying to clean database: {}", fex);
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NodeInterface(org.structr.core.graph.NodeInterface) Before(org.junit.Before) After(org.junit.After)

Aggregations

NodeInterface (org.structr.core.graph.NodeInterface)186 FrameworkException (org.structr.common.error.FrameworkException)120 Tx (org.structr.core.graph.Tx)116 Test (org.junit.Test)81 PropertyKey (org.structr.core.property.PropertyKey)61 LinkedList (java.util.LinkedList)36 StructrTest (org.structr.common.StructrTest)29 PropertyMap (org.structr.core.property.PropertyMap)26 TestOne (org.structr.core.entity.TestOne)24 List (java.util.List)23 GraphObject (org.structr.core.GraphObject)22 App (org.structr.core.app.App)21 StructrApp (org.structr.core.app.StructrApp)21 GenericNode (org.structr.core.entity.GenericNode)21 Before (org.junit.Before)18 Result (org.structr.core.Result)18 AbstractRelationship (org.structr.core.entity.AbstractRelationship)16 Random (java.util.Random)15 RelationshipInterface (org.structr.core.graph.RelationshipInterface)14 ErrorToken (org.structr.common.error.ErrorToken)12