Book a Demo

Author Topic: [Code generation] List all opTag:"myTag" for an operation  (Read 5079 times)

YanDJ

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
[Code generation] List all opTag:"myTag" for an operation
« on: February 12, 2020, 01:45:45 am »
Hello,

I try to configure the Code Template Editor.
We have define a tag value : "Error_Code" to write all the return code that the functions could return.
But the same tag has been created several times because the size of the value is too big (name + description).
When I generate the code, I use $returnCode += %opTag:"Error_Code"% to retrieve the tag.
But I get only the first tag name "Error_code" the generator find.
I try to find a way to do this in https://www.sparxsystems.com/enterprise_architect_user_guide/15.1/model_domains/taggedvaluemacros.html but I didn't found.

Is it possible to retrieve all the tags "Error_code" at once ?
(Maybe with something like %list="myTag" @separator="\n*"%)

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: [Code generation] List all opTag:"myTag" for an operation
« Reply #1 on: February 12, 2020, 02:49:00 am »
Hello,

Pretty sure the answer is No. In the case of multiple same-name tags, EA returns the first one it finds and you can't iterate over tags.
But then it's been a few years since I messed around with code / transform templates. Maybe they've fixed things.

/Uffe
My theories are always correct, just apply them to the right reality.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
Re: [Code generation] List all opTag:"myTag" for an operation
« Reply #2 on: February 12, 2020, 09:37:20 am »
To get multiples you'll need to call an add-in.

YanDJ

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: [Code generation] List all opTag:"myTag" for an operation
« Reply #3 on: February 12, 2020, 08:22:08 pm »
Thank for yours reply, but what is an add-in ?
This is what you are talking about : https://www.sparxsystems.com/resources/developers/autint_vb_calling_from_ea_addin.html
Do you have an example to use it ?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
Re: [Code generation] List all opTag:"myTag" for an operation
« Reply #4 on: February 13, 2020, 09:33:28 am »
I was thinking more along the lines of a Javascript add-in, but same basic idea.

Once you've followed a tutorial to get a basic add-in running, add a signal with the name you want and drop it as a reception onto your add-in.

In the code, the following should do roughly what you want.
Code: [Select]
if(arguments.length != 4)
return "";

var opGuid = arguments[1];
var tagName = arguments[2];
var separator = arguments[3];
var op = Repository.GetMethodByGuid(opGuid);
if(op == null)
return "";

var ret = "";
for(var i = 0; i < op.TaggedValues.Count; i ++)
{
var tag = op.TaggedValues.GetAt(i);
if(tag.Name == tagName)
{
if(ret != "")
ret += separator;
ret += tag.Value;
}
}
return ret;

In my case the name of my class was CgtAddin and the signal was OperationTags. I called it from an operation template using
Code: [Select]
%EXEC_ADD_IN("CgtAddIn","OperationTags",opGUID, "myTag", "\n")%

YanDJ

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: [Code generation] List all opTag:"myTag" for an operation
« Reply #5 on: March 12, 2020, 06:03:56 am »
Hello, so I try to follow your advice.

I wrote a JavaScript (I am not sure it's a add-in) to return all my tag value name "Satisfies" (instead of "Error_Code" in my first post but it should works the same).
I created this script in the Scripting repository cf. image : https://pasteboard.co/IYDqyZ5.png
Code: [Select]
!INC Local Scripts.EAConstants-JScript
/*
 * Script Name:
 * Author:
 * Purpose:
 * Date:
 */
function getSatisfies(args)
{
    var tagName = "Satisfies";
    var separator = ", ";
    var opGuid = arguments[0];
   
    // Select the operation by Guid
    var selectedObject as EA.Element;
    selectedObject = Repository.GetMethodByGuid(opGuid);
    if(selectedObject == null)
    {
        // Operation not found
        Session.Output("Op NotFound");
        return "";
    }
    // Select tags associated to the selected operation
    var tags as EA.Collection;
    tags = selectedObject.TaggedValues;
    if(tags == null)
    {
        // tag value not found
        Session.Output("Tag NotFound");
        return "";
    }
    var ret = "";
    for(var i = 0; i < selectedObject.TaggedValues.Count; i ++)
    {
        var currentTag = selectedObject.TaggedValues.GetAt(i);
        // Select only tag value "Satisfies"
        if(currentTag.Name == tagName)
        {
            if(ret != "")
                ret += separator;
            ret += currentTag.Value;
        }
    }
    Session.Output("Find, List Satisfies: " + ret);
    return ret;
}
getSatisfies("{5A1C4F8A-32B5-40a2-B151-391CA4DD8FC2}");
This script works well and I got my string with all the value I need. But now I try to call in "Code Template Editor":
Code: [Select]
$satifies = ""
$satifies = %EXEC_ADD_IN("tagValue","getSatisfies",opGUID)%
But nothing happen when I generate.
What is wrong with my Script? I am pretty sure its not an ADD IN but I can not how to figure this out.

By the way I use a EA Version 13 and on the link you give me it is wrote "This feature is available from Release 15.0", but I saw some topics on this forum talking about EXEC_ADD_IN in 2007 so I imagine I can used it ?

Last question, I have to generate also the design in Word format and I have the same problem with this tagValue.
I had opened an old topic to write my SQL querry to get all my informations : https://www.sparxsystems.com/forums/smf/index.php/topic,43712.msg258942.html#msg258942

Can I also call the same script in my SQL Fragment ?

Thanks for the help

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
Re: [Code generation] List all opTag:"myTag" for an operation
« Reply #6 on: March 12, 2020, 10:23:06 am »
If you're limited to version 13 you'll need to create an add-in in a language like C#. See the help for examples about how to do that.

The javascript add-in described in the help is a way to define your add-in within your model and code it using an external IDE and language. As the help says, that functionality was introduced in version 15.