public RepositoryFile internalGetFile( File f ) { RepositoryFile file = null; if ( f.exists() ) { String jcrPath = f.getAbsolutePath().substring( rootDir.getAbsolutePath().length() ); if ( jcrPath.length() == 0 ) { jcrPath = "/"; } else if ( IS_WINDOWS ) { jcrPath = FilenameUtils.separatorsToUnix( jcrPath ); } file = new RepositoryFile.Builder( f.getAbsolutePath(), f.getName() ).createdDate( new Date( f.lastModified() ) ) .lastModificationDate( new Date( f.lastModified() ) ).folder( f.isDirectory() ).versioned( false ).path( jcrPath ).versionId( f.getName() ).locked( false ).lockDate( null ).lockMessage( null ).lockOwner( null ).title( f.getName() ).description( f.getName() ).locale( null ).fileSize( f.length() ).build(); } return file; }
private static RepositoryFile getRootFolder( final Session session ) throws RepositoryException { Node node = session.getRootNode(); RepositoryFile file = new RepositoryFile.Builder( node.getIdentifier(), "" ).folder( true ).versioned( false ).path( //$NON-NLS-1$ JcrStringHelper.pathDecode( node.getPath() ) ).build(); return file; }
/** * Stubs a {@code getFile} call. */ private static void stubGetFile( final IUnifiedRepository repo, final String path, final boolean folder ) { final String fileName = StringUtils.substringAfterLast( path, RepositoryFile.SEPARATOR ); RepositoryFile file = new RepositoryFile.Builder( makeIdObject( path ), fileName ).path( path ).folder( folder ).build(); doReturn( file ).when( repo ).getFile( path ); }
lastModified ).folder( folder ).versioned( versioned ).path( path ).versionId( versionId ).fileSize( fileSize ).locked( locked ).lockDate( lockDate ).hidden( hidden ).schedulable( schedulable ) .lockMessage( lockMessage ).lockOwner( lockOwner ).title( title ).description( description ).locale(
RepositoryFile tmpFolder = new RepositoryFile.Builder( folder ).path( path ).build();
new FileRecord( new RepositoryFile.Builder( src.getFile() ).name( newName ).path( newPath ).build(), src .getData(), src.getAcl(), src.getMetadata() ); if ( !move ) {
return builder.path( v.getPath() ).createdDate( unmarshalDate( v.getCreatedDate() ) ).creatorId( v.getCreatorId() ).description( v.getDescription() ) .folder( v.isFolder() ).fileSize( v.getFileSize() ).lastModificationDate( unmarshalDate( v.getLastModifiedDate() ) ).locale( v.getLocale() ) .lockDate( unmarshalDate( v.getLockDate() ) ).locked( v.isLocked() ).lockMessage( v.getLockMessage() ).lockOwner( v.getLockOwner() )
@Test public void testUpdateDatasourceWithName() throws Exception { final String fileId = "456"; final String databasesFolderPath = "/etc/pdi/databases"; final String dotKdb = ".kdb"; IUnifiedRepository repo = mock( IUnifiedRepository.class ); // stub out get parent folder doReturn( new RepositoryFile.Builder( "123", "databases" ).folder( true ).build() ).when( repo ).getFile( databasesFolderPath ); doReturn( reservedChars ).when( repo ).getReservedChars(); // stub out get file to update RepositoryFile f = new RepositoryFile.Builder( fileId, EXP_DBMETA_NAME + dotKdb ).path( databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb ).build(); doReturn( f ).when( repo ).getFile( databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb ); // stub out update file which requires a file to be returned doReturn( f ).when( repo ) .updateFile( any( RepositoryFile.class ), any( NodeRepositoryFileData.class ), anyString() ); IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService( repo, new DatabaseDialectService() ); IDatabaseConnection databaseConnection = createDatabaseConnection( EXP_DBMETA_NAME ); updateDatabaseConnection( databaseConnection ); datasourceMgmtService.updateDatasourceByName( EXP_DBMETA_NAME, databaseConnection ); verify( repo ).updateFile( argThat( isLikeFile( new RepositoryFile.Builder( EXP_DBMETA_NAME + ".kdb" ).build() ) ), argThat( hasData( pathPropertyPair( "/databaseMeta/HOST_NAME", EXP_UPDATED_DBMETA_HOSTNAME ) ) ), anyString() ); }
@Test public void testGetDatasources() throws Exception { final String fileId = "456"; final String databasesFolderPath = "/etc/pdi/databases"; final String dotKdb = ".kdb"; IUnifiedRepository repo = mock( IUnifiedRepository.class ); // stub out get parent folder doReturn( new RepositoryFile.Builder( "123", "databases" ).folder( true ).build() ).when( repo ).getFile( databasesFolderPath ); doReturn( reservedChars ).when( repo ).getReservedChars(); // stub out get file to update RepositoryFile f = new RepositoryFile.Builder( fileId, EXP_DBMETA_NAME + dotKdb ).path( databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb ).build(); doReturn( f ).when( repo ).getFile( databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb ); final String EXP_HOST_NAME = "hello"; DataNode rootNode = new DataNode( "databaseMeta" ); rootNode.setProperty( "TYPE", "Hypersonic" ); // required rootNode.setProperty( "HOST_NAME", EXP_HOST_NAME ); rootNode.addNode( "attributes" ); // required doReturn( new NodeRepositoryFileData( rootNode ) ).when( repo ).getDataForRead( eq( fileId ), eq( NodeRepositoryFileData.class ) ); IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService( repo, new DatabaseDialectService() ); IDatabaseConnection conn = datasourceMgmtService.getDatasourceByName( EXP_DBMETA_NAME ); assertEquals( EXP_HOST_NAME, conn.getHostname() ); }
RepositoryFile tmpFile = new RepositoryFile.Builder( file ).path( path ).build();
protected void init() { RepositoryFile rootFolder = new RepositoryFile.Builder( "" ).path( RepositoryFile.SEPARATOR ).folder( true ).build(); RepositoryFileAcl rootFolderAcl = new RepositoryFileAcl.Builder( root() ).entriesInheriting( false ).ace( everyone(), READ ).build(); root = new FileRecord( rootFolder, rootFolderAcl ); idManager.register( root ); RepositoryFile publicFolder = new RepositoryFile.Builder( "public" ).path( RepositoryFile.SEPARATOR + "public" ).folder( true ).build(); RepositoryFileAcl publicFolderAcl = new RepositoryFileAcl.Builder( root() ).entriesInheriting( false ).ace( everyone(), READ, WRITE ).build(); FileRecord pub = new FileRecord( publicFolder, publicFolderAcl ); root.addChild( pub ); idManager.register( pub ); RepositoryFile etcFolder = new RepositoryFile.Builder( "etc" ).path( RepositoryFile.SEPARATOR + "etc" ).folder( true ).build(); RepositoryFileAcl etcFolderAcl = new RepositoryFileAcl.Builder( root() ).entriesInheriting( true ).build(); FileRecord etc = new FileRecord( etcFolder, etcFolderAcl ); root.addChild( etc ); idManager.register( etc ); }
@Override public RepositoryFile createFile( final Serializable parentFolderId, final RepositoryFile file, final IRepositoryFileData data, final RepositoryFileAcl acl, final String versionMessage ) { Validate.isTrue( !file.isFolder() ); if ( !hasAccess( parentFolderId, EnumSet.of( WRITE ) ) ) { throw new AccessDeniedException( "access denied" ); } FileRecord parentFolder = idManager.getFileById( parentFolderId ); RepositoryFile fileFromRepo = new RepositoryFile.Builder( file ).path( parentFolder.getPath() + RepositoryFile.SEPARATOR + file.getName() ) .title( findTitle( file ) ).description( findDesc( file ) ).build(); RepositoryFileAcl aclFromRepo = new RepositoryFileAcl.Builder( acl ).build(); FileRecord fileRecord = new FileRecord( fileFromRepo, data, aclFromRepo, new HashMap<String, Serializable>() ); idManager.register( fileRecord ); process( fileRecord, null ); parentFolder.addChild( fileRecord ); if ( file.isVersioned() ) { versionManager.createVersion( fileRecord.getFile().getId(), currentUserProvider.getUser(), versionMessage, new Date() ); } return fileRecord.getFile(); }
public RepositoryFile getFolder( final String path, final RepositoryFileAcl acl, final boolean createIfNotExist, final boolean createParents, final String versionMessage ) { RepositoryFile folder = repository.getFile( path ); if ( null == folder && createIfNotExist ) { final String parentPath = RepositoryFilenameUtils.getFullPathNoEndSeparator( path ); if ( !parentPath.equals( path ) ) { final RepositoryFile parentFolder = getFolder( parentPath, acl, createParents, createParents, versionMessage ); if ( null != parentFolder ) { final String folderName = RepositoryFilenameUtils.getName( path ); folder = new RepositoryFile.Builder( folderName ).path( path ).folder( true ).build(); if ( null != acl ) { folder = repository.createFolder( parentFolder.getId(), folder, acl, versionMessage ); } else { folder = repository.createFolder( parentFolder.getId(), folder, versionMessage ); } } } } return folder; }
@Override public RepositoryFile createFolder( final Serializable parentFolderId, final RepositoryFile file, final RepositoryFileAcl acl, final String versionMessage ) { Validate.isTrue( file.isFolder() ); Validate.isTrue( !file.isVersioned() ); if ( !hasAccess( parentFolderId, EnumSet.of( WRITE ) ) ) { throw new AccessDeniedException( "access denied" ); } FileRecord parentFolder = idManager.getFileById( parentFolderId ); RepositoryFile fileFromRepo = new RepositoryFile.Builder( file ).path( parentFolder.getPath() + ( parentFolder.getPath().endsWith( RepositoryFile.SEPARATOR ) ? "" : RepositoryFile.SEPARATOR ) + file.getName() ).title( findTitle( file ) ).description( findDesc( file ) ).build(); RepositoryFileAcl aclFromRepo = new RepositoryFileAcl.Builder( acl ).build(); FileRecord fileRecord = new FileRecord( fileFromRepo, null, aclFromRepo, new HashMap<String, Serializable>() ); idManager.register( fileRecord ); parentFolder.addChild( fileRecord ); return fileRecord.getFile(); }
private RepositoryFile createFile( String fileName ) { return new RepositoryFile.Builder( fileName ).path( publicDirPath + "/" + fileName ).build(); }
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() ); } }
/** * Creates a {@code RepositoryFile}. If {@code fromRepo} is {@code true}, then it is populated as if it had been * returned from the repository (e.g. non-null ID). */ public static RepositoryFile makeFileObject( final String path, final boolean fromRepo ) { final String fileName = StringUtils.substringAfterLast( path, RepositoryFile.SEPARATOR ); RepositoryFile.Builder b = new RepositoryFile.Builder( fileName ); // files returned from repo have non-null id and path properties if ( fromRepo ) { b.id( makeIdObject( path ) ).path( path ); } return b.build(); }