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

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


  public GeneratedContentCleaner() {
    repository = PentahoSystem.get( IUnifiedRepository.class );
  }

  private void findGeneratedContent( List<RepositoryFile> generatedContentList, RepositoryFileTree parent ) {
    RepositoryFile parentFile = parent.getFile();
    if ( !parentFile.isFolder() ) {
      long createTime = parentFile.getCreatedDate().getTime();
      if ( createTime <= ( System.currentTimeMillis() - ( age * 1000 ) ) ) {
        // now check metadata for RESERVEDMAPKEY_LINEAGE_ID (all generated content has)
        Map<String, Serializable> metadata = repository.getFileMetadata( parentFile.getId() );
        if ( metadata.containsKey( QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID ) ) {
          generatedContentList.add( parentFile );
        }
      }
    } else {
View Full Code Here


    repository = new MockUnifiedRepository( new MockUserProvider() );
    repositoryWS = new DefaultUnifiedRepositoryWebService( repository );
  }

  public void testFileMetadata() throws Exception {
    final RepositoryFile testfile =
        repository.createFile( repository.getFile( "/etc" ).getId(), new RepositoryFile.Builder( "testfile" ).build(),
            new SimpleRepositoryFileData( new ByteArrayInputStream( "test".getBytes() ),
              "UTF-8", "text/plain" ), null );
    //CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
      // Make sure the repository is setup correctly
      assertNotNull( testfile );
      assertNotNull( testfile.getId() );
      final Map<String, Serializable> fileMetadata = repository.getFileMetadata( testfile.getId() );
      assertNotNull( fileMetadata );
      assertEquals( 0, fileMetadata.size() );
    }

    final List<StringKeyStringValueDto> metadata = new ArrayList<StringKeyStringValueDto>();
    metadata.add( new StringKeyStringValueDto( "sample key", "sample value" ) );
    metadata.add( new StringKeyStringValueDto( "complex key?", "\"an even more 'complex' value\"! {and them some}" ) );

    repositoryWS.setFileMetadata( testfile.getId().toString(), metadata );
    //CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
      // Make sure the repository sees the metadata
      assertNotNull( testfile );
      assertNotNull( testfile.getId() );
      final Map<String, Serializable> fileMetadata = repository.getFileMetadata( testfile.getId() );
      assertNotNull( fileMetadata );
      assertEquals( 2, fileMetadata.size() );
    }
    //CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
      // Make sure we can get the same metadata back via the web service
      final List<StringKeyStringValueDto> fileMetadata = repositoryWS.getFileMetadata( testfile.getId().toString() );
      assertNotNull( fileMetadata );
      assertEquals( 2, fileMetadata.size() );
      assertTrue( metadata.get( 0 ).equals( fileMetadata.get( 0 ) ) || metadata.get( 0 )
        .equals( fileMetadata.get( 1 ) ) );
      assertTrue( metadata.get( 1 ).equals( fileMetadata.get( 0 ) ) || metadata.get( 1 )
View Full Code Here

   * Assert empty list in RepositoryFileTree#children survives full jaxb serialization roundtrip
   */
  @Test
  public void testBIServer7777() throws Exception {
    // file tree with empty children
    RepositoryFile empty = new RepositoryFile.Builder( "empty" ).build();
    RepositoryFileTree emptyDir = new RepositoryFileTree( empty, Collections.<RepositoryFileTree>emptyList() );
    RepositoryFile root = new RepositoryFile.Builder( "rootDir" ).build();
    ArrayList<RepositoryFileTree> children = new ArrayList<RepositoryFileTree>( 1 );
    children.add( emptyDir );
    RepositoryFileTree rootDir = new RepositoryFileTree( root, children );
    // to DTO
    RepositoryFileTreeAdapter adapter = new RepositoryFileTreeAdapter();
View Full Code Here

    logger.info( "getFile" );
    JcrRepositoryDumpToFile dumpToFile =
        new JcrRepositoryDumpToFile( testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername,
            "c:/build/testrepo_9", Mode.CUSTOM );
    dumpToFile.execute();
    RepositoryFile f = repo.getFile( ClientRepositoryPaths.getUserHomeFolderPath( USERNAME_SUZY ) );
    assertNotNull( f.getId() );
    assertEquals( ClientRepositoryPaths.getUserHomeFolderPath( USERNAME_SUZY ), f.getPath() );
    assertNotNull( f.getCreatedDate() );
    assertEquals( USERNAME_SUZY, f.getName() );
    assertTrue( f.isFolder() );

    logger.info( "getFileById" );
    assertNotNull( repo.getFileById( f.getId() ) );

    logger.info( "createFolder" );
    RepositoryFile folder1 =
        repo.createFolder( f.getId(), new RepositoryFile.Builder( "folder1" ).folder( true ).build(), null );
    assertNotNull( folder1 );
    assertEquals( "folder1", folder1.getName() );
    assertNotNull( folder1.getId() );

    NodeRepositoryFileData data = makeNodeRepositoryFileData1();
    logger.info( "createFile" );
    RepositoryFile file1 =
        repo.createFile( folder1.getId(), new RepositoryFile.Builder( "file1.whatever" ).versioned( true ).build(),
            data, null );
    assertNotNull( file1 );
    assertNotNull( file1.getId() );

    logger.info( "getDataForRead" );
    NodeRepositoryFileData file1Data = repo.getDataForRead( file1.getId(), NodeRepositoryFileData.class );
    assertNotNull( file1Data );
    assertEquals( "testNode", file1Data.getNode().getName() );
    assertEquals( "hello world", file1Data.getNode().getProperty( "prop1" ).getString() );
    assertEquals( false, file1Data.getNode().getProperty( "prop2" ).getBoolean() );
    assertEquals( DataPropertyType.BOOLEAN, file1Data.getNode().getProperty( "prop2" ).getType() );
    assertEquals( 12L, file1Data.getNode().getProperty( "prop3" ).getLong() );

    logger.info( "createFile (binary)" );
    SimpleRepositoryFileData simpleData =
        new SimpleRepositoryFileData( new ByteArrayInputStream( "Hello World!".getBytes( "UTF-8" ) ), "UTF-8",
            "text/plain" );
    RepositoryFile simpleFile =
        repo.createFile( folder1.getId(), new RepositoryFile.Builder( "file2.whatever" ).versioned( true ).build(),
            simpleData, null );

    Serializable simpleVersion = simpleFile.getVersionId();

    logger.info( "getDataForRead (binary)" );
    SimpleRepositoryFileData simpleFileData = repo.getDataForRead( simpleFile.getId(), SimpleRepositoryFileData.class );
    assertNotNull( simpleFileData );
    assertEquals( "Hello World!", IOUtils.toString( simpleFileData.getInputStream(), simpleFileData.getEncoding() ) );
    assertEquals( "text/plain", simpleFileData.getMimeType() );
    assertEquals( "UTF-8", simpleFileData.getEncoding() );

    logger.info( "updateFile (binary)" );
    simpleData =
        new SimpleRepositoryFileData( new ByteArrayInputStream( "Ciao World!".getBytes( "UTF-8" ) ), "UTF-8",
            "text/plain" );
    simpleFile = repo.updateFile( simpleFile, simpleData, null );
    assertNotNull( simpleFile.getLastModifiedDate() );

    logger.info( "getDataForRead (binary)" );
    simpleFileData = repo.getDataForRead( simpleFile.getId(), SimpleRepositoryFileData.class );
    assertNotNull( simpleFileData );
    assertEquals( "Ciao World!", IOUtils.toString( simpleFileData.getInputStream(), simpleFileData.getEncoding() ) );

    logger.info( "getDataForReadAtVersion (binary)" );
    simpleFileData = repo.getDataAtVersionForRead( simpleFile.getId(), simpleVersion, SimpleRepositoryFileData.class );
    assertNotNull( simpleFileData );
    assertEquals( "Hello World!", IOUtils.toString( simpleFileData.getInputStream(), simpleFileData.getEncoding() ) );

    logger.info( "getChildren" );
    List<RepositoryFile> folder1Children = repo.getChildren( new RepositoryRequest( String.valueOf( folder1.getId() ), true, -1, null ) );
    assertNotNull( folder1Children );
    assertEquals( 2, folder1Children.size() );
    logger.info( "getChildren" );
    List<RepositoryFile> folder1ChildrenFiltered = repo.getChildren( new RepositoryRequest( String.valueOf( folder1.getId() ), true, -1, "*.sample" ) );
    assertNotNull( folder1ChildrenFiltered );
    assertEquals( 0, folder1ChildrenFiltered.size() );
    logger.info( "getDeletedFiles" );
    assertEquals( 0, repo.getDeletedFiles().size() );
    logger.info( "deleteFile" );
    repo.deleteFile( file1.getId(), null );
    logger.info( "getDeletedFiles" );
    assertEquals( 0, repo.getDeletedFiles( folder1.getPath(), "*.sample" ).size() );

    logger.info( "hasAccess" );
    assertFalse( repo.hasAccess( "/pentaho", EnumSet.of( RepositoryFilePermission.WRITE ) ) );

    logger.info( "getEffectiveAces" );
    List<RepositoryFileAce> folder1EffectiveAces = repo.getEffectiveAces( folder1.getId() );
    assertEquals( 1, folder1EffectiveAces.size() );

    logger.info( "getAcl" );
    RepositoryFileAcl folder1Acl = repo.getAcl( folder1.getId() );
    assertEquals( USERNAME_SUZY, folder1Acl.getOwner().getName() );

    logger.info( "updateAcl" );
    userRoleDao.createUser( tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null );
    RepositoryFileAcl updatedFolder1Acl =
        repo.updateAcl( new RepositoryFileAcl.Builder( folder1Acl ).entriesInheriting( false ).ace(
            userNameUtils.getPrincipleId( tenantAcme, USERNAME_TIFFANY ), RepositoryFileSid.Type.USER,
            RepositoryFilePermission.ALL ).build() );
    assertNotNull( updatedFolder1Acl );
    assertEquals( 1, updatedFolder1Acl.getAces().size() );

    logger.info( "lockFile" );
    assertFalse( file1.isLocked() );
    repo.lockFile( file1.getId(), "I locked this file" );
    logger.info( "canUnlockFile" );
    assertTrue( repo.canUnlockFile( file1.getId() ) );
    logger.info( "unlockFile" );
    repo.unlockFile( file1.getId() );

    logger.info( "moveFile" );
    repo.moveFile( file1.getId(), ClientRepositoryPaths.getUserHomeFolderPath( USERNAME_SUZY ) + "/folder1", null );
    logger.info( "copyFile" );
    repo.copyFile( file1.getId(), ClientRepositoryPaths.getUserHomeFolderPath( USERNAME_SUZY )
        + "/folder1/fileB.whatever", null );
    RepositoryFile copiedFile = repo.getFile( ClientRepositoryPaths.getUserHomeFolderPath( USERNAME_SUZY )
        + "/folder1/fileB.whatever" );
    copiedFile = repo.updateFile( copiedFile, data, null );

    logger.info( "getVersionSummaries" );
    List<VersionSummary> versionSummaries = repo.getVersionSummaries( file1.getId() );
    assertNotNull( versionSummaries );
    // copy doesn't increase version number
    assertTrue( versionSummaries.size() >= 1 );
    assertEquals( USERNAME_SUZY, versionSummaries.get( 0 ).getAuthor() );

    logger.info( "getVersionSummary" );
    VersionSummary versionSummary = repo.getVersionSummary( file1.getId(), null );
    assertNotNull( versionSummary );
    assertNotNull( versionSummary.getId() );

    logger.info( "getFileAtVersion" );
    RepositoryFile file1AtVersion = repo.getFileAtVersion( file1.getId(), versionSummary.getId() );
    assertNotNull( file1AtVersion );
    assertEquals( versionSummary.getId(), file1AtVersion.getVersionId() );

    logger.info( "getTree" );
    RepositoryFileTree tree = repo.getTree( new RepositoryRequest( ClientRepositoryPaths.getRootFolderPath(), true, -1, null ) );
    assertNotNull( tree.getFile().getId() );

View Full Code Here

    ITenant mainTenant_1 =
        tenantManager.createTenant( systemTenant, MAIN_TENANT_1, tenantAdminRoleName,
            tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
    userRoleDao.createUser( mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName } );
    login( USERNAME_ADMIN, mainTenant_1, new String[] { tenantAuthenticatedRoleName } );
    RepositoryFile file = repo.getFile( ClientRepositoryPaths.getPublicFolderPath() );
    final RepositoryFile testfile =
        repo.createFile( file.getId(), new RepositoryFile.Builder( "testfile" ).build(),
            new SimpleRepositoryFileData( new ByteArrayInputStream( "test".getBytes() ), "UTF-8",
              "text/plain" ), null );
    //CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
      // Make sure the repository is setup correctly
      assertNotNull( testfile );
      assertNotNull( testfile.getId() );
      final Map<String, Serializable> fileMetadata = repo.getFileMetadata( testfile.getId() );
      assertNotNull( fileMetadata );
      assertEquals( 0, fileMetadata.size() );
    }

    final Map<String, Serializable> metadata = new HashMap<String, Serializable>();
    metadata.put( "sample key", "sample value" );
    metadata.put( "complex key?", "\"an even more 'complex' value\"! {and them some}" );

    adapter.setFileMetadata( testfile.getId(), metadata );
    //CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
      // Make sure the repository sees the metadata
      assertNotNull( testfile );
      assertNotNull( testfile.getId() );
      final Map<String, Serializable> fileMetadata = repo.getFileMetadata( testfile.getId() );
      assertNotNull( fileMetadata );
      assertEquals( 2, fileMetadata.size() );
    }
    //CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
    {
      // Make sure we can get the same metadata back via the web service
      final Map<String, Serializable> fileMetadata = adapter.getFileMetadata( testfile.getId() );
      assertNotNull( fileMetadata );
      assertEquals( 2, fileMetadata.size() );
      assertTrue( StringUtils.equals( "sample value", (String) fileMetadata.get( "sample key" ) ) );
      assertTrue( StringUtils.equals( "\"an even more 'complex' value\"! {and them some}", (String) fileMetadata
          .get( "complex key?" ) ) );
View Full Code Here

    List<RepositoryFile> mockList = mock( List.class );
    when( unifiedRepository.getChildren( mockSerializable ) ).thenReturn( mockList );

    Iterator<RepositoryFile> mockIterator = mock( Iterator.class );
    RepositoryFile repositoryFile2 = mock( RepositoryFile.class );
    when( mockIterator.hasNext() ).thenReturn( true, false );
    when( mockIterator.next() ).thenReturn( repositoryFile2 );
    when( mockList.iterator() ).thenReturn( mockIterator );

    when( repositoryFile2.isFolder() ).thenReturn( false );

    when( repositoryFile2.getPath() ).thenReturn( REPO_PATH );

    Serializable mockSerializable2 = mock( Serializable.class );
    when( repositoryFile2.getId() ).thenReturn( mockSerializable2 );

    SimpleRepositoryFileData mockRepoFileData = mock( SimpleRepositoryFileData.class );
    when( unifiedRepository.getDataForRead( mockSerializable2, SimpleRepositoryFileData.class ) ).thenReturn(
        mockRepoFileData );
View Full Code Here

    List<RepositoryFile> mockList = mock( List.class );
    when( unifiedRepository.getChildren( mockSerializable ) ).thenReturn( mockList );

    Iterator<RepositoryFile> mockIterator = mock( Iterator.class );
    RepositoryFile repositoryFile2 = mock( RepositoryFile.class );
    when( mockIterator.hasNext() ).thenReturn( true, false );
    when( mockIterator.next() ).thenReturn( repositoryFile2 );
    when( mockList.iterator() ).thenReturn( mockIterator );

    when( repositoryFile2.isFolder() ).thenReturn( false );

    Serializable mockSerializable2 = mock( Serializable.class );
    when( repositoryFile2.getId() ).thenReturn( mockSerializable2 );

    SimpleRepositoryFileData mockRepoFileData = mock( SimpleRepositoryFileData.class );
    when( unifiedRepository.getDataForRead( mockSerializable2, SimpleRepositoryFileData.class ) ).thenReturn(
        mockRepoFileData );

    InputStream mockInputStream = new InputStream() {
      @Override
      public int read() throws IOException {
        return -1; // EOF
      }
    };
    when( mockRepoFileData.getStream() ).thenReturn( mockInputStream );

    String name2 = "name.txt";
    when( repositoryFile2.getName() ).thenReturn( name2 );

    File parentDir = new File( System.getProperty( "java.io.tmpdir" ) );
    File file = new File( parentDir, name );
    // already exists
    if ( file.isDirectory() ) {
View Full Code Here

   *
   * @throws java.io.IOException
   */
  public void doExport() throws IOException {
    exportDir = new File( filePath );
    RepositoryFile exportRepositoryFile = unifiedRepository.getFile( repoPath );

    if ( exportRepositoryFile == null ) {
      throw new FileNotFoundException( Messages.getInstance().getErrorString(
          "Exporter.ERROR_0001_INVALID_SOURCE_DIRECTORY", repoPath ) );
    }

    if ( exportRepositoryFile.isFolder() ) { // Handle recursive export
      exportDirectory( exportRepositoryFile, exportDir );
    } else { // Handle a single file export
      exportFile( exportRepositoryFile, exportDir );
    }
  }
View Full Code Here

   *
   * @return
   * @throws java.io.IOException
   */
  public File doExportAsZip() throws IOException {
    RepositoryFile exportRepositoryFile = unifiedRepository.getFile( repoPath );
    return doExportAsZip( exportRepositoryFile );
  }
View Full Code Here

  public boolean isLocaleFile( IRepositoryFileBundle file, String parentPath, byte[] bytes ) throws IOException {

    boolean isLocale = false;
    String fileName = file.getFile().getName();
    String actualFilePath = file.getPath();
    RepositoryFile localeRepositoryFile = file.getFile();
    if ( ImportSession.getSession().getManifest() != null && ImportSession.getSession().getManifest().getManifestInformation().getManifestVersion() != null ) {
      fileName = ExportFileNameEncoder.decodeZipFileName( fileName );
      actualFilePath = ExportFileNameEncoder.decodeZipFileName( actualFilePath );
      localeRepositoryFile = new RepositoryFile.Builder( localeRepositoryFile ).name(
          ExportFileNameEncoder.decodeZipFileName( localeRepositoryFile.getName() ) ).build();
    }
    int sourceVersion = 0; // 0 = Not a local file, 1 = 4.8 .properties file, 2= Sugar 5.0 .local file
    if ( fileName.endsWith( PROPERTIES_EXT ) ) {
      sourceVersion = 1;
    } else if ( fileName.endsWith( LOCALE_EXT ) ) {
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.