Search in sources :

Example 6 with RepositoryFileInputStream

use of org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream in project pentaho-platform by pentaho.

the class FileServiceTest method testDoGetFileOrDirException.

@Test
public void testDoGetFileOrDirException() throws Exception {
    RepositoryFile file = mock(RepositoryFile.class);
    doReturn("file.txt").when(file).getName();
    RepositoryFileInputStream mockInputStream = mock(RepositoryFileInputStream.class);
    doReturn(1).when(fileService).copy(any(java.io.InputStream.class), any(java.io.OutputStream.class));
    doReturn(mockInputStream).when(fileService).getRepositoryFileInputStream(any(RepositoryFile.class));
    String pathId = "/usr/folder/file.txt";
    try {
        fileService.doGetFileOrDir(pathId);
        // This line should never be reached
        fail();
    } catch (FileNotFoundException fileNotFound) {
    // Expected exception
    }
}
Also used : RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) InputStream(java.io.InputStream) RepositoryFileOutputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputStream) FileNotFoundException(java.io.FileNotFoundException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) Test(org.junit.Test)

Example 7 with RepositoryFileInputStream

use of org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method getDomainFilesData.

/*
   * retrieves the data streams for the metadata referenced by domainId. This could be a single .xmi file or an .xmi
   * file and multiple .properties files.
   */
public Map<String, InputStream> getDomainFilesData(final String domainId) {
    Set<RepositoryFile> metadataFiles;
    lock.readLock().lock();
    try {
        metadataFiles = metadataMapping.getFiles(domainId);
    } finally {
        lock.readLock().unlock();
    }
    Map<String, InputStream> values = new HashMap<String, InputStream>(metadataFiles.size());
    for (RepositoryFile repoFile : metadataFiles) {
        RepositoryFileInputStream is;
        try {
            is = new RepositoryFileInputStream(repoFile);
        } catch (Exception e) {
            // This pretty much ensures an exception will be thrown later and passed to the client
            return null;
        }
        String fileName = repoFile.getName().endsWith(".properties") ? repoFile.getName() : domainId + (domainId.endsWith(".xmi") ? "" : ".xmi");
        values.put(fileName, is);
    }
    return values;
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) InputStream(java.io.InputStream) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException)

Aggregations

RepositoryFileInputStream (org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream)7 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)6 FileNotFoundException (java.io.FileNotFoundException)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)3 RepositoryFileOutputStream (org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)1 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)1 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)1 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)1 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)1 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)1 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)1 IContentItem (org.pentaho.platform.api.repository.IContentItem)1