Commit 0bd515bc authored by Jörg Richter's avatar Jörg Richter

ChildTopicsModel API: set()/add() auto-sets type URI (#341)

Concenience: in case `typeUri` is not initialized in a `TopicModel` passed to `set()`/`add()`
it will be set automatically (based on `compDefUri`).
parent e4f4cf08
Pipeline #9892 passed with stages
in 8 minutes
......@@ -221,6 +221,7 @@ class ChildTopicsModelImpl implements ChildTopicsModel {
throw new IllegalArgumentException("Tried to set null as a ChildTopicsModel value");
}
//
checkValue(compDefUri, value);
childTopics.put(compDefUri, value);
return this;
} catch (Exception e) {
......@@ -296,6 +297,7 @@ class ChildTopicsModelImpl implements ChildTopicsModel {
childTopics.put(compDefUri, topics);
}
//
checkValue(compDefUri, value);
topics.add((RelatedTopicModelImpl) value);
//
return this;
......@@ -318,6 +320,7 @@ class ChildTopicsModelImpl implements ChildTopicsModel {
@Override
public final ChildTopicsModel set(String compDefUri, List<RelatedTopicModel> values) {
// FIXME: call checkValue() on every value
childTopics.put(compDefUri, values);
return this;
}
......@@ -513,4 +516,16 @@ class ChildTopicsModelImpl implements ChildTopicsModel {
throw new RuntimeException("Accessing \"" + compDefUri + " failed", e);
}
}
// ---
private void checkValue(String compDefUri, RelatedTopicModel value) {
String childTypeUri = mf.childTypeUri(compDefUri);
if (value.getTypeUri() == null) {
value.setTypeUri(childTypeUri); // convenience: auto-set typeUri
} else if (!value.getTypeUri().equals(childTypeUri)) {
throw new IllegalArgumentException("\"" + childTypeUri + "\" value expected, got \"" + value.getTypeUri() +
"\"");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment