Search in sources :

Example 11 with SampleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryVersioningIT method testGetDataForReadInBatch_versioned.

@Test
public void testGetDataForReadInBatch_versioned() 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);
    String sampleString1 = "sampleString1";
    String sampleString2 = "sampleString2";
    RepositoryFile newFile1 = createSampleFile(parentFolderPath, "helloworld.sample1", sampleString1, true, 1, true);
    RepositoryFile newFile2 = createSampleFile(parentFolderPath, "file2", sampleString2, false, 2);
    // Update newFile1 to create a new version
    SampleRepositoryFileData updatedContent = new SampleRepositoryFileData(sampleString1 + "mod", true, 1);
    RepositoryFile modFile1 = repo.updateFile(newFile1, updatedContent, "New Version For Test");
    assertNotNull(newFile1.getId());
    assertTrue(newFile1.isVersioned());
    assertNotNull(newFile2.getId());
    assertFalse(newFile2.isVersioned());
    assertNotNull(modFile1.getId());
    assertTrue(modFile1.isVersioned());
    // Check that no version provided returns latest
    RepositoryFile lookup1 = new RepositoryFile.Builder(newFile1.getId(), null).build();
    RepositoryFile lookup2 = new RepositoryFile.Builder(newFile2.getId(), null).build();
    List<SampleRepositoryFileData> data = repo.getDataForReadInBatch(Arrays.asList(lookup1, lookup2), SampleRepositoryFileData.class);
    assertEquals(2, data.size());
    SampleRepositoryFileData d = data.get(0);
    assertEquals(updatedContent.getSampleString(), d.getSampleString());
    d = data.get(1);
    assertEquals(sampleString2, d.getSampleString());
    // Check that providing a version will fetch it properly
    lookup1 = new RepositoryFile.Builder(newFile1.getId(), null).versionId(newFile1.getVersionId()).build();
    lookup2 = new RepositoryFile.Builder(newFile2.getId(), null).versionId(newFile2.getVersionId()).build();
    data = repo.getDataForReadInBatch(Arrays.asList(lookup1, lookup2), SampleRepositoryFileData.class);
    assertEquals(2, data.size());
    d = data.get(0);
    assertEquals(sampleString1, d.getSampleString());
    d = data.get(1);
    assertEquals(sampleString2, d.getSampleString());
}
Also used : SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 12 with SampleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData 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 13 with SampleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData 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 14 with SampleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData in project pentaho-platform by pentaho.

the class SampleRepositoryFileDataTransformer method fromContentNode.

/**
 * {@inheritDoc}
 */
public SampleRepositoryFileData fromContentNode(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node fileNode) throws RepositoryException {
    Node unstructuredNode = fileNode.getNode(pentahoJcrConstants.getJCR_CONTENT());
    String sampleString = unstructuredNode.getProperty(PROPERTY_NAME_SAMPLE_STRING).getString();
    boolean sampleBoolean = unstructuredNode.getProperty(PROPERTY_NAME_SAMPLE_BOOLEAN).getBoolean();
    int sampleInteger = (int) unstructuredNode.getProperty(PROPERTY_NAME_SAMPLE_INTEGER).getLong();
    return new SampleRepositoryFileData(sampleString, sampleBoolean, sampleInteger);
}
Also used : SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) Node(javax.jcr.Node)

Aggregations

SampleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData)14 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)13 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)10 ITenant (org.pentaho.platform.api.mt.ITenant)10 VersionSummary (org.pentaho.platform.api.repository2.unified.VersionSummary)4 Date (java.util.Date)3 Locale (java.util.Locale)2 IPentahoLocale (org.pentaho.platform.api.locale.IPentahoLocale)2 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)2 PentahoLocale (org.pentaho.platform.repository2.locale.PentahoLocale)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Properties (java.util.Properties)1 Node (javax.jcr.Node)1 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)1 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)1 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)1