Search in sources :

Example 31 with IRepositoryFileData

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

the class MockUnifiedRepository method updateFile.

@Override
public RepositoryFile updateFile(final RepositoryFile file, final IRepositoryFileData data, final String versionMessage) {
    Validate.isTrue(!file.isFolder());
    if (!hasAccess(file.getId(), EnumSet.of(WRITE))) {
        throw new AccessDeniedException("access denied");
    }
    FileRecord fileRecord = idManager.getFileById(file.getId());
    fileRecord.setFile(new RepositoryFile.Builder(file).title(findTitle(file)).description(findDesc(file)).build());
    IRepositoryFileData oldData = fileRecord.getData();
    fileRecord.setData(data);
    process(fileRecord, oldData);
    if (file.isVersioned()) {
        versionManager.createVersion(fileRecord.getFile().getId(), currentUserProvider.getUser(), versionMessage, new Date());
    }
    return fileRecord.getFile();
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Date(java.util.Date)

Example 32 with IRepositoryFileData

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

the class MockUnifiedRepository method createFile.

@Override
public RepositoryFile createFile(final Serializable parentFolderId, final RepositoryFile file, final IRepositoryFileData data, final RepositoryFileAcl acl, final String versionMessage) {
    Validate.isTrue(!file.isFolder());
    if (!hasAccess(parentFolderId, EnumSet.of(WRITE))) {
        throw new AccessDeniedException("access denied");
    }
    FileRecord parentFolder = idManager.getFileById(parentFolderId);
    RepositoryFile fileFromRepo = new RepositoryFile.Builder(file).path(parentFolder.getPath() + RepositoryFile.SEPARATOR + file.getName()).title(findTitle(file)).description(findDesc(file)).build();
    RepositoryFileAcl aclFromRepo = new RepositoryFileAcl.Builder(acl).build();
    FileRecord fileRecord = new FileRecord(fileFromRepo, data, aclFromRepo, new HashMap<String, Serializable>());
    idManager.register(fileRecord);
    process(fileRecord, null);
    parentFolder.addChild(fileRecord);
    if (file.isVersioned()) {
        versionManager.createVersion(fileRecord.getFile().getId(), currentUserProvider.getUser(), versionMessage, new Date());
    }
    return fileRecord.getFile();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Date(java.util.Date)

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