Package org.structr.core.app

Examples of org.structr.core.app.App


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

          // Create new relationship to user and grant permissions to user or group
          Principal owner = (Principal)user;

          App app = StructrApp.getInstance(securityContext);
         
          app.create(owner, (NodeInterface)node, PrincipalOwnsNode.class);
         
          Security securityRel = app.create(owner, (NodeInterface)node, Security.class);
          securityRel.setAllowed(Permission.values());

          node.unlockReadOnlyPropertiesOnce();
          node.setProperty(AbstractNode.createdBy, user.getProperty(GraphObject.id));
        }
View Full Code Here


    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded                      = false;

    if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {

      final App app = StructrApp.getInstance(securityContext);

      if (exactMatch) {

        for (NodeInterface node : searchValue) {
View Full Code Here

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

  @Override
  public T deserialize(final SecurityContext securityContext, final Class<T> type, final S source) throws FrameworkException {

    final App app = StructrApp.getInstance(securityContext);

    if (source != null) {

      Result<T> results = Result.EMPTY_RESULT;
     
      if (source instanceof JsonInput) {

        JsonInput properties = (JsonInput) source;
        PropertyMap map      = PropertyMap.inputTypeToJavaType(securityContext, type, properties.getAttributes());
       
        // If property map contains the uuid, search only for uuid
        if (map.containsKey(GraphObject.id)) {
       
          return (T) app.get(map.get(GraphObject.id));

         
        } else {
         
          throw new FrameworkException(type.getSimpleName(), new IdNotFoundToken(source));
         
        }

      } else if (source instanceof GraphObject) {
       
        GraphObject obj = (GraphObject)source;
        if (propertyKey != null) {
         
          results = (Result<T>) app.nodeQuery(NodeInterface.class).and(propertyKey, obj.getProperty(propertyKey)).getResult();
         
         
        } else {
         
          // fetch property key for "id", may be different for AbstractNode and AbstractRelationship!
          PropertyKey<String> idProperty = StructrApp.getConfiguration().getPropertyKeyForDatabaseName(obj.getClass(), GraphObject.id.dbName());
         
          return (T) app.get(obj.getProperty(idProperty));
         
        }
       
       
      } else {

        return (T) app.get(source.toString());

      }

      int size       = results.size();

      switch (size) {

        case 0 :
          throw new FrameworkException(type.getSimpleName(), new IdNotFoundToken(source));

        case 1 :
          return results.get(0);

        default :
          logger.log(Level.WARNING, "Got more than one result for UUID {0}. Either this is not an UUID or we have a collision.", source.toString());

      }

    } else if (createIfNotExisting) {

      return app.create(type);
    }

    return null;
  }
View Full Code Here

    return null;
  }

  private T deserialize(SecurityContext securityContext, Class<T> type, PropertyMap attributes) throws FrameworkException {

    final App app = StructrApp.getInstance(securityContext);
   
    if (attributes != null) {
     
      Result<T> result = Result.EMPTY_RESULT;
     
      // Check if properties contain the UUID attribute
      if (attributes.containsKey(GraphObject.id)) {

        result = new Result(app.get(attributes.get(GraphObject.id)), false);
       
      } else {

       
        boolean attributesComplete = true;
       
        // Check if all property keys of the PropertySetNotion are present
        for (PropertyKey key : propertyKeys) {
          attributesComplete &= attributes.containsKey(key);
        }
       
        if (attributesComplete) {
         
          result = app.nodeQuery(type).and(attributes).getResult();
         
        }
      }

      // just check for existance
      final int size = result.size();
      switch (size) {

        case 0:

          if (createIfNotExisting) {

            // create node and return it
            T newNode = app.create(type, attributes);
            if (newNode != null) {

              return newNode;
            }           
          }
View Full Code Here

  @Override
  public T deserialize(final SecurityContext securityContext, Class<T> type, S source) throws FrameworkException {

    // TODO: check why this doesn't work for setProperty with plain uuid..

    final App app = StructrApp.getInstance(securityContext);
   
    Result<T> result = Result.EMPTY_RESULT;
   
   
    // create and fill input map with source object
    Map<String, Object> sourceMap = new LinkedHashMap<>();
    sourceMap.put(propertyKey.jsonName(), source);

    // try to convert input type to java type in order to create object correctly
    PropertyMap convertedSourceMap = PropertyMap.inputTypeToJavaType(securityContext, type, sourceMap);
    Object convertedSource = convertedSourceMap.get(propertyKey);
   
    if (convertedSource != null) {

      // FIXME: use uuid only here?
      if (convertedSource instanceof JsonInput) {

        Object value = ((JsonInput)convertedSource).getAttributes().get(propertyKey.jsonName());
        if (value != null) {
         
          result = app.nodeQuery(type).and(propertyKey, value.toString()).getResult();
        }

      } else if (convertedSource instanceof GraphObject) {
       
        GraphObject obj = (GraphObject)convertedSource;
        if (propertyKey != null) {
         
          result = app.nodeQuery(type).and(propertyKey, obj.getProperty(propertyKey)).getResult();
         
        } else {
         
          // fetch property key for "id", may be different for AbstractNode and AbstractRelationship!
          PropertyKey<String> idProperty = StructrApp.getConfiguration().getPropertyKeyForDatabaseName(obj.getClass(), GraphObject.id.dbName());
          result = new Result(app.get(obj.getProperty(idProperty)), false);
        }
       
      } else {

        result = app.nodeQuery(type).and(propertyKey, convertedSource).getResult();

      }
    }


    // just check for existance
    int resultCount = result.size();

    switch (resultCount) {

      case 0 :
        if ((convertedSource != null) && createIfNotExisting) {

          // create node and return it
          T newNode = app.create(type);

          if (newNode != null) {
            newNode.setProperty(propertyKey, convertedSource);
            return newNode;
          }
View Full Code Here

      relatedNode = localNode.getProperty(sourceKey);
     
      if (relatedNode == null && add && sourceKey instanceof RelationProperty) {

        final RelationProperty relationProperty = (RelationProperty)sourceKey;
        final App app                           = StructrApp.getInstance();
        final Class<T> relatedType              = relationProperty.getTargetType();

        if (relatedType != null) {
         
          try {
            relatedNode = app.create(relatedType);
            relationProperty.addSingleElement(securityContext, localNode, relatedNode);

          } catch (FrameworkException fex) {

            fex.printStackTrace();
View Full Code Here

    StructrApp.getInstance(securityContext).create(startNode, endNode, linkType, properties);
  }

  private void unlinkNodes(final Class<R> linkType, final T startNode, final T endNode) throws FrameworkException {

    final App app = StructrApp.getInstance(securityContext);

    for (RelationshipInterface rel : startNode.getRelationships(linkType)) {

      if (rel != null && rel.getTargetNode().equals(endNode)) {
        app.delete(rel);
      }
    }
  }
View Full Code Here

  }

  @Override
  public void ensureCardinality(final SecurityContext securityContext, final NodeInterface sourceNode, final NodeInterface targetNode) throws FrameworkException {

    final App app                          = StructrApp.getInstance();
    final Class<? extends ManyToOne> clazz = this.getClass();
    final Class<T> targetType              = getTargetType();

    if (sourceNode != null) {

      // check existing relationships
      final Relation<?, T, ?, ?> outgoingRel = sourceNode.getOutgoingRelationship(clazz);
//      if (outgoingRel != null && targetType.isAssignableFrom(outgoingRel.getTargetType())) {
      if (outgoingRel != null && targetType.isInstance(outgoingRel.getTargetNode())) {

        app.delete(outgoingRel);
      }
    }
  }
View Full Code Here

    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded                      = false;

    if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {

      final App app = StructrApp.getInstance(securityContext);

      if (exactMatch) {

        for (NodeInterface node : searchValue) {
View Full Code Here

      return null;
    }

    deletedNodes.add(node);

    App app = StructrApp.getInstance(securityContext);

    try {

      List<NodeInterface> nodesToCheckAfterDeletion = new LinkedList<>();

      // Delete all end nodes of outgoing relationships which are connected
      // by relationships which are marked with DELETE_OUTGOING
      for (AbstractRelationship rel : node.getOutgoingRelationships()) {

        int cascadeDelete = rel.cascadeDelete();
        NodeInterface endNode = rel.getTargetNode();

        if ((cascadeDelete & Relation.CONSTRAINT_BASED) == Relation.CONSTRAINT_BASED) {

          nodesToCheckAfterDeletion.add(endNode);
        }

        if (!deletedNodes.contains(endNode) && ((cascadeDelete & Relation.SOURCE_TO_TARGET) == Relation.SOURCE_TO_TARGET)) {

          // remove end node from index
          endNode.removeFromIndex();
          doDeleteNode(endNode);
        }

      }

      // Delete all start nodes of incoming relationships which are connected
      // by relationships which are marked with DELETE_INCOMING
      for (AbstractRelationship rel : node.getIncomingRelationships()) {

        int cascadeDelete = rel.cascadeDelete();
        NodeInterface startNode = rel.getSourceNode();

        if ((cascadeDelete & Relation.CONSTRAINT_BASED) == Relation.CONSTRAINT_BASED) {

          nodesToCheckAfterDeletion.add(startNode);
        }

        if (!deletedNodes.contains(startNode) && ((cascadeDelete & Relation.TARGET_TO_SOURCE) == Relation.TARGET_TO_SOURCE)) {

          // remove start node from index
          startNode.removeFromIndex();
          doDeleteNode(startNode);
        }

      }

      // deletion callback, must not prevent node deletion!
      node.onNodeDeletion();

      // Delete any relationship (this is PASSIVE DELETION)
      for (AbstractRelationship r : node.getRelationships()) {

        app.delete(r);
      }

      // remove node from index
      node.removeFromIndex();
View Full Code Here

TOP

Related Classes of org.structr.core.app.App

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.