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

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

BREAKING CHANGE

systems.dmx.core.ChildTopics

remove the 3 set() methods:

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

CODE TRANSFORMATION

Instead of

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

write

    topic.update(mf.newChildTopicsModel().set(compDefUri, ...));
parent 9695c1a5
Pipeline #9898 passed with stages
in 7 minutes and 51 seconds
......@@ -121,28 +121,6 @@ public interface ChildTopics extends Iterable<String> {
// --- Single-valued Children ---
/**
* Sets a child.
*/
ChildTopics set(String compDefUri, TopicModel value);
// ---
/**
* Convenience method to set the simple value of a child.
*
* @param value The simple value.
* Either String, Integer, Long, Double, or Boolean. Primitive values are auto-boxed.
*/
ChildTopics set(String compDefUri, Object value);
/**
* Convenience method to set the composite value of a child.
*/
ChildTopics set(String compDefUri, ChildTopicsModel value);
// ---
ChildTopics setRef(String compDefUri, long refTopicId);
ChildTopics setRef(String compDefUri, long refTopicId, ChildTopicsModel relatingAssocChildTopics);
......
......@@ -208,25 +208,6 @@ class ChildTopicsImpl implements ChildTopics {
// --- Single-valued Children ---
@Override
public ChildTopics set(String compDefUri, TopicModel value) {
return _updateOne(compDefUri, mf.newRelatedTopicModel(value));
}
// ---
@Override
public ChildTopics set(String compDefUri, Object value) {
return _updateOne(compDefUri, mf.newRelatedTopicModel(mf.childTypeUri(compDefUri), new SimpleValue(value)));
}
@Override
public ChildTopics set(String compDefUri, ChildTopicsModel value) {
return _updateOne(compDefUri, mf.newRelatedTopicModel(mf.childTypeUri(compDefUri), value));
}
// ---
@Override
public ChildTopics setRef(String compDefUri, long refTopicId) {
return _updateOne(compDefUri, mf.newTopicReferenceModel(refTopicId));
......
......@@ -6,7 +6,6 @@ import systems.dmx.core.DMXType;
import systems.dmx.core.RelatedAssoc;
import systems.dmx.core.RelatedTopic;
import systems.dmx.core.model.ChildTopicsModel;
import systems.dmx.core.model.DMXObjectModel;
import systems.dmx.core.model.SimpleValue;
import org.codehaus.jettison.json.JSONObject;
......
......@@ -240,7 +240,7 @@ public class PluginImpl implements Plugin, EventHandler {
}
void setMigrationNr(int migrationNr) {
pluginTopic.getChildTopics().set(PLUGIN_MIGRATION_NR, migrationNr);
pluginTopic.update(mf.newChildTopicsModel().set(PLUGIN_MIGRATION_NR, migrationNr));
}
// ---
......
......@@ -8,7 +8,7 @@
</div>
<div class="field">
<div class="field-label">Released</div>
Apr 25, 2020
Apr 26, 2020
</div>
<div class="field">
<div class="field-label">License</div>
......
......@@ -88,12 +88,12 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
Topic topic = dmx.createTopic(mf.newTopicModel("systems.dmx.notes", PLUGIN,
new SimpleValue("DMX Notes")));
//
topic.getChildTopics().set(PLUGIN_MIGRATION_NR, 23);
topic.update(mf.newChildTopicsModel().set(PLUGIN_MIGRATION_NR, 23));
//
int nr = topic.getChildTopics().getTopic(PLUGIN_MIGRATION_NR).getSimpleValue().intValue();
assertEquals(23, nr);
//
topic.getChildTopics().set(PLUGIN_MIGRATION_NR, 42);
topic.update(mf.newChildTopicsModel().set(PLUGIN_MIGRATION_NR, 42));
//
nr = topic.getChildTopics().getTopic(PLUGIN_MIGRATION_NR).getSimpleValue().intValue();
assertEquals(42, nr);
......@@ -118,7 +118,7 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
int nr = topic.getChildTopics().getTopic(PLUGIN_MIGRATION_NR).getSimpleValue().intValue();
assertEquals(23, nr);
//
topic.getChildTopics().set(PLUGIN_MIGRATION_NR, 42);
topic.update(mf.newChildTopicsModel().set(PLUGIN_MIGRATION_NR, 42));
//
nr = topic.getChildTopics().getTopic(PLUGIN_MIGRATION_NR).getSimpleValue().intValue();
assertEquals(42, nr);
......@@ -203,7 +203,7 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
Topic topic = dmx.createTopic(mf.newTopicModel(PLUGIN));
assertEquals("", topic.getSimpleValue().toString());
//
topic.getChildTopics().set(PLUGIN_NAME, "My Plugin");
topic.update(mf.newChildTopicsModel().set(PLUGIN_NAME, "My Plugin"));
assertEquals("My Plugin", topic.getChildTopics().getString(PLUGIN_NAME));
assertEquals("My Plugin", topic.getSimpleValue().toString());
//
......@@ -229,10 +229,10 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
));
assertEquals("My Plugin", topic.getSimpleValue().toString());
//
topic = dmx.getTopic(topic.getId()); // Note: the children are not loaded
assertEquals("My Plugin", topic.getSimpleValue().toString()); // the label is intact
topic.getChildTopics().set(PLUGIN_NAME, "HuHu"); // setting child used for labeling
assertEquals("HuHu", topic.getSimpleValue().toString()); // the label is recalculated
topic = dmx.getTopic(topic.getId()); // Note: the children are not loaded
assertEquals("My Plugin", topic.getSimpleValue().toString()); // the label is intact
topic.update(mf.newChildTopicsModel().set(PLUGIN_NAME, "HuHu")); // setting child used for labeling
assertEquals("HuHu", topic.getSimpleValue().toString()); // the label is recalculated
//
tx.success();
} finally {
......@@ -251,10 +251,10 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
));
assertEquals("My Plugin", topic.getSimpleValue().toString());
//
topic = dmx.getTopic(topic.getId()); // Note: the children are not loaded
assertEquals("My Plugin", topic.getSimpleValue().toString()); // the label is intact
topic.getChildTopics().set(PLUGIN_MIGRATION_NR, 3); // setting child NOT used for labeling
assertEquals("My Plugin", topic.getSimpleValue().toString()); // the label is still intact
topic = dmx.getTopic(topic.getId()); // Note: the children are not loaded
assertEquals("My Plugin", topic.getSimpleValue().toString()); // the label is intact
topic.update(mf.newChildTopicsModel().set(PLUGIN_MIGRATION_NR, 3)); // setting child NOT used for labeling
assertEquals("My Plugin", topic.getSimpleValue().toString()); // the label is still intact
//
tx.success();
} finally {
......@@ -367,10 +367,10 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
// 2) create instances
// "Comment"
Topic comment = dmx.createTopic(mf.newTopicModel("dmx.test.comment"));
comment.getChildTopics().set("dmx.test.person_name", mf.newChildTopicsModel()
comment.update(mf.newChildTopicsModel().set("dmx.test.person_name", mf.newChildTopicsModel()
.set("dmx.test.first_name", "Karl")
.set("dmx.test.last_name", "Albrecht")
);
));
//
assertEquals("Karl Albrecht", comment.getSimpleValue().toString());
//
......@@ -424,7 +424,9 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
TopicTypeImpl tt = dmx.getTopicType(PLUGIN);
//
// set "Include in Label" flag
ChildTopics ct = tt.getCompDef(PLUGIN_NAME).getChildTopics().set(INCLUDE_IN_LABEL, true);
CompDef cd = tt.getCompDef(PLUGIN_NAME);
ChildTopics ct = cd.getChildTopics();
cd.update(mf.newChildTopicsModel().set(INCLUDE_IN_LABEL, true));
//
assertEquals(true, ct.getBoolean(INCLUDE_IN_LABEL));
//
......@@ -450,12 +452,13 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
mf.newCompDefModel("dmx.test.birthday", false, false,
"dmx.test.person", "dmx.test.date", ONE)));
// test comp def children *before* set
ChildTopics ct = tt.getCompDef("dmx.test.date#dmx.test.birthday").getChildTopics();
CompDef cd = tt.getCompDef("dmx.test.date#dmx.test.birthday");
ChildTopics ct = cd.getChildTopics();
assertEquals(false, ct.getBoolean(INCLUDE_IN_LABEL));
assertEquals("dmx.test.birthday", ct.getTopic("dmx.core.assoc_type#dmx.core.custom_assoc_type").getUri());
//
// 2) set "Include in Label" flag
ct.set(INCLUDE_IN_LABEL, true);
cd.update(mf.newChildTopicsModel().set(INCLUDE_IN_LABEL, true));
//
// test comp def children *after* set (custom assoc type must not change)
assertEquals(true, ct.getBoolean(INCLUDE_IN_LABEL));
......@@ -479,7 +482,7 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
try {
// set "Include in Label" flag
long compDefId = dmx.getTopicType(PLUGIN).getCompDef(PLUGIN_NAME).getId();
dmx.getAssoc(compDefId).getChildTopics().set(INCLUDE_IN_LABEL, false);
dmx.getAssoc(compDefId).update(mf.newChildTopicsModel().set(INCLUDE_IN_LABEL, false));
//
// comp def order must not have changed
Collection<CompDef> compDefs = dmx.getTopicType(PLUGIN).getCompDefs();
......@@ -1163,7 +1166,7 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
//
assertEquals("Child 1", parent1.getChildTopics().getTopic("dmx.test.child").getSimpleValue().toString());
// 3) update child topics
parent1.getChildTopics().set("dmx.test.child", "Child 2");
parent1.update(mf.newChildTopicsModel().set("dmx.test.child", "Child 2"));
//
assertEquals("Child 2", parent1.getChildTopics().getTopic("dmx.test.child").getSimpleValue().toString());
//
......
......@@ -188,7 +188,7 @@ public class DM5CoreServiceTest extends CoreServiceTestEnvironment {
}
}
// Author: Malte Reißig, revised by jri at 2020/04/16
// Author: Malte Reißig, revised by jri at 2020/04/26
@Test
public void childParentValueUpdate() {
DMXTransaction tx = dmx.beginTx();
......@@ -202,7 +202,7 @@ public class DM5CoreServiceTest extends CoreServiceTestEnvironment {
));
assertEquals("Test", topic.getSimpleValue().toString());
// update child
topic.getChildTopics().set(SIMPLE_NAME, "Test Studio");
topic.update(mf.newChildTopicsModel().set(SIMPLE_NAME, "Test Studio"));
// both have changed, child value and parent value
assertEquals("Test Studio", topic.getChildTopics().getString(SIMPLE_NAME));
assertEquals("Test Studio", topic.getSimpleValue().toString());
......
......@@ -75,7 +75,7 @@ public class PersonTest extends CoreServiceTestEnvironment {
Topic person = createPerson();
Topic address = person.getChildTopics().getTopics("dmx.contacts.address#dmx.contacts.address_entry").get(0);
// this looks like we override "Berlin" with "Hamburg"
address.getChildTopics().set("dmx.contacts.city", "Hamburg");
address.update(mf.newChildTopicsModel().set("dmx.contacts.city", "Hamburg"));
// ... BUT the original address is unchanged
assertEquals("Berlin", address.getChildTopics().getString("dmx.contacts.city"));
// ... and another Address topic has been created
......@@ -106,7 +106,7 @@ public class PersonTest extends CoreServiceTestEnvironment {
ChildTopics children = person.getChildTopics();
assertEquals("<p>Software Developer</p>", children.getString("dmx.contacts.person_description"));
// change Person Description in-place
children.set("dmx.contacts.person_description", "<p>Cook</p>");
person.update(mf.newChildTopicsModel().set("dmx.contacts.person_description", "<p>Cook</p>"));
assertEquals("<p>Cook</p>", children.getString("dmx.contacts.person_description"));
// there is still only 1 person in the DB (it was mutated in-place), refetch ...
List<Topic> persons = dmx.getTopicsByType("dmx.contacts.person");
......@@ -140,10 +140,10 @@ public class PersonTest extends CoreServiceTestEnvironment {
Topic person = createPerson();
ChildTopics children = person.getChildTopics();
// change Last Name
children.set("dmx.contacts.person_name", mf.newChildTopicsModel()
person.update(mf.newChildTopicsModel().set("dmx.contacts.person_name", mf.newChildTopicsModel()
.set("dmx.contacts.first_name", "Dave")
.set("dmx.contacts.last_name", "Habling")
);
));
// name has changed in memory
ChildTopics name = children.getChildTopics("dmx.contacts.person_name");
assertEquals("Dave", name.getString("dmx.contacts.first_name"));
......@@ -173,7 +173,9 @@ public class PersonTest extends CoreServiceTestEnvironment {
Topic person = createPerson();
ChildTopics children = person.getChildTopics();
// change Last Name -- DON'T DO IT THIS WAY (it produces unexpected result)
children.getChildTopics("dmx.contacts.person_name").set("dmx.contacts.last_name", "Habling");
children.getTopic("dmx.contacts.person_name").update(
mf.newChildTopicsModel().set("dmx.contacts.last_name", "Habling")
);
// last name is still unchanged
assertEquals("Stauges", children.getChildTopics("dmx.contacts.person_name")
.getString("dmx.contacts.last_name"));
......
......@@ -9,7 +9,7 @@ import extraElementUI from './element-ui'
import 'font-awesome/css/font-awesome.css'
import './websocket'
console.log('[DMX] 2020/04/25')
console.log('[DMX] 2020/04/26')
// 1) Init dm5 library
// The dm5 library must be inited *before* the dm5-webclient component is instantiated.
......
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