use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testGetDatasources.
@Test
public void testGetDatasources() throws Exception {
final String fileId = "456";
final String databasesFolderPath = "/etc/pdi/databases";
final String dotKdb = ".kdb";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
doReturn(reservedChars).when(repo).getReservedChars();
// stub out get file to update
RepositoryFile f = new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).path(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb).build();
doReturn(f).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
final String EXP_HOST_NAME = "hello";
DataNode rootNode = new DataNode("databaseMeta");
// required
rootNode.setProperty("TYPE", "Hypersonic");
rootNode.setProperty("HOST_NAME", EXP_HOST_NAME);
// required
rootNode.addNode("attributes");
doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(eq(fileId), eq(NodeRepositoryFileData.class));
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
IDatabaseConnection conn = datasourceMgmtService.getDatasourceByName(EXP_DBMETA_NAME);
assertEquals(EXP_HOST_NAME, conn.getHostname());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryWebServiceTest method testFileMetadata.
public void testFileMetadata() throws Exception {
final RepositoryFile testfile = repository.createFile(repository.getFile("/etc").getId(), new RepositoryFile.Builder("testfile").build(), new SimpleRepositoryFileData(new ByteArrayInputStream("test".getBytes()), "UTF-8", "text/plain"), null);
// CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure the repository is setup correctly
assertNotNull(testfile);
assertNotNull(testfile.getId());
final Map<String, Serializable> fileMetadata = repository.getFileMetadata(testfile.getId());
assertNotNull(fileMetadata);
assertEquals(0, fileMetadata.size());
}
final List<StringKeyStringValueDto> metadata = new ArrayList<StringKeyStringValueDto>();
metadata.add(new StringKeyStringValueDto("sample key", "sample value"));
metadata.add(new StringKeyStringValueDto("complex key?", "\"an even more 'complex' value\"! {and them some}"));
repositoryWS.setFileMetadata(testfile.getId().toString(), metadata);
// CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure the repository sees the metadata
assertNotNull(testfile);
assertNotNull(testfile.getId());
final Map<String, Serializable> fileMetadata = repository.getFileMetadata(testfile.getId());
assertNotNull(fileMetadata);
assertEquals(2, fileMetadata.size());
}
// CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure we can get the same metadata back via the web service
final List<StringKeyStringValueDto> fileMetadata = repositoryWS.getFileMetadata(testfile.getId().toString());
assertNotNull(fileMetadata);
assertEquals(2, fileMetadata.size());
assertTrue(metadata.get(0).equals(fileMetadata.get(0)) || metadata.get(0).equals(fileMetadata.get(1)));
assertTrue(metadata.get(1).equals(fileMetadata.get(0)) || metadata.get(1).equals(fileMetadata.get(1)));
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class MockUnifiedRepository method createFolder.
@Override
public RepositoryFile createFolder(final Serializable parentFolderId, final RepositoryFile file, final RepositoryFileAcl acl, final String versionMessage) {
Validate.isTrue(file.isFolder());
Validate.isTrue(!file.isVersioned());
if (!hasAccess(parentFolderId, EnumSet.of(WRITE))) {
throw new AccessDeniedException("access denied");
}
FileRecord parentFolder = idManager.getFileById(parentFolderId);
RepositoryFile fileFromRepo = new RepositoryFile.Builder(file).path(parentFolder.getPath() + (parentFolder.getPath().endsWith(RepositoryFile.SEPARATOR) ? "" : RepositoryFile.SEPARATOR) + file.getName()).title(findTitle(file)).description(findDesc(file)).build();
RepositoryFileAcl aclFromRepo = new RepositoryFileAcl.Builder(acl).build();
FileRecord fileRecord = new FileRecord(fileFromRepo, null, aclFromRepo, new HashMap<String, Serializable>());
idManager.register(fileRecord);
parentFolder.addChild(fileRecord);
return fileRecord.getFile();
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class MockUnifiedRepository method getTree.
@Override
public RepositoryFileTree getTree(final String path, final int depth, final String filter, final boolean showHidden) {
FileRecord r = root.getFileRecord(path);
RepositoryFile rootFile = r.getFile();
if ((!showHidden && rootFile.isHidden()) || rootFile.isAclNode()) {
return null;
}
List<RepositoryFileTree> children;
if (depth != 0) {
children = new ArrayList<RepositoryFileTree>();
if (rootFile.isFolder()) {
List<RepositoryFile> childrenTmp = getChildren(rootFile.getId(), filter);
for (RepositoryFile child : childrenTmp) {
RepositoryFileTree repositoryFileTree = getTree(child.getPath(), depth - 1, filter, showHidden);
if (repositoryFileTree != null) {
children.add(repositoryFileTree);
}
}
}
Collections.sort(children);
} else {
children = null;
}
return new RepositoryFileTree(rootFile, children);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class MockUnifiedRepository method init.
protected void init() {
RepositoryFile rootFolder = new RepositoryFile.Builder("").path(RepositoryFile.SEPARATOR).folder(true).build();
RepositoryFileAcl rootFolderAcl = new RepositoryFileAcl.Builder(root()).entriesInheriting(false).ace(everyone(), READ).build();
root = new FileRecord(rootFolder, rootFolderAcl);
idManager.register(root);
RepositoryFile publicFolder = new RepositoryFile.Builder("public").path(RepositoryFile.SEPARATOR + "public").folder(true).build();
RepositoryFileAcl publicFolderAcl = new RepositoryFileAcl.Builder(root()).entriesInheriting(false).ace(everyone(), READ, WRITE).build();
FileRecord pub = new FileRecord(publicFolder, publicFolderAcl);
root.addChild(pub);
idManager.register(pub);
RepositoryFile etcFolder = new RepositoryFile.Builder("etc").path(RepositoryFile.SEPARATOR + "etc").folder(true).build();
RepositoryFileAcl etcFolderAcl = new RepositoryFileAcl.Builder(root()).entriesInheriting(true).build();
FileRecord etc = new FileRecord(etcFolder, etcFolderAcl);
root.addChild(etc);
idManager.register(etc);
}
Aggregations