mdj-files from Version 4 non compatible with 5.0.1

52 views
Skip to first unread message

Günther Demetz

unread,
Apr 6, 2022, 10:53:20 AM4/6/22
to StarUML
In StarUML4  "navigable" attribute on relations was of type boolean (checkbox) and per default true.
Now with StarUML5.0.1 sudenly the "navigable" attribute  default is 'unspecified'.
This means that all relations which were defined navigable, now suddenly are 'unspecified'.
This is very annoying and I had to write following java-app for adapting our mdj.files

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

    public class StarUmlMDJFileFixer {
        public static void main(String[] args) {

            try {
                // read the Version 4 mdj file
                FileReader reader = new FileReader(args[0]);

                JSONParser jsonParser = new JSONParser();
                JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);

                JSONArray models = (JSONArray) jsonObject.get("ownedElements");
                JSONArray elements = (JSONArray) ((JSONObject) models.get(0)).get("ownedElements");
                JSONObject businessclasses =  (JSONObject) elements.get(0);
                //System.out.println(businessclasses);
                JSONArray classes = (JSONArray) businessclasses.get("ownedElements");
                for (int i = 0, size = classes.size(); i < size; i++)
                {
                  JSONObject clazz = (JSONObject) classes.get(i);
                  System.out.println(clazz.get("name"));
                  JSONArray roles = (JSONArray) clazz.get("ownedElements");
                  if (roles != null)
                  {
                      for (int j = 0; j < roles.size(); j++)
                      {
                          JSONObject role = (JSONObject) roles.get(j);  
                          if ( "UMLAssociation".equals(role.get("_type")))
                          {
                              JSONObject end1 =  (JSONObject)  role.get("end1");
                              if (end1.get("navigable") == null)
                                  end1.put("navigable", "navigable");
                              else
                                  end1.put("navigable", "notNavigable");
                              JSONObject end2 =  (JSONObject)  role.get("end2");
                              if (end2.get("navigable") == null)
                                  end2.put("navigable", "navigable");
                              else
                                  end2.put("navigable", "notNavigable");
                          }
                      }
                  }
                }
               
                 models.get(0).get("ownedElements");

                OutputStream os = new FileOutputStream(new File("adaptedto501.mdj"));
                PrintWriter p = new PrintWriter(os);
                p.write(jsonObject.toString());
                p.close();
                System.out.println("FINISHED!");
            } catch (Exception ex) {}
}




Günther Demetz

unread,
Apr 7, 2022, 5:04:54 AM4/7/22
to StarUML
N.B.: Ideally StarUML on opening a mdj file should recognize that it is from an older version and ask for conversion (or do the conversion implicitly).

StarUML

unread,
Apr 10, 2022, 12:09:27 AM4/10/22
to StarUML
Hi,

Sorry for the inconvenience.
Here is another thread about navigability with different opinion: https://groups.google.com/g/staruml/c/4t0yQN1lP18/m/3EphMQDFDwAJ

Thanks,
StarUML Team

2022년 4월 7일 목요일 오후 6시 4분 54초 UTC+9에 guenthe...@hotmail.com님이 작성:

Günther Demetz

unread,
Apr 12, 2022, 10:14:31 AM4/12/22
to StarUML
Hi, 

I have already read  the thread you mention.
The way 5.0.1 behaves is OK, I'm just missing a migration guide or automatic migration,
because I believe a migration as shown above is needed in many use-cases.
Reply all
Reply to author
Forward
0 new messages