X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FStandardGraphPropertyVariable.java;h=c9214e398c69577da69642536c8b932e67e5bc69;hb=15af8a20abe8b2ba24b52c9da8bce6c92351dc43;hp=9b0befc78442fa47d02022ca9e8863f01d1b5647;hpb=e6e555f4c17e686c44d0681a01eab17d0ec6f2aa;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java index 9b0befc78..c9214e398 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java @@ -11,6 +11,7 @@ import org.simantics.databoard.accessor.reference.ChildReference; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.binding.impl.ObjectVariantBinding; import org.simantics.databoard.type.Datatype; +import org.simantics.db.DevelopmentKeys; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -19,8 +20,8 @@ import org.simantics.db.common.validation.L0Validations; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.DatatypeNotFoundException; import org.simantics.db.exception.ValidationException; -import org.simantics.db.exception.VariableException; import org.simantics.db.layer0.exception.InvalidVariableException; +import org.simantics.db.layer0.exception.MissingVariableException; import org.simantics.db.layer0.exception.MissingVariableValueException; import org.simantics.db.layer0.exception.PendingVariableException; import org.simantics.db.layer0.function.All; @@ -35,12 +36,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class StandardGraphPropertyVariable extends AbstractPropertyVariable { + private static final Logger LOGGER = LoggerFactory.getLogger(StandardGraphPropertyVariable.class); - - protected static final PropertyInfo NO_PROPERTY = new PropertyInfo(null, null, - false, Collections. emptySet(), null, null, null, null, null, null, - Collections.> emptyMap(), - null, false); + + protected static final PropertyInfo NO_PROPERTY = new PropertyInfo(null, null, true, + false, false, Collections. emptySet(), null, null, null, null, null, null, + Collections.> emptyMap(), + null, false); final public Variable parent; final public Resource parentResource; @@ -99,11 +101,15 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { @Override public String getPossibleLabel(ReadGraph graph) throws DatabaseException { + if (property.predicate == null) + return null; return graph.getPossibleRelatedValue2(property.predicate, graph.getService(Layer0.class).HasLabel, parent, Bindings.STRING); } @Override public String getLabel(ReadGraph graph) throws DatabaseException { + if (property.predicate == null) + throw new NoPredicateResourceException("No predicate resource for property " + getName(graph)); return graph.getRelatedValue2(property.predicate, graph.getService(Layer0.class).HasLabel, parent, Bindings.STRING); } @@ -122,10 +128,14 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { public T getValue(ReadGraph graph) throws DatabaseException { if(Development.DEVELOPMENT) { - String error = L0Validations.checkValueType(graph, parentResource, property.predicate); - if(error != null) { - LOGGER.error(error); - //throw new ValidationException(error); + if(Development.getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) { + if (property.predicate != null) { + String error = L0Validations.checkValueType(graph, parentResource, property.predicate); + if(error != null) { + LOGGER.error(error); + throw new ValidationException(error); + } + } } } @@ -141,10 +151,14 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { return getValue(graph); if(Development.DEVELOPMENT) { - String error = L0Validations.checkValueType(graph, parentResource, property.predicate); - if(error != null) { - LOGGER.error(error); - throw new ValidationException(error); + if(Development.getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) { + if (property.predicate != null) { + String error = L0Validations.checkValueType(graph, parentResource, property.predicate); + if(error != null) { + LOGGER.error(error); + throw new ValidationException(error); + } + } } } @@ -166,13 +180,10 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { if(represents == null) throw new InvalidVariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ")."); return represents; -// return graph.getSingleObject(parentResource, property.predicate); } @Override public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException { -// if(parentResource == null) return null; -// return graph.getPossibleObject(parentResource, property.predicate); return represents; } @@ -180,10 +191,14 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException { if(Development.DEVELOPMENT) { - String error = L0Validations.checkValueType(graph, parentResource, property.predicate); - if(error != null) { - LOGGER.error(error); - //throw new ValidationException(error); + if(Development.getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) { + if (property.predicate != null) { + String error = L0Validations.checkValueType(graph, parentResource, property.predicate); + if(error != null) { + LOGGER.error(error); + throw new ValidationException(error); + } + } } } @@ -195,10 +210,14 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { public void setValue(WriteGraph graph, Object value) throws DatabaseException { if(Development.DEVELOPMENT) { - String error = L0Validations.checkValueType(graph, parentResource, property.predicate); - if(error != null) { - LOGGER.error(error); - throw new ValidationException(error); + if(Development.getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) { + if (property.predicate != null) { + String error = L0Validations.checkValueType(graph, parentResource, property.predicate); + if(error != null) { + LOGGER.error(error); + throw new ValidationException(error); + } + } } } @@ -218,16 +237,6 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { @Override public Datatype getDatatype(ReadGraph graph) throws DatabaseException { -//<<<<<<< .mine -// -// Binding binding = getPossibleDefaultBinding(graph); -// if(binding != null) return binding.type(); -// -// Variant vt = getVariantValue(graph); -// binding = vt.getBinding(); -// if(binding == null) throw new DatabaseException("No binding in Variant with value " + vt.getValue()); -// return binding.type(); -//======= Datatype type; try { type = getValueAccessor(graph).getDatatype(graph, this); @@ -244,7 +253,6 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { } return type; -//>>>>>>> .r30794 } @@ -329,11 +337,15 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { @Override public Variable getPredicate(ReadGraph graph) throws DatabaseException { + if (property.predicate == null) + throw new MissingVariableException("No predicate for property " + getName(graph)); return Variables.getVariable(graph, graph.getURI(property.predicate)); } @Override public Resource getPredicateResource(ReadGraph graph) throws DatabaseException { + if (property.predicate == null) + throw new NoPredicateResourceException("No predicate for property " + getName(graph)); return property.predicate; }