Search in sources :

Example 31 with SimpleRepositoryFileData

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

the class DefaultUnifiedRepositoryContentIT method testGetTreeWithShowHidden.

@Test
public void testGetTreeWithShowHidden() throws Exception {
    RepositoryFileTree root = null;
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    RepositoryFile publicFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
    final String dataString = "Hello World!";
    final String encoding = "UTF-8";
    byte[] data = dataString.getBytes(encoding);
    ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
    final String mimeType = "text/plain";
    final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
    RepositoryFile newFile1 = repo.createFile(publicFolder.getId(), new RepositoryFile.Builder("helloworld.xaction").versioned(true).hidden(true).build(), content, null);
    root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, -1, null));
    assertFalse(root.getChildren().isEmpty());
    root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), false, -1, null));
    assertTrue(root.getChildren().isEmpty());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) Test(org.junit.Test)

Example 32 with SimpleRepositoryFileData

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

the class DefaultUnifiedRepositoryContentIT method testDeleteLockedFile.

@Test
public void testDeleteLockedFile() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName());
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    final String dataString = "Hello World!";
    final String encoding = "UTF-8";
    byte[] data = dataString.getBytes(encoding);
    ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
    final String mimeType = "text/plain";
    final String fileName = "helloworld.xaction";
    final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
    RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(fileName).build(), content, null);
    final String filePath = parentFolderPath + RepositoryFile.SEPARATOR + fileName;
    assertFalse(repo.getFile(filePath).isLocked());
    final String lockMessage = "test by Mat";
    repo.lockFile(newFile.getId(), lockMessage);
    repo.deleteFile(newFile.getId(), null);
    // lock only removed when file is permanently deleted
    assertNotNull(SimpleJcrTestUtils.getItem(testJcrTemplate, ServerRepositoryPaths.getUserHomeFolderPath(tenantAcme, USERNAME_SUZY) + "/.lockTokens/" + newFile.getId()));
    repo.undeleteFile(newFile.getId(), null);
    repo.deleteFile(newFile.getId(), null);
    repo.deleteFile(newFile.getId(), true, null);
    // make sure lock token node has been removed
    assertNull(SimpleJcrTestUtils.getItem(testJcrTemplate, ServerRepositoryPaths.getUserHomeFolderPath(tenantAcme, USERNAME_SUZY) + "/.lockTokens/" + newFile.getId()));
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 33 with SimpleRepositoryFileData

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

the class DefaultUnifiedRepositoryContentIT method createSimpleFile.

private RepositoryFile createSimpleFile(final Serializable parentFolderId, final String fileName) throws Exception {
    final String dataString = "Hello World!";
    final String encoding = "UTF-8";
    byte[] data = dataString.getBytes(encoding);
    ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
    final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, "text/plain");
    return repo.createFile(parentFolderId, new RepositoryFile.Builder(fileName).build(), content, null);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) Matchers.anyString(org.mockito.Matchers.anyString)

Example 34 with SimpleRepositoryFileData

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

the class DefaultUnifiedRepositoryContentIT method testLockFile.

