Package org.structr.core.app

Examples of org.structr.core.app.App


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

    if (isNode) {

      final App app         = StructrApp.getInstance(securityContext);
      NodeInterface newNode = null;

      newNode = createNode(propertySet);

      final RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
      if (newNode != null) {

        result.addHeader("Location", buildLocationHeader(newNode));
        result.addContent(newNode);
      }

      result.serializeAsPrimitiveArray(true);
     
      // finally: return 201 Created
      return result;

    } else {

      final App app                         = StructrApp.getInstance(securityContext);
      final Relation template               = getRelationshipTemplate();
      final ErrorBuffer errorBuffer         = new ErrorBuffer();

      if (template != null) {

        final NodeInterface sourceNode        = identifyStartNode(template, propertySet);
        final NodeInterface targetNode        = identifyEndNode(template, propertySet);
        final PropertyMap properties          = PropertyMap.inputTypeToJavaType(securityContext, entityClass, propertySet);
        RelationshipInterface newRelationship = null;

        if (sourceNode == null) {
          errorBuffer.add(entityClass.getSimpleName(), new EmptyPropertyToken(template.getSourceIdProperty()));
        }

        if (targetNode == null) {
          errorBuffer.add(entityClass.getSimpleName(), new EmptyPropertyToken(template.getTargetIdProperty()));
        }

        if (errorBuffer.hasError()) {
          throw new FrameworkException(422, errorBuffer);
        }

        newRelationship = app.create(sourceNode, targetNode, entityClass, properties);

        RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
        if (newRelationship != null) {

          result.addHeader("Location", buildLocationHeader(newRelationship));
View Full Code Here


  public NodeInterface createNode(final Map<String, Object> propertySet) throws FrameworkException {

    if (entityClass != null) {

      final App app                = StructrApp.getInstance(securityContext);
      final PropertyMap properties = PropertyMap.inputTypeToJavaType(securityContext, entityClass, propertySet);

      return app.create(entityClass, properties);
    }

    throw new NotFoundException();
  }
View Full Code Here

  }

  @Override
  public boolean delete() {

    final App app = StructrApp.getInstance();

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

  // ----- public static methods -----
  public static Page parsePageFromSource(final SecurityContext securityContext, final String source, final String name) throws FrameworkException {

    final Importer importer = new Importer(securityContext, source, null, "source", 0, true, true);
    final App localAppCtx   = StructrApp.getInstance(securityContext);
    Page page               = null;

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

      page   = localAppCtx.create(Page.class, new NodeAttribute<>(Page.name, name));

      if (importer.parse()) {

        importer.createChildNodesWithHtml(page, page);
      }
View Full Code Here

  @Override
  public List<FtpFile> listFiles() {

    List<FtpFile> ftpFiles = new ArrayList();

    final App app = StructrApp.getInstance();

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

      String requestedPath = getAbsolutePath();
      logger.log(Level.INFO, "Children of {0} requested", requestedPath);

      if ("/".equals(requestedPath)) {
        try {
          Result<Folder> folders = app.nodeQuery(Folder.class).getResult();
          logger.log(Level.INFO, "{0} folders found", folders.size());

          for (Folder f : folders.getResults()) {

            if (f.getProperty(AbstractFile.parent) != null) {
              continue;
            }

            FtpFile ftpFile = new StructrFtpFolder(f);
            logger.log(Level.INFO, "Folder found: {0}", ftpFile.getAbsolutePath());

            ftpFiles.add(ftpFile);

          }

          Result<File> files = app.nodeQuery(File.class).getResult();
          logger.log(Level.INFO, "{0} files found", files.size());

          for (File f : files.getResults()) {

            if (f.getProperty(AbstractFile.parent) != null) {
              continue;
            }

            logger.log(Level.FINEST, "Structr file found: {0}", f);

            FtpFile ftpFile = new StructrFtpFile(f);
            logger.log(Level.FINE, "File found: {0}", ftpFile.getAbsolutePath());

            ftpFiles.add(ftpFile);

          }

          Result<Page> pages = app.nodeQuery(Page.class).getResult();
          logger.log(Level.INFO, "{0} pages found", pages.size());

          for (Page p : pages.getResults()) {

            logger.log(Level.FINEST, "Structr page found: {0}", p);
View Full Code Here

  }

  @Override
  public boolean mkdir() {

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

      logger.log(Level.INFO, "mkdir() Folder");

      AbstractFile existing = FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), newPath);
      if (existing != null) {
View Full Code Here

   * @param origNodes
   * @param shadowIdPropertyKey
   */
  public static <T extends NodeInterface> void merge(final Set<T> origNodes, final Set<T> newNodes, final PropertyKey shadowIdPropertyKey) {

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

      // Compare uuid of original nodes with the id given in the shadow id property
      // and mark all original nodes as deleted which are not contained in new nodes list anymore
      for (final NodeInterface origNode : origNodes) {

        origNode.setProperty(NodeInterface.deleted, true);
       
        for (final NodeInterface newNode : newNodes) {
       
          final String shadowId = (String) newNode.getProperty(shadowIdPropertyKey);
          logger.log(Level.INFO, "New node shadow id: {0}", shadowId);
         
          if (origNode.getUuid().equals(shadowId)) {
            origNode.setProperty(NodeInterface.deleted, false);
          }
       
        }

      }

      // Delete all original nodes which are marked as deleted
      for (final NodeInterface origNode : origNodes) {

        if (origNode.getProperty(NodeInterface.deleted)) {
       
          app.delete(origNode);
       
        }
       

      }

      // Delete all new nodes
      for (final NodeInterface newNode : newNodes) {

        app.delete(newNode);

      }

      tx.success();
     
View Full Code Here

  }

  @Override
  public void afterCreation(SecurityContext securityContext) {
   
    final App app = StructrApp.getInstance(securityContext);

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

      final int value = getIncreasedValue(modifiedInAfterCreation);
      setProperty(modifiedInAfterCreation, value);
     
      tx.success();
View Full Code Here

  }

  @Override
  public void afterModification(SecurityContext securityContext) {
   
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {

      final int value = getIncreasedValue(modifiedInAfterModification);
     
      setProperty(modifiedInAfterModification, value);
      tx.success();
View Full Code Here

    final String id = (String)attributes.get("id");

    if (id != null) {

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

        CloudService.doRemote(new PullTransmission(id, true, "admin", "admin", "localhost", 54556), new LoggingListener());
      }
    }
  }
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.