Package org.pentaho.platform.api.repository2.unified

Examples of org.pentaho.platform.api.repository2.unified.RepositoryFile


    Assert.notNull( fileId );
    jcrTemplate.execute( new JcrCallback() {
      @Override
      public Object doInJcr( final Session session ) throws RepositoryException, IOException {
        RepositoryFile fileToBeDeleted = getFileById( fileId );
        // Get repository file info and acl info of parent
        if ( fileToBeDeleted != null ) {
          RepositoryFileAcl toBeDeletedFileAcl = aclDao.getAcl( fileToBeDeleted.getId() );
          // Invoke accessVoterManager to see if we have access to perform this operation
          if ( !accessVoterManager.hasAccess( fileToBeDeleted, RepositoryFilePermission.DELETE, toBeDeletedFileAcl,
              PentahoSessionHolder.getSession() ) ) {
            return null;
          }
        }
        List<RepositoryFilePermission> perms = new ArrayList<RepositoryFilePermission>();
        perms.add( RepositoryFilePermission.DELETE );
        if ( !aclDao.hasAccess( fileToBeDeleted.getPath(), EnumSet.copyOf( perms ) ) ) {
          throw new AccessDeniedException( Messages.getInstance().getString(
              "JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED_DELETE", fileId ) );
        }
        PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session );
        Serializable parentFolderId = JcrRepositoryFileUtils.getParentId( session, fileId );
View Full Code Here


    Assert.notNull( fileId );
    Assert.notNull( versionId );
    jcrTemplate.execute( new JcrCallback() {
      @Override
      public Object doInJcr( final Session session ) throws RepositoryException, IOException {
        RepositoryFile fileToBeDeleted = getFileById( fileId );
        // Get repository file info and acl info of parent
        if ( fileToBeDeleted != null ) {
          RepositoryFileAcl toBeDeletedFileAcl = aclDao.getAcl( fileToBeDeleted.getId() );
          // Invoke accessVoterManager to see if we have access to perform this operation
          if ( !accessVoterManager.hasAccess( fileToBeDeleted, RepositoryFilePermission.DELETE, toBeDeletedFileAcl,
              PentahoSessionHolder.getSession() ) ) {
            return null;
          }
View Full Code Here

    Assert.notNull( fileId );
    jcrTemplate.execute( new JcrCallback() {
      @Override
      public Object doInJcr( final Session session ) throws RepositoryException, IOException {
        RepositoryFile fileToBeDeleted = getFileById( fileId );
        // Get repository file info and acl info of parent
        if ( fileToBeDeleted != null ) {
          RepositoryFileAcl toBeDeletedFileAcl = aclDao.getAcl( fileToBeDeleted.getId() );
          // Invoke accessVoterManager to see if we have access to perform this operation
          if ( !accessVoterManager.hasAccess( fileToBeDeleted, RepositoryFilePermission.DELETE, toBeDeletedFileAcl,
              PentahoSessionHolder.getSession() ) ) {
            return null;
          }
View Full Code Here

      public Object doInJcr( final Session session ) throws RepositoryException, IOException {
        PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session );
        String absOrigParentFolderPath =
            deleteHelper.getOriginalParentFolderPath( session, pentahoJcrConstants, fileId );
        Serializable origParentFolderId = null;
        RepositoryFile file = getFileById( fileId );
        RepositoryFileAcl acl = aclDao.getAcl( fileId );
        if ( !accessVoterManager.hasAccess( file, RepositoryFilePermission.WRITE, acl, PentahoSessionHolder
            .getSession() ) ) {
          return null;
        }
        // original parent folder path may no longer exist!
        if ( session.itemExists( JcrStringHelper.pathEncode( absOrigParentFolderPath ) ) ) {
          origParentFolderId =
              ( (Node) session.getItem( JcrStringHelper.pathEncode( absOrigParentFolderPath ) ) ).getIdentifier();
        } else {
          // go through each of the segments of the original parent folder path, creating as necessary
          String[] segments = pathConversionHelper.absToRel( absOrigParentFolderPath ).split( RepositoryFile.SEPARATOR );
          RepositoryFile lastParentFolder =
              internalGetFile( session, ServerRepositoryPaths.getTenantRootFolderPath(), false, null );
          for ( String segment : segments ) {
            if ( StringUtils.hasLength( segment ) ) {
              RepositoryFile tmp =
                  internalGetFile( session, pathConversionHelper
                      .relToAbs( ( lastParentFolder.getPath().equals( RepositoryFile.SEPARATOR )
                          ? "" : lastParentFolder.getPath() ) + RepositoryFile.SEPARATOR + segment ), false, null ); //$NON-NLS-1$
              if ( tmp == null ) {
                lastParentFolder =
View Full Code Here

    Assert.notNull( fileId );
    jcrTemplate.execute( new JcrCallback() {
      @Override
      public Object doInJcr( final Session session ) throws RepositoryException, IOException {
        RepositoryFile file = getFileById( fileId );
        RepositoryFileAcl acl = aclDao.getAcl( fileId );
        if ( !accessVoterManager.hasAccess( file, RepositoryFilePermission.WRITE, acl, PentahoSessionHolder
            .getSession() ) ) {
          return null;
        }

        PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session );
        String destAbsPath = pathConversionHelper.relToAbs( destRelPath );
        String cleanDestAbsPath = destAbsPath;
        if ( cleanDestAbsPath.endsWith( RepositoryFile.SEPARATOR ) ) {
          cleanDestAbsPath.substring( 0, cleanDestAbsPath.length() - 1 );
        }
        Node srcFileNode = session.getNodeByIdentifier( fileId.toString() );
        Serializable srcParentFolderId = JcrRepositoryFileUtils.getParentId( session, fileId );
        boolean appendFileName = false;
        boolean destExists = true;
        Node destFileNode = null;
        Node destParentFolderNode = null;
        try {
          destFileNode = (Node) session.getItem( JcrStringHelper.pathEncode( cleanDestAbsPath ) );
        } catch ( PathNotFoundException e ) {
          destExists = false;
        }
        if ( destExists ) {
          // make sure it's a file or folder
          Assert.isTrue( JcrRepositoryFileUtils.isSupportedNodeType( pentahoJcrConstants, destFileNode ) );
          // existing item; make sure src is not a folder if dest is a file
          Assert.isTrue(
              !( JcrRepositoryFileUtils.isPentahoFolder( pentahoJcrConstants, srcFileNode ) && JcrRepositoryFileUtils
                  .isPentahoFile( pentahoJcrConstants, destFileNode ) ), Messages.getInstance().getString(
                  "JcrRepositoryFileDao.ERROR_0002_CANNOT_OVERWRITE_FILE_WITH_FOLDER" ) ); //$NON-NLS-1$
          if ( JcrRepositoryFileUtils.isPentahoFolder( pentahoJcrConstants, destFileNode ) ) {
            // existing item; caller is not renaming file, only moving it
            appendFileName = true;
            destParentFolderNode = destFileNode;
          } else {
            // get parent of existing dest item
            int lastSlashIndex = cleanDestAbsPath.lastIndexOf( RepositoryFile.SEPARATOR );
            Assert.isTrue( lastSlashIndex > 1, Messages.getInstance().getString(
                "JcrRepositoryFileDao.ERROR_0003_ILLEGAL_DEST_PATH" ) ); //$NON-NLS-1$
            String absPathToDestParentFolder = cleanDestAbsPath.substring( 0, lastSlashIndex );
            destParentFolderNode = (Node) session.getItem( JcrStringHelper.pathEncode( absPathToDestParentFolder ) );
          }
        } else {
          // destination doesn't exist; go up one level to a folder that does exist
          int lastSlashIndex = cleanDestAbsPath.lastIndexOf( RepositoryFile.SEPARATOR );
          Assert.isTrue( lastSlashIndex > 1, Messages.getInstance().getString(
              "JcrRepositoryFileDao.ERROR_0003_ILLEGAL_DEST_PATH" ) ); //$NON-NLS-1$
          String absPathToDestParentFolder = cleanDestAbsPath.substring( 0, lastSlashIndex );
          // Not need to check the name if we encoded it
          // JcrRepositoryFileUtils.checkName( cleanDestAbsPath.substring( lastSlashIndex + 1 ) );
          try {
            destParentFolderNode = (Node) session.getItem( JcrStringHelper.pathEncode( absPathToDestParentFolder ) );
          } catch ( PathNotFoundException e1 ) {
            Assert.isTrue( false, Messages.getInstance()
                .getString( "JcrRepositoryFileDao.ERROR_0004_PARENT_MUST_EXIST" ) ); //$NON-NLS-1$
          }
          Assert.isTrue( JcrRepositoryFileUtils.isPentahoFolder( pentahoJcrConstants, destParentFolderNode ), Messages
              .getInstance().getString( "JcrRepositoryFileDao.ERROR_0005_PARENT_MUST_BE_FOLDER" ) ); //$NON-NLS-1$
        }
        if ( !copy ) {
          JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary( session, pentahoJcrConstants,
              srcParentFolderId );
        }
        JcrRepositoryFileUtils.checkoutNearestVersionableNodeIfNecessary( session, pentahoJcrConstants,
            destParentFolderNode );
        String finalEncodedSrcAbsPath = srcFileNode.getPath();
        String finalDestAbsPath =
            appendFileName && !file.isFolder() ? cleanDestAbsPath + RepositoryFile.SEPARATOR + srcFileNode.getName()
                : cleanDestAbsPath;
        try {
          if ( copy ) {
            session.getWorkspace().copy( finalEncodedSrcAbsPath, JcrStringHelper.pathEncode( finalDestAbsPath ) );
          } else {
            session.getWorkspace().move( finalEncodedSrcAbsPath, JcrStringHelper.pathEncode( finalDestAbsPath ) );
          }
        } catch ( ItemExistsException iae ) {
          throw new UnifiedRepositoryException( ( file.isFolder() ? "Folder " : "File " ) + "with path ["
              + cleanDestAbsPath + "] already exists in the repository" );
        }

        JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary( session, pentahoJcrConstants,
            destParentFolderNode, versionMessage );
View Full Code Here

        PropertyIterator refIter = fileNode.getReferences();
        if ( refIter.hasNext() ) {
          while ( refIter.hasNext() ) {
            // for each referrer property, march up the tree until we find the file node to which the property
            // belongs
            RepositoryFile referrer = getReferrerFile( session, pentahoJcrConstants, refIter.nextProperty() );
            if ( referrer != null ) {
              referrers.add( referrer );
            }
          }
        }
View Full Code Here

    this.defaultAclHandler = defaultAclHandler;
  }

  @Override
  public List<Locale> getAvailableLocalesForFileById( Serializable fileId ) {
    RepositoryFile repositoryFile = getFileById( fileId, true );
    return getAvailableLocalesForFile( repositoryFile );
  }
View Full Code Here

    return getAvailableLocalesForFile( repositoryFile );
  }

  @Override
  public List<Locale> getAvailableLocalesForFileByPath( String relPath ) {
    RepositoryFile repositoryFile = getFileById( relPath, true );
    return getAvailableLocalesForFile( repositoryFile );
  }
View Full Code Here

    return localeList;
  }

  @Override
  public Properties getLocalePropertiesForFileById( Serializable fileId, String locale ) {
    RepositoryFile repositoryFile = getFileById( fileId, true );
    return getLocalePropertiesForFile( repositoryFile, locale );
  }
View Full Code Here

  }

  @Override
  public Properties getLocalePropertiesForFileByPath( String relPath, String locale ) {

    RepositoryFile repositoryFile = getFileById( relPath, true );
    return getLocalePropertiesForFile( repositoryFile, locale );
  }
View Full Code Here

TOP

Related Classes of org.pentaho.platform.api.repository2.unified.RepositoryFile

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.