use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateSimpleFile.
@Test
public void testCreateSimpleFile() 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 });
RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
final String expectedDataString = "Hello World!";
final String expectedEncoding = "UTF-8";
byte[] data = expectedDataString.getBytes(expectedEncoding);
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
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);
Date beginTime = Calendar.getInstance().getTime();
// when the test runs too fast, begin and lastModifiedDate are the same; manual pause
Thread.sleep(1000);
Calendar cal = Calendar.getInstance(Locale.US);
SimpleDateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
cal.setTime(df.parse("Wed, 4 Jul 2000 12:08:56 -0700"));
RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).hidden(true).versioned(true).createdDate(cal.getTime()).build(), content, null);
assertEquals(cal.getTime(), repo.getVersionSummaries(newFile.getId()).get(0).getDate());
Date endTime = Calendar.getInstance().getTime();
assertTrue(beginTime.before(newFile.getLastModifiedDate()));
assertTrue(endTime.after(newFile.getLastModifiedDate()));
assertNotNull(newFile.getId());
RepositoryFile foundFile = repo.getFile(expectedAbsolutePath);
assertNotNull(foundFile);
assertEquals(expectedName, foundFile.getName());
assertEquals(expectedAbsolutePath, foundFile.getPath());
assertNotNull(foundFile.getCreatedDate());
assertNotNull(foundFile.getLastModifiedDate());
assertTrue(foundFile.isHidden());
assertTrue(foundFile.getFileSize() > 0);
SimpleRepositoryFileData contentFromRepo = repo.getDataForRead(foundFile.getId(), SimpleRepositoryFileData.class);
assertEquals(expectedEncoding, contentFromRepo.getEncoding());
assertEquals(expectedMimeType, contentFromRepo.getMimeType());
assertEquals(expectedDataString, IOUtils.toString(contentFromRepo.getStream(), expectedEncoding));
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateFileAtRootIllegal.
@Test(expected = UnifiedRepositoryException.class)
public void testCreateFileAtRootIllegal() 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 dataString = "Hello World!";
final String encoding = "UTF-8";
byte[] data = dataString.getBytes(encoding);
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
final String fileName = "helloworld.xaction";
final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, "text/plain");
repo.createFile(null, new RepositoryFile.Builder(fileName).build(), content, null);
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testGetTreeWithFileTypeFilter.
@Test
public void testGetTreeWithFileTypeFilter() throws Exception {
RepositoryFileTree root = null;
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 });
RepositoryFile publicFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
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 SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
RepositoryFile newFile1 = repo.createFile(publicFolder.getId(), new RepositoryFile.Builder("helloworld.xaction").versioned(true).hidden(false).build(), content, null);
RepositoryFile newFile2 = repo.createFolder(publicFolder.getId(), new RepositoryFile.Builder("testFolder").versioned(false).hidden(false).folder(true).build(), null, null);
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*|FILES"));
assertFalse(root.getChildren().isEmpty());
assertEquals(1, root.getChildren().size());
assertEquals("helloworld.xaction", root.getChildren().get(0).getFile().getName());
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*"));
assertFalse(root.getChildren().isEmpty());
assertEquals(2, root.getChildren().size());
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*|FILES_FOLDERS"));
assertFalse(root.getChildren().isEmpty());
assertEquals(2, root.getChildren().size());
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, 1, "*|FOLDERS"));
assertFalse(root.getChildren().isEmpty());
assertEquals(1, root.getChildren().size());
assertEquals("testFolder", root.getChildren().get(0).getFile().getName());
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testFileCreator.
@Test
public void testFileCreator() 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, "helloworld.sample2", sampleString2, true, 1, true);
RepositoryFile.Builder builder = new RepositoryFile.Builder(newFile1);
builder.creatorId((String) newFile2.getId());
final String mimeType = "text/plain";
final String dataString = "Hello World!";
final String encoding = "UTF-8";
byte[] data = dataString.getBytes(encoding);
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
RepositoryFile updatedFile = repo.updateFile(builder.build(), content, null);
RepositoryFile reconstituedFile = repo.getFileById(updatedFile.getId());
assertEquals(reconstituedFile.getCreatorId(), newFile2.getId());
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryVersioningIT method testCreateVersionedFile.
@Test
public void testCreateVersionedFile() 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);
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, null);
assertTrue(newFile.isVersioned());
assertNotNull(newFile.getVersionId());
final String filePath = ServerRepositoryPaths.getUserHomeFolderPath(tenantAcme, USERNAME_SUZY) + RepositoryFile.SEPARATOR + fileName;
int versionCount = SimpleJcrTestUtils.getVersionCount(testJcrTemplate, filePath);
assertTrue(versionCount > 0);
repo.updateFile(newFile, content, null);
try {
repo.updateFile(newFile, content, null);
fail();
} catch (UnifiedRepositoryException e) {
// ignore
}
assertTrue(SimpleJcrTestUtils.getVersionCount(testJcrTemplate, filePath) > versionCount);
}
Aggregations