Package org.structr.core.graph

Examples of org.structr.core.graph.NodeInterface


  // ----- private methods -----
  private WebSocketMessage getMessageForEvent(final SecurityContext securityContext, final ModificationEvent modificationEvent) throws FrameworkException {

    if (modificationEvent.isNode()) {

      final NodeInterface node = (NodeInterface) modificationEvent.getGraphObject();

      if (modificationEvent.isDeleted()) {

        final WebSocketMessage message = createMessage("DELETE");

        message.setId(modificationEvent.getRemovedProperties().get(GraphObject.id));

        return message;
      }

      if (modificationEvent.isCreated()) {

        final WebSocketMessage message = createMessage("CREATE");

        message.setGraphObject(node);
        message.setResult(Arrays.asList(new GraphObject[]{node}));

        return message;
      }

      if (modificationEvent.isModified()) {

        final WebSocketMessage message = createMessage("UPDATE");

        message.setGraphObject(node);
        message.setResult(Arrays.asList(new GraphObject[]{node}));
        message.setId(node.getUuid());
        message.getModifiedProperties().addAll(modificationEvent.getModifiedProperties().keySet());
        message.getRemovedProperties().addAll(modificationEvent.getRemovedProperties().keySet());
        message.setNodeData(modificationEvent.getData(securityContext));

        return message;
      }

    } else {

      // handle relationship
      final RelationshipInterface relationship = (RelationshipInterface) modificationEvent.getGraphObject();
      final RelationshipType relType = modificationEvent.getRelationshipType();

      // only interested in CONTAINS relationships
      if (!("CONTAINS".equals(relType.name()))) {
        return null;
      }

      if (modificationEvent.isDeleted()) { // && "CONTAINS".equals(relType.name())) {

        final WebSocketMessage message = createMessage("REMOVE_CHILD");

        message.setNodeData("parentId", relationship.getSourceNodeId());
        message.setId(relationship.getTargetNodeId());

        return message;
      }

      if (modificationEvent.isCreated()) {

        final WebSocketMessage message = new WebSocketMessage();
        final NodeInterface startNode = relationship.getSourceNode();
        final NodeInterface endNode = relationship.getTargetNode();

        message.setResult(Arrays.asList(new GraphObject[]{endNode}));
        message.setId(endNode.getUuid());
        message.setNodeData("parentId", startNode.getUuid());

        message.setCommand("APPEND_CHILD");

        if (endNode instanceof DOMNode) {

          org.w3c.dom.Node refNode = ((DOMNode) endNode).getNextSibling();
          if (refNode != null) {

            message.setCommand("INSERT_BEFORE");
            message.setNodeData("refId", ((AbstractNode) refNode).getUuid());
          }

        } else if (endNode instanceof User) {

          message.setCommand("APPEND_USER");
          message.setNodeData("refId", startNode.getUuid());
        }

        return message;
      }

      if (modificationEvent.isModified()) {

        final WebSocketMessage message = createMessage("UPDATE");

        message.setGraphObject(relationship);
        message.setId(relationship.getUuid());
        message.getModifiedProperties().addAll(modificationEvent.getModifiedProperties().keySet());
        message.getRemovedProperties().addAll(modificationEvent.getRemovedProperties().keySet());
        message.setNodeData(modificationEvent.getData(securityContext));

        final PropertyMap relProperties = relationship.getProperties();
        final NodeInterface startNode = relationship.getSourceNode();
        final NodeInterface endNode = relationship.getTargetNode();

        relProperties.put(new StringProperty("startNodeId"), startNode.getUuid());
        relProperties.put(new StringProperty("endNodeId"), endNode.getUuid());

        final Map<String, Object> properties = PropertyMap.javaTypeToInputType(securityContext, relationship.getClass(), relProperties);

        message.setRelData(properties);
View Full Code Here


  public RestMethodResult doPost(final Map<String, Object> propertySet) throws FrameworkException {

    if (isNode) {

      final App app         = StructrApp.getInstance(securityContext);
      NodeInterface newNode = null;

      newNode = createNode(propertySet);

      final RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
      if (newNode != null) {

        result.addHeader("Location", buildLocationHeader(newNode));
        result.addContent(newNode);
      }

      result.serializeAsPrimitiveArray(true);
     
      // finally: return 201 Created
      return result;

    } else {

      final App app                         = StructrApp.getInstance(securityContext);
      final Relation template               = getRelationshipTemplate();
      final ErrorBuffer errorBuffer         = new ErrorBuffer();

      if (template != null) {

        final NodeInterface sourceNode        = identifyStartNode(template, propertySet);
        final NodeInterface targetNode        = identifyEndNode(template, propertySet);
        final PropertyMap properties          = PropertyMap.inputTypeToJavaType(securityContext, entityClass, propertySet);
        RelationshipInterface newRelationship = null;

        if (sourceNode == null) {
          errorBuffer.add(entityClass.getSimpleName(), new EmptyPropertyToken(template.getSourceIdProperty()));
View Full Code Here

      return null;
    }

    final PropertyMap properties             = PropertyMap.databaseTypeToJavaType(securityContext, nodeType, receivedNodeData.getProperties());
    final String uuid                        = receivedNodeData.getSourceNodeId();
    NodeInterface newOrExistingNode          = null;

    final NodeInterface existingCandidate = app.nodeQuery().and(GraphObject.id, uuid).includeDeletedAndHidden().getFirst();
    if (existingCandidate != null && existingCandidate instanceof NodeInterface) {

      newOrExistingNode = (NodeInterface) existingCandidate;

      // merge properties
View Full Code Here

    if (targetStartNodeId != null && targetEndNodeId != null) {

      // Get new start and end node
      final SecurityContext securityContext = SecurityContext.getSuperUserInstance();
      final NodeInterface targetStartNode   = (NodeInterface) app.get(targetStartNodeId);
      final NodeInterface targetEndNode     = (NodeInterface) app.get(targetEndNodeId);
      final String typeName                 = receivedRelationshipData.getType();
      final Class relType                   = config.getRelationshipEntityClass(typeName);

      if (targetStartNode != null && targetEndNode != null) {
View Full Code Here

    } else {

      container.flushAndCloseTemporaryFile();

      final NodeInterface newNode = storeNode(container);
      final String filesPath = StructrApp.getConfigurationValue(Services.FILES_PATH);
      final String relativePath = newNode.getProperty(File.relativeFilePath);
      String newPath = null;

      if (filesPath.endsWith("/")) {

        newPath = filesPath + relativePath;
View Full Code Here

    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    String id = webSocketData.getId();

    if (id != null) {

      final NodeInterface node = getNode(id);

      if (node != null) {

        if (node instanceof DOMNode) {

          // Use new DOM interface
          DOMNode domNode = (DOMNode) node;

          domNode.getParentNode().removeChild(domNode);

          try {

            // Remove node from page
            domNode.setProperty(DOMNode.syncedNodes, Collections.EMPTY_LIST);
            domNode.setProperty(DOMNode.pageId, null);

          } catch (FrameworkException ex) {

            logger.log(Level.SEVERE, "Could not remove node from page " + domNode, ex);

          }

        } else {

          final App app = StructrApp.getInstance(securityContext);

          try {

            // Old style: Delete all incoming CONTAINS rels
            for (AbstractRelationship rel : node.getIncomingRelationships()) {

              if ("CONTAINS".equals(rel.getType())) {

                app.delete(rel);
View Full Code Here

    final Iterable<RelationshipInterface> rels = new IterableAdapter<>(node.getNode().getRelationships(RelType.CONTAINS, Direction.OUTGOING), factory);
    final List<GraphObject> result             = new LinkedList();

    for (RelationshipInterface rel : rels) {

      NodeInterface endNode = rel.getTargetNode();
      if (endNode == null) {

        continue;
      }
View Full Code Here

    if (syncable != null) {

      if (syncable.isNode()) {

        final NodeInterface node = syncable.getSyncNode();
        this.id           = node.getUuid();
        this.name         = node.getName();
        this.type         = node.getType();
        this.lastModified = node.getLastModifiedDate();
        this.node         = true;

        if (node instanceof File) {
          this.size = ((File)node).getSize();
        }
View Full Code Here

    try {

      final PropertyMap props = new PropertyMap();
      final String type       = "UnknownTestType";
      final String name       = "GenericNode-name";
      NodeInterface node      = null;
      String uuid             = null;

      props.put(AbstractNode.type, type);
      props.put(AbstractNode.name, name);

      try (final Tx tx = app.tx()) {

        node = app.create(NodeInterface.class, props);
        tx.success();
      }

      assertTrue(node != null);

      try (final Tx tx = app.tx()) {
        uuid = node.getUuid();
      }

      try (final Tx tx = app.tx()) {

        app.delete(node);
View Full Code Here

    try {

      // Create a relationship with DELETE_OUTGOING
      AbstractRelationship rel = cascadeRel(TestOne.class, TestTwo.class, Relation.SOURCE_TO_TARGET);
      NodeInterface sourceNode;
      NodeInterface targetNode;
      String startNodeId;
      String endNodeId;

      try (final Tx tx = app.tx()) {
View Full Code Here

TOP

Related Classes of org.structr.core.graph.NodeInterface

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.