How to set a custom ID for a concept created via Open API?

Hi all,

I am creating different concepts via Open API. Instances of those concepts are then used in my model solution. If I delete such a concept and recreate it again, my model will be broken. I figured that this is due to the internal id of a concept.

So is there a way to set the id of such a concept to a custom one?

node<ConceptDeclaration> cncpt = new node<ConceptDeclaration>(); 
cncpt.name = "Test";
info "ID: " + cncpt/.getNodeId();

// Now I want to the set id kinda like this:
cncpt/.setNodeId(...); // ??
prettyPrint();

Best,
Dennis
4 comments
Maybe the new project-level migration stuff does the trick? Check:
https://confluence.jetbrains.com/display/MPSD32/Migrations
0
Thx! But if I understood it correctly, I have to iterate through all models in the solution that are using/referencing one of those (replaced) concepts and update the reference correctly. In my case I don't know which other projects and solutions are going to use parts of my language. Thus, I cannot iterate through them. I guess, what I need is a way to directly change/set the specific id to the (replaced) concepts.
0
Yep, now you can do it exactly you've as mentioned:
conceptNode.setId(oldConceptNodeId);
Currently, concept id is a pair of [languageId, conceptNodeId]. So, if the concept node has the same id as the old concept node and is located in the same language, conceptIds will be the same

However, it is not guaranteed that it will remain the same in future, our plan is to introduce a new property in AbstractConceptDeclaration, which will contain the id of the concept, so that it would be possible to change the future conceptId just in the editor of structure model or using smodel language.
0
Thank you very much Mihail! It is now working properly. I finally figured out how to access this method:

node<ConceptDeclaration> cncpt = new node<ConceptDeclaration>(); 
cncpt.name = "Test";
info "ID: " + cncpt/.getNodeId();

// Now I set the custom id:
(((SNode) cncpt/)).setId(SNodeId.fromString("1260541602407982656"));
prettyPrint();
0

Please sign in to leave a comment.