-package org.simantics.document.server.request;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.request.VariableRead;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.document.server.JSONObject;\r
-\r
-public class NodeRequest extends VariableRead<JSONObject> {\r
- \r
- public static String ERRORS = "Errors";\r
-\r
- public NodeRequest(Variable node) {\r
- super(node);\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public JSONObject perform(ReadGraph graph) throws DatabaseException {\r
- \r
- long s = System.nanoTime();\r
-\r
- JSONObject staticContent = graph.syncRequest(new NodeRequestStatic(variable));\r
- Map<String,Object> dynamicContent = graph.syncRequest(new NodeRequestDynamic(variable));\r
- \r
- if(dynamicContent.isEmpty()) {\r
- return staticContent;\r
- }\r
- \r
- JSONObject result = staticContent.clone();\r
- result.add(dynamicContent);\r
-\r
- if(dynamicContent.containsKey(ERRORS) || staticContent.getJSONField(ERRORS) != null) {\r
- ArrayList<String> errorList = new ArrayList<String>();\r
- \r
- if(dynamicContent.containsKey(ERRORS))\r
- errorList.addAll((List<String>)dynamicContent.get(ERRORS));\r
- \r
- if(staticContent.getJSONField(ERRORS) != null)\r
- errorList.addAll((List<String>)staticContent.getJSONField(ERRORS));\r
- \r
- result.addJSONField(ERRORS, errorList);\r
- }\r
- \r
- if(DocumentRequest.PROFILE) {\r
- long dura = System.nanoTime()-s;\r
- System.err.println("NodeRequest " + System.identityHashCode(this) + " " + variable.getURI(graph) + " in " + 1e-6*dura + "ms." + result);\r
- }\r
- \r
- return result;\r
-\r
- } \r
-\r
+package org.simantics.document.server.request;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.VariableRead;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.document.server.DocumentServerUtils.AttributesRequest;
+import org.simantics.document.server.JSONObject;
+import org.simantics.utils.datastructures.Pair;
+
+public class NodeRequest extends VariableRead<JSONObject> {
+
+ public static final String ERRORS = "Errors";
+ public static final String PROPERTY_VALUE_EXCEPTIONS = "_PropertyValueExceptions";
+
+ public NodeRequest(Variable node) {
+ super(node);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public JSONObject perform(ReadGraph graph) throws DatabaseException {
+
+ long s = System.nanoTime();
+
+ Pair<JSONObject, Collection<Variable>> attribs = graph.syncRequest(new AttributesRequest(variable));
+
+ JSONObject staticContent = attribs.first;
+ if(attribs.second.isEmpty()) {
+
+ if(DocumentRequest.PROFILE) {
+ long dura = System.nanoTime()-s;
+ if(dura > DocumentRequest.PROFILE_THRESHOLD_NODEREQUEST * 1e3) {
+ System.err.println("NodeRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
+ }
+ }
+
+ return staticContent;
+ }
+
+ Map<String,Object> dynamicContent = graph.syncRequest(new NodeRequestDynamic(variable));
+ if(dynamicContent.isEmpty()) {
+ return staticContent;
+ }
+
+ JSONObject result = staticContent.clone();
+ result.add(dynamicContent);
+
+ if(dynamicContent.containsKey(ERRORS) || staticContent.getJSONField(ERRORS) != null) {
+ ArrayList<String> errorList = new ArrayList<>();
+
+ if(dynamicContent.containsKey(ERRORS))
+ errorList.addAll((List<String>)dynamicContent.get(ERRORS));
+
+ if(staticContent.getJSONField(ERRORS) != null)
+ errorList.addAll((List<String>)staticContent.getJSONField(ERRORS));
+
+ result.addJSONField(ERRORS, errorList);
+ }
+
+ if(DocumentRequest.PROFILE) {
+ long dura = System.nanoTime()-s;
+ if(dura > DocumentRequest.PROFILE_THRESHOLD_NODEREQUEST * 1e3) {
+ System.err.println("NodeRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
+ }
+ }
+
+ return result;
+
+ }
+
}
\ No newline at end of file