- public Pair<Collection<Variable>,Collection<Variable>> perform(ReadGraph graph) throws DatabaseException {
- ArrayList<Variable> statics = new ArrayList<Variable>();
- ArrayList<Variable> dynamics = new ArrayList<Variable>();
- DocumentationResource DOC = DocumentationResource.getInstance(graph);
- for(Variable property : getAttributes(graph, DOC, variable)) {
- Boolean defaultProperty = property.getPossiblePropertyValue(graph, "default");
- if(defaultProperty != null && defaultProperty) {
-// System.err.println("" + property.getURI(graph) + " is default");
- continue;
- }
-// else {
-// System.err.println("" + property.getURI(graph) + " is not default");
-// }
- Boolean dynamicProperty = property.getPossiblePropertyValue(graph, DOC.Document_AttributeRelation_dynamic);
- if(dynamicProperty != null && dynamicProperty) dynamics.add(property);
- else statics.add(property);
- }
- return new Pair<Collection<Variable>, Collection<Variable>>(statics, dynamics);
+ public JSONObject perform(ReadGraph graph) throws DatabaseException {
+
+ DocumentationResource DOC = DocumentationResource.getInstance(graph);
+
+ DocumentProperties properties = variable.getPropertyValue(graph, DOC.Properties_primitiveProperties);
+
+ return computeStatic(graph, variable, properties);
+
+ }
+
+ JSONObject computeStatic(ReadGraph graph, Variable variable, DocumentProperties statics) throws DatabaseException {
+
+ JSONObject base = graph.syncRequest(new org.simantics.document.server.request.DefaultFields(variable));
+ JSONObject object = base.clone();
+
+ for(String name : statics.getKeys(graph, variable)) {
+ try {
+ if (name.equals(NodeRequest.PROPERTY_VALUE_EXCEPTIONS)) {
+ @SuppressWarnings("unchecked")
+ Map<String, Exception> exceptions = (Map<String, Exception>)statics.getValue(graph, variable, name);//(Map<String, Exception>)DocumentServerUtils.getValue(graph, attrib);
+
+ List<String> errorList = object.getJSONField(NodeRequest.ERRORS);
+ if(errorList == null)
+ errorList = new ArrayList<String>();
+
+ for (Map.Entry<String, Exception> entry : exceptions.entrySet()) {
+ String errorMessage = NodeRequestUtils.formatErrorMessage(entry.getKey(), entry.getValue());
+ errorList.add(errorMessage);
+ }
+ object.addJSONField(NodeRequest.ERRORS, errorList);
+
+ } else {
+ object.addJSONField(name, statics.getValue(graph, variable, name));
+ }
+ } catch (Throwable t) {
+ List<String> errorList = object.getJSONField(NodeRequest.ERRORS);
+ if(errorList == null)
+ errorList = new ArrayList<String>();
+
+ String errorMessage = NodeRequestUtils.formatErrorMessage(name, t);
+
+ errorList.add(errorMessage);
+ object.addJSONField(NodeRequest.ERRORS, errorList);
+ }
+
+ }
+
+ return object;
+