Search in sources :

Example 36 with SimpleRepositoryFileData

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

the class DefaultUnifiedRepositoryVersioningIT method testGetVersionSummaries.

@Test
public void testGetVersionSummaries() 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).versioned(true).build(), content, "created helloworld.xaction");
    repo.updateFile(newFile, content, "update 1");
    newFile = repo.getFileById(newFile.getId());
    repo.updateFile(newFile, content, "update 2");
    newFile = repo.getFileById(newFile.getId());
    RepositoryFile updatedFile = repo.updateFile(newFile, content, "update 3");
    List<VersionSummary> versionSummaries = repo.getVersionSummaries(updatedFile.getId());
    assertNotNull(versionSummaries);
    assertTrue(versionSummaries.size() >= 3);
    assertEquals("update 3", versionSummaries.get(versionSummaries.size() - 1).getMessage());
    assertEquals(USERNAME_SUZY, versionSummaries.get(0).getAuthor());
    System.out.println(versionSummaries);
    System.out.println(versionSummaries.size());
}
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)

Example 37 with SimpleRepositoryFileData

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

the class DefaultUnifiedRepositoryVersioningIT method testRestoreFileAtVersion.

@Test
public void testRestoreFileAtVersion() 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));
    // Restore first version
    repo.restoreFileAtVersion(foundFile.getId(), origVerList.get(0).getId(), "restore version");
    // Verify version restoration
    List<VersionSummary> newVerList = repo.getVersionSummaries(foundFile.getId());
    assertEquals(3, newVerList.size());
    SimpleRepositoryFileData newOrigResult = repo.getDataForRead(foundFile.getId(), SimpleRepositoryFileData.class);
    assertEquals(expectedDataString, IOUtils.toString(newOrigResult.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)

Example 38 with SimpleRepositoryFileData

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

the class DefaultUnifiedRepositoryVersioningIT method testGetVersionSummaryInBatch.

@Test
public void testGetVersionSummaryInBatch() 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 fileName1 = "helloworld1.xaction";
    final String fileName2 = "helloworld2.xaction";
    final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
    RepositoryFile newFile1 = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(fileName1).versioned(true).build(), content, "created helloworld.xaction");
    final String createMsg = "created helloworld2.xaction";
    RepositoryFile newFile2 = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(fileName2).versioned(true).build(), content, createMsg);
    final String updateMsg1 = "updating 1";
    newFile1 = repo.updateFile(newFile1, content, updateMsg1);
    // Update file2 but don't save the info. We'll look up the original revision
    repo.updateFile(newFile2, content, "updating 2");
    // Create a new file with just the Id set so we get the latest revision
    RepositoryFile lookup1 = new RepositoryFile.Builder(newFile1.getId(), null).build();
    // Create a new file with the original version id and file id for file #2
    RepositoryFile lookup2 = new RepositoryFile.Builder(newFile2.getId(), null).versionId(newFile2.getVersionId()).build();
    List<VersionSummary> versionSummaries = repo.getVersionSummaryInBatch(Arrays.asList(lookup1, lookup2));
    assertNotNull(versionSummaries);
    assertEquals(2, versionSummaries.size());
    VersionSummary summary = versionSummaries.get(0);
    // First version summary should be for the latest version of file1
    assertEquals(newFile1.getId(), summary.getVersionedFileId());
    assertEquals(updateMsg1, summary.getMessage());
    assertEquals(newFile1.getVersionId(), summary.getId());
    summary = versionSummaries.get(1);
    // Second version summary should be for the first version of file2
    assertEquals(newFile2.getId(), summary.getVersionedFileId());
    assertEquals(newFile2.getVersionId(), summary.getId());
    assertEquals(createMsg, summary.getMessage());
}
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)

Example 39 with SimpleRepositoryFileData

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

the class DefaultUnifiedRepositoryJaxwsWebServiceIT method testEverything.

