use of org.structr.cloud.message.RelationshipDataContainer 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;
}
use of org.structr.cloud.message.RelationshipDataContainer in project structr by structr.
the class CloudConnection method storeRelationship.
public RelationshipInterface storeRelationship(final DataContainer receivedData) throws FrameworkException {
final RelationshipDataContainer receivedRelationshipData = (RelationshipDataContainer) receivedData;
final String sourceStartNodeId = receivedRelationshipData.getSourceStartNodeId();
final String sourceEndNodeId = receivedRelationshipData.getSourceEndNodeId();
final String uuid = receivedRelationshipData.getRelationshipId();
// if end node ID was not found in the ID map,
// assume it already exists in the database
// (i.e. it was created earlier)
String targetStartNodeId = idMap.get(sourceStartNodeId);
if (targetStartNodeId == null) {
targetStartNodeId = sourceStartNodeId;
}
// if end node ID was not found in the ID map,
// assume it already exists in the database
// (i.e. it was created earlier)
String targetEndNodeId = idMap.get(sourceEndNodeId);
if (targetEndNodeId == null) {
targetEndNodeId = sourceEndNodeId;
}
if (targetStartNodeId != null && targetEndNodeId != null) {
// Get new start and end node
final SecurityContext securityContext = SecurityContext.getSuperUserInstance();
final NodeInterface targetStartNode = app.getNodeById(targetStartNodeId);
final NodeInterface targetEndNode = app.getNodeById(targetEndNodeId);
final String typeName = receivedRelationshipData.getType();
final Class relType = config.getRelationshipEntityClass(typeName);
if (targetStartNode != null && targetEndNode != null) {
final RelationshipInterface existingCandidate = app.relationshipQuery().and(GraphObject.id, uuid).includeDeletedAndHidden().getFirst();
count++;
total++;
if (existingCandidate != null) {
// merge properties?
existingCandidate.setProperties(securityContext, PropertyMap.databaseTypeToJavaType(securityContext, relType, receivedRelationshipData.getProperties()));
return existingCandidate;
} else {
final PropertyMap properties = PropertyMap.databaseTypeToJavaType(securityContext, relType, receivedRelationshipData.getProperties());
return app.create(targetStartNode, targetEndNode, relType, properties);
}
} else {
logger.warn("Could not store relationship {} -> {}", new Object[] { targetStartNode, targetEndNode });
}
}
logger.warn("Could not store relationship {} -> {}", new Object[] { sourceStartNodeId, sourceEndNodeId });
return null;
}
use of org.structr.cloud.message.RelationshipDataContainer 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;
}
use of org.structr.cloud.message.RelationshipDataContainer 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;
}
Aggregations