Search in sources :

Example 16 with GenericNode

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

the class StructrKnowledgeModuleTest 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 17 with GenericNode

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

the class LicensingTest 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 18 with GenericNode

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

the class StructrTest 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 19 with GenericNode

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

the class BasicTest method test03CreateRelationship.

@Test
public void test03CreateRelationship() {
    try {
        final List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
        final NodeInterface startNode = nodes.get(0);
        final NodeInterface endNode = nodes.get(1);
        NodeHasLocation rel = null;
        assertTrue(startNode != null);
        assertTrue(endNode != null);
        try (final Tx tx = app.tx()) {
            rel = app.create(startNode, endNode, NodeHasLocation.class);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            assertEquals(startNode.getUuid(), rel.getSourceNodeId());
            assertEquals(endNode.getUuid(), rel.getTargetNodeId());
            assertEquals(RelType.IS_AT.name(), rel.getType());
            assertEquals(NodeHasLocation.class, rel.getClass());
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) GenericNode(org.structr.core.entity.GenericNode) NodeHasLocation(org.structr.core.entity.relationship.NodeHasLocation) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test)

Example 20 with GenericNode

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

the class BasicTest method test01ModifyNode.

@Test
public void test01ModifyNode() {
    try {
        final PropertyMap props = new PropertyMap();
        final String type = "UnknownTestType";
        final String name = "GenericNode-name";
        NodeInterface node = null;
        props.put(AbstractNode.type, type);
        props.put(AbstractNode.name, name);
        try (final Tx tx = app.tx()) {
            node = app.create(GenericNode.class, props);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            // Check defaults
            assertEquals(GenericNode.class.getSimpleName(), node.getProperty(AbstractNode.type));
            assertTrue(node.getProperty(AbstractNode.name).equals(name));
            assertTrue(!node.getProperty(AbstractNode.hidden));
            assertTrue(!node.getProperty(AbstractNode.deleted));
            assertTrue(!node.getProperty(AbstractNode.visibleToAuthenticatedUsers));
            assertTrue(!node.getProperty(AbstractNode.visibleToPublicUsers));
        }
        final String name2 = "GenericNode-name-äöüß";
        try (final Tx tx = app.tx()) {
            // Modify values
            node.setProperty(AbstractNode.name, name2);
            node.setProperty(AbstractNode.hidden, true);
            node.setProperty(AbstractNode.deleted, true);
            node.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
            node.setProperty(AbstractNode.visibleToPublicUsers, true);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            assertTrue(node.getProperty(AbstractNode.name).equals(name2));
            assertTrue(node.getProperty(AbstractNode.hidden));
            assertTrue(node.getProperty(AbstractNode.deleted));
            assertTrue(node.getProperty(AbstractNode.visibleToAuthenticatedUsers));
            assertTrue(node.getProperty(AbstractNode.visibleToPublicUsers));
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) GenericNode(org.structr.core.entity.GenericNode) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test)

Aggregations

GenericNode (org.structr.core.entity.GenericNode)24 Tx (org.structr.core.graph.Tx)21 NodeInterface (org.structr.core.graph.NodeInterface)20 LinkedList (java.util.LinkedList)19 Test (org.junit.Test)5 FrameworkException (org.structr.common.error.FrameworkException)4 NodeHasLocation (org.structr.core.entity.relationship.NodeHasLocation)3 RelationshipInterface (org.structr.core.graph.RelationshipInterface)3 PropertyMap (org.structr.core.property.PropertyMap)2 IOException (java.io.IOException)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 RelationshipType (org.structr.api.graph.RelationshipType)1 Result (org.structr.core.Result)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 AbstractRelationship (org.structr.core.entity.AbstractRelationship)1 GenericRelationship (org.structr.core.entity.GenericRelationship)1 StructrUiTest (org.structr.web.StructrUiTest)1