@Override public void saveRepositoryDirectory( final RepositoryDirectoryInterface dir ) throws KettleException { // id of root dir is null--check for it if ( "/".equals( dir.getParent().getName() ) ) { throw new KettleException( BaseMessages.getString( PKG, "PurRepository.FailedDirectoryCreation.Message" ) ); } readWriteLock.writeLock().lock(); try { RepositoryFile newFolder = pur.createFolder( dir.getParent().getObjectId() != null ? dir.getParent().getObjectId().getId() : null, new RepositoryFile.Builder( dir.getName() ).folder( true ).build(), null ); dir.setObjectId( new StringObjectId( newFolder.getId().toString() ) ); } catch ( Exception e ) { throw new KettleException( "Unable to save repository directory with path [" + getPath( null, dir, null ) + "]", e ); } finally { readWriteLock.writeLock().unlock(); } }
@Override public void createElementType( String namespace, IMetaStoreElementType elementType ) throws MetaStoreException { RepositoryFile namespaceFile = validateNamespace( namespace ); IMetaStoreElementType existingType = getElementTypeByName( namespace, elementType.getName() ); if ( existingType != null ) { throw new MetaStoreElementTypeExistsException( Collections.singletonList( existingType ), "Can not create element type with id '" + elementType.getId() + "' because it already exists" ); } RepositoryFile elementTypeFile = new RepositoryFile.Builder( elementType.getName() ).folder( true ).versioned( false ).build(); RepositoryFile folder = pur.createFolder( namespaceFile.getId(), elementTypeFile, null ); elementType.setId( folder.getId().toString() ); // In this folder there is a hidden file which contains the description // and the other future properties of the element type // RepositoryFile detailsFile = new RepositoryFile.Builder( ELEMENT_TYPE_DETAILS_FILENAME ).folder( false ).title( ELEMENT_TYPE_DETAILS_FILENAME ).description( elementType.getDescription() ).hidden( true ).build(); DataNode dataNode = getElementTypeDataNode( elementType ); pur.createFile( folder.getId(), detailsFile, new NodeRepositoryFileData( dataNode ), null ); elementType.setMetaStoreName( getName() ); }
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; }
public void setUp() throws Exception { IUnifiedRepository repository = new MockUnifiedRepository( new MockUnifiedRepository.SpringSecurityCurrentUserProvider() ); datasourceMgmtService = new JcrBackedDatasourceMgmtService( repository, new DatabaseDialectService() ); datasourceMgmtWebService = new DefaultDatasourceMgmtWebService( datasourceMgmtService ); dbConnectionAdapter = new DatabaseConnectionAdapter(); SecurityContextHolder.getContext() .setAuthentication( new UsernamePasswordAuthenticationToken( MockUnifiedRepository.root().getName(), null, new ArrayList<GrantedAuthority>() ) ); repository.createFolder( repository.getFile( "/etc" ).getId(), new RepositoryFile.Builder( FOLDER_PDI ).folder( true ).build(), new RepositoryFileAcl.Builder( MockUnifiedRepository.root() ).ace( MockUnifiedRepository.everyone(), READ, WRITE ).build(), null ); repository.createFolder( repository.getFile( "/etc/pdi" ).getId(), new RepositoryFile.Builder( FOLDER_DATABASES ) .folder( true ).build(), null ); SecurityContextHolder.getContext().setAuthentication( new UsernamePasswordAuthenticationToken( EXP_LOGIN, null, new ArrayList<GrantedAuthority>() ) ); KettleClientEnvironment.init(); }
@Test public void testDatasourceNotFound() throws Exception { final String datasourceName = "not_here"; final String dotKdb = ".kdb"; final String fileName = datasourceName + dotKdb; final String databasesFolderPath = "/etc/pdi/databases"; 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 not found doReturn( null ).when( repo ).getFile( databasesFolderPath + RepositoryFile.SEPARATOR + fileName ); IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService( repo, new DatabaseDialectService() ); Assert.assertNull( datasourceMgmtService.getDatasourceByName( datasourceName ) ); }
private void testDeleteDatasourceWithId( boolean throwException ) throws Exception { 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 ).getFileById( EXP_FILE_ID ); doReturn( reservedChars ).when( repo ).getReservedChars(); // stub out get file to delete doReturn( new RepositoryFile.Builder( EXP_FILE_ID, EXP_DBMETA_NAME + dotKdb ).build() ).when( repo ).getFileById( EXP_FILE_ID); IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService( repo, new DatabaseDialectService() ); if( throwException ) { deleteDatasourceWithIdThrowException( repo ); } datasourceMgmtService.deleteDatasourceById( EXP_FILE_ID ); verify( repo ).deleteFile( eq( EXP_FILE_ID ), eq( true ), anyString() ); }
@Test public void testCreateDatasource() throws Exception { final String parentFolderId = "123"; IUnifiedRepository repo = mock( IUnifiedRepository.class ); // stub out get parent folder doReturn( new RepositoryFile.Builder( parentFolderId, "databases" ).folder( true ).build() ).when( repo ).getFile( "/etc/pdi/databases" ); doReturn( reservedChars ).when( repo ).getReservedChars(); IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService( repo, new DatabaseDialectService() ); IDatabaseConnection databaseConnection = createDatabaseConnection( EXP_DBMETA_NAME ); datasourceMgmtService.createDatasource( databaseConnection ); verify( repo ).createFile( eq( parentFolderId ), argThat( isLikeFile( new RepositoryFile.Builder( EXP_DBMETA_NAME + ".kdb" ).build() ) ), argThat( hasData( pathPropertyPair( "/databaseMeta/HOST_NAME", EXP_DBMETA_HOSTNAME ) ) ), anyString() ); }
@Test public void testWriteBinary() throws IOException { final String fileName = "test.bin"; final String filePath = publicDirPath + "/" + fileName; IUnifiedRepository repo = mock( IUnifiedRepository.class ); // simulate request for publicDir RepositoryFile publicDir = new RepositoryFile.Builder( "123", ClientRepositoryPaths.getPublicFolderName() ).folder( true ).build(); doReturn( publicDir ).when( repo ).getFile( publicDirPath ); mp.defineInstance( IUnifiedRepository.class, repo ); final byte[] expectedPayload = "binary string".getBytes(); RepositoryFileOutputStream rfos = new RepositoryFileOutputStream( filePath ); IOUtils.write( expectedPayload, rfos ); rfos.close(); verify( repo ).createFile( eq( "123" ), argThat( isLikeFile( new RepositoryFile.Builder( fileName ).build() ) ), argThat( hasData( expectedPayload, "application/octet-stream" ) ), anyString() ); }
@Test public void testWriteToFile() throws IOException { final String fileName = "test-file2.txt"; RepositoryFile file = createFile( fileName ); IUnifiedRepository repo = mock( IUnifiedRepository.class ); // simulate request for publicDir RepositoryFile publicDir = new RepositoryFile.Builder( "123", ClientRepositoryPaths.getPublicFolderName() ).folder( true ).build(); doReturn( publicDir ).when( repo ).getFile( publicDirPath ); mp.defineInstance( IUnifiedRepository.class, repo ); RepositoryFileWriter writer = new RepositoryFileWriter( file, "UTF-8" ); writer.write( "test123" ); writer.close(); verify( repo ).createFile( eq( "123" ), argThat( isLikeFile( new RepositoryFile.Builder( fileName ).build() ) ), argThat( hasData( "test123", "UTF-8", "text/plain" ) ), anyString() ); }
@Override public void doInTransactionWithoutResult( final TransactionStatus status ) { final RepositoryFileSid repositoryAdminUserSid = new RepositoryFileSid( userNameUtils.getPrincipleId( tenant, repositoryAdminUsername ) ); RepositoryFile tenantEtcFolder = repositoryFileDao.getFileByAbsolutePath( ServerRepositoryPaths.getTenantEtcFolderPath( tenant ) ); Assert.notNull( tenantEtcFolder ); if ( repositoryFileDao.getFileByAbsolutePath( ServerRepositoryPaths.getTenantEtcFolderPath( tenant ) + RepositoryFile.SEPARATOR + FOLDER_MONDRIAN ) == null ) { // mondrian folder internalCreateFolder( tenantEtcFolder.getId(), new RepositoryFile.Builder( FOLDER_MONDRIAN ).folder( true ) .build(), true, repositoryAdminUserSid, Messages.getInstance().getString( "MondrianRepositoryLifecycleManager.USER_0001_VER_COMMENT_MONDRIAN" ) ); //$NON-NLS-1$ } } } );
private RepositoryFile createHomeFolder( ITenant tenant, RepositoryFile tenantRootFolder, RepositoryFileSid fileOwnerSid ) { String tenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId( tenant, tenantAdminRoleName ); RepositoryFileSid tenantAdminRoleSid = new RepositoryFileSid( tenantAdminRoleId, Type.ROLE ); String tenantAuthenticatedRoleId = tenantedRoleNameResolver.getPrincipleId( tenant, tenantAuthenticatedRoleName ); RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid( tenantAuthenticatedRoleId, Type.ROLE ); RepositoryFile homeFolder = repositoryFileDao.createFolder( tenantRootFolder.getId(), new RepositoryFile.Builder( ServerRepositoryPaths .getTenantHomeFolderName() ).folder( true ).title( Messages.getInstance().getString( "RepositoryTenantManager.usersFolderDisplayName" ) ).build(), new RepositoryFileAcl.Builder( fileOwnerSid ).ace( tenantAdminRoleSid, EnumSet.of( RepositoryFilePermission.ALL ) ).ace( tenantAuthenticatedRoleSid, EnumSet.of( RepositoryFilePermission.READ ) ).build(), null ); return homeFolder; }
private RepositoryFile createPublicFolder( ITenant tenant, RepositoryFile tenantRootFolder, RepositoryFileSid fileOwnerSid ) { String tenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId( tenant, tenantAdminRoleName ); RepositoryFileSid tenantAdminRoleSid = new RepositoryFileSid( tenantAdminRoleId, Type.ROLE ); String tenantAuthenticatedRoleId = tenantedRoleNameResolver.getPrincipleId( tenant, tenantAuthenticatedRoleName ); RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid( tenantAuthenticatedRoleId, Type.ROLE ); RepositoryFile publicFolder = repositoryFileDao.createFolder( tenantRootFolder.getId(), new RepositoryFile.Builder( ServerRepositoryPaths .getTenantPublicFolderName() ).folder( true ).title( Messages.getInstance().getString( "RepositoryTenantManager.publicFolderDisplayName" ) ).build(), new RepositoryFileAcl.Builder( fileOwnerSid ).ace( tenantAdminRoleSid, EnumSet.of( RepositoryFilePermission.ALL ) ).ace( tenantAuthenticatedRoleSid, EnumSet.of( RepositoryFilePermission.READ ) ).build(), null ); return publicFolder; }
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() ); } }
/** * Same as {@link #makeFileObject(String, boolean)} except that the file is a folder. */ public static RepositoryFile makeFolderObject( final String path, final boolean fromRepo ) { RepositoryFile.Builder b = new RepositoryFile.Builder( makeFileObject( path, fromRepo ) ); b.folder( true ); return b.build(); }
protected void createInitialTenantFolders( Session session, final RepositoryFile tenantRootFolder, final RepositoryFileSid fileOwnerSid, final RepositoryFileSid authenticatedRoleSid ) throws RepositoryException { // We create a tenant's home folder while creating a user repositoryFileDao.createFolder( tenantRootFolder.getId(), new RepositoryFile.Builder( ServerRepositoryPaths .getTenantPublicFolderName() ).folder( true ).build(), new RepositoryFileAcl.Builder( fileOwnerSid ).build(), null ); repositoryFileDao .createFolder( tenantRootFolder.getId(), new RepositoryFile.Builder( ServerRepositoryPaths .getTenantEtcFolderName() ).folder( true ).build(), new RepositoryFileAcl.Builder( fileOwnerSid ).build(), null ); }
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 ); }
@Test( expected = FileNotFoundException.class ) public void testWriteDirectory() throws IOException { IUnifiedRepository repo = mock( IUnifiedRepository.class ); // simulate file exists but is a directory doReturn( new RepositoryFile.Builder( "123", ClientRepositoryPaths.getPublicFolderName() ).folder( true ).build() ) .when( repo ).getFile( ClientRepositoryPaths.getPublicFolderPath() ); mp.defineInstance( IUnifiedRepository.class, repo ); RepositoryFileWriter writer = new RepositoryFileWriter( ClientRepositoryPaths.getPublicFolderPath(), "UTF-8" ); writer.close(); }
@Test( expected = FileNotFoundException.class ) public void testReadDirectoryPath() throws IOException { IUnifiedRepository repo = mock( IUnifiedRepository.class ); // simulate file exists but is a directory doReturn( new RepositoryFile.Builder( "123", ClientRepositoryPaths.getPublicFolderName() ).folder( true ).build() ) .when( repo ).getFile( ClientRepositoryPaths.getPublicFolderPath() ); mp.defineInstance( IUnifiedRepository.class, repo ); RepositoryFileReader reader = new RepositoryFileReader( ClientRepositoryPaths.getPublicFolderPath() ); reader.close(); }
@Override public void createNamespace( String namespace ) throws MetaStoreException { if ( namespaceExists( namespace ) ) { throw new MetaStoreNamespaceExistsException( "Namespace '" + namespace + "' can not be created, it already exists" ); } RepositoryFile namespaceFolder = new RepositoryFile.Builder( namespace ).folder( true ).versioned( false ).build(); pur.createFolder( namespacesFolder.getId(), namespaceFolder, "Created namespace" ); }