Search in sources :

Example 6 with RelationshipInterface

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();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) RelationshipInterface(org.structr.core.graph.RelationshipInterface) Page(org.structr.web.entity.dom.Page) Folder(org.structr.web.entity.Folder) NodeInterface(org.structr.core.graph.NodeInterface)

Example 7 with RelationshipInterface

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);
            }
        }
    }
}
Also used : RelationshipInterface(org.structr.core.graph.RelationshipInterface) DOMNode(org.structr.web.entity.dom.DOMNode)

Example 8 with RelationshipInterface

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");
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) IllegalPathException(org.structr.rest.exception.IllegalPathException) AbstractNode(org.structr.core.entity.AbstractNode) GraphObject(org.structr.core.GraphObject) LinkedList(java.util.LinkedList) Result(org.structr.core.Result) RelationshipInterface(org.structr.core.graph.RelationshipInterface)

Example 9 with RelationshipInterface

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");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) RelationshipInterface(org.structr.core.graph.RelationshipInterface) StringProperty(org.structr.core.property.StringProperty) NodeHasLocation(org.structr.core.entity.relationship.NodeHasLocation) PropertyKey(org.structr.core.property.PropertyKey) Test(org.junit.Test)

Example 10 with RelationshipInterface

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;
}
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)

Aggregations

RelationshipInterface (org.structr.core.graph.RelationshipInterface)28 NodeInterface (org.structr.core.graph.NodeInterface)15 GraphObject (org.structr.core.GraphObject)8 LinkedList (java.util.LinkedList)6 FrameworkException (org.structr.common.error.FrameworkException)6 PropertyMap (org.structr.core.property.PropertyMap)6 App (org.structr.core.app.App)5 StructrApp (org.structr.core.app.StructrApp)5 List (java.util.List)4 SecurityContext (org.structr.common.SecurityContext)4 AbstractNode (org.structr.core.entity.AbstractNode)4 GenericNode (org.structr.core.entity.GenericNode)4 Tx (org.structr.core.graph.Tx)4 RelationshipDataContainer (org.structr.cloud.message.RelationshipDataContainer)3 Result (org.structr.core.Result)3 PropertyKey (org.structr.core.property.PropertyKey)3 LinkedHashSet (java.util.LinkedHashSet)2 Test (org.junit.Test)2 NotFoundException (org.structr.api.NotFoundException)2 RelationshipType (org.structr.api.graph.RelationshipType)2