Search in sources :

Example 21 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.

the class JcrRepositoryFileDaoIT method testUpdateFile2.

@Test
public // Running without defined date
void testUpdateFile2() throws Exception {
    RepositoryFile newFile = createFile("JcrRepositoryFileDaoTest1.test");
    IRepositoryFileData dataMock = new SampleRepositoryFileData("", true, 0);
    Date startDate = new Date();
    newFile = new RepositoryFile.Builder(newFile).createdDate(null).build();
    repo.updateFile(newFile, dataMock, "edition #2");
    Date finishDate = new Date();
    List<VersionSummary> summaries = repo.getVersionSummaries(newFile.getId());
    Date lastVersionDate = summaries.get(summaries.size() - 1).getDate();
    if (lastVersionDate.before(startDate) || lastVersionDate.after(finishDate)) {
        fail("incorrect version date");
    }
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Date(java.util.Date) Test(org.junit.Test)

Example 22 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData 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 23 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.

the class FileSystemBackedUnifiedRepository method getDataForReadInBatch.

public <T extends IRepositoryFileData> List<T> getDataForReadInBatch(List<RepositoryFile> files, Class<T> dataClass) {
    Assert.notNull(files);
    List<T> data = new ArrayList<T>(files.size());
    for (RepositoryFile f : files) {
        Assert.notNull(f);
        data.add(repositoryFileDao.getData(f.getId(), f.getVersionId(), dataClass));
    }
    return data;
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 24 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData 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 25 with IRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData 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)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)23 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)16 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)9 Test (org.junit.Test)6 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)5 FileNotFoundException (java.io.FileNotFoundException)4 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Converter (org.pentaho.platform.api.repository2.unified.Converter)4 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 List (java.util.List)3 Node (javax.jcr.Node)3 Session (javax.jcr.Session)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)3