use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryJaxwsWebServiceIT method testEverything.
@Test
public void testEverything() throws Exception {
login(sysAdminUserName, systemTenant, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", new String[] { tenantAdminRoleName });
logout();
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
logger.info("getFile");
JcrRepositoryDumpToFile dumpToFile = new JcrRepositoryDumpToFile(testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername, "c:/build/testrepo_9", Mode.CUSTOM);
dumpToFile.execute();
RepositoryFile f = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
assertNotNull(f.getId());
assertEquals(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY), f.getPath());
assertNotNull(f.getCreatedDate());
assertEquals(USERNAME_SUZY, f.getName());
assertTrue(f.isFolder());
logger.info("getFileById");
assertNotNull(repo.getFileById(f.getId()));
logger.info("createFolder");
RepositoryFile folder1 = repo.createFolder(f.getId(), new RepositoryFile.Builder("folder1").folder(true).build(), null);
assertNotNull(folder1);
assertEquals("folder1", folder1.getName());
assertNotNull(folder1.getId());
NodeRepositoryFileData data = makeNodeRepositoryFileData1();
logger.info("createFile");
RepositoryFile file1 = repo.createFile(folder1.getId(), new RepositoryFile.Builder("file1.whatever").versioned(true).build(), data, null);
assertNotNull(file1);
assertNotNull(file1.getId());
logger.info("getDataForRead");
NodeRepositoryFileData file1Data = repo.getDataForRead(file1.getId(), NodeRepositoryFileData.class);
assertNotNull(file1Data);
assertEquals("testNode", file1Data.getNode().getName());
assertEquals("hello world", file1Data.getNode().getProperty("prop1").getString());
assertEquals(false, file1Data.getNode().getProperty("prop2").getBoolean());
assertEquals(DataPropertyType.BOOLEAN, file1Data.getNode().getProperty("prop2").getType());
assertEquals(12L, file1Data.getNode().getProperty("prop3").getLong());
logger.info("createFile (binary)");
SimpleRepositoryFileData simpleData = new SimpleRepositoryFileData(new ByteArrayInputStream("Hello World!".getBytes("UTF-8")), "UTF-8", "text/plain");
RepositoryFile simpleFile = repo.createFile(folder1.getId(), new RepositoryFile.Builder("file2.whatever").versioned(true).build(), simpleData, null);
Serializable simpleVersion = simpleFile.getVersionId();
logger.info("getDataForRead (binary)");
SimpleRepositoryFileData simpleFileData = repo.getDataForRead(simpleFile.getId(), SimpleRepositoryFileData.class);
assertNotNull(simpleFileData);
assertEquals("Hello World!", IOUtils.toString(simpleFileData.getInputStream(), simpleFileData.getEncoding()));
assertEquals("text/plain", simpleFileData.getMimeType());
assertEquals("UTF-8", simpleFileData.getEncoding());
logger.info("updateFile (binary)");
simpleData = new SimpleRepositoryFileData(new ByteArrayInputStream("Ciao World!".getBytes("UTF-8")), "UTF-8", "text/plain");
simpleFile = repo.updateFile(simpleFile, simpleData, null);
assertNotNull(simpleFile.getLastModifiedDate());
logger.info("getDataForRead (binary)");
simpleFileData = repo.getDataForRead(simpleFile.getId(), SimpleRepositoryFileData.class);
assertNotNull(simpleFileData);
assertEquals("Ciao World!", IOUtils.toString(simpleFileData.getInputStream(), simpleFileData.getEncoding()));
logger.info("getDataForReadAtVersion (binary)");
simpleFileData = repo.getDataAtVersionForRead(simpleFile.getId(), simpleVersion, SimpleRepositoryFileData.class);
assertNotNull(simpleFileData);
assertEquals("Hello World!", IOUtils.toString(simpleFileData.getInputStream(), simpleFileData.getEncoding()));
logger.info("getChildren");
List<RepositoryFile> folder1Children = repo.getChildren(new RepositoryRequest(String.valueOf(folder1.getId()), true, -1, null));
assertNotNull(folder1Children);
assertEquals(2, folder1Children.size());
logger.info("getChildren");
List<RepositoryFile> folder1ChildrenFiltered = repo.getChildren(new RepositoryRequest(String.valueOf(folder1.getId()), true, -1, "*.sample"));
assertNotNull(folder1ChildrenFiltered);
assertEquals(0, folder1ChildrenFiltered.size());
logger.info("getDeletedFiles");
assertEquals(0, repo.getDeletedFiles().size());
logger.info("deleteFile");
repo.deleteFile(file1.getId(), null);
logger.info("getDeletedFiles");
assertEquals(0, repo.getDeletedFiles(folder1.getPath(), "*.sample").size());
logger.info("hasAccess");
assertFalse(repo.hasAccess("/pentaho", EnumSet.of(RepositoryFilePermission.WRITE)));
logger.info("getEffectiveAces");
List<RepositoryFileAce> folder1EffectiveAces = repo.getEffectiveAces(folder1.getId());
assertEquals(1, folder1EffectiveAces.size());
logger.info("getAcl");
RepositoryFileAcl folder1Acl = repo.getAcl(folder1.getId());
assertEquals(USERNAME_SUZY, folder1Acl.getOwner().getName());
logger.info("updateAcl");
userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
RepositoryFileAcl updatedFolder1Acl = repo.updateAcl(new RepositoryFileAcl.Builder(folder1Acl).entriesInheriting(false).ace(userNameUtils.getPrincipleId(tenantAcme, USERNAME_TIFFANY), RepositoryFileSid.Type.USER, RepositoryFilePermission.ALL).build());
assertNotNull(updatedFolder1Acl);
assertEquals(1, updatedFolder1Acl.getAces().size());
logger.info("lockFile");
assertFalse(file1.isLocked());
repo.lockFile(file1.getId(), "I locked this file");
logger.info("canUnlockFile");
assertTrue(repo.canUnlockFile(file1.getId()));
logger.info("unlockFile");
repo.unlockFile(file1.getId());
logger.info("moveFile");
repo.moveFile(file1.getId(), ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/folder1", null);
logger.info("copyFile");
repo.copyFile(file1.getId(), ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/folder1/fileB.whatever", null);
RepositoryFile copiedFile = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/folder1/fileB.whatever");
copiedFile = repo.updateFile(copiedFile, data, null);
logger.info("getVersionSummaries");
List<VersionSummary> versionSummaries = repo.getVersionSummaries(file1.getId());
assertNotNull(versionSummaries);
// copy doesn't increase version number
assertTrue(versionSummaries.size() >= 1);
assertEquals(USERNAME_SUZY, versionSummaries.get(0).getAuthor());
logger.info("getVersionSummary");
VersionSummary versionSummary = repo.getVersionSummary(file1.getId(), null);
assertNotNull(versionSummary);
assertNotNull(versionSummary.getId());
logger.info("getFileAtVersion");
RepositoryFile file1AtVersion = repo.getFileAtVersion(file1.getId(), versionSummary.getId());
assertNotNull(file1AtVersion);
assertEquals(versionSummary.getId(), file1AtVersion.getVersionId());
logger.info("getTree");
RepositoryFileTree tree = repo.getTree(new RepositoryRequest(ClientRepositoryPaths.getRootFolderPath(), true, -1, null));
assertNotNull(tree.getFile().getId());
logger.info("getDataForReadInBatch");
List<NodeRepositoryFileData> result = repo.getDataForReadInBatch(Arrays.asList(file1, copiedFile), NodeRepositoryFileData.class);
assertEquals(2, result.size());
logger.info("getVersionSummaryInBatch");
List<VersionSummary> vResult = repo.getVersionSummaryInBatch(Arrays.asList(file1, simpleFile));
assertEquals(2, vResult.size());
logger.info("getReservedChars");
assertFalse(repo.getReservedChars().isEmpty());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-platform by pentaho.
the class JcrRepositoryFileUtils method getTreeByNode.
/**
* Returns a RepositoryFileTree for a given node. This method will be called recursively for each folder it processes.
* The childNodeFilter is a filter used directly by the JCR jar to filter node names. Since JCR does not know a folder
* from a file (that is our construct), it is not capable of filtering out filenames but not folder names. Therefore,
* this logic will create two sets of children nodes. The <code>filteredChildrenSet</code> keeps the child nodes that
* satisfied the childNodeFilter. The <code> childrenFolderSet</code> keeps a set of all child folder nodes regardless
* of the value of the filter. We use the <code>childrenFolderSet</code> to know what folders to traverse, but we use
* the <code>filteredChildrenSet </code> to determine what actual files to include in the returned tree.
* <p>
* Just because we process a folder node does not necessarily mean the folder will be reported in the tree. It must
* first find a file that satisfies the criteria of the <code>childNodeFilter</code> mask. A file meeting the criteria
* may be any number of folders down the repository structure, so the <code>foundFiltered</code> MutableBoolean tells
* the caller if a file was found, at any level, meeting that criteria.
*
* @param session
* The current session in progress
* @param pentahoJcrConstants
* @param pathConversionHelper
* @param lockHelper
* @param fileNode
* The node which will serve as the root of the tree
* @param depth
* how many levels do we go down.
* @param childNodeFilter
* The filter sent to JCR to retrieve defining which files are in scope
* @param showHidden
* Whether to return hidden files
* @param accessVoterManager
* See IRepositoryAccessVoterManager
* @param types
* <code>FILE_TYPE_FILTERS</code> Types of files to return including FILES, FOLDERS, FILES_FOLDERS
* @param foundFiltered
* This <code>MutableBoolean</code> will tell the caller if there was a file encountered, (at any level up to
* the depth), that was compliant with the childNodeFilter. This will determine if this node, (and its
* children), should be discarded because there are no relevant files.
* @return A RepositoryFileTree representing the entire tree at and below the given node that complies with file
* filtering and other parameters of the tree request.
* @throws RepositoryException
*/
private static RepositoryFileTree getTreeByNode(final Session session, final PentahoJcrConstants pentahoJcrConstants, final IPathConversionHelper pathConversionHelper, final ILockHelper lockHelper, final Node fileNode, final int depth, final String childNodeFilter, final boolean showHidden, IRepositoryAccessVoterManager accessVoterManager, RepositoryRequest.FILES_TYPE_FILTER types, MutableBoolean foundFiltered, final boolean includeSystemFolders, final String rootPath) throws RepositoryException {
RepositoryFile rootFile = nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode, false, null);
if ((!showHidden && rootFile.isHidden()) || rootFile.isAclNode() || (!accessVoterManager.hasAccess(rootFile, RepositoryFilePermission.READ, JcrRepositoryFileAclUtils.getAcl(session, pentahoJcrConstants, rootFile.getId()), PentahoSessionHolder.getSession()))) {
return null;
}
List<RepositoryFileTree> children;
HashSet<Node> childrenFolderSet;
// to go)
if (depth != 0) {
children = new ArrayList<RepositoryFileTree>();
int numberOfPasses = childNodeFilter != null && !childNodeFilter.equals("*") ? 2 : 1;
// get Filtered Children set
HashSet<Node> filteredChildrenSet;
filteredChildrenSet = new HashSet<Node>();
NodeIterator childNodes = fileNode.getNodes(childNodeFilter);
while (childNodes.hasNext()) {
Node childNode = childNodes.nextNode();
boolean pentahoFolder = isPentahoFolder(pentahoJcrConstants, childNode);
if (!(!pentahoFolder && types == RepositoryRequest.FILES_TYPE_FILTER.FOLDERS || pentahoFolder && types == RepositoryRequest.FILES_TYPE_FILTER.FILES)) {
// do not to include (skip) system_folder children that are at root level if includeSystemFolders is false
if (!(!includeSystemFolders && (rootPath.equals(childNode.getParent().getPath()) && isSystemFolder(session, childNode)))) {
filteredChildrenSet.add(childNode);
}
}
}
// Now get the unfiltered folder set not already in Filtered Set
childrenFolderSet = new HashSet<Node>();
if (numberOfPasses == 2) {
if (isPentahoFolder(pentahoJcrConstants, fileNode)) {
childNodes = fileNode.getNodes();
while (childNodes.hasNext()) {
Node childNode = childNodes.nextNode();
boolean pentahoFolder = isPentahoFolder(pentahoJcrConstants, childNode);
if (pentahoFolder) {
childrenFolderSet.add(childNode);
}
}
}
}
// tree
for (Node childNode : childrenFolderSet) {
checkNodeForTree(childNode, children, session, pentahoJcrConstants, pathConversionHelper, childNodeFilter, lockHelper, depth, showHidden, accessVoterManager, types, foundFiltered, false, includeSystemFolders, rootPath);
}
// And finally, add Children in filtered
for (Node childNode : filteredChildrenSet) {
foundFiltered.setValue(true);
checkNodeForTree(childNode, children, session, pentahoJcrConstants, pathConversionHelper, childNodeFilter, lockHelper, depth, showHidden, accessVoterManager, types, foundFiltered, true, includeSystemFolders, rootPath);
}
children.removeIf(Objects::isNull);
Collections.sort(children);
} else {
children = null;
}
return new RepositoryFileTree(rootFile, children);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method getTree.
private RepositoryFileTree getTree(final File file, final int depth, final String childNodeFilter, RepositoryRequest.FILES_TYPE_FILTER types) {
RepositoryFile rootFile = internalGetFile(file);
List<RepositoryFileTree> children;
if (depth != 0) {
children = new ArrayList<RepositoryFileTree>();
if (file.isDirectory()) {
File[] childrenArray = file.listFiles();
for (File child : childrenArray) {
if (child.isFile()) {
if (types == RepositoryRequest.FILES_TYPE_FILTER.FILES_FOLDERS || types == RepositoryRequest.FILES_TYPE_FILTER.FILES) {
children.add(new RepositoryFileTree(internalGetFile(child), new ArrayList<>()));
}
continue;
}
RepositoryFileTree repositoryChildFileTree = getTree(child, depth - 1, childNodeFilter, types);
if (repositoryChildFileTree != null) {
children.add(repositoryChildFileTree);
}
}
}
Collections.sort(children);
} else {
children = null;
}
return new RepositoryFileTree(rootFile, children);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-platform by pentaho.
the class RepositoryFileTreeAdapter method marshal.
@Override
public RepositoryFileTreeDto marshal(final RepositoryFileTree v) {
RepositoryFileTreeDto treeDto = new RepositoryFileTreeDto();
RepositoryFileDto file = RepositoryFileAdapter.toFileDto(v, membersSet, exclude, includeAcls);
if (file != null) {
treeDto.setFile(RepositoryFileAdapter.toFileDto(v, membersSet, exclude, includeAcls));
List<RepositoryFileTreeDto> children = null;
if (v.getChildren() != null) {
children = new ArrayList<RepositoryFileTreeDto>();
for (RepositoryFileTree child : v.getChildren()) {
RepositoryFileTreeDto childTreeDto = marshal(child);
if (childTreeDto != null) {
children.add(childTreeDto);
}
}
}
treeDto.setChildren(children);
return treeDto;
} else {
return null;
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-platform by pentaho.
the class UnifiedRepositoryTestUtils method addChild.
/**
* Helper method to construct a {@link RepositoryFileTree} from a list of paths.
*/
private static void addChild(final RepositoryFileTree.Builder root, final boolean leafIsFolder, final String[] pathSegments, final int currentSegmentIndex) {
int currentSegmentIdx = currentSegmentIndex;
for (RepositoryFileTree.Builder child : root.getChildren()) {
if (child.getFile().isFolder() && child.getFile().getName().equals(pathSegments[currentSegmentIdx])) {
if (currentSegmentIdx < pathSegments.length - 1) {
addChild(child, leafIsFolder, pathSegments, ++currentSegmentIdx);
return;
}
}
}
String reconstructedPath = root.getFile().getPath() + RepositoryFile.SEPARATOR + StringUtils.join(Arrays.copyOfRange(pathSegments, 0, currentSegmentIdx + 1), RepositoryFile.SEPARATOR);
RepositoryFile file = null;
if ((currentSegmentIdx < pathSegments.length - 1) || (currentSegmentIdx == pathSegments.length - 1 && leafIsFolder)) {
file = makeFolderObject(reconstructedPath, true);
} else {
file = makeFileObject(reconstructedPath, true);
}
RepositoryFileTree.Builder newChild = new RepositoryFileTree.Builder(file);
root.child(newChild);
if (currentSegmentIdx < pathSegments.length - 1) {
addChild(newChild, leafIsFolder, pathSegments, ++currentSegmentIdx);
}
}
Aggregations