use of org.structr.core.graph.RelationshipInterface in project structr by structr.
the class UiSyncCommand method doExport.
// ----- private methods -----
private void doExport(final String fileName) throws FrameworkException {
// collect all nodes etc that belong to the frontend (including files)
// and export them to the given output file
final Set<RelationshipInterface> rels = new LinkedHashSet<>();
final Set<NodeInterface> nodes = new LinkedHashSet<>();
final Set<String> filePaths = new LinkedHashSet<>();
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
// collect folders that are marked for export
for (final Folder folder : app.nodeQuery(Folder.class).and(StructrApp.key(Folder.class, "includeInFrontendExport"), true).getAsList()) {
collectDataRecursively(app, folder, nodes, rels, filePaths);
}
// collect pages (including files, shared components etc.)
for (final Page page : app.nodeQuery(Page.class).getAsList()) {
collectDataRecursively(app, page, nodes, rels, filePaths);
}
SyncCommand.exportToFile(fileName, nodes, rels, filePaths, true);
tx.success();
}
}
use of org.structr.core.graph.RelationshipInterface in project structr by structr.
the class CreateOperation method apply.
// ----- interface InvertibleModificationOperation -----
@Override
public void apply(final App app, final Page sourcePage, final Page newPage) throws FrameworkException {
final InsertPosition insertPosition = findInsertPosition(sourcePage, parentHash, siblingHashes, newNode);
if (insertPosition != null) {
final DOMNode parent = insertPosition.getParent();
final DOMNode sibling = insertPosition.getSibling();
if (parent != null && !parent.isSynced()) {
if (sourcePage != null) {
sourcePage.adoptNode(newNode);
}
parent.insertBefore(newNode, sibling);
// make existing node known to other operations
hashMappedExistingNodes.put(newNode.getIdHashOrProperty(), newNode);
// remove children of new node so that existing nodes can be moved later
for (final RelationshipInterface childRel : newNode.getChildRelationships()) {
app.delete(childRel);
}
}
}
}
use of org.structr.core.graph.RelationshipInterface in project structr by structr.
the class RelationshipResource method doGet.
@Override
public Result doGet(final PropertyKey sortKey, final boolean sortDescending, final int pageSize, final int page) throws FrameworkException {
// fetch all results, paging is applied later
final List<? extends GraphObject> results = wrappedResource.doGet(null, false, NodeFactory.DEFAULT_PAGE_SIZE, NodeFactory.DEFAULT_PAGE).getResults();
final App app = StructrApp.getInstance();
if (results != null && !results.isEmpty()) {
try {
final List<GraphObject> resultList = new LinkedList<>();
for (GraphObject obj : results) {
if (obj instanceof AbstractNode) {
final List<? extends RelationshipInterface> relationships = Direction.INCOMING.equals(direction) ? Iterables.toList(((AbstractNode) obj).getIncomingRelationships()) : Iterables.toList(((AbstractNode) obj).getOutgoingRelationships());
if (relationships != null) {
boolean filterInternalRelationshipTypes = false;
if (securityContext != null && securityContext.getRequest() != null) {
final String filterInternal = securityContext.getRequest().getParameter(REQUEST_PARAMETER_FILTER_INTERNAL_RELATIONSHIP_TYPES);
if (filterInternal != null) {
filterInternalRelationshipTypes = "true".equals(filterInternal);
}
}
// the result set using the request parameter "filterInternal=true"
if (filterInternalRelationshipTypes) {
for (final RelationshipInterface rel : relationships) {
if (!rel.isInternal()) {
resultList.add(rel);
}
}
} else {
resultList.addAll(relationships);
}
}
}
}
final int rawResultCount = resultList.size();
return new Result(PagingHelper.subList(resultList, pageSize, page), rawResultCount, true, false);
} catch (Throwable t) {
logger.warn("Exception while fetching relationships", t);
}
} else {
logger.info("No results from parent..");
}
throw new IllegalPathException(getResourceSignature() + " can only be applied to a non-empty resource");
}
use of org.structr.core.graph.RelationshipInterface in project structr by structr.
the class SearchAndSortingTest method test03SearchRelationship.
@Test
public void test03SearchRelationship() {
try {
final NodeHasLocation rel = createTestRelationships(NodeHasLocation.class, 1).get(0);
final PropertyKey key1 = new StringProperty("jghsdkhgshdhgsdjkfgh").indexed();
final Class type = NodeHasLocation.class;
final String val1 = "54354354546806849870";
final Result<RelationshipInterface> result;
try (final Tx tx = app.tx()) {
rel.setProperty(key1, val1);
tx.success();
}
try (final Tx tx = app.tx()) {
assertTrue(rel.getProperty(key1).equals(val1));
result = app.relationshipQuery(type).and(key1, val1).getResult();
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(rel));
}
final String val2 = "ölllldjöoa8w4rasf";
try (final Tx tx = app.tx()) {
rel.setProperty(key1, val2);
tx.success();
}
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(rel));
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.graph.RelationshipInterface 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;
}
Aggregations