Say that I have an index named "user". How do I get all the nodes belonging to that index using Neo4j-Java Api?
I tried the code below
val nodeIndex = getNodeIndex("article").get
val nodes = nodeIndex.getGraphDatabase().getAllNodes()
But, I got all the nodes present in the db. How do I solve this?
You should use "get" or "query" on the nodeIndex, like:
IndexHits<Node> allArticles = nodeIndex.query( "*:*" );
... do stuff ...
allArticles.close();
or
Node myArticle = nodeIndex.get( "name", "MyArticle" ).getSingle();
What you did above was to regardless of the index, get the graph database and return all nodes.
Related
I understand how the JCR API works and is used in Magnolia. I want to get the result as JSON object
My Node object has a hierarchical structure(each subnode has type mgnl:category)
test_1
test_a
test_b
test_c
test_c1
test_d
If I use
var session = context.getJCRSession("category");
Iterable<Node> categoryItems = NodeUtil.collectAllChildren(
session.getNode(nodePath),
new NodeTypePredicate("mgnl:category"));
List<String> result = new ArrayList<>();
for (Node node : categoryItems) {
result.add(node.getName());
}
I get just a list of children like: [test_a, test_b, test_c, text_c1, test_d].
How can I check if a child has a subnode? Because I need [test_a, test_b, test_c: {text_c1}, test_d].
I think recursion will do here... but I need info about if a node has a subnode...
You can check if a node has a subnode by hasNodes() method. You can refer more JCR Node APIs here https://developer.adobe.com/experience-manager/reference-materials/spec/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html
Thanks
Below is the snapshot of my API XML response
<Plaintiff>
<PlaintiffName>SEB B.A.
</PlaintiffName>
<PlaintiffName>SEB??
</PlaintiffName>
</Plaintiff>
I want to extract all the PlaintiffName under the Plaintiff node.
Code:
String caseResponseText = response.getResponseText()
def xmlResult = new XmlSlurper().parseText(caseResponseText)
def plaintiff = xmlResult.Case.Plaintiff.PlaintiffName[0].text()
The above one i got the result of first plaintiff name / second plaintiff name. But how should i looping thru this node and get all the palintiff value dynamically?
Because response may have only one plaintiff or more than one, so I need to parse dynamically and get all the values thru looping
Simply loop over the nodes:
def plaintiffs = xmlResult.Case.Plaintiff.PlaintiffName
for (plaintiff in plaintiffs) {
// do something with plaintiff
}
I have created a test that adds xyz1 , xyz2, xyz3 ....xyz(n) element , what is presented as a list on page. I need to be sure that among these names exists element titled " xyz3" (or titled different , what I will define)
My idea is to build list/ array /collection that will gather all values of web element and then I need to write a method that will looking for my defined "xyz3" among these values collected in list.
My web element:
#FindBy(how = How.XPATH, using = "//div[#id='_field']")
public List <WebElement> listOfNames;
My attempts in creating a list :
LList<WebElement> myElements = createEvalTemplateLocators.getListOfNames();
boolean temp1;
for(WebElement e : myElements) {
System.out.println(e.getText() + "");
}
for(WebElement e : myElements) {
temp1 = e.getText().contains("temp1");
if (temp1==true) System.out.println("hurray temp1 is on page ");
else {System.out.println("something gone wrong with temp1");}
}
RESULT IN CONSOLE:
I am not able to create better locator- more appropiate that will not 'take' element next to it...
Moreover I want to know if on the list exist 'temp1' one at least only, info message about each entity is not neccessary....
I don't have any better ideas for my test, in the future I would like to use asserts for this case..
I am beginner :( and I am learning on my own mostly, so could anybody help me with this case ?
( Greetings from Baltic Sea for All :))
I have the following code:
Vertex v = g.addV().property("valueStr", "3").next();
Vertex v2 = g.addV().property("valueStr", "4").next();
Vertex v3 = g.addV().property("valueStr", "5").next();
Edge e = g.V(v.id()).as("a").V(v2.id()).as("b").addE("anEdge").from("a").to("b").property("value", "4").as("e").next();
Edge e2 = g.V(v.id()).as("a").V(v3.id()).as("b").addE("anEdge").from("a").to("b").property("value", "5").as("e").next();
List vertices1 = g.V().match(
__.as("a").hasId(v.id()).outE("anEdge").inV().hasId(v2.id()).as("b"),
__.as("a").hasId(v.id()).outE("anEdge").inV().hasId(v3.id()).as("c")).toList();
System.out.println(vertices1);
List vertices2 = g.V().match(
__.as("a").hasId(v.id()).outE("anEdge").inV().hasId(v2.id()).as("b"),
__.as("a").hasId(v.id()).outE("anEdge").inV().hasId(v3.id()).as("c")).select("a","b").toList();
System.out.println(vertices2);
List vertices3 = g.V().match(
__.as("a").hasId(v.id()).outE("anEdge").inV().hasId(v2.id()).as("b"),
__.as("a").hasId(v.id()).outE("anEdge").inV().hasId(v3.id()).as("c")).select("a").toList();
System.out.println(vertices3);
It is basically node a connecting to b, and node a connecting to c.
I am doing a match query over this subgraph and each time I return a subset of the elements that were matched..
Here are the outputs:
[{a=v[20], b=v[22], c=v[24]}]
[{a=v[20], b=v[22]}]
[v[20]]
In the first two cases I get a List of Maps.. In the last case I get a List.
How is it possible for the last case to make it also a List of Maps or [{a=v[20}]? I know I can do a hack with select("a","a") but it seems there should be a cleaner way.
Where does the documentation explain in which cases I will be getting a List of Vertices/Edges, a Map or a List of Maps etc?
Thanks!
In place of select("a") use project("a").by(select("a"))
I'm new in Graph databases, and i can't resolve problem listed below.
How i can implement OrientDb query like
TRAVERSE OUT() FROM (SELECT FROM SomeClassThatExtendsV WHERE name = 'SomeUsefulName')
If i will execute this query via OrientDb java api :
new OSQLSynchQuery<Vertex>("TRAVERSE OUT() FROM (SELECT FROM SomeClassThatExtendsV WHERE name = 'SomeUsefulName')");
The result will be all child verticies with child and child and so on.
I need to implement same logic using gremlin api, that's what i have:
GraphQuery query = framedGraph.getBaseGraph().query().has("#class", "SomeClassThatExtendsV").has("name", "SomeUsefulName");
OrientVertex vertex = (OrientVertex) query.vertices().iterator().next();
Tree tree = new Tree();
new GremlinPipeline(vertex).out().tree(tree).loop("TestLoop", loopBundle -> false).iterate();
Iterator it = tree.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
}
As result i have NullPointerException.
java.lang.NullPointerException
at com.tinkerpop.pipes.branch.LoopPipe.getLoops(LoopPipe.java:75)
at com.tinkerpop.pipes.branch.LoopPipe.processNextStart(LoopPipe.java:49)
at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89)
at com.tinkerpop.pipes.util.Pipeline.next(Pipeline.java:115)
at com.tinkerpop.pipes.util.PipeHelper.iterate(PipeHelper.java:35)
at com.tinkerpop.gremlin.java.GremlinPipeline.iterate(GremlinPipeline.java:1542)
Maybe i'm doing something wrong in when in GremlinPipeline?
At this point i don't know full graph structure and i need to get something like tree, or something like result in OrientDb studio.
Some update here, i tried to use loop but as i told before i can't setup count of loops and due to this my test application stuck because in some vertices i have in edge and out edge.
Could somebody help me with this problem?