diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/data/KnowledgeGraph.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/data/KnowledgeGraph.java index fb40cf6c6..276a4e95b 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/data/KnowledgeGraph.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/data/KnowledgeGraph.java @@ -66,16 +66,14 @@ interface Operation extends Closeable { /** * Link the two passed assets. - *
- * FIXME remove scope when the other is gone - * + *
*
* @param source
* @param destination
* @param additionalProperties any pair of properties we want overridden. Pass pairs and do it right
* or you'll get an exception.
*/
void link(RuntimeAsset source, RuntimeAsset destination,
- DigitalTwin.Relationship relationship, Scope scope,
+ DigitalTwin.Relationship relationship,
Object... additionalProperties);
//
diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/resolver/ResolutionConstraint.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/resolver/ResolutionConstraint.java
index adef53235..ad6869698 100644
--- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/resolver/ResolutionConstraint.java
+++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/resolver/ResolutionConstraint.java
@@ -112,7 +112,7 @@ private Type(Class> dataClass, boolean incremental) {
*/
ResolutionConstraint merge(ResolutionConstraint constraint);
- static ResolutionConstraint of(Type type, Object data) {
+ static ResolutionConstraint of(Type type, Object... data) {
return new ResolutionConstraintImpl(type, data);
}
diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/resolver/objects/ResolutionConstraintImpl.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/resolver/objects/ResolutionConstraintImpl.java
index 4fbbdeda2..3f662928d 100644
--- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/resolver/objects/ResolutionConstraintImpl.java
+++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/resolver/objects/ResolutionConstraintImpl.java
@@ -24,7 +24,9 @@ public ResolutionConstraintImpl(Type type, Object... data) {
throw new KlabIllegalArgumentException("Cannot create resolution constraint: illegal data " +
"content");
}
- this.data.add(o);
+ if (o != null) {
+ this.data.add(o);
+ }
}
}
diff --git a/klab.core.common/src/main/java/org/integratedmodelling/common/data/jackson/JacksonConfiguration.java b/klab.core.common/src/main/java/org/integratedmodelling/common/data/jackson/JacksonConfiguration.java
index e2ab5d460..66e721136 100644
--- a/klab.core.common/src/main/java/org/integratedmodelling/common/data/jackson/JacksonConfiguration.java
+++ b/klab.core.common/src/main/java/org/integratedmodelling/common/data/jackson/JacksonConfiguration.java
@@ -32,6 +32,9 @@
import org.integratedmodelling.klab.api.lang.kactors.KActorsBehavior;
import org.integratedmodelling.klab.api.lang.kdl.KdlDataflow;
import org.integratedmodelling.klab.api.lang.kim.*;
+import org.integratedmodelling.klab.api.provenance.Activity;
+import org.integratedmodelling.klab.api.provenance.Agent;
+import org.integratedmodelling.klab.api.provenance.Provenance;
import org.integratedmodelling.klab.api.services.resolver.ResolutionConstraint;
import org.integratedmodelling.klab.api.services.runtime.Actuator;
import org.integratedmodelling.klab.api.services.runtime.Dataflow;
@@ -252,7 +255,8 @@ public static void configureObjectMapperForKlabTypes(ObjectMapper mapper) {
Currency.class, Message.class, Worldview.class, Workspace.class,
Concept.class, Observable.class, Resource.class, KimOntology.class,
KimNamespace.class, KimObservationStrategyDocument.class,
- KdlDataflow.class, KActorsBehavior.class, KimModel.class,
+ KActorsBehavior.class, KimModel.class, Activity.class,
+ Agent.class, Provenance.Node.class, Provenance.class,
KimSymbolDefinition.class, Contextualizable.class, Identifier.class,
KimConcept.class, KimObservable.class, Quantity.class,
Model.class, ServiceCall.class, Observation.class,
diff --git a/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/RuntimeService.java b/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/RuntimeService.java
index 81fe053e3..e33473862 100644
--- a/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/RuntimeService.java
+++ b/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/RuntimeService.java
@@ -11,6 +11,7 @@
import org.integratedmodelling.klab.api.data.RuntimeAsset;
import org.integratedmodelling.klab.api.digitaltwin.DigitalTwin;
import org.integratedmodelling.klab.api.exceptions.KlabIllegalArgumentException;
+import org.integratedmodelling.klab.api.exceptions.KlabIllegalStateException;
import org.integratedmodelling.klab.api.exceptions.KlabInternalErrorException;
import org.integratedmodelling.klab.api.knowledge.observation.Observation;
import org.integratedmodelling.klab.api.knowledge.observation.impl.ObservationImpl;
@@ -271,20 +272,37 @@ public String registerContext(ContextScope contextScope) {
@Override
public long submit(Observation observation, ContextScope scope) {
+
+ if (observation.isResolved()) {
+ // TODO there may be a context for this at some point.
+ throw new KlabIllegalStateException("A resolved observation cannot be submitted to the " +
+ "knowledge graph for now");
+ }
+
if (scope instanceof ServiceContextScope serviceContextScope) {
var digitalTwin = getDigitalTwin(scope);
var parentActivity = getInstantiationActivity(observation, scope);
var agent = getAgent(scope);
var instantiation = digitalTwin.knowledgeGraph().operation(agent, parentActivity,
Activity.Type.INSTANTIATION, observation);
+
try (instantiation) {
var ret = instantiation.store(observation);
+ if (scope.getContextObservation() != null) {
+ instantiation.link(scope.getContextObservation(), observation,
+ DigitalTwin.Relationship.HAS_CHILD);
+ }
+ if (scope.getObserver() != null) {
+ instantiation.link(observation, scope.getObserver(),
+ DigitalTwin.Relationship.HAS_OBSERVER);
+ }
instantiation.success(scope, observation);
return ret;
} catch (Throwable t) {
instantiation.fail(scope, observation);
}
}
+
return Observation.UNASSIGNED_ID;
}
@@ -326,8 +344,7 @@ public Future