Examples of GraphObject


Examples of org.structr.core.GraphObject

  //~--- methods --------------------------------------------------------

  @Override
  public Result doGet(PropertyKey sortKey, boolean sortDescending, int pageSize, int page, String offsetId) throws FrameworkException {

    GraphObject obj = getEntity();
    if (obj != null) {

      List<GraphObject> results = new LinkedList<>();

      results.add(obj);
View Full Code Here

Examples of org.structr.core.GraphObject

  public GraphObject getEntity() throws FrameworkException {

    final App app = StructrApp.getInstance();
   
    GraphObject entity = app.nodeQuery().uuid(uuid).getFirst();
    if (entity == null) {
     
      entity = app.relationshipQuery().uuid(uuid).getFirst();
    }

    if (entity == null) {
      throw new NotFoundException();
    }

    if (entity instanceof AbstractNode && !securityContext.isReadable((AbstractNode)entity, true, false)) {
      throw new NotAllowedException();
    }

    entity.setSecurityContext(securityContext);

    return entity;
  }
View Full Code Here

Examples of org.structr.core.GraphObject

        final FileItem fileItem = fileItemsIterator.next();

        try {

          final GraphObject node = StructrApp.getInstance().get(uuid);

          if (node == null) {

            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            response.getOutputStream().write("ERROR (404): File not found.\n".getBytes("UTF-8"));
View Full Code Here

Examples of org.structr.core.GraphObject

    if (!securityContext.isVisible(this)) {
      return;
    }

    final GraphObject details = renderContext.getDetailsDataObject();
    final boolean detailMode = details != null;

    if (detailMode && getProperty(hideOnDetail)) {
      return;
    }

    if (!detailMode && getProperty(hideOnIndex)) {
      return;
    }

    final EditMode editMode  = renderContext.getEditMode(securityContext.getUser(false));

    if (EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) {

      renderContent(securityContext, renderContext, depth);

    } else {

      final String subKey = getProperty(dataKey);

      if (StringUtils.isNotBlank(subKey)) {

        setDataRoot(renderContext, this, subKey);

        final GraphObject currentDataNode = renderContext.getDataObject();

        // fetch (optional) list of external data elements
        final List<GraphObject> listData = checkListSources(securityContext, renderContext);

        final PropertyKey propertyKey;

        if (getProperty(renderDetails) && detailMode) {

          renderContext.setDataObject(details);
          renderContext.putDataObject(subKey, details);
          renderContent(securityContext, renderContext, depth);

        } else {

          if (listData.isEmpty() && currentDataNode != null) {

          // There are two alternative ways of retrieving sub elements:
            // First try to get generic properties,
            // if that fails, try to create a propertyKey for the subKey
            final Object elements = currentDataNode.getProperty(new GenericProperty(subKey));
            renderContext.setRelatedProperty(new GenericProperty(subKey));
            renderContext.setSourceDataObject(currentDataNode);

            if (elements != null) {

              if (elements instanceof Iterable) {

                for (Object o : (Iterable) elements) {

                  if (o instanceof GraphObject) {

                    GraphObject graphObject = (GraphObject) o;
                    renderContext.putDataObject(subKey, graphObject);
                    renderContent(securityContext, renderContext, depth);

                  }
                }
View Full Code Here

Examples of org.structr.core.GraphObject

  //~--- methods --------------------------------------------------------
  @Override
  public Result doGet(final PropertyKey sortKey, final boolean sortDescending, final int pageSize, final int page, final String offsetId) throws FrameworkException {

    // ok, source node exists, fetch it
    final GraphObject sourceEntity = typedIdResource.getEntity();
    if (sourceEntity != null) {

      // first try: look through existing relations
      if (propertyKey == null) {

        if (sourceEntity instanceof NodeInterface) {

          if (!typeResource.isNode) {

            final NodeInterface source = (NodeInterface) sourceEntity;
            final Node sourceNode = source.getNode();
            final Class relationshipType = typeResource.entityClass;
            final Relation relation = AbstractNode.getRelationshipForType(relationshipType);
            final Class destNodeType = relation.getOtherType(typedIdResource.getEntityClass());
            final Set partialResult = new LinkedHashSet<>(typeResource.doGet(sortKey, sortDescending, NodeFactory.DEFAULT_PAGE_SIZE, NodeFactory.DEFAULT_PAGE, null).getResults());

            // filter list according to end node type
            final Set<GraphObject> set = Iterables.toSet(Iterables.filter(new OtherNodeTypeRelationFilter(securityContext, sourceNode, destNodeType), source.getRelationships(relationshipType)));

            // intersect partial result with result list
            set.retainAll(partialResult);

            final List<GraphObject> finalResult = new LinkedList<>(set);

            // sort after merge
            applyDefaultSorting(finalResult, sortKey, sortDescending);

            // return result
            return new Result(PagingHelper.subList(finalResult, pageSize, page, offsetId), finalResult.size(), isCollectionResource(), isPrimitiveArray());

          } else {

            // what here?
          }
        }

      } else {
//
//      // second try: property key
//      if (propertyKey != null) {

        Query query = typeResource.query;
        if (query == null) {

          query = StructrApp.getInstance(securityContext).nodeQuery();
        }

        // use search context from type resource
        typeResource.collectSearchAttributes(query);

        final Predicate<GraphObject> predicate = query.toPredicate();
        final Object value = sourceEntity.getProperty(propertyKey, predicate);

        if (value != null) {

          if (value instanceof Iterable) {
View Full Code Here

Examples of org.structr.core.GraphObject

    if (results != null) {

      // fetch static relationship definition
      if (propertyKey != null && propertyKey instanceof RelationProperty) {

        final GraphObject sourceEntity = typedIdResource.getEntity();
        if (sourceEntity != null) {

          if (propertyKey.isReadOnly()) {

            logger.log(Level.INFO, "Read-only property on {1}: {0}", new Object[]{sourceEntity.getClass(), typeResource.getRawType()});
            return new RestMethodResult(HttpServletResponse.SC_FORBIDDEN);

          }

          final List<GraphObject> nodes = new LinkedList<>();

          // Now add new relationships for any new id: This should be the rest of the property set
          for (final Object obj : propertySet.values()) {

            nodes.add(app.get(obj.toString()));
          }

          // set property on source node
          sourceEntity.setProperty(propertyKey, nodes);
        }

      }
    }
View Full Code Here

Examples of org.structr.core.GraphObject

  }

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

    final GraphObject sourceNode = typedIdResource.getEntity();

    if (sourceNode != null && propertyKey != null && propertyKey instanceof RelationProperty) {

      final RelationProperty relationProperty = (RelationProperty) propertyKey;
      final Class sourceNodeType = sourceNode.getClass();
      NodeInterface newNode = null;

      if (propertyKey.isReadOnly()) {

        logger.log(Level.INFO, "Read-only property on {0}: {1}", new Object[]{sourceNodeType, typeResource.getRawType()});

        return null;
      }

      // fetch notion
      final Notion notion = relationProperty.getNotion();
      final PropertyKey primaryPropertyKey = notion.getPrimaryPropertyKey();

      // apply notion if the property set contains the ID property as the only element
      if (primaryPropertyKey != null && propertySet.containsKey(primaryPropertyKey.jsonName()) && propertySet.size() == 1) {

        /*
         * FIXME: is this needed at all??
         *
         // the notion that is defined for this relationship can deserialize
         // objects with a single key (uuid for example), and the POSTed
         // property set contains value(s) for this key, so we only need
         // to create relationships
         final Object keySource = propertySet.get(primaryPropertyKey.jsonName());
         if (keySource != null) {

         if (keySource instanceof Collection) {

         sourceNode.setProperty(propertyKey, notion.getCollectionAdapterForSetter(securityContext).adapt(keySource));

         } else {

         sourceNode.setProperty(propertyKey, notion.getAdapterForSetter(securityContext).adapt(keySource));
         }

         /*
         GraphObject otherNode = null;

         if (keySource instanceof Collection) {

         final Collection collection = (Collection) keySource;

         for (final Object key : collection) {

         otherNode = deserializationStrategy.adapt(key);

         if (otherNode != null && otherNode instanceof AbstractNode) {

         relationshipProperty.createRelationship(securityContext, sourceNode, (AbstractNode)otherNode);

         } else {

         logger.log(Level.WARNING, "Relationship end node has invalid type {0}", otherNode.getClass().getName());
         }

         }

         } else {

         // create a single relationship
         otherNode = deserializationStrategy.adapt(keySource);

         if (otherNode != null && otherNode instanceof AbstractNode) {

         relationshipProperty.createRelationship(securityContext, sourceNode, (AbstractNode)otherNode);

         } else {

         logger.log(Level.WARNING, "Relationship end node has invalid type {0}", otherNode.getClass().getName());

         }
         }

         return otherNode;

         } else {

         logger.log(Level.INFO, "Key {0} not found in {1}", new Object[] { primaryPropertyKey.jsonName(), propertySet.toString() });

         }
         */
      } else {

        // the notion can not deserialize objects with a single key, or the POSTed propertySet did not contain a key to deserialize,
        // so we create a new node from the POSTed properties and link the source node to it. (this is the "old" implementation)
        newNode = typeResource.createNode(propertySet);
        if (newNode != null) {

          relationProperty.addSingleElement(securityContext, sourceNode, newNode);
        }
      }

      if (newNode != null) {

        RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
        result.addHeader("Location", buildLocationHeader(newNode));

        return result;
      }

    } else {

      // look for methods that have an @Export annotation
      GraphObject entity = typedIdResource.getIdResource().getEntity();
      Class entityType = typedIdResource.getEntityClass();
      String methodName = typeResource.getRawType();

      if (entity != null && entityType != null && methodName != null) {

View Full Code Here

Examples of org.structr.core.GraphObject

        defaultValue = "";
      }
    }

    Page _page = this.getPage();
    GraphObject _data = null;

    // walk through template parts
    for (int i = 0; (i < parts.length); i++) {

      String part = parts[i];

      if (_data != null) {

        Object value = _data.getProperty(StructrApp.getConfiguration().getPropertyKeyForJSONName(_data.getClass(), part));

        if (value instanceof GraphObject) {
          _data = (GraphObject) value;

          continue;

        }

        // special keyword "size"
        if (i > 0 && "size".equals(part)) {

          Object val = _data.getProperty(StructrApp.getConfiguration().getPropertyKeyForJSONName(_data.getClass(), parts[i - 1]));

          if (val instanceof List) {

            return ((List) val).size();

          }

        }

        // special keyword "link", works on deeper levels, too
        if ("link".equals(part) && _data instanceof AbstractNode) {

          ResourceLink rel = ((AbstractNode) _data).getOutgoingRelationship(ResourceLink.class);
          if (rel != null) {

            _data = rel.getTargetNode();

            break;

          }

          continue;

        }

        if (value == null) {

          // check for default value
          if (defaultValue != null && StringUtils.contains(refKey, "!")) {
            return numberOrString(defaultValue);
          }

          // Need to return null here to avoid _data sticking to the (wrong) parent object
          return null;

        }

      }

      // data objects from parent elements
      if (this.hasDataForKey(part)) {

        _data = this.getDataNode(part);

        if (parts.length == 1) {
          return _data;
        }

        continue;

      }

      // special keyword "request"
      if ("request".equals(part)) {

        final HttpServletRequest request = this.getRequest(); //securityContext.getRequest();
        if (request != null) {

          if (StringUtils.contains(refKey, "!")) {

            return numberOrString(StringUtils.defaultIfBlank(request.getParameter(referenceKey), defaultValue));

          } else {

            return numberOrString(StringUtils.defaultString(request.getParameter(referenceKey)));
          }
        }

      }

      // special keyword "now":
      if ("now".equals(part)) {

        return new Date();
      }

      // special keyword "me"
      if ("me".equals(part)) {

        Principal me = (Principal) securityContext.getUser(false);

        if (me != null) {

          _data = me;

          if (parts.length == 1) {
            return _data;
          }

          continue;
        }

      }

      // special boolean keywords
      if ("true".equals(part)) {
        return true;
      }

      if ("false".equals(part)) {
        return false;
      }

      // the following keywords work only on root level
      // so that they can be used as property keys for data objects
      if (_data == null) {

        // details data object id
        if ("id".equals(part)) {

          GraphObject detailsObject = this.getDetailsDataObject();

          if (detailsObject != null) {
            return detailsObject.getUuid();
          }

        }

        // details data object
        if ("current".equals(part)) {

          GraphObject detailsObject = this.getDetailsDataObject();

          if (detailsObject != null) {

            _data = detailsObject;
View Full Code Here

Examples of org.structr.core.GraphObject

  public void processMessage(WebSocketMessage webSocketData) throws FrameworkException {

    final App app          = StructrApp.getInstance(getWebSocket().getSecurityContext());
    final Boolean recValue = (Boolean) webSocketData.getNodeData().get("recursive");
    final boolean rec      = recValue != null ? recValue : false;
    GraphObject obj        = getNode(webSocketData.getId());

    webSocketData.getNodeData().remove("recursive");

    if (obj != null) {

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

        if (!getWebSocket().getSecurityContext().isAllowed(((AbstractNode) obj), Permission.write)) {

          getWebSocket().send(MessageBuilder.status().message("No write permission").code(400).build(), true);
          logger.log(Level.WARNING, "No write permission for {0} on {1}", new Object[]{getWebSocket().getCurrentUser().toString(), obj.toString()});

          tx.success();
          return;

        }

        tx.success();
      }
    }

    if (obj == null) {

      // No node? Try to find relationship
      obj = getRelationship(webSocketData.getId());
    }

    if (obj != null) {

      final Set<GraphObject> entities = new LinkedHashSet<>();
      try (final Tx tx = app.tx()) {

        collectEntities(entities, obj, null, rec);

        // commit and close transaction
        tx.success();
      }

      final PropertyMap properties         = PropertyMap.inputTypeToJavaType(this.getWebSocket().getSecurityContext(), obj.getClass(), webSocketData.getNodeData());
      final Iterator<GraphObject> iterator = entities.iterator();

      while (iterator.hasNext()) {

        count = 0;
View Full Code Here

Examples of org.structr.core.GraphObject

    if (sourceId != null && host != null && port != null && username != null && password != null && key != null) {

      final App app    = StructrApp.getInstance();
      try (final Tx tx = app.tx()) {

        final GraphObject root = app.get(sourceId);
        if (root != null) {

          if (root instanceof Syncable) {

            boolean recursive = false;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.