Search in sources :

Example 31 with VersionSummary

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

the class DefaultUnifiedRepositoryVersioningIT method testGetFileByVersionSummary.

@Test
public void testGetFileByVersionSummary() 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(USERNAME_SUZY);
    final String fileName = "helloworld.sample";
    final String origSampleString = "Hello World!";
    final boolean origSampleBoolean = false;
    final int origSampleInteger = 1024;
    RepositoryFile newFile = createSampleFile(parentFolderPath, fileName, origSampleString, origSampleBoolean, origSampleInteger, true);
    final Serializable fileId = newFile.getId();
    final String absolutePath = newFile.getPath();
    final String modSampleString = "Ciao World!";
    final boolean modSampleBoolean = true;
    final int modSampleInteger = 2048;
    final SampleRepositoryFileData modData = new SampleRepositoryFileData(modSampleString, modSampleBoolean, modSampleInteger);
    RepositoryFile.Builder builder = new RepositoryFile.Builder(newFile);
    final String desc = "Hello World description";
    builder.description(RepositoryFile.DEFAULT_LOCALE, desc);
    repo.updateFile(builder.build(), modData, null);
    List<VersionSummary> versionSummaries = repo.getVersionSummaries(newFile.getId());
    RepositoryFile v1 = repo.getFileAtVersion(newFile.getId(), versionSummaries.get(0).getId());
    RepositoryFile v2 = repo.getFileAtVersion(newFile.getId(), versionSummaries.get(1).getId());
    assertEquals(fileName, v1.getName());
    assertEquals(fileName, v2.getName());
    assertEquals(fileId, v1.getId());
    assertEquals(fileId, v2.getId());
    assertEquals("1.0", v1.getVersionId());
    assertEquals("1.1", v2.getVersionId());
    assertEquals(absolutePath, v1.getPath());
    assertEquals(absolutePath, v2.getPath());
    assertNull(v1.getDescription());
    assertEquals(desc, v2.getDescription());
    System.out.println("or: " + newFile);
    System.out.println("v1: " + v1);
    System.out.println("v2: " + v2);
    SampleRepositoryFileData c1 = repo.getDataAtVersionForRead(v1.getId(), v1.getVersionId(), SampleRepositoryFileData.class);
    SampleRepositoryFileData c2 = repo.getDataAtVersionForRead(v2.getId(), v2.getVersionId(), SampleRepositoryFileData.class);
    assertEquals(origSampleString, c1.getSampleString());
    assertEquals(origSampleBoolean, c1.getSampleBoolean());
    assertEquals(origSampleInteger, c1.getSampleInteger());
    assertEquals(modSampleString, c2.getSampleString());
    assertEquals(modSampleBoolean, c2.getSampleBoolean());
    assertEquals(modSampleInteger, c2.getSampleInteger());
}
Also used : SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) Serializable(java.io.Serializable) ITenant(org.pentaho.platform.api.mt.ITenant) 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 32 with VersionSummary

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

Example 33 with VersionSummary

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

the class DefaultUnifiedRepositoryVersioningIT method testGetVersionSummary.

@Test
public void testGetVersionSummary() 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(USERNAME_SUZY);
    final String fileName = "helloworld.sample";
    final String origSampleString = "Hello World!";
    final boolean origSampleBoolean = false;
    final int origSampleInteger = 1024;
    RepositoryFile newFile = createSampleFile(parentFolderPath, fileName, origSampleString, origSampleBoolean, origSampleInteger, true);
    SampleRepositoryFileData newContent = repo.getDataForRead(newFile.getId(), SampleRepositoryFileData.class);
    VersionSummary v1 = repo.getVersionSummary(newFile.getId(), newFile.getVersionId());
    assertNotNull(v1);
    assertEquals(USERNAME_SUZY, v1.getAuthor());
    assertEquals(new Date().getDate(), v1.getDate().getDate());
    repo.updateFile(newFile, newContent, null);
    // gets last version summary
    VersionSummary v2 = repo.getVersionSummary(newFile.getId(), null);
    assertNotNull(v2);
    assertEquals(USERNAME_SUZY, v2.getAuthor());
    assertEquals(new Date().getDate(), v2.getDate().getDate());
    assertFalse(v1.equals(v2));
    List<VersionSummary> sums = repo.getVersionSummaries(newFile.getId());
    // unfortunate impl issue that the 3rd version is the one that the user sees as the original file version
    assertEquals(sums.get(0), v1);
    assertEquals(sums.get(1), v2);
}
Also used : SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) ITenant(org.pentaho.platform.api.mt.ITenant) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) Test(org.junit.Test)

Example 34 with VersionSummary

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

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

Aggregations

VersionSummary (org.pentaho.platform.api.repository2.unified.VersionSummary)32 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)18 Matchers.anyString (org.mockito.Matchers.anyString)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 List (java.util.List)12 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)9 Date (java.util.Date)7 ITenant (org.pentaho.platform.api.mt.ITenant)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)5 Serializable (java.io.Serializable)4 KettleException (org.pentaho.di.core.exception.KettleException)4 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)4 SampleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData)4 Calendar (java.util.Calendar)3 Node (javax.jcr.Node)3 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)3 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)3 KettleFileException (org.pentaho.di.core.exception.KettleFileException)3