return graph.getValue2(object, variable);
} else {
for (Pair<PropertyInfo, Resource> assertion : assertions.values()) {
- if (assertion.first.predicate.equals(variable.property.predicate)) {
+ if (assertion.first.predicate.equals(variable.getPossiblePredicateResource(graph))) {
return graph.getValue2(assertion.second, variable);
}
}
return graph.getValue2(object, variable, binding);
} else {
for (Pair<PropertyInfo, Resource> assertion : assertions.values()) {
- if (assertion.first.predicate.equals(variable.property.predicate)) {
+ if (assertion.first.predicate.equals(variable.getPossiblePredicateResource(graph))) {
return graph.getValue2(assertion.second, variable, binding);
}
}
if(property instanceof StandardGraphPropertyVariable) {
StandardGraphPropertyVariable variable = (StandardGraphPropertyVariable)property;
if (variable.parentResource != null) {
- Statement stm = graph.getPossibleStatement(variable.parentResource, variable.property.predicate);
- return stm != null && stm.isAsserted(variable.parentResource);
+ Resource predicate = variable.getPossiblePredicateResource(graph);
+ if (predicate != null) {
+ Statement stm = graph.getPossibleStatement(variable.parentResource, predicate);
+ return stm != null && stm.isAsserted(variable.parentResource);
+ }
}
}
return Boolean.FALSE;
throw new InvalidVariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ").");
try {
- return graph.getRelatedValue2(variable.parentResource, variable.property.predicate, variable);
+ return graph.getRelatedValue2(variable.parentResource, variable.getPredicateResource(graph), variable);
} catch (NoSingleResultException e) {
throw new MissingVariableValueException(variable.getPossibleURI(graph), e);
} catch (DoesNotContainValueException e) {
if (variable.parentResource == null)
throw new MissingVariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ").", context.getPossibleRepresents(graph));
+
try {
- return graph.getRelatedValue2(variable.parentResource, variable.property.predicate, variable);
+ return graph.getRelatedValue2(variable.parentResource, variable.getPredicateResource(graph), variable);
} catch (NoSingleResultException e) {
throw new MissingVariableValueException(variable.getPossibleURI(graph), e);
} catch (DoesNotContainValueException e) {
--- /dev/null
+package org.simantics.db.layer0.variable;
+
+import org.simantics.db.Resource;
+import org.simantics.db.exception.AssumptionException;
+
+public class NoPredicateResourceException extends AssumptionException {
+
+ private static final long serialVersionUID = -374051341908276908L;
+
+ public NoPredicateResourceException(Throwable cause) {
+ super(cause);
+ }
+
+ public NoPredicateResourceException(String message, Throwable cause, Resource... rs) {
+ super(message, cause, rs);
+ }
+
+ public NoPredicateResourceException(String message, Resource... resources) {
+ super(message, resources);
+ }
+
+ public NoPredicateResourceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public NoPredicateResourceException(String message, int... args) {
+ super(message, args);
+ }
+
+ public NoPredicateResourceException(String message) {
+ super(message);
+ }
+
+}
import org.simantics.db.exception.DatatypeNotFoundException;
import org.simantics.db.exception.ValidationException;
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;
@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);
}
if(Development.DEVELOPMENT) {
if(Development.<Boolean>getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) {
- String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
- if(error != null) {
- LOGGER.error(error);
- throw new ValidationException(error);
+ if (property.predicate != null) {
+ String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
+ if(error != null) {
+ LOGGER.error(error);
+ throw new ValidationException(error);
+ }
}
}
}
if(Development.DEVELOPMENT) {
if(Development.<Boolean>getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) {
- String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
- if(error != null) {
- LOGGER.error(error);
- throw new ValidationException(error);
+ if (property.predicate != null) {
+ String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
+ if(error != null) {
+ LOGGER.error(error);
+ throw new ValidationException(error);
+ }
}
}
}
if(Development.DEVELOPMENT) {
if(Development.<Boolean>getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) {
- String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
- if(error != null) {
- LOGGER.error(error);
- throw new ValidationException(error);
+ if (property.predicate != null) {
+ String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
+ if(error != null) {
+ LOGGER.error(error);
+ throw new ValidationException(error);
+ }
}
}
}
if(Development.DEVELOPMENT) {
if(Development.<Boolean>getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) {
- String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
- if(error != null) {
- LOGGER.error(error);
- throw new ValidationException(error);
+ if (property.predicate != null) {
+ String error = L0Validations.checkValueType(graph, parentResource, property.predicate);
+ if(error != null) {
+ LOGGER.error(error);
+ throw new ValidationException(error);
+ }
}
}
}
@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;
}