archimatetool / archi-modelrepository-plugin

coArchi - a plug-in to share and collaborate on Archi models.
153 stars 53 forks source link

FeatureNotFoundException fails to load model #96

Closed Phillipus closed 5 years ago

Phillipus commented 5 years ago

To reproduce this, manually edit a grafico XML file and add an unknown XML attribute. For example, in a text editor edit a ArchimateDiagramModel_xxxxxxx file and add something=value:

  <children
      xsi:type="archimate:DiagramModelArchimateObject"
      id="00a70508-1837-4243-bfbc-528065f10dc8"
      something="value"
      targetConnections="1f03ea73-36c1-4e95-8bab-21a2370bfbf5">

Save the file and in another git tool (SmartGit) commit the change.

Back in Archi load that model and do "Abort Uncommitted changes". This will trigger the GraficoModelImporter to re-load the model from the XML files.

An Exception will be thrown and the model will not load.

The problem is triggered at GraficoModelImporter#loadModel(File)

XMLResource resource = (XMLResource)fResourceSet.getResource(URI.createFileURI(file.getAbsolutePath()), true);

If EMF fails to resolve the feature "something" it throws an exception and the load fails. It would be nice if it would simply ignore the missing feature but it doesn't. And there's no way to catch the exception and use a default.

Compare this with EditorModelManager#loadModel() where we load the single XML file in one go into a Resource Set and an unknown feature can be ignored.

I don't know how we can guard against this.

Phillipus commented 5 years ago

The problem is when two or more users may have different versions of Archi and/or an Archi model with different features such as reported in #95

Phillipus commented 5 years ago

I'm working on sorting this out. Grafico Importer has to be re-written to handle EMF Resources and Resource Sets differently...

...I'll be back in a couple of days. :-(

Phillipus commented 5 years ago

I've now come up with a solution. They key is not to call this:

XMLResource resource = (XMLResource)resourceSet.getResource(file, true);

EMF will eventually call resource.load() and if it encounters any problems throw an exception and abandon the resource.

What we need to do is load the resource ourselves and handle exceptions, just as we do in EditorModelManager#loadModel()

So I've written a new Resource loader class that does all of this.

We also get model backwards-compatible checking so if anything needs fixing, such as text alignment defaults, it will do that too.

Phillipus commented 5 years ago

Fixed for next version