Search in sources :

Example 76 with NodeInterface

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

the class StructrApiModuleTest 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 77 with NodeInterface

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

the class PushTransmission method doRemote.

@Override
public Boolean doRemote(final CloudConnection client) throws IOException, FrameworkException {
    // reset sequence number
    sequenceNumber = 0;
    // send child nodes when recursive sending is requested
    final Set<NodeInterface> nodes = exportSet.getNodes();
    for (final NodeInterface n : nodes) {
        if (n instanceof File) {
            sendFile(client, (File) n, CloudService.CHUNK_SIZE);
        } else {
            client.send(new NodeDataContainer(n, sequenceNumber++));
        }
    }
    // send relationships
    Set<RelationshipInterface> rels = exportSet.getRelationships();
    for (RelationshipInterface r : rels) {
        if (nodes.contains(r.getSourceNode()) && nodes.contains(r.getTargetNode())) {
            client.send(new RelationshipDataContainer(r, sequenceNumber++));
        } else {
            System.out.println("NOT sending relationship data container " + r + " because source or target node are not in the export set.");
        }
    }
    client.send(new End());
    // wait for end of transmission
    client.waitForTransmission();
    return true;
}
Also used : RelationshipDataContainer(org.structr.cloud.message.RelationshipDataContainer) RelationshipInterface(org.structr.core.graph.RelationshipInterface) FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer) NodeDataContainer(org.structr.cloud.message.NodeDataContainer) End(org.structr.cloud.message.End) File(org.structr.dynamic.File) NodeInterface(org.structr.core.graph.NodeInterface)

Example 78 with NodeInterface

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

the class PullFile method onRequest.

@Override
public void onRequest(CloudConnection serverConnection) throws IOException, FrameworkException {
    final Object value = serverConnection.getValue(key + "Nodes");
    if (value instanceof List) {
        final List<NodeInterface> nodes = (List<NodeInterface>) value;
        final NodeInterface node = nodes.get(nodeIndex);
        final File file = (File) node;
        serverConnection.send(new FileNodeDataContainer(file));
    }
}
Also used : List(java.util.List) File(org.structr.dynamic.File) NodeInterface(org.structr.core.graph.NodeInterface)

Example 79 with NodeInterface

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

the class PullNode method onRequest.

@Override
public void onRequest(CloudConnection serverConnection) throws IOException, FrameworkException {
    final Object value = serverConnection.getValue(key + "Nodes");
    if (value instanceof List) {
        final List<NodeInterface> nodes = (List<NodeInterface>) value;
        final NodeInterface node = nodes.get(nodeIndex);
        if (node instanceof File) {
            PushTransmission.sendFile(serverConnection, (File) node, CloudService.CHUNK_SIZE);
        } else {
            serverConnection.send(new NodeDataContainer(node, nodeIndex));
        }
    }
}
Also used : List(java.util.List) File(org.structr.dynamic.File) NodeInterface(org.structr.core.graph.NodeInterface)

Example 80 with NodeInterface

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

the class OWLInstance method resolveProperties.

public void resolveProperties() throws FrameworkException {
    if (instance != null && type != null) {
        OWLParserv2.logger.println("#################################################################################################");
        OWLParserv2.logger.println("Resolving properties of " + type.getStructrName(true) + ": " + getId());
        final App app = StructrApp.getInstance();
        final ConfigurationProvider config = StructrApp.getConfiguration();
        final Class baseNodeType = config.getNodeEntityClass("BaseNode");
        final Class localizedNameType = config.getNodeEntityClass("LocalizedName");
        final PropertyKey namesKey = StructrApp.key(baseNodeType, "names");
        final PropertyKey langKey = StructrApp.key(localizedNameType, "locale");
        if (localizedNameType != null && namesKey != null) {
            // set name(s)
            final List<NodeInterface> localizedNames = new LinkedList<>();
            for (final Name name : names) {
                localizedNames.add(app.create(localizedNameType, new NodeAttribute<>(AbstractNode.name, name.name), new NodeAttribute<>(langKey, name.lang)));
            }
            instance.setProperty(namesKey, localizedNames);
        }
        // extract creation and modification dates
        try {
            setProperty(nodeType, instance, "createdAt", isoFormat.format(dateFormat.parse(createdAt)));
        } catch (Throwable ignore) {
        }
        try {
            setProperty(nodeType, instance, "modifiedAt", isoFormat.format(dateFormat.parse(modifiedAt)));
        } catch (Throwable ignore) {
        }
        for (final OWLProperty property : type.getAllProperties()) {
            final String rawPropertyName = property.getId().getFragment();
            final String cleanPropertyName = property.getFragmentName(false);
            if (property.multipleOccurrences()) {
                final NodeList values = getElements(getElement(), rawPropertyName);
                final int len = values.getLength();
                final ArrayList<String> array = new ArrayList<>();
                for (int i = 0; i < len; i++) {
                    final Object value = getValue(values.item(i));
                    if (value != null) {
                        array.add(value.toString());
                    }
                }
                final String[] value = array.toArray(new String[0]);
                OWLParserv2.logger.println(cleanPropertyName + " = " + value);
                setProperty(nodeType, instance, cleanPropertyName, value);
            } else {
                Object value = getValue(getFirstElement(getElement(), rawPropertyName));
                OWLParserv2.logger.println(cleanPropertyName + " = " + value);
                setProperty(nodeType, instance, cleanPropertyName, property.convertValue(value));
            }
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) ConfigurationProvider(org.structr.schema.ConfigurationProvider) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface)

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