private String getMetaStoreFolders( StringBuilder builder, RepositoryFile folder, int level ) { String spaces = Const.rightPad( " ", level * 2 ); builder.append( spaces ); if ( folder.isFolder() ) { builder.append( "/" ); } builder.append( folder.getName() ).append( Const.CR ); for ( RepositoryFile file : getChildren( folder.getId() ) ) { getMetaStoreFolders( builder, file, level + 1 ); } return builder.toString(); }
@Override public String[] getDirectoryNames( final ObjectId idDirectory ) throws KettleException { try { readWriteLock.readLock().lock(); List<RepositoryFile> children; try { children = pur.getChildren( idDirectory.getId() ); } finally { readWriteLock.readLock().unlock(); } List<String> childNames = new ArrayList<String>(); for ( RepositoryFile child : children ) { if ( child.isFolder() ) { childNames.add( child.getName() ); } } return childNames.toArray( new String[ 0 ] ); } catch ( Exception e ) { throw new KettleException( "Unable to get list of object names from directory [" + idDirectory + "]", e ); } }
private List<RepositoryFile> getAllURChildrenFiles() { RepositoryRequest repositoryRequest = new RepositoryRequest(); repositoryRequest.setShowHidden( showHidden ); repositoryRequest.setTypes( RepositoryRequest.FILES_TYPE_FILTER.FOLDERS ); repositoryRequest.setPath( this.self.getId().toString() ); List<RepositoryFile> children = repository.getChildren( repositoryRequest ); // Special case: /etc should not be returned from a directory listing. RepositoryFile etcFile = null; if ( this.isRoot() ) { etcFile = repository.getFile( ClientRepositoryPaths.getEtcFolderPath() ); } // Filter for Folders only doesn't appear to work Iterator<RepositoryFile> iterator = children.iterator(); while ( iterator.hasNext() ) { RepositoryFile next = iterator.next(); if ( !next.isFolder() ) { iterator.remove(); } // Special case: /etc should not be returned from a directory listing. if ( this.isRoot() && next.equals( etcFile ) ) { iterator.remove(); } } return children; }
@Override public RepositoryDirectory findDirectory( ObjectId id_directory ) { RepositoryFile file = repository.getFileById( id_directory.getId() ); if ( file == null || !file.isFolder() ) { return null; } if ( isRoot() && RepositoryDirectory.DIRECTORY_SEPARATOR.equals( file.getPath() ) ) { return this; } // Verifies if this is the parent directory of file and if so passes this as parent argument String parentPath = getParentPath( file.getPath() ); if ( self.getPath().endsWith( RepositoryDirectory.DIRECTORY_SEPARATOR ) ) { if ( parentPath.equals( self.getPath().substring( 0, self.getPath().length() - 1 ) ) ) { return new LazyUnifiedRepositoryDirectory( file, this, repository, registry, showHidden ); } } else { if ( parentPath.equals( self.getPath() ) ) { return new LazyUnifiedRepositoryDirectory( file, this, repository, registry, showHidden ); } } return new LazyUnifiedRepositoryDirectory( file, findDirectory( parentPath ), repository, registry, showHidden ); }
if ( file == null || !file.isFolder() ) { return null;
if ( repObj.getFile().isFolder() ) {
if ( repositoryFile.isFolder() ) { RepositoryDirectoryInterface repositoryDirectory = new RepositoryDirectory(); repositoryDirectory.setName( repositoryFile.getName() );
@Override public List<RepositoryElementMetaInterface> getRepositoryObjects( ) { if ( fileChildren == null ) { fileChildren = new ArrayList<>(); synchronized ( fileChildren ) { UnifiedRepositoryLockService lockService = (UnifiedRepositoryLockService) registry.getService( ILockService.class ); RepositoryFileTree tree = repository.getTree( new RepositoryRequest( this.self.getPath(), showHidden, 1, null ) ); for ( RepositoryFileTree tchild : tree.getChildren() ) { RepositoryFile child = tchild.getFile(); if ( !child.isFolder() ) { RepositoryLock lock = null; try { lock = lockService.getLock( child ); RepositoryObjectType objectType = PurRepository.getObjectType( child.getName() ); EERepositoryObject repositoryObject = new EERepositoryObject( child, this, null, objectType, null, lock, false ); repositoryObject.setVersioningEnabled( tchild.getVersioningEnabled() ); repositoryObject.setVersionCommentEnabled( tchild.getVersionCommentEnabled() ); fileChildren.add( repositoryObject ); } catch ( KettleException e ) { logger.error( "Error converting Unified Repository file to PDI RepositoryObject: " + child.getPath() + ". File will be skipped", e ); } } } } } return fileChildren; }
private void fillRepositoryDirectoryFromTree( final RepositoryDirectoryInterface parentDir, final RepositoryFileTree treeNode ) throws KettleException { try { List<RepositoryElementMetaInterface> fileChildren = new ArrayList<RepositoryElementMetaInterface>(); List<RepositoryFileTree> children = treeNode.getChildren(); if ( children != null ) { for ( RepositoryFileTree child : children ) { if ( child.getFile().isFolder() ) { RepositoryDirectory dir = new RepositoryDirectory( parentDir, child.getFile().getName() ); dir.setObjectId( new StringObjectId( child.getFile().getId().toString() ) ); parentDir.addSubdirectory( dir ); fillRepositoryDirectoryFromTree( dir, child ); } else { // a real file, like a Transformation or Job RepositoryLock lock = unifiedRepositoryLockService.getLock( child.getFile() ); RepositoryObjectType objectType = getObjectType( child.getFile().getName() ); fileChildren.add( new EERepositoryObject( child, parentDir, null, objectType, null, lock, false ) ); } } parentDir.setRepositoryObjects( fileChildren ); } } catch ( Exception e ) { throw new KettleException( "Unable to load directory structure from repository", e ); } }
public FileType getType() throws FileSystemException { return ( ( repositoryFile != null ) && !repositoryFile.isFolder() ) ? FileType.FILE : FileType.FOLDER; }
/** * {@inheritDoc} */ public RepositoryFile createFile( final Serializable parentFolderId, final RepositoryFile file, final IRepositoryFileData data, final RepositoryFileAcl acl, final String versionMessage ) { Assert.notNull( file ); Assert.isTrue( !file.isFolder() ); Assert.notNull( data ); // external callers never allowed to create files at repo root Assert.notNull( parentFolderId ); return internalCreateFile( parentFolderId, file, data, acl, versionMessage ); }
/** * {@inheritDoc} */ public RepositoryFile createFolder( final Serializable parentFolderId, final RepositoryFile file, final RepositoryFileAcl acl, final String versionMessage ) { Assert.notNull( file ); Assert.isTrue( file.isFolder() ); // external callers never allowed to create folders at repo root Assert.notNull( parentFolderId ); return internalCreateFolder( parentFolderId, file, acl, versionMessage ); }
/** * {@inheritDoc} */ @Override public RepositoryFile createFolder( final Serializable parentFolderId, final RepositoryFile folder, final RepositoryFileAcl acl, final String versionMessage ) { Assert.notNull( folder ); Assert.isTrue( folder.isFolder() ); return (RepositoryFile) jcrTemplate.execute( new JcrCallback() { @Override public Object doInJcr( final Session session ) throws RepositoryException, IOException { return internalCreateFolder( session, parentFolderId, folder, acl, versionMessage ); } } ); }
public RepositoryFileInputStream( Serializable id, IUnifiedRepository repository ) throws FileNotFoundException { assert ( null != repository ); assert ( null != id ); this.repository = repository; file = repository.getFileById( id ); if ( file == null ) { throw new FileNotFoundException( MessageFormat.format( "Repository file with id {0} not readable or does not exist", id ) ); } if ( file.isFolder() ) { throw new FileNotFoundException( MessageFormat.format( "Repository file {0} is a directory", file.getPath() ) ); } }
public RepositoryFileInputStream( String path, IUnifiedRepository repository ) throws FileNotFoundException { if ( path == null ) { throw new FileNotFoundException( "Repository file path cannot be null" ); } assert ( null != repository ); this.repository = repository; this.file = repository.getFile( path ); if ( file == null ) { throw new FileNotFoundException( MessageFormat .format( "Repository file {0} not readable or does not exist", path ) ); } if ( file.isFolder() ) { throw new FileNotFoundException( MessageFormat.format( "Repository file {0} is a directory", file.getPath() ) ); } }
@Override public RepositoryFile updateFolder( final RepositoryFile file, final String versionMessage ) { if ( isKioskEnabled() ) { throw new RuntimeException( Messages.getInstance().getString( "JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED" ) ); //$NON-NLS-1$ } Assert.notNull( file ); Assert.isTrue( file.isFolder() ); return (RepositoryFile) jcrTemplate.execute( new JcrCallback() { @Override public Object doInJcr( final Session session ) throws RepositoryException, IOException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session ); return internalUpdateFolder( session, pentahoJcrConstants, file, versionMessage ); } } ); }
@Override public RepositoryFile updateFolder( RepositoryFile folder, String versionMessage ) { Assert.notNull( folder ); Assert.isTrue( folder.isFolder() ); return repository.updateFolder( folder, versionMessage ); }
@Override public RepositoryFile updateFolder( RepositoryFile folder, String versionMessage ) { Validate.isTrue( folder.isFolder() ); if ( !hasAccess( folder.getId(), EnumSet.of( WRITE ) ) ) { throw new AccessDeniedException( "access denied" ); } FileRecord fileRecord = idManager.getFileById( folder.getId() ); fileRecord.setFile( new RepositoryFile.Builder( folder ).hidden( folder.isHidden() ).title( findTitle( folder ) ) .description( findDesc( folder ) ).aclNode( folder.isAclNode() ).build() ); if ( folder.isVersioned() ) { versionManager.createVersion( fileRecord.getFile().getId(), currentUserProvider.getUser(), versionMessage, new Date() ); } return fileRecord.getFile(); }
@Test public void testGetFolder() throws Exception { final MockUnifiedRepository repository = new MockUnifiedRepository( new SpringSecurityCurrentUserProvider() ); final RepositoryUtils repositoryUtils = new RepositoryUtils( repository ); RepositoryFile test = repositoryUtils.getFolder( "/public/one/two/three", true, true, null ); assertNotNull( test ); assertEquals( "The folder name is invalid", "three", test.getName() ); assertEquals( "The path is invalid", "/public/one/two/three", test.getPath() ); assertTrue( "The folder should be defined as a folder", test.isFolder() ); // Make sure it created the parents RepositoryFile one = repositoryUtils.getFolder( "/public/one", false, false, null ); assertNotNull( one ); RepositoryFile two = repositoryUtils.getFolder( "/public/one/two", false, false, null ); assertNotNull( two ); }
public Builder( final RepositoryFile other ) { this( other.getName() ); synchronized ( other ) { this.id( other.getId() ).path( other.getPath() ).createdDate( other.getCreatedDate() ).creatorId( other.getCreatorId() ).fileSize( other.getFileSize() ).folder( other.isFolder() ).lastModificationDate( other.getLastModifiedDate() ).versioned( other.isVersioned() ).hidden( other.isHidden() ).schedulable( other.isSchedulable() ).versionId( other.getVersionId() ).locked( other.isLocked() ).lockDate( other.getLockDate() ).lockOwner( other.getLockOwner() ).lockMessage( other.getLockMessage() ).title( other.getTitle() ).description( other.getDescription() ).locale( other.getLocale() ).originalParentFolderPath( other.getOriginalParentFolderPath() ).deletedDate( other.getDeletedDate() ).localePropertiesMap( other.getLocalePropertiesMap() ).aclNode( other.isAclNode() ); } }