Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Mixing UUIDs and positional identifiers in one model
Mixing UUIDs and positional identifiers in one model [message #1852659] Mon, 30 May 2022 13:40 Go to next message
Jan-Philipp Steghöfer is currently offline Jan-Philipp SteghöferFriend
Messages: 12
Registered: May 2019
Junior Member
Hey there,

I have recently switched the models of the Eclipse Capra project to use xmi:id to identify model elements. Previously, Eclipse Capra used the positional information to identify elements in other models. For instance:

<source href="artifactWrappers.xmi#//@artifacts.9"/>


has turned into:

<source href="artifactWrappers.xmi#_vMX68djjEeyw9s6Xboqnpw"/>


I did this via overwriting useUUIDs() in a custom XMIResourceImpl descendent as described in many places. A small script creates the UUIDs for existing models and replaces the positional reference with the new UUID. This all works as expected.

However, an interesting side effect of this is that Eclipse Capra is now enforcing the use of xmi:id-based references everywhere, including to models that do not contain xmi:ids. Since Eclipse Capra is a traceability tool, we have limited control over how other models are structured and whether they contain UUIDs or not. But since the model that contains the traceability links is loaded into a resource that enforces the use of UUIDs, all references to models which do not use UUIDs are now broken.

This is completely rational behaviour on EMF's part. Since we are loading all EMF models into the same resource in order to be able to establish the references, it is clear that EMF is enforcing the use of UUIDs once we enabled it across the board.

I admit that Capra is somewhat of an odd use case. However, I still wonder if there is a way to control what UUIDs are used for. I would like to use them in all references to models that contain UUIDs and use the positional references for all other cases. Does anyone have any idea how to accomplish that?

[Updated on: Mon, 30 May 2022 13:41]

Report message to a moderator

Re: Mixing UUIDs and positional identifiers in one model [message #1852660 is a reply to message #1852659] Mon, 30 May 2022 13:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
I'm slightly confused by the description. If you look at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(String), you'll see that it checks if the first character starts with '/'; the implementation will only call org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObjectByID(String) when that's not the case. So I generally expect any resource to be able to resolve any reference that uses fragment path, even if there intrinsic or extrinsic IDs available. When you create a reference to something in any other resource, you should respect what's returned by org.eclipse.emf.ecore.resource.impl.ResourceImpl.getURIFragment(EObject) however that is implemented by the model resource being referenced...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Mixing UUIDs and positional identifiers in one model [message #1852664 is a reply to message #1852660] Mon, 30 May 2022 17:16 Go to previous messageGo to next message
Jan-Philipp Steghöfer is currently offline Jan-Philipp SteghöferFriend
Messages: 12
Registered: May 2019
Junior Member
Hello Ed,

Thanks for the response. And yes, I am slightly confused as well.
Maybe an important detail that is missing: when I load a model that mixes references with UUIDs and with fragment paths, it loads without issues. The problem arises when I save the model again. All fragment paths are then replaced with UUIDs. We're not doing anything fancy when saving the model, we're just calling:
resource.save(null);

Any ideas?

Best,
Jan-Philipp
Re: Mixing UUIDs and positional identifiers in one model [message #1852666 is a reply to message #1852664] Mon, 30 May 2022 17:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
You said "all references to models which do not use UUIDs are now broken" but that sounds not to be the case now. Your stated goal is to use UUIDs so I assume that fact that UUIDs are used when you save is what you want. So what exactly is not working the way you want? I cannot really guess without concrete code or a relatively concrete example...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Mixing UUIDs and positional identifiers in one model [message #1852667 is a reply to message #1852666] Mon, 30 May 2022 18:14 Go to previous messageGo to next message
Jan-Philipp Steghöfer is currently offline Jan-Philipp SteghöferFriend
Messages: 12
Registered: May 2019
Junior Member
All right, fair point. Let me give this a shot.
Eclipse Capra is a traceability management tool, which means that we maintain traceability links between diverse development artifacts. The traceability links themselves are stored as an EMF model. A traceability link consists of a source and a number of targets. The types of traceability links, the multiplicities, etc. are defined in a metamodel (also called traceability information model). As a matter of fact, Eclipse Capra maintains three models with separate metamodels: the trace model which contains the traceability links, the artifacts model which contains information about non-EMF artifacts we link to (such as source code elements, rows in Excel files, etc.) and the metadata model which contains metadata about the traceability links such as when they were created and by which user. There are a number of reasons why these models are separate, but this shouldn't be the point of discussion.

Now a traceability link connects at least two artifacts. For instance, it expresses a relationship between a safety requirement stored in a row in an Excel file and a safety measure stored in an ODE model. ODE is a metamodel for dependency based on EMF. In the trace model XMI, this looks as follows:

<traces name="Include a second environemnt senor (image grabber) : Measure -> Requirements!SR-1.1.1 (mobstr-requirements.xlsx)" xsi:type="tim:SpecifiedByRequirement">
    <source href="../org.panorama-research.mobstr.fmea/mobstr-fmea.integration#//@odeProductPackages.3/@measures.0"/>
    <target href="artifactWrappers.xmi#//@artifacts.16"/>
</traces>


As you can see, we point to an ODE model (in mobstr-fmea.integration) and to our artifact model (in artifactWrappers.xmi), both using path fragments. Now, what I want to do is to use UUIDs when pointing to the artifact model. I can do that because I have control over the artifact model, i.e., I can manipulate and write it in Eclipse Capra and I can make sure it has UUIDs. However, I want to keep using path fragments when referring to the ODE model since I have no control over that model and cannot modify it to use UUIDs. What I want is essentially this:

<traces name="Include a second environemnt senor (image grabber) : Measure -> Requirements!SR-1.1.1 (mobstr-requirements.xlsx)" xsi:type="tim:SpecifiedByRequirement">
    <source href="../org.panorama-research.mobstr.fmea/mobstr-fmea.integration#//@odeProductPackages.3/@measures.0"/>
    <target href="artifactWrappers.xmi#_vMTCctjjEeyw9s6Xboqnpw"/>
</traces>


However, as soon as I active UUIDs in the resource in which I load the trace model and the artifact model and save these models, the path fragment pointing to the ODE model is also replaced with UUIDs. Since the ODE model does not contain UUIDs, however, the references break the next time I load my trace model.

I hope this made my problem clearer. Please let me know if you need more detail.
Re: Mixing UUIDs and positional identifiers in one model [message #1852669 is a reply to message #1852667] Mon, 30 May 2022 19:24 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You've jumped straight in and told us that you are changing to use xmi:id without really telling us why. As you've discovered there are significant tradeoffs.

The default EMF approach has the major advantage that there are only references, no definitions, so you do not need to modify targets to provide definitions. However the references are fragile in the event of model evolution whether manual or automated.

UUIDs are totally unreadable and require universal consistency and are differently fragile in the event of model evolution.

Since you are interested in traceability, you may have evolution concerns that need to be respected.

UUIDs have unpleasant global characteristics. A uri#fragment ids can be more appropriate.

The OCL project uses LUSSIDs (Locally Unique Semantically Sensentive IDs) to compact the fragment and entity qualifiers to compact the uri. This gives very compact xmi:ids that are stable for some semantic changes, and in particular are predictable allowing references to unmodified resources that have 'missing' xmi:ids. The compact xmi:ids save about 10% and are also unredable, but they are short and diverse and so amenable to human mental comparisons. See [1] for an example.

I suggest that having discovered some of the tradeoffs, you try to formulate your requirements more precisely.

That said, provided you observe the save-the-whole-ResourceSet policy, you should find that all the xmi:ids are there, but of course only after injecting them into xmi:id free resources. If you need diverse policies it should be possible to have a save helper that ensures that references to xmi:id free resources use the traditional EMF approach; just populate the object-to-id map with the xmi:id spelling that you require.

Regards

Ed Willink

[1] https://git.eclipse.org/r/plugins/gitiles/ocl/org.eclipse.ocl/+/refs/heads/master/plugins/org.eclipse.ocl.pivot/model-gen/Pivot.oclas
Re: Mixing UUIDs and positional identifiers in one model [message #1852674 is a reply to message #1852669] Tue, 31 May 2022 06:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
The fragment used to refer to objects in the mobstr-fmea.integration resource come from org.eclipse.emf.ecore.resource.impl.ResourceImpl.getURIFragment(EObject), or from some specialized override, so you will only get UUIDs for objects in that that resource if you have "activated" UUIDs for it as well. So check what type of resource implementation is being used to load (and save) the mobstr-fmea.integration resource.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Mixing UUIDs and positional identifiers in one model [message #1852681 is a reply to message #1852674] Tue, 31 May 2022 11:03 Go to previous messageGo to next message
Jan-Philipp Steghöfer is currently offline Jan-Philipp SteghöferFriend
Messages: 12
Registered: May 2019
Junior Member
Dear Ed^2,

Thanks to both of you to bringing your combined expertise to bear on this issue! As always, your insights are much appreciated.

Ed W., yes, you are right, I never stated why I wanted to switch to UUIDs. The reason is model evolution: I would like to evolve the trace models and make them manipulable outside of Eclipse (which is handy since I often have students that want to use machine learning in Python or similar things on trace models). But I can see now that this might be more trouble than it is worth.
Regarding your suggestion of a helper, I am wondering how I would go about doing that. Can I somehow detect if a model uses xmi:id or not and then manually create the object to id map?

Ed M., this is very interesting. The thing is that mobstr-fmea.integration is never explicitly loaded. I guess EMF loads it automatically when derefencing the trace model. If there is no resource factory registered for .integration files, it uses the standard resource factory which in our case is the CapraResourceFactory. So this might be the clue here: I need to make sure that the default resource factory is used for .integration files to get a default ResourceImpl for them. Will try and see if that fixes things.

Thanks again!
Re: Mixing UUIDs and positional identifiers in one model [message #1852682 is a reply to message #1852681] Tue, 31 May 2022 11:39 Go to previous message
Jan-Philipp Steghöfer is currently offline Jan-Philipp SteghöferFriend
Messages: 12
Registered: May 2019
Junior Member
Hello again,

It turns out that Ed Merks was on the right track: Capra was too eager in registering it's own resource factory and added its own ResourceFactory with the default extension. This caused all file extensions for which no specific ResourceFactory was registered to end up in a CapraResource which does enforce UUIDs. By only using the CapraResourceFactory for a specific extension, the .integration files are now loaded in an XMIResourceImpl and Capra indeed uses path fragments as desired.

Thanks to both of you again!
Previous Topic:How to get a column with CDO
Next Topic:EmfModel creation from a Resource object?
Goto Forum:
  


Current Time: Wed May 01 23:43:47 GMT 2024

Powered by FUDForum. Page generated in 0.03842 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top