Search in sources :

Example 1 with NodeDataContainer

use of org.structr.cloud.message.NodeDataContainer 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 2 with NodeDataContainer

use of org.structr.cloud.message.NodeDataContainer in project structr by structr.

the class CloudConnection method storeNode.

public NodeInterface storeNode(final DataContainer receivedData) throws FrameworkException {
    final SecurityContext securityContext = SecurityContext.getSuperUserInstance();
    final NodeDataContainer receivedNodeData = (NodeDataContainer) receivedData;
    final String typeName = receivedNodeData.getType();
    final Class nodeType = config.getNodeEntityClass(typeName);
    if (nodeType == null) {
        logger.error("Unknown entity type {}", typeName);
        return null;
    }
    // skip builtin schema node types
    if (Boolean.TRUE.equals(receivedNodeData.getProperties().get(SchemaNode.isBuiltinType.dbName()))) {
        return null;
    }
    final String uuid = receivedNodeData.getSourceNodeId();
    GraphObject newOrExistingNode = app.get(nodeType, uuid);
    if (newOrExistingNode != null) {
        // merge properties
        newOrExistingNode.setProperties(securityContext, PropertyMap.databaseTypeToJavaType(securityContext, nodeType, receivedNodeData.getProperties()));
    } else {
        final PropertyMap properties = PropertyMap.databaseTypeToJavaType(securityContext, nodeType, receivedNodeData.getProperties());
        final List<DOMNode> existingChildren = new LinkedList<>();
        // special handling for ShadowDocument (all others must be deleted)
        if (ShadowDocument.class.getSimpleName().equals(typeName)) {
            // delete shadow document
            for (ShadowDocument existingDoc : app.nodeQuery(ShadowDocument.class).includeDeletedAndHidden().getAsList()) {
                existingChildren.addAll(existingDoc.getProperty(Page.elements));
                app.delete(existingDoc);
            }
            // add existing children to new shadow document
            properties.put(Page.elements, existingChildren);
        }
        // create node
        newOrExistingNode = app.create(nodeType, properties);
    }
    idMap.put(receivedNodeData.getSourceNodeId(), newOrExistingNode.getUuid());
    count++;
    total++;
    return (NodeInterface) newOrExistingNode;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) SecurityContext(org.structr.common.SecurityContext) NodeDataContainer(org.structr.cloud.message.NodeDataContainer) FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer) GraphObject(org.structr.core.GraphObject) DOMNode(org.structr.web.entity.dom.DOMNode) ShadowDocument(org.structr.web.entity.dom.ShadowDocument) LinkedList(java.util.LinkedList) NodeInterface(org.structr.core.graph.NodeInterface)

Example 3 with NodeDataContainer

use of org.structr.cloud.message.NodeDataContainer in project structr by structr.

the class SyncTransmission method doRemote.

@Override
public Boolean doRemote(final CloudConnection client) throws IOException, FrameworkException {
    int count = 0;
    try (final Tx tx = StructrApp.getInstance().tx()) {
        for (final ModificationEvent event : transaction) {
            final GraphObject graphObject = event.getGraphObject();
            if (event.isDeleted()) {
                final String id = event.getRemovedProperties().get(GraphObject.id);
                if (id != null) {
                    client.send(new Delete(id));
                }
            } else {
                try {
                    final Set<String> propertyKeys = new LinkedHashSet<>();
                    // collect all possibly modified property keys
                    mapPropertyKeysToStrings(propertyKeys, event.getNewProperties().keySet());
                    mapPropertyKeysToStrings(propertyKeys, event.getModifiedProperties().keySet());
                    mapPropertyKeysToStrings(propertyKeys, event.getRemovedProperties().keySet());
                    if (graphObject.isNode()) {
                        if (graphObject instanceof File) {
                            sendFile(client, (File) graphObject, CloudService.CHUNK_SIZE);
                        } else {
                            client.send(new NodeDataContainer(graphObject.getSyncNode(), count, propertyKeys));
                        }
                    } else {
                        client.send(new RelationshipDataContainer(graphObject.getSyncRelationship(), count, propertyKeys));
                    }
                } catch (NotFoundException nfex) {
                    logger.info("Trying to synchronize deleted entity, ignoring");
                }
            }
            count++;
        }
        tx.success();
    }
    // synchronize last sync timestamp with slave instance
    // (we're sending out own instance ID (master) for the slave to store)
    final String masterId = StructrApp.getInstance().getInstanceId();
    client.send(new ReplicationStatus(masterId, StructrApp.getInstance().getGlobalSetting(masterId + ".lastModified", 0L)));
    // wait for end of transmission
    client.waitForTransmission();
    return true;
}
Also used : Delete(org.structr.cloud.message.Delete) LinkedHashSet(java.util.LinkedHashSet) Tx(org.structr.core.graph.Tx) FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer) NodeDataContainer(org.structr.cloud.message.NodeDataContainer) NotFoundException(org.structr.api.NotFoundException) GraphObject(org.structr.core.GraphObject) RelationshipDataContainer(org.structr.cloud.message.RelationshipDataContainer) ModificationEvent(org.structr.core.graph.ModificationEvent) File(org.structr.dynamic.File)

