]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodesRequest2.java
Do not override jersey in p2.site pom.xml as release/1.43.0 is jdk8
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / request / NodesRequest2.java
1 package org.simantics.document.server.request;
2
3 import gnu.trove.set.hash.THashSet;
4
5 import java.util.Collections;
6 import java.util.Set;
7
8 import org.simantics.databoard.Bindings;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.request.VariableRead;
13 import org.simantics.db.layer0.variable.Variable;
14 import org.simantics.document.base.ontology.DocumentationResource;
15
16 public class NodesRequest2 extends VariableRead<Set<Variable>> {
17
18     public NodesRequest2(Variable var) {
19         super(var);
20         }
21
22         @Override
23         public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
24             
25                 DocumentationResource DOC = DocumentationResource.getInstance(graph);
26
27                 Resource type = variable.getPossibleType(graph);
28                 if(type == null) return Collections.emptySet();
29                 
30                 if(!graph.isInheritedFrom(type, DOC.Components_Component)) return Collections.emptySet();
31
32                 Boolean pathExists = variable.getPossiblePropertyValue(graph, DOC.Properties_pathExists, Bindings.BOOLEAN);
33                 if(pathExists != null && !pathExists) return Collections.emptySet();
34
35                 if(graph.isInheritedFrom(type, DOC.Components_PrimitiveComponent)) {
36                         return Collections.singleton(variable);
37                 } else {
38                         Set<Variable> result = new THashSet<Variable>();
39                         for(Variable child : variable.getChildren(graph)) {
40                                 Set<Variable> nodes = graph.syncRequest(new NodesRequest2(child));
41                                 result.addAll(nodes);
42                         }
43                 
44                         return result;
45                 }
46
47         }
48
49 }