import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import org.simantics.db.layer0.variable.Variables;
import org.simantics.document.base.ontology.DocumentationResource;
import org.simantics.document.server.Functions.RootVariable;
+import org.simantics.document.server.request.NodeRequest;
+import org.simantics.document.server.request.NodeRequestUtils;
import org.simantics.structural2.variables.Connection;
import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
import org.simantics.utils.datastructures.Pair;
SortedMap<String, Variable> childMap = new TreeMap<String, Variable>(AlphanumComparator.COMPARATOR);
- for(Variable property : variable.getProperties(graph)) {
- Collection<String> classifications = property.getPossiblePropertyValue(graph, Variables.CLASSIFICATIONS);
- if(classifications != null) {
- if(classifications.contains(DocumentationResource.URIs.Document_ChildRelation)) {
- Resource cp = property.getPossiblePredicateResource(graph);
- String i = graph.getRelatedValue(cp, DOC.Document_ChildRelation_ordinal, Bindings.STRING);
-
- Connection conn = property.getValue(graph);
- Variable childConnectionPoint = DocumentServerUtils.getPossibleOtherConnectionPoint(graph, property, conn);
- if(childConnectionPoint != null) {
- childMap.put(i, childConnectionPoint.getParent(graph));
- }
- } else if (DOC.Relations_partN.equals(property.getPossiblePredicateResource(graph))) {
- Connection conn = property.getValue(graph);
-
- for (Variable childConnectionPoint : DocumentServerUtils.getOtherConnectionPoints(graph, property, conn)) {
- Variable child = childConnectionPoint.getParent(graph);
- String i = findManualOrdinal(graph, child);
- if (i == null) {
- i = "0";
- }
- childMap.put(i, child);
- }
+ for(Variable property : variable.getProperties(graph, DocumentationResource.URIs.Document_ChildRelation)) {
+ Resource cp = property.getPossiblePredicateResource(graph);
+ String i = graph.getRelatedValue(cp, DOC.Document_ChildRelation_ordinal, Bindings.STRING);
+ Connection conn = property.getValue(graph);
+ Variable childConnectionPoint = DocumentServerUtils.getPossibleOtherConnectionPoint(graph, property, conn);
+ if(childConnectionPoint != null) {
+ childMap.put(i, childConnectionPoint.getParent(graph));
+ }
+ }
+
+ Variable property = variable.getPossibleProperty(graph, "partN");
+ if(property != null) {
+ Connection conn = property.getValue(graph);
+ for (Variable childConnectionPoint : DocumentServerUtils.getOtherConnectionPoints(graph, property, conn)) {
+ Variable child = childConnectionPoint.getParent(graph);
+ String i = findManualOrdinal(graph, child);
+ if (i == null) {
+ i = "0";
}
+ childMap.put(i, child);
}
}
+
return childMap.values();
}
return null;
}
+
+ public static Variable getPossibleChildConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
+
+ Collection<VariableConnectionPointDescriptor> descs = conn.getConnectionPointDescriptors(graph, null);
+ if(descs.size() != 2) return null;
+
+ DocumentationResource DOC = DocumentationResource.getInstance(graph);
+
+ for(VariableConnectionPointDescriptor desc : descs) {
+ Resource res = desc.getConnectionPointResource(graph);
+ if(graph.isInstanceOf(res, DOC.Relations_parentRelation)) continue;
+ //if(desc.isFlattenedFrom(graph, connectionPoint)) continue;
+ return desc.getVariable(graph);
+ }
+
+ return null;
+
+ }
public static Collection<Variable> getOtherConnectionPoints(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
}
- public static class DocumentValue extends VariableRead<Object> {
-
- public DocumentValue(Variable variable) {
- super(variable);
- }
-
- @Override
- public Object perform(ReadGraph graph) throws DatabaseException {
- return variable.getValue(graph);
- }
-
- @Override
- public String toString() {
- return "DocumentValue[" + variable + "]";
- }
-
- }
-
public static Object getValue(ReadGraph graph, Variable attrib) throws DatabaseException {
return graph.syncRequest(new DocumentValue(attrib));
}
return variable.getProperties(graph, DOC.Document_AttributeRelation);
}
- static class AttributesRequest extends VariableRead<Pair<Collection<Variable>, Collection<Variable>>> {
+ public static class AttributesRequest extends VariableRead<Pair<JSONObject, Collection<Variable>>> {
public AttributesRequest(Variable variable) {
super(variable);
}
@Override
- public Pair<Collection<Variable>,Collection<Variable>> perform(ReadGraph graph) throws DatabaseException {
+ public Pair<JSONObject,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);
+
+ Variable primitives = variable.getProperty(graph, DOC.Properties_primitiveProperties);
+ for(Variable property : primitives.getProperties(graph)) {
+ statics.add(property);
+ // NO SUPPORT FOR DYNAMICS AT THIS STAGE
}
- return new Pair<Collection<Variable>, Collection<Variable>>(statics, dynamics);
+
+ JSONObject staticContent = computeStatic(graph, variable, statics);
+
+ return new Pair<JSONObject, Collection<Variable>>(staticContent, Collections.emptyList());
+
+ }
+
+ JSONObject computeStatic(ReadGraph graph, Variable variable, ArrayList<Variable> statics) throws DatabaseException {
+
+ JSONObject base = graph.syncRequest(new org.simantics.document.server.request.DefaultFields(variable));
+ JSONObject object = base.clone();
+
+ for(Variable attrib : statics) {
+ String name = attrib.getName(graph);
+ try {
+ if (name.equals(NodeRequest.PROPERTY_VALUE_EXCEPTIONS)) {
+ @SuppressWarnings("unchecked")
+ Map<String, Exception> exceptions = (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 value = DocumentServerUtils.getValue(graph, attrib);
+ object.addJSONField(name, value);
+ }
+ } 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;
+
}
}
-
- public static Collection<Variable> getStaticAttributes(ReadGraph graph, DocumentationResource DOC, Variable variable) throws DatabaseException {
- Pair<Collection<Variable>, Collection<Variable>> attribs = graph.syncRequest(new AttributesRequest(variable));
- return attribs.first;
- }
public static Collection<Variable> getDynamicAttributes(ReadGraph graph, final DocumentationResource DOC, Variable variable) throws DatabaseException {
- Pair<Collection<Variable>, Collection<Variable>> attribs = graph.syncRequest(new AttributesRequest(variable));
+ Pair<JSONObject, Collection<Variable>> attribs = graph.syncRequest(new AttributesRequest(variable));
return attribs.second;
}