X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2FFunctions.java;h=13444fdba944701e2454fea1174283d89045f8ca;hp=6ccffbe973ddecdeef07e4a8bcbdaebe3acf52e2;hb=4f87cc11bc1e4a56860f278798e41834ea1fbb3f;hpb=b4d40b271019ac79aa3003551ec89f1e15aed950 diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java index 6ccffbe97..13444fdba 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java @@ -62,6 +62,7 @@ import org.simantics.document.server.io.CommandContextImpl; import org.simantics.document.server.io.CommandContextMutable; import org.simantics.document.server.io.CommandResult; import org.simantics.document.server.io.IConsole; +import org.simantics.document.server.request.NodeRequest; import org.simantics.document.server.request.ServerSCLHandlerValueRequest; import org.simantics.document.server.request.ServerSCLValueRequest; import org.simantics.document.server.serverResponse.ServerResponse; @@ -117,7 +118,35 @@ public class Functions { @SCLValue(type = "VariableMap") public static VariableMap primitiveProperties = new VariableMapImpl() { + private void storePropertyValueAndExceptions(ReadGraph graph, Variable parent, String name, Variable property, Map map) { + try { + Object value = property.getValue(graph); + map.put(name, new ConstantPropertyVariable(parent, name, value, null)); + } catch (DatabaseException e) { + Variable propertyExceptions = map.get(NodeRequest.PROPERTY_VALUE_EXCEPTIONS); + Map exceptionMap; + if (propertyExceptions == null) { + exceptionMap = new TreeMap(); + propertyExceptions = new ConstantPropertyVariable(parent, NodeRequest.PROPERTY_VALUE_EXCEPTIONS, exceptionMap, null); + map.put(NodeRequest.PROPERTY_VALUE_EXCEPTIONS, propertyExceptions); + } else { + try { + exceptionMap = propertyExceptions.getValue(graph); + } catch (DatabaseException e1) { + Logger.defaultLogError(e1); + return; + } + } + String label = name; + try { + label = property.getLabel(graph); + } catch (DatabaseException e2) { + } + exceptionMap.put(label, e); + } + } + @Override public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException { return All.getStandardPropertyDomainPropertyVariableFromValue(graph, context, name); @@ -126,6 +155,8 @@ public class Functions { @Override public Map getVariables(final ReadGraph graph, Variable context, Map map) throws DatabaseException { + if(map == null) map = new HashMap(); + Variable parent = context.getParent(graph); DocumentationResource DOC = DocumentationResource.getInstance(graph); @@ -136,9 +167,8 @@ public class Functions { for(Variable property : procedural.getProperties(graph/*, DocumentationResource.URIs.Document_AttributeRelation*/)) { if(property instanceof StandardAssertedGraphPropertyVariable) { StandardAssertedGraphPropertyVariable ass = (StandardAssertedGraphPropertyVariable)property; - if("datadefinitions".equals(ass.property.name) || "commands".equals(ass.property.name) || "pollingFunction".equals(ass.property.name)) { - Object value = property.getPossibleValue(graph); - if(value != null) map.put(ass.property.name, new ConstantPropertyVariable(parent, ass.property.name, value, null)); + if("dataDefinitions".equals(ass.property.name) || "commands".equals(ass.property.name) || "pollingFunction".equals(ass.property.name)) { + storePropertyValueAndExceptions(graph, parent, ass.property.name, property, map); } continue; } @@ -146,56 +176,47 @@ public class Functions { if(predicate != null) { PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate)); if(info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) { - Variable prop = parent.getProperty(graph, predicate); - Object value = prop.getValue(graph); - if(map == null) map = new HashMap(); - map.put(info.name, new ConstantPropertyVariable(parent, info.name, value, null)); + Variable prop = parent.getProperty(graph, predicate); + storePropertyValueAndExceptions(graph, parent, info.name, prop, map); } } } } else { + Resource parentRes = parent.getRepresents(graph); + { + Variable prop = new StandardGraphPropertyVariable(graph, parent, DOC.Properties_commands); + storePropertyValueAndExceptions(graph, parent, "commands", prop, map); + } + + if (graph.getPossibleObject(parentRes, DOC.Properties_dataDefinitions) != null) { + Variable prop = new StandardGraphPropertyVariable(graph, parent, DOC.Properties_dataDefinitions); + storePropertyValueAndExceptions(graph, parent, "dataDefinitions", prop, map); + } + DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); PrimitivePropertyStatementsProcedure foo = new PrimitivePropertyStatementsProcedure(); - dqs.forEachDirectPersistentStatement(graph, parent.getRepresents(graph), foo); + dqs.forEachDirectPersistentStatement(graph, parentRes, foo); for(Statement stm : foo.result) { Resource predicate = stm.getPredicate(); PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate)); if(info.isHasProperty && info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) { - if(map == null) map = new HashMap(); - Variable prop = new StandardGraphPropertyVariable(graph, parent, predicate); - Object value = prop.getValue(graph); - map.put(info.name, new ConstantPropertyVariable(parent, info.name, value, null)); + Variable prop = new StandardGraphPropertyVariable(graph, parent, predicate); + storePropertyValueAndExceptions(graph, parent, info.name, prop, map); } else { Resource definition = graph.getPossibleObject(predicate, DOC.Document_definesAttributeRelation); if(definition != null) { - if(map == null) map = new HashMap(); - try { - PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition)); - Variable prop = new StandardGraphPropertyVariable(graph, parent, definition); - map.put(info2.name, new PrimitiveValueVariable(parent, info2.name, prop)); - } catch (DatabaseException e) { - Logger.defaultLogError(e); - } + PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition)); + Variable prop = new StandardGraphPropertyVariable(graph, parent, definition); + map.put(info2.name, new PrimitiveValueVariable(parent, info2.name, prop)); } } } - - Variable prop = new StandardGraphPropertyVariable(graph, parent, DOC.Properties_dataDefinitions); - Object value = prop.getPossibleValue(graph); - if(value != null) map.put("dataDefinitions", new ConstantPropertyVariable(parent, "dataDefinitions", value, null)); - prop = new StandardGraphPropertyVariable(graph, parent, DOC.Properties_commands); - value = prop.getPossibleValue(graph); - if(value != null) map.put("commands", new ConstantPropertyVariable(parent, "commands", value, null)); - } - - if(map == null) return Collections.emptyMap(); - return map; }