The type definition already exists

Hi,

I’m using the IDocumentModelService to expand included models but I got an issue as below:

java.lang.IllegalArgumentException: The type definition id 'typedef_3254b118-7bc3-4154-8117-461e19f0d1f9' already exists.
	at com.mgmtp.a12.kernel.md.model.internal.service.expansion.TypeDefCache.addUniqueTypeDef(TypeDefCache.java:36)
	at com.mgmtp.a12.kernel.md.model.internal.service.DocumentModelExpandService$IncludeExpandVisitor.visitFieldTypeDefinition(DocumentModelExpandService.java:414)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.acceptFieldTypeDefinitions(DocumentModelWalker.java:59)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.acceptDocumentModel(DocumentModelWalker.java:42)
	at com.mgmtp.a12.kernel.md.model.internal.service.DocumentModelExpandService$IncludeExpandVisitor.handleInclude(DocumentModelExpandService.java:265)
	at com.mgmtp.a12.kernel.md.model.internal.service.DocumentModelExpandService$IncludeExpandVisitor.visitGroup(DocumentModelExpandService.java:227)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.visitElementInheritance(DocumentModelWalker.java:99)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.acceptElement(DocumentModelWalker.java:85)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.acceptChildren(DocumentModelWalker.java:125)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.visitElementInheritance(DocumentModelWalker.java:101)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.acceptElement(DocumentModelWalker.java:85)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.acceptChildren(DocumentModelWalker.java:125)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.acceptElements(DocumentModelWalker.java:75)
	at com.mgmtp.a12.kernel.md.model.a12internal.visitor.DocumentModelWalker.acceptDocumentModel(DocumentModelWalker.java:45)
	at com.mgmtp.a12.kernel.md.model.internal.service.DocumentModelExpandService.expand(DocumentModelExpandService.java:99)

I’ve tried to include a TypeDefinition in the Tender and FleetData models. I also include TypeDefinition in FleetData. You can see my models below.
FleetData.json (2.2 KB)
Tender.json (12.2 KB)
TypeDefinition.json (45.2 KB)

My question is why do you have to ensure that the TypeDefinition has to be unique? What can I do in this case to expand the Tender document model?

Hello @son-fast-shard , thanks for your post within A12 discourse! We’ve forwarded your request to our Kernel team. As they are currently very busy, there may be delays in processing. We apologize for this and hope to be able to provide an answer in a timely manner.

Your discourse team

Hi @son-fast-shard,
I took your models in two workspaces (the current Kernel master and Kernel 28). I implemented a small test to expand Tender.json and in none of the workspaces, I could reproduce what you describe. Having a look at the files, I could not see anything wrong as well. A difference between our workspaces could be the implementation of IDocumentModelReferenceResolver, especially the fact that the method #getDocumentModel(String) returns not expanded document models, you could check that.
Regarding to your questions:

  • Why do you have to ensure that the TypeDefinition has to be unique? A: In order to avoid inconsistencies among document models, e.g. when copying a json-file which is not a supported operation in Kernel.
  • What can I do in this case to expand the Tender document model? A: You can check your implementation of IDocumentModelReferenceResolver (see also above). If that does not help, we will see what else we can do.

It’s true. My implementation of IDocumentModelReferenceResolver#getDocumentModel(String) tries to expand document models (by using IDocumentModelService#expand function). If I get you correctly, I should only return not expanded document models from #getDocumentModel(String) method and try to expand the returned document model later, right?

Exactly, the returned document model in the method IDocumentModelReferenceResolver#getDocumentModel(String) must not be expanded. Please have a look at the Javadoc of the method, if this is not clear enough, please let me know and we will try to improve it.