Test if a node owns a specific child - xpath

I would like to know if there is a way to check in my xpath if a node owns a specific child
to avoid all others nodes that don't meet the condition.
For instance i have this :
/Device/Report
And i want to filter, only 'Report' node that owns a node child which name is 'Client', so something like this :
/Device/Report::"Client"

you can have:
/Device/Report[Client]

Related

Using jscodeshift, Is there a way to extract a node path from a collection if there is only one node path?

I'm just getting started with writing CodeMods with jscodeshift. I noticed that the find method seems to always return a Collection. If there is only one node path in the collection is there an easy way to extract that node path?
For example, I can easily get the default export, of which there will only ever be one:
j(file.source).find(j.ExportDefaultDeclaration)
However, this returns a collection, which I then need to call forEach on to process the one and only node.
Is there a better way?
It looks like .get(0) will get the first Node Path in a Collection, so
j(file.source).find(j.ExportDefaultDeclaration).get(0);
would return the Node Path in question.

Google Drive API v3, is there a way to get a list of folders that are parents of a fileId?

In v2 it was possible to make a call to /files with the query fileId in children to get a list of DriveFile objects that were parents of the supplied file.
Now, it seems to be required to make a call to /files/:fileId?fields=parents, then make a separate call to /files/:parentId for each returned parent, possibly turning one call into a dozen.
Is this correct, and if so why? This is a huge performance hit to our app, so hopefully there's an undocumented method.
The query "'fileId' in children'" doesn't publicly exist (not documented/supported) in v2 either and I don't recall it ever existing. What does exist in V2 is the Parents collection which effectively answers the same question. In v3, to get the parents of a file you just get the child and ask for the parents field.
As for whether or not that is a performance hit, I don't think it is in practice. The Parents resource in v2 was very light to begin with, and other than the ID the only useful field was the 'isRoot' property. That you can calculate yourself by calling files/root up front to get the ID of the root folder for that user (just once and save it, it won't change for that user.)
If you need to get more information about the parents than just the IDs and are worried about the # of calls you have to make, use batching to fetch them. If you just have one parent, no need to batch (it's just overhead.) If you find that a file has multiple parents, create a batch request. That'll be sent as a single HTTP request/response and is handled very efficiently on the back end.
Point is, if you just need IDs, it's no worse than before. It's one call to get the parents of a file.
If you need more than IDs, it's at most 2 HTTP requests (outside really bizarre edge cases like 1000+ parents which would exceed the batch size :)
In V3 it is possible to list all children of a parent as it's explained here: https://developers.google.com/drive/v3/web/search-parameters
Example call:
https://www.googleapis.com/drive/v3/files?q=parents in '0Byho0qAdzabmVl8xcDR1S0pNY3c' of course replace spaces with %20, this will list all the files in the folder which has id='0Byho0qAdzabmVl8xcDR1S0pNY3c'
you just need to mention like below:
var request = service.Files.List();
request.Q = "('root' in parents)";
var FileListOfParentOnly = request.Execute();

Getting a level of an ALV tree node?

I created an ALV TREE report, using cl_gui_alv_tree, that has 3 levels. I'm also implementing an event handler for when he double clicks a node.
My problem is that I want to take some actions only when he double clicks a node that is a root node. The event 'node_double_click' gives a node_key, but that's the index of the displayed table. How could I achieve this?
The node ID is not an index, it's the ID you assigned to the node when adding it to the tree.
If possible, I'd suggest switching to CL_SALV_TREE - not only because it is documented
and supported by SAP, but also because it comes with some query methods that are quite handy. These methods are documented as well. You can use, for example, GET_NODE to retrieve a node by its ID and then use GET_PARENT to check whether the node in question is a top-level node or has a parent node it is attached to.
I created a pattern for myself, which i am using.
lv_parent1 = node_key.
while lv_parent1 ne go_Main_tree->C_VIRTUAL_ROOT_NODE.
CALL METHOD go_main_tree->get_parent
EXPORTING
i_node_key = lv_parent1
IMPORTING
e_parent_node_key = lv_parent1.
lv_hierlevel = lv_hierlevel + 1 .
ENDWHILE.
if lv_hierlevel > 2.
“ do what You want to do
endif.

can I manually set nodeId in neo4j graph on creation of a node?

I am developing a Facebook app in which I login with my Facebook account and Facebook returns me a JSON with my Facebook data as a JSON which I project into a User.class (me) like so:
#NodeEntity public class User{ #GraphId Long NodeId; String facebook_id; String facebook_name; }
and then I do a template.save(me);
this creates a node in the graph with 2 properties: Example: facebook_id="1000023453464" and name="John Smith" and the nodeId is set automatically by neo4j: Example nodeId:1.
The problem is that when I login again, it creates another node with same properties and nodeId:2.
I avoided this by checking if the user already exists in the graph before I saved it in the graph like so:
User retrieved_user = userRepository.findByFacebook_id(me.getFacebook_id());
if(retrieved_user != null) { me.setNodeId(retrieved_user.getNodeId()); }
Now, whenever I login, it doesn't create a duplicate node, it just updates the properties on the existing node.
But this is not what I'm looking for because when I import other data such as list of friends which can be about 1000 nodes to create, I don't want my app to check each individual node for his existence in the database before it saves it.
My point is: If there is a way in which I can manually set the nodeId before I template.save(me) the problem would be solved and my app would not have to check if the node exists in the graph. So if this is doable please help me achieve it. I tried for example the setHighId(215431323), but I get exceptions. I tried to #Override the IdGenerator, EntityIdGenerator, etc. but no success.
If there is another way in which I can save users without having to check if they exist and avoid duplicate nodes, please let me know.
I don't think there is a way to manually set the id. But even if there was, you still had to check if your node exists. Checking for the existence of a node is not that expensive anyway, it's just an index check, so it should be O(log n).

What is the correct way to remove a node from a tree managed by awesome_nested_set?

It is unclear how to correctly remove a node or set of nodes from a tree managed by awesome_nested_set.
Given a parent node and a child node, I've tried
parent.children.clear
however, this then leaves the tree in a state such that I can't re-add the child back to the parent object.
Do I have to explicitly null out all of the lft, rgt, and parent_id columns?
The OP wrote:
Further research shows that if I do child.update_attribute(:parent_id, nil) and reload both parent and child, that seems to work.

Resources