Package org.structr.core.app

Examples of org.structr.core.app.App


  // ----- diff methods -----
  @Export
  public void diff(final String file) throws FrameworkException {

    final App app = StructrApp.getInstance(securityContext);

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

      final String source = IOUtils.toString(new FileInputStream(file));
      final List<InvertibleModificationOperation> changeSet = new LinkedList<>();
      final Page diffPage = Importer.parsePageFromSource(securityContext, source, this.getProperty(Page.name) + "diff");

      // build change set
      changeSet.addAll(Importer.diffPages(this, diffPage));

      for (final InvertibleModificationOperation op : changeSet) {

        System.out.println(op);

        op.apply(app, this, diffPage);
      }

      // delete remaining children
      for (final DOMNode child : diffPage.getProperty(Page.elements)) {
        app.delete(child);
      }

      // delete imported page
      app.delete(diffPage);

      tx.success();

    } catch (Throwable t) {
      t.printStackTrace();
View Full Code Here


    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  }

  @Override
  public boolean delete() {
    final App app = StructrApp.getInstance();

    try (Tx tx = StructrApp.getInstance().tx()) {
      app.delete(this);
      tx.success();
    } catch (FrameworkException ex) {
      logger.log(Level.SEVERE, null, ex);
    }
View Full Code Here

      @Override
      public void flush() throws IOException {

        final String source = toString();

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

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

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

          for (final InvertibleModificationOperation op : changeSet) {

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

          }

          app.delete(modifiedPage);

          tx.success();

        } catch (FrameworkException fex) {
          fex.printStackTrace();
View Full Code Here

  @Override
  public void onRequest(CloudConnection serverConnection, ExportContext context) throws IOException, FrameworkException {

    try {
      final App app = serverConnection.getApplicationContext();

      // try node first, then relationship
      Syncable syncable = (Syncable)app.nodeQuery().and(GraphObject.id, rootNodeId).includeDeletedAndHidden().getFirst();
      if (syncable == null) {

        syncable = (Syncable)app.relationshipQuery().and(GraphObject.id, rootNodeId).includeDeletedAndHidden().getFirst();
      }

      if (syncable != null) {

        final ExportSet exportSet = ExportSet.getInstance(syncable, recursive);
View Full Code Here

    final Boolean recursive = (Boolean) webSocketData.getNodeData().get("recursive");
    final AbstractNode obj  = getNode(webSocketData.getId());

    if (obj != null) {

      final App app = StructrApp.getInstance(securityContext);

      if (Boolean.TRUE.equals(recursive)) {
       
        // Remove all child nodes first

        try {

          final List<AbstractNode> filteredResults = new LinkedList();
          if (obj instanceof DOMNode) {

            DOMNode node = (DOMNode) obj;

            filteredResults.addAll(DOMNode.getAllChildNodes(node));

          } else if (obj instanceof LinkedTreeNode) {
           
            LinkedTreeNode node = (LinkedTreeNode) obj;

            filteredResults.addAll(node.getAllChildNodes());
           
          }

          for (NodeInterface node : filteredResults) {
            app.delete(node);
          }

        } catch (FrameworkException fex) {

          logger.log(Level.WARNING, "Exception occured", fex);
          getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
        }

      }

      try {
        app.delete(obj);

      } catch (FrameworkException fex) {
        logger.log(Level.WARNING, "Unable to delete node(s)", fex);
      }
View Full Code Here

   * @return folder
   * @throws FrameworkException
   */
  public static Folder createFolderPath(final SecurityContext securityContext, final String path) throws FrameworkException {

    App app = StructrApp.getInstance(securityContext);

    if (path == null) {

      return null;
    }

    Folder folder = (Folder) FileHelper.getFileByAbsolutePath(securityContext, path);

    if (folder != null) {
      return folder;
    }

    String[] parts = PathHelper.getParts(path);
    String partialPath = "";

    for (String part : parts) {

      // ignore ".." and "." in paths
      if ("..".equals(part) || ".".equals(part)) {
        continue;
      }

      Folder parent = folder;

      partialPath += PathHelper.PATH_SEP + part;
      folder = (Folder) FileHelper.getFileByAbsolutePath(securityContext, partialPath);

      if (folder == null) {

        folder = app.create(Folder.class, part);

      }

      if (parent != null) {

View Full Code Here

    return (T)createTestNode(type, new PropertyMap(), user);
  }

  protected <T extends AbstractNode> T createTestNode(final Class<T> type, final PropertyMap props, final Principal user) throws FrameworkException {

    final App backendApp = StructrApp.getInstance(SecurityContext.getInstance(user, AccessMode.Backend));

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

      final T result = backendApp.create(type, props);
      tx.success();

      return result;
    }
  }
View Full Code Here

    }
  }

  public static void clearResourceAccess() {

    final App app = StructrApp.getInstance();

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

      for (final ResourceAccess access : app.nodeQuery(ResourceAccess.class).getAsList()) {
        app.delete(access);
      }

      tx.success();

    } catch (Throwable t) {
View Full Code Here

  }

  // ----- private methods -----
  public static void ensureBuiltinTypesExist() throws FrameworkException {

    final App app = StructrApp.getInstance();

    for (final Entry<String, String> entry : builtinTypeMap.entrySet()) {

      final String type = entry.getKey();
      final String fqcn = entry.getValue();

      SchemaNode schemaNode = app.nodeQuery(SchemaNode.class).andName(type).getFirst();
      if (schemaNode == null) {

        schemaNode = app.create(SchemaNode.class, type);
      }

      schemaNode.setProperty(SchemaNode.extendsClass, fqcn);
      schemaNode.unlockReadOnlyPropertiesOnce();
      schemaNode.setProperty(SchemaNode.isBuiltinType, true);
View Full Code Here

  public static List<DynamicResourceAccess> createDynamicGrants(final String signature) {

    final List<DynamicResourceAccess> grants = new LinkedList<>();
    final long initialFlagsValue             = 0;

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

      ResourceAccess grant = app.nodeQuery(ResourceAccess.class).and(ResourceAccess.signature, signature).getFirst();
      if (grant == null) {

        // create new grant
        grants.add(app.create(DynamicResourceAccess.class,
          new NodeAttribute(DynamicResourceAccess.signature, signature),
          new NodeAttribute(DynamicResourceAccess.flags, initialFlagsValue)
        ));

        // create additional grant for the _schema resource
        grants.add(app.create(DynamicResourceAccess.class,
          new NodeAttribute(DynamicResourceAccess.signature, "_schema/" + signature),
          new NodeAttribute(DynamicResourceAccess.flags, initialFlagsValue)
        ));

        // create additional grant for the Ui view
        grants.add(app.create(DynamicResourceAccess.class,
          new NodeAttribute(DynamicResourceAccess.signature, signature + "/_Ui"),
          new NodeAttribute(DynamicResourceAccess.flags, initialFlagsValue)
        ));
      }
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.