Retrieve different labeled vertices, AND/OR between vertices properties - acl

below is my graph
g.addV('user').property('userId','user1').as('u1').
addV('user').property('userId','user2').as('u2').
addV('user').property('userId','user3').as('u3').
addV('group').property('groupId','group1').as('g1').
addV('group').property('groupId','group2').as('g2').
addV('group').property('groupId','group3').as('g3').
addV('folder').property('folderId','folder1').property('folderName','level1_1').property('description','level1_desc1').as('f1').
addV('folder').property('folderId','folder2').property('folderName','level2_2').property('description','level2_desc2').as('f2').
addV('folder').property('folderId','folder3').property('folderName','level3_3').property('description','level3_desc3').as('f3').
addV('object').property('objId','obj1').property('objTitle','objtitle1_1').property('description','o1_desc1').as('o1').
addV('object').property('objId','obj2').property('objTitle','objtitle2_2').property('description','o2_desc2').as('o2').
addV('object').property('objId','obj3').property('objTitle','objtitle3_3').property('description','o3_desc3').as('o3').
addE('in_folder').from('o1').to('f2').
addE('in_folder').from('o2').to('f3').
addE('in_folder').from('o1').to('f3').
addE('in_folder').from('f2').to('f1').
addE('in_folder').from('f3').to('f2').
addE('member_of').from('u1').to('g1').
addE('member_of').from('u2').to('g2').
addE('member_of').from('u3').to('g3').
addE('member_of').from('g3').to('g1').
addE('has_permission').from('g1').to('f1').
addE('has_permission').from('g1').to('f1').
addE('has_permission').from('g2').to('f2').
addE('has_permission').from('g3').to('f3').
addE('has_permission').from('u2').to('f1').iterate()
Two questions on the graph
#1 - how do i retrieve all the folders and objects where user have access in single query
g.V().has('user','userId','user1').emit().until(__.not(outE('member_of'))).repeat(out('member_of')).outE('has_permission').inV().as('f').inE('in_folder').outV().as('a').select('a','f').range(1,20)
but this query results in each object and its folder vertex instead my expectation is to receive like a search results considering folders and objects as search result ?
#2 - get object vertices's based object vertex property OR folder vertex property in hierarchy, meaning all the objects are reachable based on folder vertex property at any level.
i have written below query which returns results when both folder and object vertex property values matches.
g.V().has('user','userId','user1').emit().until(__.not(outE('member_of'))).repeat(out('member_of')).outE('has_permission').inV().has('folderName',textContains('level1')).inE('in').outV().has('objTitle',textContains('objtitle3')).as('o').select('o').valueMap('objTitle','objId').dedup().range(1,20)
How can i do OR between object and folder vertex properties and how to do OR on multiple properties of folder and object vertices's ?

#1 - how do i retrieve all the folders and objects where user have access in single query
g.V().has('user','userId','user1').
repeat(out('member_of')).emit().
until(__.not(outE('member_of'))).
out('has_permission').dedup().
union(
// all folders
identity(),
// all sub-folders and objects
__.repeat(__.in('in_folder')).emit().until(__.not(inE('in_folder')))
).dedup()

Related

GoogleDrive API - how to get folder hierarchy from file in python

I using the following code to get all the files in my drive
files_list = service_v3.files().list(corpora='drive',
supportsAllDrives=True,
includeItemsFromAllDrives=True,
driveId=drive['id'],
spaces='drive',
fields='*').execute()
Now in each file I have a parent:
files_list[0]['parents']
How can I get data about this parent?
I've tried to use
service_v2.parents().list(fileId='xxx')
but it does not return much data.
You need to implement three steps:
List all files of interest - as you are already doing with files_list = service_v3.files().list
Loop through the list results or pick a certain file (as you are doing with files_list[0]) and retrieve its parents (as you are doing), e.g. parent = files_list[0].get('parents')
Use the method service_v3.files().get(fileId=parents[0], fields="*").execute() to retrieve the information about the parent by its Id
I recommend you to use the Try It API of the list and get methods in order to get a better understanding of the results those methods give you.
Also, please note that service_v2.parents().list(fileId='xxx') is using the old version of the Drive API (v2), and in any case - if you want to retrieve a file with a specified ID, the correct method to do it is getopposed to list.

Google Drive Windows App to/from fileId - items with same names, and multiple parents

