Commit b472773a authored by Jörg Richter's avatar Jörg Richter

ChildTopics API: remove add() method (3x) (#341)

BREAKING CHANGE

systems.dmx.core.ChildTopics

remove the 3 add() methods:

ChildTopics add(String compDefUri, TopicModel value);
ChildTopics add(String compDefUri, Object value);
ChildTopics add(String compDefUri, ChildTopicsModel value);

CODE TRANSFORMATION

Instead of

    topic.getChildTopics().add(compDefUri, ...);

write

    topic.update(mf.newChildTopicsModel().add(compDefUri, ...));
parent aca74c05
Pipeline #9907 passed with stages
in 7 minutes and 41 seconds
......@@ -121,16 +121,6 @@ public interface ChildTopics extends Iterable<String> {
// --- Multiple-valued Children ---
// TODO: add add(String compDefUri, RelatedTopicModel value)? Compare to ChildTopicsModel
ChildTopics add(String compDefUri, TopicModel value);
ChildTopics add(String compDefUri, Object value);
ChildTopics add(String compDefUri, ChildTopicsModel value);
// ---
ChildTopics addRef(String compDefUri, long refTopicId);
ChildTopics addRef(String compDefUri, long refTopicId, ChildTopicsModel relatingAssocChildTopics);
......
......@@ -208,23 +208,6 @@ class ChildTopicsImpl implements ChildTopics {
// --- Multiple-valued Children ---
@Override
public ChildTopics add(String compDefUri, TopicModel value) {
return _updateMany(compDefUri, mf.newRelatedTopicModel(value));
}
@Override
public ChildTopics add(String compDefUri, Object value) {
return _updateMany(compDefUri, mf.newRelatedTopicModel(mf.childTypeUri(compDefUri), new SimpleValue(value)));
}
@Override
public ChildTopics add(String compDefUri, ChildTopicsModel value) {
return _updateMany(compDefUri, mf.newRelatedTopicModel(mf.childTypeUri(compDefUri), value));
}
// ---
@Override
public ChildTopics addRef(String compDefUri, long refTopicId) {
return _updateMany(compDefUri, mf.newTopicReferenceModel(refTopicId));
......
......@@ -1142,7 +1142,7 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
);
// 2) create composite instance
parent1 = dmx.createTopic(mf.newTopicModel("dmx.test.parent"));
parent1.getChildTopics().add("dmx.test.child", "Child 1");
parent1.update(mf.newChildTopicsModel().add("dmx.test.child", "Child 1"));
tx.success();
} finally {
tx.finish();
......
......@@ -82,9 +82,10 @@ public class DM5CoreServiceTest extends CoreServiceTestEnvironment {
defineLottoModel();
Topic draw = dmx.createTopic(mf.newTopicModel("lotto.draw"));
long drawId = draw.getId();
draw.getChildTopics()
draw.update(mf.newChildTopicsModel()
.add("lotto.number", 23)
.add("lotto.number", 42);
.add("lotto.number", 42)
);
//
draw = dmx.getTopic(drawId);
List<RelatedTopic> numbers = draw.getChildTopics().getTopics("lotto.number");
......@@ -229,7 +230,7 @@ public class DM5CoreServiceTest extends CoreServiceTestEnvironment {
assertSame(2, dmx.getTopicsByType(SIMPLE_NAME).size());
//
// add child topic by-value
topic.getChildTopics().add(SIMPLE_NAME, "Text 2");
topic.update(mf.newChildTopicsModel().add(SIMPLE_NAME, "Text 2"));
// now the composite has 2 children -- the existing "Text 2" topic was identified (by-value) and reused
List<RelatedTopic> children = topic.getChildTopics().getTopics(SIMPLE_NAME);
assertEquals(2, children.size());
......
......@@ -213,7 +213,7 @@ public class PersonTest extends CoreServiceTestEnvironment {
assertEquals(1, emailAddresses.size());
assertEquals("me@example.com", emailAddresses.get(0).getSimpleValue().toString());
// add 2nd Email Address
children.add("dmx.contacts.email_address", "me@example2.com");
person.update(mf.newChildTopicsModel().add("dmx.contacts.email_address", "me@example2.com"));
//
// check memory
emailAddresses = children.getTopics("dmx.contacts.email_address");
......@@ -244,12 +244,12 @@ public class PersonTest extends CoreServiceTestEnvironment {
Topic person = createPerson();
ChildTopics children = person.getChildTopics();
// add 2nd Email Address
children.add("dmx.contacts.email_address", "me@example2.com");
person.update(mf.newChildTopicsModel().add("dmx.contacts.email_address", "me@example2.com"));
// replace 1st Email Address
Topic ea1 = dmx.getTopicByValue("dmx.contacts.email_address", new SimpleValue("me@example.com"));
children.add("dmx.contacts.email_address",
person.update(mf.newChildTopicsModel().add("dmx.contacts.email_address",
mf.newTopicModel(ea1.getId(), new SimpleValue("me@example3.com"))
);
));
//
// check memory
List<RelatedTopic> emailAddresses = children.getTopics("dmx.contacts.email_address");
......@@ -281,7 +281,7 @@ public class PersonTest extends CoreServiceTestEnvironment {
ChildTopics children = person.getChildTopics();
Topic ea1 = children.getTopics("dmx.contacts.email_address").get(0);
// add 2nd Email Address
children.add("dmx.contacts.email_address", "me@example2.com");
person.update(mf.newChildTopicsModel().add("dmx.contacts.email_address", "me@example2.com"));
// remove 1st Email Address
children.addDeletionRef("dmx.contacts.email_address", ea1.getId());
//
......
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