Move composition definitions to custom workspace

Hi! :slight_smile:

I declared a composite topic type in a declarative migration and added all involved topic types to a dedicated workspace in a Java migration. Now I am looking for a way to move the associations of the composition definition to the same workspace. (Otherwise they cannot be edited in the web client.) The plan was to fetch the topic type and search for all related associations of type composition definition. I tried the snippet below but according to the errors I cannot call getRelatedAssocs() like that.

    TopicType mycomposite = dmx.getTopicType("org.example.mycomposite");
    myCompDef = mycomposite.getRelatedAssocs("dmx.core.composition_def");

Can you please give me some advice on how to proceed? How do I call getRelatedAssocs() and what do I have to import at the top of the migration?

Thanks for any hints!

You’re trying to get a type’s composition definitions via DMX’s generic traversal API (DMXObject). It would go like this:

import systems.dmx.core.Assoc;
import static systems.dmx.core.Constants.*;
import systems.dmx.core.RelatedTopic;
import systems.dmx.core.TopicType;
import java.util.List;

TopicType myType = dmx.getTopicType("my.type.uri");
List<RelatedTopic> childTypes = myType.getRelatedTopics(COMPOSITION_DEF, PARENT_TYPE, CHILD_TYPE, TOPIC_TYPE);
for (RelatedTopic childType : childTypes) {
    Assoc compDef = childType.getRelatingAssoc();
    ...
}

This would work. Some notes:

  • Here you’re actually traversing to the child types, and get a list of RelatedTopic. A RelatedTopic is a topic plus the association you’ve traversed. Types are topics (never assocs) so you use getRelatedTopics() (not getRelatedAssocs()).
  • Traversing with just one param ("dmx.core.composition_def") is not sufficient. This would give you the comp defs where your type acts as child type as well. So you have to give your traversal a direction – in the form of role types: you traverse from PARENT_TYPE to CHILD_TYPE.
  • To get the traversed association of a RelatedTopic you call getRelatingAssoc(). These associations are the comp defs you’re looking for.

But in reality you would not do it like this. It’s too complicated.
Instead for types there is a higher-level API (DMXType):

import systems.dmx.core.CompDef;
import systems.dmx.core.TopicType;

TopicType myType = dmx.getTopicType("my.type.uri");
for (CompDef compDef : myType.getCompDefs()) {
   ...
}

This gives you the composition definitions straight away.
Note: CompDef is a subclass of Assoc.

One more hint about the WorkspacesService: the APIdocs shows there are 2 assign-to-workspace methods:

  1. void assignToWorkspace(DMXObject object, long workspaceId)

    Assigns an object to a workspace.

  2. void assignTypeToWorkspace(DMXType type, long workspaceId)

    Assigns a type as well as its “parts” to a workspace. In particular:

    • the type
    • the type’s view config
    • the direct comp defs (not recursively)
    • the direct comp def’s view configs

So for types there is a special assign method which assigns all the type parts as well. The 1st call in constrast is the “generic” one.

In your migrations: to assign types to worksapces use the special method for types. This saves you from the manual comp defs assignments in the first place.

Hints: DMXObject is the superclass of both, Topic and Assoc.
DMXType is the superclass of both, TopicType and AssocType.
For an illustration of the DMX Core class hierarchy see DMX Java API.