I'm trying to translate from a Google Drive link on the web (well, the fileId anyway) to the Windows Google Drive app's path on the hard disk, and back again.
It would be helpful if there was something in the API for this (eg produce a path excluding the C:\Users\[User]\Google Drive\ from a file/folder ID, and vice versa), but there isn't.
So far I do:
Windows Path to ID: get the first folder of the path and (starting from the root) look for a matching folder, then repeat until finished (possibly with a file name). PROBLEM: Items can be called the same thing, whether files or folders or combinations of both, which is tricky in Windows. The app adds a number ' (1)' and so on, which I have to catch, but how can I know which item ID is the correct one? I believe that numbering is based on date but I'm not sure. So I can potentially end up with multiple results and no way to tell which is which.
ID to Windows Path: take the name of the file/folder from the ID, then keep adding the parent folder(s) until I build up a path. PROBLEM: same as 1 above, if there are multiple matching items then I can't tell which I should use when translating to Windows. PROBLEM: Apparently items in Google Drive can have more than one parent. Not sure how that works in the Windows app.
Can anyone help me fine tune how I do this, or tell me the exact details of how the Google Drive app does it? Code is welcome but not required, and I in turn can provide the code I use if needed.
I'm not sure if I fully understand the question, but I try to smack an answer anyway:
1/ assuming you have a Windows path,
C:\Users\User\Google Drive\myfile.ext
you create a file with a similar path on GooDrive iterating your path's tokens
recursively creating a tree structure on GooDrive. If the tree nodes (folders/files) exist, return ID's, otherwise create the objects. The main difference in GooDrive is that title query may return multiple objects (list of folders/files). Bad luck, you either use the first one or quit with an error.
global path = "C:\Users\User\Google Drive\myfile.ext"
createTree(String path) {
rootFolderId = create your root or use GooDrive root
fileId = iterate (firstToken(path, "\"), rootFolderId);
}
iterate(title, parentFolderId) {
ID (or multiple IDs) = search for title in parentFolderId
if (multiple IDs exist)
BOOM - report error and quit or use the first one
if (token not last) {
if (single ID for title exists) {
folderId = found ID
} else {
folderId = createFolder with title and parentFolderId metadata
}
iterate(nextToken(path, "\"), folderId)
} else { (last token represent file)
if (single ID for title exists) {
fileId = found ID
} else {
fileId = createFile with title and parentFolderId metadata
}
return fileId
}
}
You did not specify the language, but in case it is Java, you can see similar procedure here in the createTree() method (it is Android code, so there is a lot of Android specific goo there, sorry)
2/ assuming you have a Google Drive fileId, you construct the Windows path with this pseudocode (going from bottom up to the root). Again, you may have multiple parents you have to deal with (error or multiple paths with links to a single object)
String path = fileId's title
while () {
parentID = get fileId's parent
if (multiple parentIDs exist)
BOOM - report error and quit or construct multiple paths
(multiple paths would represent file/folder links)
if (parentID not valid or parentId's title not valid)
break
path = parentID's title + "\" + path
if (parentID's title is your root)
break
}
One more thing: You say "Folders and files can be called the same thing..."
In GooDrive, look at the MIME type, there is a specific MIME type "application/vnd.google-apps.folder" that tells you it is a folder. Also, any parentId metadata represents folder, since files can't be parents.
Good Luck

Using the Android Api, how to retrieve entire file path?

Given a com.box.androidlib.Utils.BoxUtils.BoxFolder object, I would like to recurse the object’s parent folders to retrieve the path from the root.
I would hope to do this with something like the below code, where currentBoxFolder is retrieved using Box.getAccountTree(…) as done in the Browse class of the included sample code. However, the getParentFolder returns null (for non-root folders for which I expect it to be non-null).
I figure that it might be possible to populate the parent variable by modfiying the source to fetch additional attributes, but I was able to. Any suggestions?
List<BoxFolder> parentDirs = new ArrayList<BoxFolder>();
parentDirs.add(new BoxFolderEntry(currentBoxFolder));
BoxFolder parent = currentBoxFolder.getParentFolder();
while(parent != null)
{
parentDirs.add(0, parent);
parent = parent.getParentFolder();
}
If the end goal is for you to know the path from the root to a folder, there are a couple ways to solve this:
OPTION 1:
Maintain your own map of folder_ids and folder_names as your application fetches them. Presumably, in order to get the id of currentBoxFolder, you would have had to do getAccountTree() calls on all its parents before-hand. So if that's the case, you could maintain 2 maps:
Folder ID => Parent Folder ID
Folder ID => Folder Name
From those two maps, you should always be able to get the path from the root.
OPTION 2:
There are 2 params that can be added to the Box.getAccountTree() method that will allow you to know the path:
"show_path_ids"
"show_path_names"
These params haven't been documented yet (we'll do that), but they will cause BoxFolder.getFolderPathIds() and BoxFolder.getFolderPath() to return values such as:
"/5435/4363"
"/blue folder/green folder"

Finding a path to a File given it's ID

I get a FileList with:
String q = "title contains '"+query+"' and trashed = false";
FileList list = drive.files().list().setQ(q).execute();
I want to find a path to each matching file in the FileList.
I understand that the same File can appear in multiple Folders.
From what I've found, the only way to create a path for a File is to repeatedly call:
drive.files().get(id).execute()
and then choose an ID from that File's parents list, walking up the tree until the root is reached.
While navigating the tree, I could just choose the first parent, or do a "BFS" until I find the root.
Is this really the only way to find a path to a File, or have I missed some part of the API?
If this is the only way, can Folders have multiple parents, too, making cycles possible?
(/a/b/c => /a/b/c/b/c/b/c... if b has parents a & c)?
Since folders (which are simply special Drive File with a specific MIME type) can have multiple parents, I would recommend the BFS approach and making sure you handle loops.
For the stop condition, you can save the root folder's ID that you can retrieve from the about.rootFolderId attribute.

Remove array from sharedObject

I have a sharedObject that contains several arrays:
sharedUploadObject:
[[4453] , [4454] , [4842] , [4999]];
How do i remove One of the array from the sharedObject?
Lets say i remove array [4453] from the object. So i end up with :
[[4454] , [4842] , [4999]];
First of all read the old value from the Shared object and Modified it in your code (as local variable) and modified new value just update the shared object.
you will find out the new value in the shared object.
Please provide me the your property name and shared object or give me your code snapshot. I will give you code for the same...
Please refer given below link
Click Here for Details
Take data in your application and clar shredobject and one again put your new data to shared object....