Package org.structr.core.app

Examples of org.structr.core.app.App


    final String type                    = (String)properties.get("type");
    final Long port                      = (Long)properties.get("port");

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

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

        final List<SyncableInfo> syncables = CloudService.doRemote(new SingleTransmission<>(new ListSyncables(type), username, password, host, port.intValue()), new WebsocketProgressListener(getWebSocket(), key));
        final StructrWebSocket webSocket   = getWebSocket();
        if (syncables != null) {
View Full Code Here


          properties.put(key, getProperty(key));
        }
      }

      final App app = StructrApp.getInstance(securityContext);

      try {
        DOMNode node = app.create(getClass(), properties);

        return node;

      } catch (FrameworkException ex) {
View Full Code Here

  @Override
  public Node doAdopt(final Page _page) throws DOMException {

    if (_page != null) {

      final App app = StructrApp.getInstance(securityContext);

      try {
        setProperty(ownerDocument, _page);

      } catch (FrameworkException fex) {
View Full Code Here

    final String pageId = webSocketData.getId();
    final Map<String, Object> nodeData = webSocketData.getNodeData();
    final String modifiedHtml = (String) nodeData.get("source");
    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final App app = StructrApp.getInstance(securityContext);

    Page modifiedPage = null;

    Page sourcePage = getPage(pageId);
    if (sourcePage != null) {

      try {

        // parse page from modified source
        modifiedPage = Importer.parsePageFromSource(securityContext, modifiedHtml, "__SavePageCommand_Temporary_Page__");

        final List<InvertibleModificationOperation> changeSet = Importer.diffPages(sourcePage, modifiedPage);

        for (final InvertibleModificationOperation op : changeSet) {

          // execute operation
          op.apply(app, sourcePage, modifiedPage);

        }


      } catch (Throwable t) {

        logger.log(Level.WARNING, t.toString());
        t.printStackTrace();

        // send exception
        getWebSocket().send(MessageBuilder.status().code(422).message(t.toString()).build(), true);
      }

      try {

        app.delete(modifiedPage);

      } catch (FrameworkException ex) {

        ex.printStackTrace();
      }
View Full Code Here

  @Override
  public void processMessage(WebSocketMessage webSocketData) throws FrameworkException {

    final SecurityContext securityContext        = getWebSocket().getSecurityContext();
    final App app                                = StructrApp.getInstance(securityContext);
    final Query query                            = app.nodeQuery();
    final List<? extends GraphObject> resultList = new LinkedList<>();
    final Set<AbstractNode> filteredResults      = new LinkedHashSet<>();

    query.includeDeletedAndHidden();
    query.orTypes(DOMElement.class);
    query.orType(Content.class);

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

      resultList.addAll(query.getAsList());

      // determine which of the nodes have incoming CONTAINS relationships and are not components
      for (GraphObject obj : resultList) {

        if (obj instanceof DOMNode) {

          DOMNode node = (DOMNode) obj;

          if (node.getProperty(DOMNode.ownerDocument) == null) {
            filteredResults.add(node);
          }

          for (final DOMNode child : DOMNode.getAllChildNodes(node)) {

            if (child.getProperty(DOMNode.ownerDocument) == null) {
              filteredResults.add(child);
            }
          }
        }
      }

      tx.success();
    }

    final Iterator<AbstractNode> iterator = filteredResults.iterator();
    int count                             = 0;

    while (iterator.hasNext()) {

      count = 0;
      try (final Tx tx = app.tx()) {

        while (iterator.hasNext() && count++ < 100) {

          app.delete(iterator.next());
        }

        // commit and close transaction
        tx.success();
      }
View Full Code Here

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

    if (obj != null) {

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

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

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

    Map<String, Object> properties        = webSocketData.getNodeData();
    String targetId                       = (String) properties.get("targetId");
    final String syncMode                 = (String) properties.get("syncMode");
    final DOMNode sourceNode              = (DOMNode) getNode(sourceId);
    final DOMNode targetNode              = (DOMNode) getNode(targetId);
    final App app                         = StructrApp.getInstance(securityContext);

    if ((sourceNode != null) && (targetNode != null)) {

      try {

        app.create(sourceNode, targetNode, Sync.class);

        if (syncMode.equals("bidir")) {

          app.create(targetNode, sourceNode, Sync.class);
        }

      } catch (Throwable t) {

        getWebSocket().send(MessageBuilder.status().code(400).message(t.getMessage()).build(), true);
View Full Code Here

      } catch (Throwable t) {}

    }

    final App app = StructrApp.getInstance(securityContext);

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

      for (Node node : toDelete) {

        logger.log(Level.INFO, "Deleting node {0}", node);
View Full Code Here

  @Override
  public void onWebSocketClose(final int closeCode, final String message) {

    logger.log(Level.INFO, "Connection closed with closeCode {0} and message {1}", new Object[]{closeCode, message});

    final App app = StructrApp.getInstance(securityContext);

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

      this.session = null;

      syncController.unregisterClient(this);
View Full Code Here


    // parse web socket data from JSON
    final WebSocketMessage webSocketData = gson.fromJson(data, WebSocketMessage.class);

    final App app = StructrApp.getInstance(securityContext);

    this.callback = webSocketData.getCallback();

    final String command = webSocketData.getCommand();
    final Class type = commandSet.get(command);

    final String sessionIdFromMessage = webSocketData.getSessionId();

    if (type != null) {

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

        if (sessionIdFromMessage != null) {

          // try to authenticated this connection by sessionId
          authenticate(sessionIdFromMessage);
        }

        // we only permit LOGIN commands if authentication based on sessionId was not successful
        if (!isAuthenticated() && !type.equals(LoginCommand.class)) {

          // send 401 Authentication Required
          send(MessageBuilder.status().code(401).message("").build(), true);

          return;
        }

        tx.success();

      } catch (FrameworkException t) {

        logger.log(Level.WARNING, "Unable to parse message.", t);

      }

      // process message
      try {

        AbstractCommand abstractCommand = (AbstractCommand) type.newInstance();

        abstractCommand.setWebSocket(this);
        abstractCommand.setSession(session);
        abstractCommand.setIdProperty(idProperty);

        // The below blocks allow a websocket command to manage its own
        // transactions in case of bulk processing commands etc.

        if (abstractCommand.requiresEnclosingTransaction()) {

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

            // store authenticated-Flag in webSocketData
            // so the command can access it
            webSocketData.setSessionValid(isAuthenticated());

            abstractCommand.processMessage(webSocketData);

            // commit transaction
            tx.success();
          }

        } else {

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

            // store authenticated-Flag in webSocketData
            // so the command can access it
            webSocketData.setSessionValid(isAuthenticated());

            // commit transaction
            tx.success();
          }

          // process message without transaction context!
          abstractCommand.processMessage(webSocketData);

        }

      } catch (FrameworkException | InstantiationException | IllegalAccessException t) {

        t.printStackTrace(System.out);

        // Clear result in case of rollback
        //webSocketData.clear();

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

          // send 400 Bad Request
          if (t instanceof FrameworkException) {

            send(MessageBuilder.status().message(t.toString()).jsonErrorObject(((FrameworkException) t).toJSON()).build(), 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.