Hello!
I am working on the biblio plugin that declares types. How can I write a migration to change the type URI of a previously existing topic type?
I found the setTypeUri method on the API documentation, but I’m obviously using it the wrong way. Any help is greatly appreciated! Here is what I tried:
package systems.dmx.biblio.migrations;
import systems.dmx.core.TopicType;
import systems.dmx.core.model.CompDefModel;
import systems.dmx.core.service.Migration;
public class Migration3 extends Migration {
@Override
public void run() {
TopicType type = dmx.getTopicType("dmx.biblio.monograph");
type.setTypeUri("dmx.biblio.book");
}
}
This migration fails with the following error:
Caused by: java.lang.RuntimeException: Topic 9839 is not associated to a topic type
at systems.dmx.core.impl.TopicModelImpl.fetchInstantiation(TopicModelImpl.java:242)
at systems.dmx.core.impl.TopicModelImpl.reassignInstantiation(TopicModelImpl.java:231)
at systems.dmx.core.impl.TopicModelImpl.storeTypeUri(TopicModelImpl.java:100)
at systems.dmx.core.impl.DMXObjectModelImpl.updateTypeUri(DMXObjectModelImpl.java:445)
at systems.dmx.core.impl.DMXObjectImpl.setTypeUri(DMXObjectImpl.java:86)
at systems.dmx.biblio.migrations.Migration3.run(Migration3.java:12)
at systems.dmx.core.impl.MigrationManager._runMigration(MigrationManager.java:137)
at systems.dmx.core.impl.MigrationManager.runMigration(MigrationManager.java:113)
... 25 more
Little update: I found an example of a typeURI modification here. When I do it like that, the migration runs without errors, but I cannot reload the topicmap. It contains an instance of the type in question and now it seems to load forever. The only errors in the log file concern a missing favicon.
setTypeUri() is for retyping things. In Migration3 you’re using setTypeUri() on a type. You’re retyping a type. The topic with URI dmx.biblio.monograph is no longer a type. (It it now a Book instance.) The former Monograph instances become corrupt. This causes the RuntimeException.
You want change a type’s URI. For changing a thing’s URI there is setUri(). However using setUri() on a type is a tricky thing. More work is required in case instances of that type do exist. You can do this work in a Migration. Tell me if you need more info.
But actually you would expect the DMX Core to better support changing a type’s URI. Consider opening a ticket.
/**
* Renames data type "Identity" -> "Entity".
*
* Part of DMX 5.0
* Runs only on UPDATE
*/
public class Migration4 extends Migration {
@Override
public void run() {
Topic identity = dmx.getTopicByUri("dmx.core.identity");
identity.setUri("dmx.core.entity");
identity.setSimpleValue(new SimpleValue("Entity"));
}
}
Here an instance URI is changed, not a type URI.
“Entity” is an instance (of type “Data Type”), not a type.
I don’t think there is a straight example for changing a type URI in existing (DM4/DMX) code. Tell me if you need more info for doing so.
General hint: usually the URI of a thing does not change. The URI identifies the thing. Usually a different URI identifies a different thing. Changing a thing’s URI is an exceptional case, and can create corrupt state when the former URI is still in use by other entities.