Example 4 with NodeDataContainer

use of org.structr.cloud.message.NodeDataContainer in project structr by structr.

the class UpdateTransmission method doRemote.

@Override
public Boolean doRemote(final CloudConnection client) throws IOException, FrameworkException {
    // send synchronization request first
    client.send(new Synchronize());
    // send all node and relationship data
    final DatabaseService graphDb = StructrApp.getInstance().getDatabaseService();
    final NodeFactory nodeFactory = new NodeFactory(SecurityContext.getSuperUserInstance());
    final RelationshipFactory relFactory = new RelationshipFactory(SecurityContext.getSuperUserInstance());
    for (final Node neo4jNode : graphDb.getAllNodes()) {
        final NodeInterface node = nodeFactory.instantiate(neo4jNode);
        if (node instanceof File) {
            PushTransmission.sendFile(client, (File) node, CloudService.CHUNK_SIZE);
        } else {
            client.send(new NodeDataContainer(node, 0));
        }
    }
    for (final Relationship relationship : graphDb.getAllRelationships()) {
        final RelationshipInterface relationshipInterface = relFactory.instantiate(relationship);
        client.send(new RelationshipDataContainer(relationshipInterface, 0));
    }
    // wait for end of transmission
    client.waitForTransmission();
    return true;
}
Also used : NodeFactory(org.structr.core.graph.NodeFactory) RelationshipDataContainer(org.structr.cloud.message.RelationshipDataContainer) RelationshipFactory(org.structr.core.graph.RelationshipFactory) Node(org.structr.api.graph.Node) Relationship(org.structr.api.graph.Relationship) RelationshipInterface(org.structr.core.graph.RelationshipInterface) NodeDataContainer(org.structr.cloud.message.NodeDataContainer) DatabaseService(org.structr.api.DatabaseService) File(org.structr.dynamic.File) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

NodeDataContainer (org.structr.cloud.message.NodeDataContainer)4 FileNodeDataContainer (org.structr.cloud.message.FileNodeDataContainer)3 RelationshipDataContainer (org.structr.cloud.message.RelationshipDataContainer)3 NodeInterface (org.structr.core.graph.NodeInterface)3 File (org.structr.dynamic.File)3 GraphObject (org.structr.core.GraphObject)2 RelationshipInterface (org.structr.core.graph.RelationshipInterface)2 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 DatabaseService (org.structr.api.DatabaseService)1 NotFoundException (org.structr.api.NotFoundException)1 Node (org.structr.api.graph.Node)1 Relationship (org.structr.api.graph.Relationship)1 Delete (org.structr.cloud.message.Delete)1 End (org.structr.cloud.message.End)1 SecurityContext (org.structr.common.SecurityContext)1 ModificationEvent (org.structr.core.graph.ModificationEvent)1 NodeFactory (org.structr.core.graph.NodeFactory)1 RelationshipFactory (org.structr.core.graph.RelationshipFactory)1 Tx (org.structr.core.graph.Tx)1