@Test
public void testEverything() throws Exception {
    login(sysAdminUserName, systemTenant, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", new String[] { tenantAdminRoleName });
    logout();
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    logger.info("getFile");
    JcrRepositoryDumpToFile dumpToFile = new JcrRepositoryDumpToFile(testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername, "c:/build/testrepo_9", Mode.CUSTOM);
    dumpToFile.execute();
    RepositoryFile f = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
    assertNotNull(f.getId());
    assertEquals(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY), f.getPath());
    assertNotNull(f.getCreatedDate());
    assertEquals(USERNAME_SUZY, f.getName());
    assertTrue(f.isFolder());
    logger.info("getFileById");
    assertNotNull(repo.getFileById(f.getId()));
    logger.info("createFolder");
    RepositoryFile folder1 = repo.createFolder(f.getId(), new RepositoryFile.Builder("folder1").folder(true).build(), null);
    assertNotNull(folder1);
    assertEquals("folder1", folder1.getName());
    assertNotNull(folder1.getId());
    NodeRepositoryFileData data = makeNodeRepositoryFileData1();
    logger.info("createFile");
    RepositoryFile file1 = repo.createFile(folder1.getId(), new RepositoryFile.Builder("file1.whatever").versioned(true).build(), data, null);
    assertNotNull(file1);
    assertNotNull(file1.getId());
    logger.info("getDataForRead");
    NodeRepositoryFileData file1Data = repo.getDataForRead(file1.getId(), NodeRepositoryFileData.class);
    assertNotNull(file1Data);
    assertEquals("testNode", file1Data.getNode().getName());
    assertEquals("hello world", file1Data.getNode().getProperty("prop1").getString());
    assertEquals(false, file1Data.getNode().getProperty("prop2").getBoolean());
    assertEquals(DataPropertyType.BOOLEAN, file1Data.getNode().getProperty("prop2").getType());
    assertEquals(12L, file1Data.getNode().getProperty("prop3").getLong());
    logger.info("createFile (binary)");
    SimpleRepositoryFileData simpleData = new SimpleRepositoryFileData(new ByteArrayInputStream("Hello World!".getBytes("UTF-8")), "UTF-8", "text/plain");
    RepositoryFile simpleFile = repo.createFile(folder1.getId(), new RepositoryFile.Builder("file2.whatever").versioned(true).build(), simpleData, null);
    Serializable simpleVersion = simpleFile.getVersionId();
    logger.info("getDataForRead (binary)");
    SimpleRepositoryFileData simpleFileData = repo.getDataForRead(simpleFile.getId(), SimpleRepositoryFileData.class);
    assertNotNull(simpleFileData);
    assertEquals("Hello World!", IOUtils.toString(simpleFileData.getInputStream(), simpleFileData.getEncoding()));
    assertEquals("text/plain", simpleFileData.getMimeType());
    assertEquals("UTF-8", simpleFileData.getEncoding());
    logger.info("updateFile (binary)");
    simpleData = new SimpleRepositoryFileData(new ByteArrayInputStream("Ciao World!".getBytes("UTF-8")), "UTF-8", "text/plain");
    simpleFile = repo.updateFile(simpleFile, simpleData, null);
    assertNotNull(simpleFile.getLastModifiedDate());
    logger.info("getDataForRead (binary)");
    simpleFileData = repo.getDataForRead(simpleFile.getId(), SimpleRepositoryFileData.class);
    assertNotNull(simpleFileData);
    assertEquals("Ciao World!", IOUtils.toString(simpleFileData.getInputStream(), simpleFileData.getEncoding()));
    logger.info("getDataForReadAtVersion (binary)");
    simpleFileData = repo.getDataAtVersionForRead(simpleFile.getId(), simpleVersion, SimpleRepositoryFileData.class);
    assertNotNull(simpleFileData);
    assertEquals("Hello World!", IOUtils.toString(simpleFileData.getInputStream(), simpleFileData.getEncoding()));
    logger.info("getChildren");
    List<RepositoryFile> folder1Children = repo.getChildren(new RepositoryRequest(String.valueOf(folder1.getId()), true, -1, null));
    assertNotNull(folder1Children);
    assertEquals(2, folder1Children.size());
    logger.info("getChildren");
    List<RepositoryFile> folder1ChildrenFiltered = repo.getChildren(new RepositoryRequest(String.valueOf(folder1.getId()), true, -1, "*.sample"));
    assertNotNull(folder1ChildrenFiltered);
    assertEquals(0, folder1ChildrenFiltered.size());
    logger.info("getDeletedFiles");
    assertEquals(0, repo.getDeletedFiles().size());
    logger.info("deleteFile");
    repo.deleteFile(file1.getId(), null);
    logger.info("getDeletedFiles");
    assertEquals(0, repo.getDeletedFiles(folder1.getPath(), "*.sample").size());
    logger.info("hasAccess");
    assertFalse(repo.hasAccess("/pentaho", EnumSet.of(RepositoryFilePermission.WRITE)));
    logger.info("getEffectiveAces");
    List<RepositoryFileAce> folder1EffectiveAces = repo.getEffectiveAces(folder1.getId());
    assertEquals(1, folder1EffectiveAces.size());
    logger.info("getAcl");
    RepositoryFileAcl folder1Acl = repo.getAcl(folder1.getId());
    assertEquals(USERNAME_SUZY, folder1Acl.getOwner().getName());
    logger.info("updateAcl");
    userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
    RepositoryFileAcl updatedFolder1Acl = repo.updateAcl(new RepositoryFileAcl.Builder(folder1Acl).entriesInheriting(false).ace(userNameUtils.getPrincipleId(tenantAcme, USERNAME_TIFFANY), RepositoryFileSid.Type.USER, RepositoryFilePermission.ALL).build());
    assertNotNull(updatedFolder1Acl);
    assertEquals(1, updatedFolder1Acl.getAces().size());
    logger.info("lockFile");
    assertFalse(file1.isLocked());
    repo.lockFile(file1.getId(), "I locked this file");
    logger.info("canUnlockFile");
    assertTrue(repo.canUnlockFile(file1.getId()));
    logger.info("unlockFile");
    repo.unlockFile(file1.getId());
    logger.info("moveFile");
    repo.moveFile(file1.getId(), ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/folder1", null);
    logger.info("copyFile");
    repo.copyFile(file1.getId(), ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/folder1/fileB.whatever", null);
    RepositoryFile copiedFile = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/folder1/fileB.whatever");
    copiedFile = repo.updateFile(copiedFile, data, null);
    logger.info("getVersionSummaries");
    List<VersionSummary> versionSummaries = repo.getVersionSummaries(file1.getId());
    assertNotNull(versionSummaries);
    // copy doesn't increase version number
    assertTrue(versionSummaries.size() >= 1);
    assertEquals(USERNAME_SUZY, versionSummaries.get(0).getAuthor());
    logger.info("getVersionSummary");
    VersionSummary versionSummary = repo.getVersionSummary(file1.getId(), null);
    assertNotNull(versionSummary);
    assertNotNull(versionSummary.getId());
    logger.info("getFileAtVersion");
    RepositoryFile file1AtVersion = repo.getFileAtVersion(file1.getId(), versionSummary.getId());
    assertNotNull(file1AtVersion);
    assertEquals(versionSummary.getId(), file1AtVersion.getVersionId());
    logger.info("getTree");
    RepositoryFileTree tree = repo.getTree(new RepositoryRequest(ClientRepositoryPaths.getRootFolderPath(), true, -1, null));
    assertNotNull(tree.getFile().getId());
    logger.info("getDataForReadInBatch");
    List<NodeRepositoryFileData> result = repo.getDataForReadInBatch(Arrays.asList(file1, copiedFile), NodeRepositoryFileData.class);
    assertEquals(2, result.size());
    logger.info("getVersionSummaryInBatch");
    List<VersionSummary> vResult = repo.getVersionSummaryInBatch(Arrays.asList(file1, simpleFile));
    assertEquals(2, vResult.size());
    logger.info("getReservedChars");
    assertFalse(repo.getReservedChars().isEmpty());
}
Also used : Serializable(java.io.Serializable) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) ITenant(org.pentaho.platform.api.mt.ITenant) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) JcrRepositoryDumpToFile(org.pentaho.platform.repository2.unified.jcr.JcrRepositoryDumpToFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 40 with SimpleRepositoryFileData

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

the class FileSystemRepositoryFileDao method moveFile.

public void moveFile(Serializable fileId, String destRelPath, String versionMessage) {
    RepositoryFile file = getFileById(fileId);
    SimpleRepositoryFileData data = getData(fileId, null, SimpleRepositoryFileData.class);
    deleteFile(fileId, versionMessage);
    createFile(null, file, data, null, versionMessage);
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

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