use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryBase method createSampleFile.
protected RepositoryFile createSampleFile(final String parentFolderPath, final String fileName, final String sampleString, final boolean sampleBoolean, final int sampleInteger, boolean versioned) throws Exception {
RepositoryFile parentFolder = repo.getFile(parentFolderPath);
final SampleRepositoryFileData content = new SampleRepositoryFileData(sampleString, sampleBoolean, sampleInteger);
return repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(fileName).versioned(versioned).build(), content, null);
}
use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryAuthorizationIT method testWriteWhenNoWritePermissionOnFile.
/**
* Tests deleting a file when no delete permission is given to the role
*/
@Test
public void testWriteWhenNoWritePermissionOnFile() 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 });
defaultBackingRepositoryLifecycleManager.newTenant();
RepositoryFile publicFolderFile = createSampleFile(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName())).getPath(), "helloworld.sample", "ddfdf", false, 83);
RepositoryFileAcl publicFolderFileAcl = new RepositoryFileAcl.Builder(publicFolderFile.getId(), userNameUtils.getPrincipleId(tenantAcme, USERNAME_ADMIN), RepositoryFileSid.Type.USER).entriesInheriting(false).ace(new RepositoryFileSid(roleNameUtils.getPrincipleId(tenantAcme, tenantAuthenticatedRoleName), RepositoryFileSid.Type.ROLE), RepositoryFilePermission.READ).build();
repo.updateAcl(publicFolderFileAcl);
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", new String[] { tenantAuthenticatedRoleName });
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
final String modSampleString = "Ciao World!";
final boolean modSampleBoolean = true;
final int modSampleInteger = 99;
final SampleRepositoryFileData modContent = new SampleRepositoryFileData(modSampleString, modSampleBoolean, modSampleInteger);
try {
repo.updateFile(publicFolderFile, modContent, null);
fail();
} catch (UnifiedRepositoryException e) {
assertNotNull(e);
}
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
try {
repo.updateFile(publicFolderFile, modContent, null);
assertTrue(true);
} catch (UnifiedRepositoryException e) {
fail();
}
}
use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateSampleFile.
@Test
public void testCreateSampleFile() 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 expectedName = "helloworld.sample";
final String sampleString = "Ciao World!";
final boolean sampleBoolean = true;
final int sampleInteger = 99;
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
final String expectedAbsolutePath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
RepositoryFile newFile = createSampleFile(parentFolderPath, expectedName, sampleString, sampleBoolean, sampleInteger);
assertNotNull(newFile.getId());
RepositoryFile foundFile = repo.getFile(expectedAbsolutePath);
assertNotNull(foundFile);
assertEquals(expectedName, foundFile.getName());
assertEquals(expectedAbsolutePath, foundFile.getPath());
assertNotNull(foundFile.getCreatedDate());
assertNotNull(foundFile.getLastModifiedDate());
SampleRepositoryFileData data = repo.getDataForRead(foundFile.getId(), SampleRepositoryFileData.class);
assertEquals(sampleString, data.getSampleString());
assertEquals(sampleBoolean, data.getSampleBoolean());
assertEquals(sampleInteger, data.getSampleInteger());
}
use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testUpdateFile.
@Test
public void testUpdateFile() 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";
RepositoryFile newFile = createSampleFile(parentFolderPath, fileName, "Hello World!", false, 222);
final String modSampleString = "Ciao World!";
final boolean modSampleBoolean = true;
final int modSampleInteger = 99;
final SampleRepositoryFileData modContent = new SampleRepositoryFileData(modSampleString, modSampleBoolean, modSampleInteger);
repo.updateFile(newFile, modContent, null);
SampleRepositoryFileData modData = repo.getDataForRead(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + RepositoryFile.SEPARATOR + fileName).getId(), SampleRepositoryFileData.class);
assertEquals(modSampleString, modData.getSampleString());
assertEquals(modSampleBoolean, modData.getSampleBoolean());
assertEquals(modSampleInteger, modData.getSampleInteger());
}
use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testGetDataForReadInBatch_unversioned.
@Test
public void testGetDataForReadInBatch_unversioned() 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);
RepositoryFile newFile2 = createSampleFile(parentFolderPath, "file2", sampleString2, false, 2);
assertNotNull(newFile1.getId());
assertNull(newFile1.getVersionId());
assertNotNull(newFile2.getId());
assertNull(newFile2.getVersionId());
List<SampleRepositoryFileData> data = repo.getDataForReadInBatch(Arrays.asList(newFile1, newFile2), SampleRepositoryFileData.class);
assertEquals(2, data.size());
SampleRepositoryFileData d = data.get(0);
assertEquals(sampleString1, d.getSampleString());
d = data.get(1);
assertEquals(sampleString2, d.getSampleString());
}
Aggregations