use of org.structr.core.graph.RelationshipFactory 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;
}
use of org.structr.core.graph.RelationshipFactory in project structr by structr.
the class DumpDatabaseCommand method execute.
@Override
public void execute(Map<String, Object> attributes) throws FrameworkException {
try {
final NodeFactory nodeFactory = new NodeFactory(SecurityContext.getSuperUserInstance());
final RelationshipFactory relFactory = new RelationshipFactory(SecurityContext.getSuperUserInstance());
final App app = StructrApp.getInstance();
final String fileName = (String) attributes.get("name");
if (fileName == null || fileName.isEmpty()) {
throw new FrameworkException(400, "Please specify name.");
}
try (final Tx tx = app.tx()) {
final File file = FileHelper.createFile(securityContext, new byte[0], "application/zip", File.class, fileName);
// make file visible for auth. users
file.setProperties(securityContext, new PropertyMap(File.visibleToAuthenticatedUsers, true));
// Don't include files
SyncCommand.exportToStream(file.getOutputStream(), nodeFactory.bulkInstantiate(app.getDatabaseService().getAllNodes()), relFactory.bulkInstantiate(app.getDatabaseService().getAllRelationships()), null, false);
tx.success();
}
} catch (Throwable t) {
throw new FrameworkException(500, t.getMessage());
}
}
use of org.structr.core.graph.RelationshipFactory in project structr by structr.
the class AbstractNode method getOutgoingRelationshipAsSuperUser.
@Override
public <A extends NodeInterface, B extends NodeInterface, S extends Source, R extends Relation<A, B, S, OneEndpoint<B>>> R getOutgoingRelationshipAsSuperUser(final Class<R> type) {
final RelationshipFactory<R> factory = new RelationshipFactory<>(SecurityContext.getSuperUserInstance());
final R template = getRelationshipForType(type);
final Relationship relationship = template.getTarget().getRawSource(SecurityContext.getSuperUserInstance(), dbNode, null);
if (relationship != null) {
return factory.adapt(relationship);
}
return null;
}
use of org.structr.core.graph.RelationshipFactory in project structr by structr.
the class AbstractNode method getRelationships.
@Override
public final <A extends NodeInterface, B extends NodeInterface, S extends Source, T extends Target, R extends Relation<A, B, S, T>> Iterable<R> getRelationships(final Class<R> type) {
final RelationshipFactory<R> factory = new RelationshipFactory<>(securityContext);
final R template = getRelationshipForType(type);
final Direction direction = template.getDirectionForType(entityType);
final RelationshipType relType = template;
return new IterableAdapter<>(dbNode.getRelationships(direction, relType), factory);
}
use of org.structr.core.graph.RelationshipFactory in project structr by structr.
the class AbstractNode method getRelationshipsAsSuperUser.
protected final <A extends NodeInterface, B extends NodeInterface, S extends Source, T extends Target, R extends Relation<A, B, S, T>> Iterable<R> getRelationshipsAsSuperUser(final Class<R> type) {
final RelationshipFactory<R> factory = new RelationshipFactory<>(SecurityContext.getSuperUserInstance());
final R template = getRelationshipForType(type);
final Direction direction = template.getDirectionForType(entityType);
final RelationshipType relType = template;
return new IterableAdapter<>(dbNode.getRelationships(direction, relType), factory);
}
Aggregations