Search in sources :

Example 41 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class FileSystemRepositoryFileDao method updateFile.

public RepositoryFile updateFile(RepositoryFile file, IRepositoryFileData data, String versionMessage) {
    File f = new File(file.getId().toString());
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(f, false);
        if (data instanceof SimpleRepositoryFileData) {
            fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream()));
        } else if (data instanceof NodeRepositoryFileData) {
            fos.write(inputStreamToBytes(new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes())));
        }
    } catch (FileNotFoundException e) {
        throw new UnifiedRepositoryException(e);
    } catch (IOException e) {
        throw new UnifiedRepositoryException(e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
    return getFile(file.getPath());
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IOException(java.io.IOException) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 42 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class RepositoryFileReader method getEncoding.

protected static String getEncoding(String path) throws FileNotFoundException {
    IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
    RepositoryFile file = (new RepositoryFileInputStream(path)).getFile();
    SimpleRepositoryFileData fileData = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
    return fileData.getEncoding();
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 43 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class FileSystemRepositoryFileDao method createFile.

public RepositoryFile createFile(Serializable parentFolderId, RepositoryFile file, IRepositoryFileData data, RepositoryFileAcl acl, String versionMessage) {
    String fileNameWithPath = RepositoryFilenameUtils.concat(parentFolderId.toString(), file.getName());
    FileOutputStream fos = null;
    File f = new File(fileNameWithPath);
    try {
        f.createNewFile();
        fos = new FileOutputStream(f);
        if (data instanceof SimpleRepositoryFileData) {
            fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream()));
        } else if (data instanceof NodeRepositoryFileData) {
            fos.write(inputStreamToBytes(new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes())));
        }
    } catch (FileNotFoundException e) {
        throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
    } catch (IOException e) {
        throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
    return internalGetFile(f);
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IOException(java.io.IOException) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 44 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class FileSystemRepositoryFileDao method getData.

@SuppressWarnings("unchecked")
public <T extends IRepositoryFileData> T getData(Serializable fileId, Serializable versionId, Class<T> dataClass) {
    File f = new File(fileId.toString());
    T data = null;
    try {
        if (SimpleRepositoryFileData.class.getName().equals(dataClass.getName())) {
            data = (T) new SimpleRepositoryFileData(new FileInputStream(f), "UTF-8", "text/plain");
        } else if (NodeRepositoryFileData.class.getName().equals(dataClass.getName())) {
            throw new UnsupportedOperationException("This operation is not support by this repository");
        }
    } catch (FileNotFoundException e) {
        throw new UnifiedRepositoryException(e);
    }
    return data;
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) FileNotFoundException(java.io.FileNotFoundException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) FileInputStream(java.io.FileInputStream)

Example 45 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class SimpleRepositoryFileDataTransformer method fromContentNode.

/**
 * {@inheritDoc}
 */
public SimpleRepositoryFileData fromContentNode(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node fileNode) throws RepositoryException {
    String encoding = null;
    Node resourceNode = fileNode.getNode(pentahoJcrConstants.getJCR_CONTENT());
    if (resourceNode.hasProperty(pentahoJcrConstants.getJCR_ENCODING())) {
        encoding = resourceNode.getProperty(pentahoJcrConstants.getJCR_ENCODING()).getString();
    }
    InputStream data = resourceNode.getProperty(pentahoJcrConstants.getJCR_DATA()).getBinary().getStream();
    String mimeType = resourceNode.getProperty(pentahoJcrConstants.getJCR_MIMETYPE()).getString();
    return new SimpleRepositoryFileData(data, encoding, mimeType);
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) InputStream(java.io.InputStream) Node(javax.jcr.Node)

Aggregations

SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)58 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)43 ByteArrayInputStream (java.io.ByteArrayInputStream)31 Test (org.junit.Test)25 Matchers.anyString (org.mockito.Matchers.anyString)18 ITenant (org.pentaho.platform.api.mt.ITenant)17 InputStream (java.io.InputStream)16 IOException (java.io.IOException)14 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)12 Serializable (java.io.Serializable)10 File (java.io.File)9 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)9 FileNotFoundException (java.io.FileNotFoundException)5 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 VersionSummary (org.pentaho.platform.api.repository2.unified.VersionSummary)5 FileOutputStream (java.io.FileOutputStream)4 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)4 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)4 RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)4