import org.simantics.db.layer0.variable.Variable;
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;
import org.simantics.utils.strings.AlphanumComparator;
public class DocumentServerUtils {
public static Variable getPossibleOtherConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
- Collection<VariableConnectionPointDescriptor> descs = conn.getConnectionPointDescriptors(graph, null);
+ Collection<VariableConnectionPointDescriptor> descs = conn.getConnection2().getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null);
if(descs.size() != 2) return null;
for(VariableConnectionPointDescriptor desc : descs) {
public static Variable getPossibleChildConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
- Collection<VariableConnectionPointDescriptor> descs = conn.getConnectionPointDescriptors(graph, null);
+ Collection<VariableConnectionPointDescriptor> descs = conn.getConnection2().getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null);
if(descs.size() != 2) return null;
DocumentationResource DOC = DocumentationResource.getInstance(graph);
public static Variable getPossibleCommandTriggerConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
- Collection<Variable> cpts = conn.getConnectionPoints(graph, null);
+ Collection<Variable> cpts = conn.getConnection2().getConnectionPoints(graph, connectionPoint.getParent(graph), null);
Variable result = null;
public static Collection<Variable> getPossibleOtherConnectionPoints(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException {
- Collection<Variable> cpts = conn.getConnectionPoints(graph, null);
+ Collection<Variable> cpts = conn.getConnection2().getConnectionPoints(graph, connectionPoint.getParent(graph), null);
if(cpts.size() < 2)
return Collections.emptyList();
public static String getId(ReadGraph graph, Variable node) throws DatabaseException {
- if(node == null) return "root";
- else {
- String uri = node.getURI(graph);
- int l = uri.lastIndexOf(ProxyChildVariable.CONTEXT_END);
- return uri.substring(l+4);
- }
+ if(node == null) return "root";
+ else {
+ String name = node.getName(graph);
+ if(ProxyChildVariable.CONTEXT_END.equals(name)) return "";
+ else {
+ String parentId = getId(graph, node.getParent(graph));
+ if(parentId.isEmpty()) return name;
+ else return parentId + "/" + name;
+ }
+
+ }
}
public static Collection<Variable> getAttributes(ReadGraph graph, DocumentationResource DOC, Variable variable) throws DatabaseException {
return variable.getProperties(graph, DOC.Document_AttributeRelation);
}
-
- public static class AttributesRequest extends VariableRead<Pair<JSONObject, Collection<Variable>>> {
+
+ public static class AttributesRequest extends VariableRead<JSONObject> {
public AttributesRequest(Variable variable) {
super(variable);
}
@Override
- public Pair<JSONObject,Collection<Variable>> perform(ReadGraph graph) throws DatabaseException {
- ArrayList<Variable> statics = new ArrayList<Variable>();
- DocumentationResource DOC = DocumentationResource.getInstance(graph);
-
- Variable primitives = variable.getProperty(graph, DOC.Properties_primitiveProperties);
- for(Variable property : primitives.getProperties(graph)) {
- statics.add(property);
- // NO SUPPORT FOR DYNAMICS AT THIS STAGE
- }
-
- JSONObject staticContent = computeStatic(graph, variable, statics);
-
- return new Pair<JSONObject, Collection<Variable>>(staticContent, Collections.emptyList());
-
+ public JSONObject perform(ReadGraph graph) throws DatabaseException {
+ DocumentProperties properties = variable.getPropertyValue(graph, "primitiveProperties");
+ return computeStatic(graph, variable, properties);
}
-
- JSONObject computeStatic(ReadGraph graph, Variable variable, ArrayList<Variable> statics) throws DatabaseException {
-
+
+ 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(Variable attrib : statics) {
- String name = attrib.getName(graph);
+
+ for(String name : statics.getKeys(graph, variable)) {
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);
- }
+ @SuppressWarnings("unchecked")
+ Map<String, Exception> exceptions = (Map<String, Exception>)statics.getValue(graph, variable, name);
+
+ List<String> errorList = object.getJSONField(NodeRequest.ERRORS);
+ if(errorList == null)
+ errorList = new ArrayList<>();
+
+ 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);
+ List<String> errorList = object.getJSONField(NodeRequest.ERRORS);
+ if(errorList == null)
+ errorList = new ArrayList<>(1);
+
+ String errorMessage = NodeRequestUtils.formatErrorMessage(name, t);
+ errorList.add(errorMessage);
+ object.addJSONField(NodeRequest.ERRORS, errorList);
}
}
return object;
-
+
}
-
+
}
public static Collection<Variable> getDynamicAttributes(ReadGraph graph, final DocumentationResource DOC, Variable variable) throws DatabaseException {
- Pair<JSONObject, Collection<Variable>> attribs = graph.syncRequest(new AttributesRequest(variable));
- return attribs.second;
+ return Collections.emptyList();
}
-
+
public static Variable getPossibleDocumentRootVariable(ReadGraph graph, Variable documentPart) throws DatabaseException {
- if(documentPart instanceof RootVariable) return documentPart;
+ if(ProxyChildVariable.CONTEXT_END.equals(documentPart.getName(graph))) return documentPart;
Variable parent = documentPart.getParent(graph);
if(parent == null) return null;
return getPossibleDocumentRootVariable(graph, parent);