Package org.structr.core.app

Examples of org.structr.core.app.App


  }

  protected <T extends NodeInterface> List<T> createTestNodes(final Class<T> type, final int number) throws FrameworkException {

    final App app       = StructrApp.getInstance(securityContext);
    final List<T> nodes = new LinkedList<>();

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

      for (int i = 0; i < number; i++) {
        nodes.add(app.create(type));
      }

      tx.success();
    }
View Full Code Here


    return nodes;
  }

  protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {

    final App app             = StructrApp.getInstance(securityContext);
    final List<TestOne> nodes = createTestNodes(TestOne.class, 2);
    final TestOne startNode   = nodes.get(0);
    final TestOne endNode     = nodes.get(1);
    final List<T> rels        = new LinkedList<>();

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

      for (int i = 0; i < number; i++) {

        rels.add((T)app.create(startNode, endNode, relType));
      }

      tx.success();
    }
View Full Code Here

  }

  protected <T extends NodeInterface> List<T> createTestNodes(final Class<T> type, final int number) throws FrameworkException {

    final App app       = StructrApp.getInstance(securityContext);
    final List<T> nodes = new LinkedList<>();

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

      for (int i = 0; i < number; i++) {
        nodes.add(app.create(type));
      }

      tx.success();
    }
View Full Code Here

    return nodes;
  }

  protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {

    final App app             = StructrApp.getInstance(securityContext);
    final List<TestOne> nodes = createTestNodes(TestOne.class, 2);
    final TestOne startNode   = nodes.get(0);
    final TestOne endNode     = nodes.get(1);
    final List<T> rels        = new LinkedList<>();

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

      for (int i = 0; i < number; i++) {

        rels.add((T)app.create(startNode, endNode, relType));
      }

      tx.success();
    }
View Full Code Here

    head.inline("title").text(baseUrl);

    Tag body = doc.block("body").attr(new Onload("CollapsibleLists.apply(true);"));
    Tag top  = body.block("div").id("top");

    final App app  = StructrApp.getInstance(securityContext);
    final Tag left = body.block("div").id("left");

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

      for (SchemaNode node : app.nodeQuery(SchemaNode.class).getAsList()) {

        final String rawType = node.getName();
        top.inline("a").attr(new Href(restPath + "/" + rawType), new If(rawType.equals(currentType), new Css("active"))).text(rawType);
      }
View Full Code Here

    }

    if (results != null) {

      final Iterable<? extends GraphObject> finalResults = results;
      final App app                                      = StructrApp.getInstance(securityContext);

      for (final GraphObject obj : finalResults) {

        if (obj instanceof AbstractRelationship) {

          app.delete((AbstractRelationship)obj);

        } else if (obj instanceof AbstractNode) {

          if (!securityContext.isAllowed((AbstractNode)obj, Permission.delete)) {

            logger.log(Level.WARNING, "Could not delete {0} because {1} has no delete permission", new Object[]{obj, securityContext.getUser(true)});
            throw new NotAllowedException();

          }

          // delete cascading
          app.delete((AbstractNode)obj);
        }

      }
    }