@Test
public void testLockFile() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
    userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName());
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    final String dataString = "Hello World!";
    final String encoding = "UTF-8";
    byte[] data = dataString.getBytes(encoding);
    ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
    final String mimeType = "text/plain";
    final String fileName = "helloworld.xaction";
    final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
    RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(fileName).versioned(true).build(), content, null);
    final String clientPath = parentFolderPath + RepositoryFile.SEPARATOR + fileName;
    final String serverPath = ServerRepositoryPaths.getTenantRootFolderPath() + clientPath;
    assertFalse(newFile.isLocked());
    assertNull(newFile.getLockDate());
    assertNull(newFile.getLockMessage());
    assertNull(newFile.getLockOwner());
    final String lockMessage = "test by :Mat";
    repo.lockFile(newFile.getId(), lockMessage);
    // verify no new versions were created on locking
    assertEquals(1, repo.getVersionSummaries(newFile.getId()).size());
    assertTrue(SimpleJcrTestUtils.isLocked(testJcrTemplate, serverPath));
    String ownerInfo = SimpleJcrTestUtils.getString(testJcrTemplate, serverPath + "/jcr:lockOwner");
    assertEquals("test by %3AMat", ownerInfo.split(":")[2]);
    assertNotNull(new Date(Long.parseLong(ownerInfo.split(":")[1])));
    // test update while locked
    repo.updateFile(repo.getFileById(newFile.getId()), content, "update by Mat");
    assertEquals(2, repo.getVersionSummaries(newFile.getId()).size());
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    RepositoryFile lockedFile = repo.getFile(clientPath);
    assertTrue(lockedFile.isLocked());
    assertNotNull(lockedFile.getLockDate());
    assertEquals(lockMessage, lockedFile.getLockMessage());
    assertEquals(userNameUtils.getPrincipleId(tenantAcme, USERNAME_SUZY), lockedFile.getLockOwner());
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    assertTrue(repo.canUnlockFile(newFile.getId()));
    repo.unlockFile(newFile.getId());
    assertEquals(2, repo.getVersionSummaries(newFile.getId()).size());
    assertFalse(SimpleJcrTestUtils.isLocked(testJcrTemplate, serverPath));
    RepositoryFile unlockedFile = repo.getFile(clientPath);
    assertFalse(unlockedFile.isLocked());
    assertNull(unlockedFile.getLockDate());
    assertNull(unlockedFile.getLockMessage());
    assertNull(unlockedFile.getLockOwner());
    // make sure lock token node has been removed
    assertNull(SimpleJcrTestUtils.getItem(testJcrTemplate, ServerRepositoryPaths.getUserHomeFolderPath(tenantAcme, USERNAME_SUZY) + "/.lockTokens/" + newFile.getId()));
    // lock it again by suzy
    repo.lockFile(newFile.getId(), lockMessage);
    assertEquals(2, repo.getVersionSummaries(newFile.getId()).size());
    // login as tenant admin; make sure we can unlock
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    assertTrue(repo.canUnlockFile(newFile.getId()));
    repo.unlockFile(newFile.getId());
    assertEquals(2, repo.getVersionSummaries(newFile.getId()).size());
    RepositoryFile unlockedFile2 = repo.getFile(clientPath);
    assertFalse(unlockedFile2.isLocked());
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    // lock it again by suzy
    repo.lockFile(newFile.getId(), lockMessage);
    assertEquals(2, repo.getVersionSummaries(newFile.getId()).size());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) Test(org.junit.Test)

Example 35 with SimpleRepositoryFileData

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

the class DefaultUnifiedRepositoryVersioningIT method testDeleteFileAtVersion.

@Test
public void testDeleteFileAtVersion() throws Exception {
    // Startup and login to repository
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    // Create a simple file
    RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
    final String expectedDataString = "Hello World!";
    final String expectedModDataString = "Ciao World!";
    final String expectedEncoding = "UTF-8";
    byte[] data = expectedDataString.getBytes(expectedEncoding);
    byte[] modData = expectedModDataString.getBytes(expectedEncoding);
    ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
    ByteArrayInputStream modDataStream = new ByteArrayInputStream(modData);
    final String expectedMimeType = "text/plain";
    final String expectedName = "helloworld.xaction";
    final String expectedAbsolutePath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/helloworld.xaction";
    final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, expectedEncoding, expectedMimeType);
    RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).versioned(true).build(), content, null);
    // Make sure the file was created
    RepositoryFile foundFile = repo.getFile(expectedAbsolutePath);
    assertNotNull(foundFile);
    // Modify file
    final SimpleRepositoryFileData modContent = new SimpleRepositoryFileData(modDataStream, expectedEncoding, expectedMimeType);
    repo.updateFile(foundFile, modContent, null);
    // Verify versions
    List<VersionSummary> origVerList = repo.getVersionSummaries(foundFile.getId());
    assertEquals(2, origVerList.size());
    SimpleRepositoryFileData result = repo.getDataAtVersionForRead(foundFile.getId(), origVerList.get(0).getId(), SimpleRepositoryFileData.class);
    SimpleRepositoryFileData modResult = repo.getDataAtVersionForRead(foundFile.getId(), origVerList.get(1).getId(), SimpleRepositoryFileData.class);
    assertEquals(expectedDataString, IOUtils.toString(result.getInputStream(), expectedEncoding));
    assertEquals(expectedModDataString, IOUtils.toString(modResult.getInputStream(), expectedEncoding));
    // Remove first version
    repo.deleteFileAtVersion(foundFile.getId(), origVerList.get(0).getId());
    // Verify version removal
    List<VersionSummary> newVerList = repo.getVersionSummaries(foundFile.getId());
    assertEquals(1, newVerList.size());
    SimpleRepositoryFileData newModResult = repo.getDataAtVersionForRead(foundFile.getId(), newVerList.get(0).getId(), SimpleRepositoryFileData.class);
    assertEquals(expectedModDataString, IOUtils.toString(newModResult.getInputStream(), expectedEncoding));
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

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