]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequestDynamic.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 / NodeRequestDynamic.java
1 package org.simantics.document.server.request;
2
3 import gnu.trove.map.hash.THashMap;
4
5 import java.util.ArrayList;
6 import java.util.Collection;
7 import java.util.Collections;
8 import java.util.List;
9 import java.util.Map;
10
11 import org.simantics.db.ReadGraph;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.request.VariableRead;
14 import org.simantics.db.layer0.variable.Variable;
15 import org.simantics.document.base.ontology.DocumentationResource;
16 import org.simantics.document.server.DocumentServerUtils;
17 import org.simantics.structural.stubs.StructuralResource2;
18
19 class NodeRequestDynamic extends VariableRead<Map<String,Object>> {
20
21         public NodeRequestDynamic(Variable node) {
22                 super(node);
23         }
24
25         @Override
26         public Map<String,Object> perform(ReadGraph graph) throws DatabaseException {
27
28                 long s = System.nanoTime();
29
30                 StructuralResource2.getInstance(graph);
31                 DocumentationResource DOC = DocumentationResource.getInstance(graph);
32
33                 Collection<Variable> attributes = DocumentServerUtils.getDynamicAttributes(graph, DOC, variable);
34                 if(attributes.isEmpty()) return Collections.emptyMap();
35                 
36                 Map<String,Object> result = new THashMap<String,Object>();
37                 for(Variable attrib : attributes) {
38                         String name = attrib.getName(graph);
39                         try {
40                             Object value = DocumentServerUtils.getValue(graph, attrib);
41                             result.put(name, value);
42                         } catch (Throwable t) {
43                 @SuppressWarnings("unchecked")
44                 List<String> errorList = (List<String>) result.get(NodeRequest.ERRORS);
45                 if(errorList == null)
46                     errorList = new ArrayList<String>();
47                 
48                     String errorMessage = NodeRequestUtils.formatErrorMessage(name, t);                
49                 
50                 errorList.add(errorMessage);
51                 result.put(NodeRequest.ERRORS, errorList);
52                         }
53
54                 }
55
56         if(DocumentRequest.PROFILE) {
57                 long dura = System.nanoTime()-s;
58                 System.err.println("NodeRequestDynamic " + System.identityHashCode(this) + " " + variable.getURI(graph) + " in " + 1e-6*dura + "ms." + result);
59         }
60
61                 return result;
62
63         }               
64
65 }