Package org.structr.core.app

Examples of org.structr.core.app.App


      try (final Tx tx = StructrApp.getInstance().tx()) {
        authenticator = config.getAuthenticator();
        securityContext = authenticator.initializeAndExamineRequest(request, response);
        tx.success();
      }
      final App app = StructrApp.getInstance(securityContext);

//                      logRequest("GET", request);
      request.setCharacterEncoding("UTF-8");
      response.setCharacterEncoding("UTF-8");
      response.setContentType("text/csv; charset=utf-8");

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

      // evaluate constraints and measure query time
      double queryTimeStart = System.nanoTime();

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

        resource = ResourceHelper.optimizeNestedResourceChain(ResourceHelper.parsePath(securityContext, request, resourceMap, propertyView, defaultIdProperty), defaultIdProperty);
        authenticator.checkResourceAccess(request, resource.getResourceSignature(), propertyView.get(securityContext));

        tx.success();
      }

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

        String resourceSignature = resource.getResourceSignature();

        // let authenticator examine request again
        authenticator.checkResourceAccess(request, resourceSignature, propertyView.get(securityContext));
View Full Code Here


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

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

    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

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

      final App app = StructrApp.getInstance(securityContext);

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

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

        tx.success();
      }

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

        try (final Tx tx = app.tx()) {
          result = resource.doDelete();
          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();
      }

    } catch (FrameworkException frameworkException) {
View Full Code Here

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

      final App app = StructrApp.getInstance(securityContext);

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

      // evaluate constraints and measure query time
      double queryTimeStart    = System.nanoTime();

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

      // add sorting & paging
      String pageSizeParameter = request.getParameter(REQUEST_PARAMETER_PAGE_SIZE);
      String pageParameter     = request.getParameter(REQUEST_PARAMETER_PAGE_NUMBER);
      String offsetId          = request.getParameter(REQUEST_PARAMETER_OFFSET_ID);
      String sortOrder         = request.getParameter(REQUEST_PARAMETER_SORT_ORDER);
      String sortKeyName       = request.getParameter(REQUEST_PARAMETER_SORT_KEY);
      boolean sortDescending   = (sortOrder != null && "desc".equals(sortOrder.toLowerCase()));
      int pageSize     = HttpService.parseInt(pageSizeParameter, NodeFactory.DEFAULT_PAGE_SIZE);
      int page                 = HttpService.parseInt(pageParameter, NodeFactory.DEFAULT_PAGE);
      String baseUrl           = request.getRequestURI();
      PropertyKey sortKey      = null;

      // set sort key
      if (sortKeyName != null) {

        Class<? extends GraphObject> type = resource.getEntityClass();
        if (type == null) {

          // fallback to default implementation
          // if no type can be determined
          type = AbstractNode.class;
        }
        sortKey = StructrApp.getConfiguration().getPropertyKeyForDatabaseName(type, sortKeyName);
      }

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

        try (final Tx tx = app.tx()) {
          result = resource.doGet(sortKey, sortDescending, pageSize, page, offsetId);
          tx.success();
          retry = false;

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

      result.setIsCollection(resource.isCollectionResource());
      result.setIsPrimitiveArray(resource.isPrimitiveArray());

      PagingHelper.addPagingParameter(result, pageSize, page);

      // timing..
      double queryTimeEnd = System.nanoTime();

      // store property view that will be used to render the results
      result.setPropertyView(propertyView.get(securityContext));

      // allow resource to modify result set
      resource.postProcessResultSet(result);

      DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
      result.setQueryTime(decimalFormat.format((queryTimeEnd - queryTimeStart) / 1000000000.0));

      String accept = request.getHeader("Accept");

      if (accept != null && accept.contains("text/html")) {

        final StreamingHtmlWriter htmlStreamer = new StreamingHtmlWriter(this.propertyView, indentJson, config.getOutputNestingDepth());

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

          response.setContentType("text/html; charset=utf-8");

          try (final Writer writer = response.getWriter()) {

            htmlStreamer.stream(securityContext, writer, result, baseUrl);
            writer.append("\n");    // useful newline
          }

          tx.success();
        }

      } else {

        final StreamingJsonWriter jsonStreamer = new StreamingJsonWriter(this.propertyView, indentJson, config.getOutputNestingDepth());

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

          response.setContentType("application/json; charset=utf-8");
          try (final Writer writer = response.getWriter()) {

            jsonStreamer.stream(securityContext, writer, result, baseUrl);
View Full Code Here

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

      final App app = StructrApp.getInstance(securityContext);

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

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

      // add sorting & paging
      String pageSizeParameter = request.getParameter(REQUEST_PARAMETER_PAGE_SIZE);
      String pageParameter     = request.getParameter(REQUEST_PARAMETER_PAGE_NUMBER);
      String offsetId          = request.getParameter(REQUEST_PARAMETER_OFFSET_ID);
      String sortOrder         = request.getParameter(REQUEST_PARAMETER_SORT_ORDER);
      String sortKeyName       = request.getParameter(REQUEST_PARAMETER_SORT_KEY);
      boolean sortDescending   = (sortOrder != null && "desc".equals(sortOrder.toLowerCase()));
      int pageSize     = HttpService.parseInt(pageSizeParameter, NodeFactory.DEFAULT_PAGE_SIZE);
      int page                 = HttpService.parseInt(pageParameter, NodeFactory.DEFAULT_PAGE);
      PropertyKey sortKey      = null;

      // set sort key
      if (sortKeyName != null) {

        Class<? extends GraphObject> type = resource.getEntityClass();
        if (type == null) {

          // fallback to default implementation
          // if no type can be determined
          type = AbstractNode.class;
        }
        sortKey = StructrApp.getConfiguration().getPropertyKeyForDatabaseName(type, sortKeyName);
      }

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

        try (final Tx tx = app.tx()) {
          resource.doGet(sortKey, sortDescending, pageSize, page, offsetId);
          tx.success();
          retry = false;

        } catch (DeadlockDetectedException ddex) {
View Full Code Here

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

      final App app = StructrApp.getInstance(securityContext);

      // 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 doOptions
      boolean retry = true;
      while (retry) {

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

          result = resource.doOptions();
          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();
      }

    } catch (FrameworkException frameworkException) {
View Full Code Here

      final GraphDatabaseService graphDb = Services.getInstance().getService(NodeService.class).getGraphDb();
      final GlobalGraphOperations ggop  = GlobalGraphOperations.at(graphDb);
      final Iterable<Relationship> rels = ggop.getAllRelationships();
      final Iterable<Node> nodes        = ggop.getAllNodes();
      final App app                     = StructrApp.getInstance();
      final String fileName             = (String)attributes.get("name");

      if (fileName == null || fileName.isEmpty()) {

        throw new FrameworkException(400, "Please specify name.");
      }

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

        final File file = FileHelper.createFile(securityContext, new byte[0], "application/zip", File.class, fileName);

        // make file visible for auth. users
        file.setProperty(File.visibleToAuthenticatedUsers, true);

        // Don't include files
        SyncCommand.exportToStream(file.getOutputStream(), app.nodeQuery(NodeInterface.class).getAsList(), app.relationshipQuery(RelationshipInterface.class).getAsList(), null, false);

        tx.success();
      }

    } catch (Throwable t) {
View Full Code Here

    final String name = (String)attributes.get("name");
    final String host = (String)attributes.get("host");

    if (name != null && host != null) {

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

        final NodeInterface entity = app.nodeQuery().andName(name).getFirst();
        if (entity != null && entity instanceof Syncable) {

          CloudService.doRemote(new PushTransmission((Syncable)entity, true, "admin", "admin", host, 54555), new LoggingListener());
        }
      }
View Full Code Here

      confKey = UUID.randomUUID().toString();

      Result result = StructrApp.getInstance().nodeQuery(User.class).and(User.eMail, emailString).getResult();
      if (!result.isEmpty()) {

        final App app = StructrApp.getInstance(securityContext);
        user = (Principal) result.get(0);

        // For existing users, update confirmation key
        user.setProperty(User.confirmationKey, confKey);
View Full Code Here

    final String id                     = webSocketData.getId();
    String pageId                      = webSocketData.getPageId();
    final Map<String, Object> nodeData = webSocketData.getNodeData();
    final String parentId              = (String) nodeData.get("parentId");
    final String baseUrl               = (String) nodeData.get("widgetHostBaseUrl");
    final App app                      = StructrApp.getInstance(getWebSocket().getSecurityContext());
   
    final Page page      = getPage(pageId);
    final AbstractNode origNode  = getNode(id);
   
    try {
     
      DOMNode existingParent = null;
      if (parentId != null) {
        // Remove original node from existing parent to ensure correct position
        existingParent = (DOMNode) getNode(parentId);
      }

      // Create temporary parent node
      DOMNode parent = app.create(Div.class);

      // Expand source code to widget
      Widget.expandWidget(getWebSocket().getSecurityContext(), page, parent, baseUrl, nodeData);

      DOMNode newWidget = (DOMNode) parent.getChildNodes().item(0);
      moveSyncRels((DOMElement) origNode, (DOMElement) newWidget);

      if (existingParent != null) {
        existingParent.removeChild((DOMNode) origNode);

      }

      deleteRecursively((DOMNode) origNode);

      // Set uuid of original node to new widget node
      newWidget.setProperty(GraphObject.id, id);

      if (existingParent != null) {

        // Append new widget to existing parent
        existingParent.appendChild(newWidget);
      }           

      // Delete temporary parent node
      app.delete(parent);
     
    } catch (FrameworkException ex) {
     
      logger.log(Level.SEVERE, null, ex);
     
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.