Book a Demo

Author Topic: Update Text for Hyperlinks to Elements  (Read 4652 times)

PatrickS

  • EA User
  • **
  • Posts: 46
  • Karma: +1/-0
    • View Profile
Update Text for Hyperlinks to Elements
« on: July 11, 2017, 02:41:15 am »
Hi,
Quite often in my use Case description I refer to another use case and use the Hyperlink to element functionality. However, during the Analysis process, I sometimes need to rename the referred Use case. I would like to have my Hyperlink references to those Use Cases updated as well. This should happend automatically so that I can always be sure all references are according to the current name of the element. Any idea how to implement that?
Greetings, Patrick

PeterHeintz

  • EA Practitioner
  • ***
  • Posts: 1001
  • Karma: +59/-18
    • View Profile
Re: Update Text for Hyperlinks to Elements
« Reply #1 on: July 11, 2017, 02:44:27 am »
I have not don that jet, but I assume you can do that be writing a script.
Best regards,

Peter Heintz

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Update Text for Hyperlinks to Elements
« Reply #2 on: July 15, 2017, 12:15:27 am »
Hi,

updating the Notes/Description isn't a complex task if you know how. The following snippet shows how to do it with C#.

I may integrate the functionality in hoTools https://github.com/Helmut-Ortmann/EnterpriseArchitect_hoTools/wiki. Then it's just a Click away.

Best regards,

Helmut

Code: [Select]
        /// <summary>
        /// Change EA Hyperlinks of type package, element, diagram, attribute, operation in notes string.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="s">Reference to the Notes string</param>
        /// <returns>True if string is changed</returns>
        private static bool ChangeHyperLinksInNote(Repository rep, ref string s)
        {
            // Possible replacements for element, package, feature(Attribute or Operation)
            Regex rgx = new Regex(@"(a href=""\$(element|diagram|package|feature)://({[ABCDEF0123456789-]+})[^u]*u>)([^<]*)",
                RegexOptions.IgnoreCase);
            Match m = rgx.Match(s);
            bool changeNote = false;
            while (m.Success)
            {
                bool changeNoteItem = false;
                string guid = m.Groups[3].Value;
                string type = m.Groups[2].Value;
                string name = "don't exists";
                switch (type)
                {
                    case "package":
                    case "element":
                        EA.Element elReplace = rep.GetElementByGuid(guid);
                        if (elReplace != null) name = $"{elReplace.Name}";
                        changeNote = true;
                        changeNoteItem = true;
                        break;

                    // Operation/Attribute
                    case "feature":

                        EA.Attribute aReplace = rep.GetAttributeByGuid(guid);
                        if (aReplace != null)
                        {
                            name = aReplace.Name;
                        }
                        else
                        {
                            EA.Method mReplace = rep.GetMethodByGuid(guid);
                            if (mReplace != null) name = mReplace.Name;
                        }
                        changeNote = true;
                        changeNoteItem = true;
                        break;


                    // EntryName:   'PackageName' : 'DiagramName'
                    case "diagram":
                        EA.Diagram diaReplace = (EA.Diagram) rep.GetDiagramByGuid(guid);
                        if (diaReplace != null)
                        {
                            EA.Package pkg = rep.GetPackageByID(diaReplace.PackageID);
                            name = $"{pkg.Name} : {diaReplace.Name}";
                        }
                        changeNote = true;
                        changeNoteItem = true;
                        break;
                    // do nothing
                    default:
                        break;
                }
                // current item changed
                if (changeNoteItem)
                {
                    s = s.Replace($"{m.Groups[0].Value}", $"{m.Groups[1].Value}{name}");
                }


                m = m.NextMatch();
            }
            return changeNote;
        }
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)