How to create a composition definition with a custom association type set?

Hello! :slightly_smiling_face:
I am looking for some advice. I am trying to write the following imperative migration:

  • It shall get an existing Composite Topic Type and add a Topic Type to the composition definition. This part is already working. The association is a “Composition Definition” as per default.
  • That new association shall be retyped to an already existing custom association type (called “source”).

How can I achieve that second part? I went through the API documentation but nothing seems to fit. This is what I have so far:

package systems.dmx.cooking.migrations;
import systems.dmx.core.TopicType;
import systems.dmx.core.model.CompDefModel;
import systems.dmx.core.DMXObject;
import systems.dmx.core.service.Migration;

public class Migration8 extends Migration {
    @Override
    public void run() {
	//
	TopicType dish = dmx.getTopicType("dmx.cooking.dish");
	TopicType book = dmx.getTopicType("dmx.library.monograph");
	// Add "Book" from library plugin as a possible source to the "Dish" composite.
	dish.addCompDefBefore(mf.newCompDefModel(
		"dmx.cooking.dish", "dmx.library.monograph", "dmx.core.one"
		), "dmx.cooking.annotation");
	// to fetch an association the documentation says: getAssoc(String assocTypeUri, String myRoleTypeUri, String othersRoleTypeUri, long othersTopicId) 
	Assoc assoc = dmx.getAssoc("dmx.core.composition_def", "dmx.core.parent_type", "dmx.core.child_type", book.getId());
    }
}

Any hints are welcome!

Instead of the 3-param newCompDefModel() method use its 6-param form:

https://apidocs.dmx.systems/systems/dmx/core/service/ModelFactory.html#newCompDefModel-java.lang.String-boolean-boolean-java.lang.String-java.lang.String-java.lang.String-

As 1st param (customAssocTypeUri) you can specify your custom association type.

Just a wording hint: you don’t want “retype an association type to a custom association type” but “create a composition definition with a custom association type set”.

Great, many thanks! It’s working!

I renamed the thread to the correct wording.