archimatetool / archi-scripting-plugin

jArchi - Scripting for Archi: ArchiMate Modelling Tool
https://www.archimatetool.com
118 stars 33 forks source link

Implement Model Importer #114

Closed Phillipus closed 5 months ago

Phillipus commented 1 year ago

@jbsarrodie I figured out how to expose the model importer's undo/redo Command to jArchi so it's possible to do this now. It will have to be for a version of jArchi that depends on Archi 5.

Suggested basic API:

model.importModel(pathToModelFile, update, updateAll)

Could probably get a better name for the boolean parameters

jbsarrodie commented 1 year ago

Good.

Maybe a better name for the function should be: model.merge(otherModelObject, update, updateAll)

This would be aligned with current element.merge() and relation.merge().

Note that this uses a model object and not a path, so the user has to first load the model with $.model.load(path) (of course we could provide an alternative function which takes a path as input and load it under the hood).

Phillipus commented 1 year ago

Note that this uses a model object and not a path...

The implementation does use a path pathToModelFile so perhaps we need both?

jbsarrodie commented 1 year ago

The implementation does use a path pathToModelFile so perhaps we need both?

Would make sense. For example, my CSV synchronization script would create a new model in memory and would merge it into current model, so in my case I will never have a path (unless I create a temporary one somewhere).

Related question: what does this merge function return? I guess returning a JS object which contains a global status and list of infos, warnings and errors make sense:

{
   status: true|false,
   informations: [
      "INFO001",
      "INFO002",
      ...
   ],
   warnings: [
      "WARN001",
      "WARN002",
      ...
   ],
   errors: [
      "ERR001",
      "ERR002",
      ...
   ]
}
Phillipus commented 1 year ago

what does this merge function return

Right now it returns the owning model proxy.

I guess returning a JS object which contains a global status and list of infos, warnings and errors make sense

Will investigate...

jbsarrodie commented 1 year ago

Will investigate...

Wait a minute. One of the good thing on jArchi is that we do method chaining. And returning the model proxy is aligned with that.

Maybe we could stick with that but raise an exception if we have some errors ?

Phillipus commented 1 year ago

Maybe we could stick with that but raise an exception if we have some errors ?

Will investigate... ;-)

jbsarrodie commented 1 year ago

Btw, if you haven't tried chatGPT yet, do it. It provided me this idea of using exception to keep the method chaining available... If only we had an opensource equivalent of it and train it on an ArchiMate model (ArchiBot...)

Phillipus commented 1 year ago

What did you ask it?

jbsarrodie commented 1 year ago

What did you ask it?

I asked: Can you tell me how (in java) we can create code that uses method chaining and still provides useful information to know if a method failed?

It then provided me a code example to illustrate method chaning, then two proposals (the first off, but the second was about exceptions)

Phillipus commented 1 year ago

Should have asked chatPhillipus

var messages = [];

model.merge("model.archimate", true, true, messages);

messages.forEach(function(message)  {
    console.log(message);
});
Phillipus commented 5 months ago

Added in 1.5.0