@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(); } }
.lastModificationDate( modifiedDate ).build(); renameIfNecessary( element, file ); checkAndSanitize( RepositoryFilenameUtils.escape( element.getName(), pur.getReservedChars() ) + RepositoryObjectType.DATABASE.getExtension() ) ).title( RepositoryFile.DEFAULT_LOCALE, element.getName() ).createdDate( createdDate ).versioned( VERSION_SHARED_OBJECTS ).build();
new RepositoryFile.Builder( file ).title( RepositoryFile.DEFAULT_LOCALE, element.getName() ).createdDate( versionDate != null ? versionDate.getTime() : new Date() ).description( RepositoryFile.DEFAULT_LOCALE, Const.NVL( element.getDescription(), "" ) ).build(); RepositoryFile.DEFAULT_LOCALE, element.getName() ).createdDate( versionDate != null ? versionDate.getTime() : new Date() ).description( RepositoryFile.DEFAULT_LOCALE, Const.NVL( element.getDescription(), "" ) ).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 RepositoryFile buildRepositoryFile( String fileName, String extension, String baseFileName ) { RepositoryFile.Builder fileBuilder = new RepositoryFile.Builder( fileName ) .hidden( hidden ) .versioned( true ); // Default versioned to true so that we're keeping history if ( isKettleExtension( extension ) ) { fileBuilder.title( RepositoryFile.DEFAULT_LOCALE, baseFileName ); } return fileBuilder.build(); }
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; }
@Override public RepositoryFile clone() { RepositoryFile.Builder builder = new RepositoryFile.Builder( this ); builder.localePropertiesMap( localePropertiesMap != null ? new HashMap<String, Properties>( localePropertiesMap ) : null ); return builder.build(); }
private RepositoryFile nodeToDeletedFile( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node trashFileNode, String owner ) throws RepositoryException { // each fileId node has at most one child that is the deleted file RepositoryFile deletedFile = JcrRepositoryFileUtils.nodeToFile( session, pentahoJcrConstants, pathConversionHelper, lockHelper, trashFileNode ); Date deletedDate = getDeletedDate( trashFileNode, pentahoJcrConstants ); String originalParentFolderPath = getOriginalParentFolderPath( session, pentahoJcrConstants, trashFileNode, true ); return new RepositoryFile.Builder( deletedFile ).deletedDate( deletedDate ).originalParentFolderPath( originalParentFolderPath ).creatorId( owner ).build(); }
/** * 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(); }
/** * 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 ); }
protected RepositoryFile createSampleFile( final String parentFolderPath, final String fileName, final String sampleString, final boolean sampleBoolean, final int sampleInteger, boolean versioned ) throws Exception { RepositoryFile parentFolder = repo.getFile( parentFolderPath ); final SampleRepositoryFileData content = new SampleRepositoryFileData( sampleString, sampleBoolean, sampleInteger ); return repo.createFile( parentFolder.getId(), new RepositoryFile.Builder( fileName ).versioned( versioned ).build(), content, null ); }
@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(); }
private RepositoryFile createAclNode( RepositoryFile fileToAddAclFor ) { DataNode dataNode = new DataNode( "acl node" ); DataNodeRef dataNodeRef = new DataNodeRef( fileToAddAclFor.getId() ); dataNode.setProperty( TARGET, dataNodeRef ); dataNode.setProperty( IS_ACL_NODE, true ); NodeRepositoryFileData nodeRepositoryFileData = new NodeRepositoryFileData( dataNode ); return unifiedRepository.createFile( unifiedRepository.getFile( "/" ).getId(), new RepositoryFile.Builder( UUID.randomUUID().toString() ).aclNode( true ).build(), nodeRepositoryFileData, "" ); }
@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(); }
public void unlockFile( final Serializable fileId ) { if ( !hasAccess( fileId, EnumSet.of( WRITE ) ) ) { throw new UnifiedRepositoryException( "access denied" ); } FileRecord r = idManager.getFileById( fileId ); if ( r.getFile().getLockOwner() == null ) { throw new IllegalStateException( "file is not locked" ); } r.setFile( new RepositoryFile.Builder( r.getFile() ).lockOwner( null ).lockDate( null ).lockMessage( null ) .locked( false ).build() ); }
file = builder.build(); NodeRepositoryFileData data; data = pur.getDataAtVersionForRead( file.getId(), null, NodeRepositoryFileData.class );
@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 void createElement( String namespace, IMetaStoreElementType elementType, IMetaStoreElement element ) throws MetaStoreException { RepositoryFile elementTypeFolder = validateElementTypeRepositoryFolder( namespace, elementType ); RepositoryFile elementFile = new RepositoryFile.Builder( PurRepository.checkAndSanitize( element.getName() ) ).title( element.getName() ) .versioned( false ).build(); DataNode elementDataNode = new DataNode( PurRepository.checkAndSanitize( element.getName() ) ); elementToDataNode( element, elementDataNode ); RepositoryFile createdFile = pur.createFile( elementTypeFolder.getId(), elementFile, new NodeRepositoryFileData( elementDataNode ), null ); element.setId( createdFile.getId().toString() ); // Verify existence. if ( pur.getFileById( createdFile.getId() ) == null ) { throw new RuntimeException( "Unable to verify creation of element '" + element.getName() + "' in folder: " + elementTypeFolder.getPath() ); } }
@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" ); }