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());
}
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);
}
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");
}
}
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);
}
Aggregations