View Full Code Here

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

    final Result<GraphObject> result = doGet(null, false, NodeFactory.DEFAULT_PAGE_SIZE, NodeFactory.DEFAULT_PAGE, null);
    final List<GraphObject> results  = result.getResults();
    final App app                    = StructrApp.getInstance(securityContext);

    if (results != null && !results.isEmpty()) {

      final Class type = results.get(0).getClass();
View Full Code Here

        authenticator = config.getAuthenticator();
        securityContext = authenticator.initializeAndExamineRequest(request, response);
        tx.success();
      }

      final App app = StructrApp.getInstance(securityContext);

      String input = IOUtils.toString(request.getReader());
      if (StringUtils.isBlank(input)) {
        input = "{}";
      }

      // isolate input parsing (will include read and write operations)
      try (final Tx tx = app.tx()) {
        jsonInput   = gson.get().fromJson(input, IJsonInput.class);
        tx.success();
      }

      if (securityContext != null) {

        // isolate resource authentication
        try (final Tx tx = app.tx()) {

          resource = ResourceHelper.applyViewTransformation(request, securityContext,
              ResourceHelper.optimizeNestedResourceChain(ResourceHelper.parsePath(securityContext, request, resourceMap, propertyView,
              config.getDefaultIdProperty()), config.getDefaultIdProperty()), propertyView);
          authenticator.checkResourceAccess(request, resource.getResourceSignature(), propertyView.get(securityContext));
          tx.success();
        }

        // isolate doPost
        boolean retry = true;
        while (retry) {

          if (resource.createPostTransaction()) {

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

              for (JsonInput propertySet : jsonInput.getJsonInputs()) {

                results.add(resource.doPost(convertPropertySetToMap(propertySet)));
              }

              tx.success();
              retry = false;

            } catch (DeadlockDetectedException ddex) {
              retry = true;
            }

          } else {

            try {

              for (JsonInput propertySet : jsonInput.getJsonInputs()) {

                results.add(resource.doPost(convertPropertySetToMap(propertySet)));
              }

              retry = false;

            } catch (DeadlockDetectedException ddex) {
              retry = true;
            }
          }
        }

        // set default value for property view
        propertyView.set(securityContext, config.getDefaultPropertyView());

        // isolate write output
        try (final Tx tx = app.tx()) {

          if (!results.isEmpty()) {

            final RestMethodResult result = results.get(0);
            final int resultCount         = results.size();

            if (resultCount > 1) {

              for (final RestMethodResult r : results) {

                final GraphObject objectCreated = r.getContent().get(0);
                if (!result.getContent().contains(objectCreated)) {

                  result.addContent(objectCreated);
                }

              }

              // remove Location header if more than one object was
              // written because it may only contain a single URL
              result.addHeader("Location", null);
            }

            result.commitResponse(gson.get(), response);
             
          }

          tx.success();
        }

      } else {

        // isolate write output
        try (final Tx tx = app.tx()) {

          new RestMethodResult(HttpServletResponse.SC_FORBIDDEN).commitResponse(gson.get(), response);
          tx.success();
        }
View Full Code Here

        authenticator = config.getAuthenticator();
        securityContext = authenticator.initializeAndExamineRequest(request, response);
        tx.success();
      }

      final App app = StructrApp.getInstance(securityContext);

      String input = IOUtils.toString(request.getReader());
      if (StringUtils.isBlank(input)) {
        input = "{}";
      }

      // isolate input parsing (will include read and write operations)
      try (final Tx tx = app.tx()) {
        jsonInput   = gson.get().fromJson(input, IJsonInput.class);
        tx.success();
      }

      if (securityContext != null) {

        // isolate resource authentication
        try (final Tx tx = app.tx()) {

          // evaluate constraint chain
          resource = ResourceHelper.applyViewTransformation(request, securityContext,
            ResourceHelper.optimizeNestedResourceChain(ResourceHelper.parsePath(securityContext, request, resourceMap, propertyView,
              config.getDefaultIdProperty()), config.getDefaultIdProperty()), propertyView);
          authenticator.checkResourceAccess(request, resource.getResourceSignature(), propertyView.get(securityContext));
          tx.success();
        }

        // isolate doPut
        boolean retry = true;
        while (retry) {

          try (final Tx tx = app.tx()) {
            result = resource.doPut(convertPropertySetToMap(jsonInput.getJsonInputs().get(0)));
            tx.success();
            retry = false;

          } catch (DeadlockDetectedException ddex) {
            retry = true;
          }
        }

        // isolate write output
        try (final Tx tx = app.tx()) {
          result.commitResponse(gson.get(), response);
          tx.success();
        }

      } else {

        // isolate write output
        try (final Tx tx = app.tx()) {
          result = new RestMethodResult(HttpServletResponse.SC_FORBIDDEN);
          result.commitResponse(gson.get(), response);
          tx.success();
        }
View Full Code Here

    this.rawType         = part;

    if (rawType != null) {

      final boolean inexactSearch = parseInteger(request.getParameter(JsonRestServlet.REQUEST_PARAMETER_LOOSE_SEARCH)) == 1;
      final App app               = StructrApp.getInstance(securityContext);

      // test if resource class exists
      entityClass = SchemaHelper.getEntityClassForRawType(rawType);
      if (entityClass != null) {

        if (AbstractRelationship.class.isAssignableFrom(entityClass)) {

          searchCommandType = SearchRelationshipCommand.class;
          query             = app.relationshipQuery(entityClass, !inexactSearch);
          isNode            = false;
          return true;

        } else {

          // include interfaces here
          searchCommandType = SearchNodeCommand.class;
          query             = app.nodeQuery(entityClass, !inexactSearch);
          isNode            = true;
          return true;
        }
      }
    }
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.