Home » Modeling » Compare » ignoring identifiers problem(Seems UseIdentifiers.NEVER does not work for me)
ignoring identifiers problem [message #1691283] |
Sat, 04 April 2015 14:28 |
furkan tanriverdi Messages: 15 Registered: November 2014 |
Junior Member |
|
|
Hi everyone,
I have 2 models to compare. In my *.ecore model, I have an "Id" attribute and its ID property have been setted to true. I am using EcoreUtil.generateUUID() for unique ids.
In my case, I have one ready model and I am creating a new one in runtime. Therefore the ids are different from each other.
In developer guide of EMFCompare, they offer us to use UseIdentifiers.NEVER and I used. However it does not work.
In short, I want to ignore Id attributes in comparison.
Quote:
Left object: DocModel.impl.ParagraphImpl@2767e23c (Id: _8pidAdVSEeSCK78kxjXrDg) (name: null) (rawText: Lorem ipsum ....)
Right object: DocModel.impl.ParagraphImpl@33bc72d1 (Id: _QSFJodrUEeSkqsl19NdwQQ) (name: null) (rawText: Lorem ipsum ....)
d.getKind(): CHANGE
thanks and regards
[Updated on: Tue, 07 April 2015 12:27] Report message to a moderator
|
|
|
Re: ignoring identifiers problem [message #1693656 is a reply to message #1691283] |
Mon, 27 April 2015 09:48 |
|
Hi,
UseIdentifier.NEVER means that we won't use either the xmi:id or the id attribute while matching your objects, but rather try and match your objects through similarity. This last means is more error-prone than relying on the IDs, and we may not be able to properly match your elements together if their similarity is too low, which is probably what "does not work". You'll might want to take a look at the matching section of the developper guids for means to override the default behavior with your own.
Please expand on your question if this does not answer it.
Laurent Goubet
Obeo
|
|
| |
Re: ignoring identifiers problem [message #1693754 is a reply to message #1693720] |
Tue, 28 April 2015 07:20 |
|
We do not detect "CHANGE" difference on xmi:ids. We will detect changes on id attributes if there's one, and that's expected (an attribute has changed, you need to merge it for the models to be identical).
UseIdentifier.NEVER only tells us not to use the ids to match elements together. We will still diff them to detect changes. xmi:id are an exception since they are not a part of the objects themselves, but rather an xmi metadata.
The small thing you posted above doesn't tell us anything about what the difference is, just that we detected a change on an element that's a Paragraph. Post the full xmi representation of that diff if you need to find that out, or display it in the UI of EMF Compare to see what it really is.
If it is a difference on an id attribute and that's what you're trying to ignore, you can look up on how to change the feature filter to tell EMF Compare to ignore that attribute.
Laurent Goubet
Obeo
|
|
|
Re: ignoring identifiers problem [message #1693803 is a reply to message #1693754] |
Tue, 28 April 2015 11:59 |
furkan tanriverdi Messages: 15 Registered: November 2014 |
Junior Member |
|
|
OK. Now I understood the principle. I turned my codes into below:
IComparisonScope scope = EMFCompare.createDefaultScope(resourceSet1, resourceSet2);
IDiffProcessor customDiffProcessor = new DiffBuilder() {
@Override
public void attributeChange(Match match, EAttribute attribute, Object value, DifferenceKind kind, DifferenceSource source) {
if (attribute != EcorePackage.Literals.EATTRIBUTE__ID) {
super.attributeChange(match, attribute, value, kind, source);
}
}
};
IDiffEngine diffEngine = new DefaultDiffEngine(customDiffProcessor);
return EMFCompare.builder().setDiffEngine(diffEngine).build().compare(scope);
Is this right? Because, the output is still not what I want. The compare result :
Quote:d.getKind(): ADD
d.getMatch(): MatchSpec{left=Paragraph@59e2d8e3 Summary, right=Paragraph@4bf48f6 Summary, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED
d.getKind(): DELETE
d.getMatch(): MatchSpec{left=Paragraph@59e2d8e3 Summary, right=Paragraph@4bf48f6 Summary, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED
I tried to use ENAMED_ELEMENT__NAME for testing if it works, and it works properly for name attributes. But EATTRIBUTE__ID does not. ADD and DELETE come up consecutively for id attribute like above.
-
Attachment: left.png
(Size: 7.24KB, Downloaded 283 times) -
Attachment: right.png
(Size: 6.31KB, Downloaded 273 times) -
Attachment: model.png
(Size: 3.22KB, Downloaded 277 times)
[Updated on: Tue, 28 April 2015 13:51] Report message to a moderator
|
|
|
Re: ignoring identifiers problem [message #1694013 is a reply to message #1693803] |
Thu, 30 April 2015 06:43 |
|
testing against "attribute != EcorePackage.Literals.EATTRIBUTE__ID" will just tell EMF Compare not to compute diffs on the "eAttributeId" attribute itself, in the ecore metamodel. Since what you compare is not the ecore metamodel, what you need is to test against the actual feature that's an id in your case. In other words, your test should look either one of :
if (!attribute.isId()) // maybe a little too generic
or
if (attribute != DocumentPackage.Litterals.PARAGRAPH_ID) // or whatever literal represents the 'id' attribute of the paragraph class in _your_ metamodel's generated XyzPackage
Regards,
Laurent Goubet
Obeo
|
|
|
Re: ignoring identifiers problem [message #1694927 is a reply to message #1694013] |
Sat, 09 May 2015 13:59 |
furkan tanriverdi Messages: 15 Registered: November 2014 |
Junior Member |
|
|
Tested on same models above:
public Comparison compare(ResourceSet resourceSet1, ResourceSet resourceSet2)
{
//Creating the comparison scope
IComparisonScope scope = EMFCompare.createDefaultScope(resourceSet1, resourceSet2);
//Configuring the comparison
IDiffProcessor customDiffProcessor = new DiffBuilder() {
@Override
public void attributeChange(Match match, EAttribute attribute, Object value, DifferenceKind kind, DifferenceSource source) {
if (attribute != DocModel.DocModelPackage.Literals.ELEMENT__ID) {
super.attributeChange(match, attribute, value, kind, source);
}
}
};
IDiffEngine diffEngine = new DefaultDiffEngine(customDiffProcessor);
return EMFCompare.builder().setDiffEngine(diffEngine).build().compare(scope);
}
output:
Quote:
d.getKind(): ADD
d.getMatch(): MatchSpec{left=Paragraph@59e2d8e3 Summary, right=Paragraph@4bf48f6 Summary, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED
d.getKind(): DELETE
d.getMatch(): MatchSpec{left=Paragraph@59e2d8e3 Summary, right=Paragraph@4bf48f6 Summary, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED
Also as you can see, diff points the paragraph named Summary. But, the difference is in Key-Value Paragraph. I thing it ignores the ID but I do not know where ADD and DELETE come from. When I don't use the feature filtering, the CHANGE diff comes up like below:
Quote:d.getKind(): CHANGE
d.getMatch(): MatchSpec{left=Paragraph@536dbea0 Key-Value Pair, right=Paragraph@47c81abf Key-Value Pair, origin=<null>, #differences=1, #submatches=0}
State: UNRESOLVED
diff points the paragraph named Key-Value Paragraph.
best regards
|
|
|
Re: ignoring identifiers problem [message #1695787 is a reply to message #1694927] |
Tue, 19 May 2015 09:40 |
|
Hi,
As I mentionned earlier, the toString of these diffs does not provide nearly enough information to understand what's going on. Post the full xmi representation of that diff if you need to find that out, or screenshot the UI of EMF Compare so that we know what these diffs really are.
You may also provide us with the metamodels and models to test and debug this case.
Laurent Goubet
Obeo
|
|
|
Goto Forum:
Current Time: Wed Dec 04 22:10:01 GMT 2024
Powered by FUDForum. Page generated in 0.14177 seconds
|