Book a Demo

Author Topic: Adding tagged values to certain elements  (Read 42096 times)

ducatiross

  • EA User
  • **
  • Posts: 114
  • Karma: +1/-0
    • View Profile
Adding tagged values to certain elements
« on: December 16, 2014, 03:22:36 am »
Hi everyone,

I need to add some tags and values to all elements of the Message stereotype in my model.

I have a relatively large number (250+) and I don't want to go through each one by hand adding the three tags I want and the values for each.

What would you suggest is the best way to do this ?

I would normally dive in and do an 'INSERT' statement against the SQL Server table t_objectproperty but I am concerned this will 'break' my model and wondered if there is a better way ? Also, I am a little unsure as to how to generate the ObjectID and ea_GUIDs correctly.

Initially, all Message elements would have the same 3 tags and the same value for each of the tags.

I'd hoped I could do something at the object type level that would then apply the 3 tags to every instance of that object, but I can't see a quick way to do it.

I'm not a VB or C# programmer so I would be scared of scripting something unless it was at Idiot-capability level  :)

Any ideas much appreciated.

thanks
« Last Edit: December 16, 2014, 04:03:44 am by ducatiross »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding tagged values to certain elements
« Reply #1 on: December 16, 2014, 04:46:43 am »
If your tags are just stand-alone tags without connection to a MDG you could use a SQL which inserts in t_objectproperties. If the tags are part of a MDG then it's getting tricky...

q.

Tomasz

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Adding tagged values to certain elements
« Reply #2 on: December 16, 2014, 10:38:43 pm »
Maybe that C# implementation will help you:


EA.ConnectorTag tag = message.TaggedValues.AddNew("operation_guid", "String");
                        tag.Value = method.MethodGUID;                        
                        tag.Update();

                        message.TaggedValues.Refresh();
                        message.Update();


That's the example how to add Tagged Value to connector element.
But "TaggedValue" is available in other elements too.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding tagged values to certain elements
« Reply #3 on: December 16, 2014, 11:04:38 pm »
You neither need message.TaggedValues.Refresh (except you want to iterate over the collection in the following) nor message.Update since you have not changed it.

q.

ducatiross

  • EA User
  • **
  • Posts: 114
  • Karma: +1/-0
    • View Profile
Re: Adding tagged values to certain elements
« Reply #4 on: December 17, 2014, 01:46:03 am »
Thank you both, but as I don't know any C# I don't really understand this. Is there a way to generate the EA_GUID and Property/Object IDs from a SQL statement ? If not, I may have to learn C# !!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding tagged values to certain elements
« Reply #5 on: December 17, 2014, 01:51:21 am »
You can use any programming language you might know :-)

Using SQL is not that difficult. Finding the element GUIDs is
Code: [Select]
SELECT ea_guid FROM t_object WHERE t_object.Stereotype = "Message"
Inserting into t_objectproperties would need the column Object_ID as well since that needs to be stored along with the tag info to link it to the element.

q.

ducatiross

  • EA User
  • **
  • Posts: 114
  • Karma: +1/-0
    • View Profile
Re: Adding tagged values to certain elements
« Reply #6 on: December 17, 2014, 08:04:31 pm »
q. - I am happy selecting existing fields (EA_GUID, Object ID etc) from records using SQL. What I am asking is that if I am to INSERT new records into t_objectproperties for my 3 tags and their values, I need to be able to generate NEW ea_GUIDs and Object_IDs in this table, and I don't know how to do this.

Does the t_objectproperties table have a trigger on it that automatically sets the ea_GUID and Object_ID when a record is inserted into it if the appropriate field is set to NULL ?

If not, how do I generate new ea_GUIDs and Object_IDs ?

thanks for your continued assistance. It's appreciated.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding tagged values to certain elements
« Reply #7 on: December 17, 2014, 10:06:29 pm »
GUIDs are GUIDs. There are lots of libraries that can generate them. Depending on the language/library of your choice select one GUID generator and use it.

Object_IDs are unique numbers per repository. If haven't tried, but when you omit it on insert the DB should generate it as unique key automatically.

q.

P.S. Just made a test with EAP and there it works.
Code: [Select]
Repository.Execute("INSERT INTO t_object (Name, ea_guid) VALUES ('test', '4711')")Of course you will not see it in the browser, but Object_ID is set automatically.
« Last Edit: December 17, 2014, 10:13:49 pm by qwerty »

ducatiross

  • EA User
  • **
  • Posts: 114
  • Karma: +1/-0
    • View Profile
Re: Adding tagged values to certain elements
« Reply #8 on: December 18, 2014, 03:18:51 am »
Great thanks q. I will give this a try.

ducatiross

  • EA User
  • **
  • Posts: 114
  • Karma: +1/-0
    • View Profile
Re: Adding tagged values to certain elements
« Reply #9 on: December 18, 2014, 04:42:07 am »
OK, I've given this a try in the Project Search window of EA, but whilst it accepts SELECT statements, it doesn't seem to run INSERT statements as I cannot get any records inserted to t_objectproperties.

Here is my statement :-
Repository.execute("insert into t_objectproperties ( Object_id, Property, Value, ea_guid) values (243,'MsgMechanism','Unknown','{EA591C5B-2E8F-4448-8358-31AA96F4B712}' )")
Repository.Update()

Nothing seems to happen.

Nor does it if I run a simple INSERT statement without the Repository.execute method.

I think I need to read your 'Scripting EA' book - qwerty !

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding tagged values to certain elements
« Reply #10 on: December 18, 2014, 05:02:55 am »
This is a VB statement. Run it in a VB script. You must not supply the object_id, it is created automatically.

There is no Repository.Update. Leave that away.

q.
« Last Edit: December 18, 2014, 05:05:18 am by qwerty »

ducatiross

  • EA User
  • **
  • Posts: 114
  • Karma: +1/-0
    • View Profile
Re: Adding tagged values to certain elements
« Reply #11 on: December 18, 2014, 11:53:48 pm »
I have done some more reading and opened the Tools>Scripting window (for the first time) and found loads of useful stuff, including a VB Script to add a tagged value to an element - TVSetElementTaggedValue - just want I wanted !!

There is even a script to generate a GUID !

I will now brush up my VB scripting skills and give this a try as it seems to be exactly what I was after.  :)
« Last Edit: December 19, 2014, 12:09:13 am by ducatiross »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding tagged values to certain elements
« Reply #12 on: December 19, 2014, 12:11:38 am »
It's almost never too late  ;)

q.

ducatiross

  • EA User
  • **
  • Posts: 114
  • Karma: +1/-0
    • View Profile
Re: Adding tagged values to certain elements
« Reply #13 on: December 20, 2014, 02:41:54 am »
I've been looking into this further, and whilst the VBScript approach would update existing elements, what I really want to do is this and ensure that any future Message element created automatically has the Tags I want.

I've been reading the help file, and found that there is a feature where I can Synchronise Stereotypes. The help for this says :-

"When you create an element, attribute, operation or connector from a profiled object, the Tagged Values and constraints are added from the Profile stereotype. Subsequently, you might update the constraints or Tagged Values of a particular stereotype in the Profile, in which case the items already created in the model would not have those additional constraints or Tagged Value tags and notes."

"You can apply the updated or missing Tagged Values and constraints using the Synchronize Stereotype function. This operates on any profiled element in your model, from any technology that is integrated with or imported into Enterprise Architect."


Now, this sounds like just what I want in that it will add the tags to all existing Message elements, and also, when I create new ones, add the tags to these as well.

However, I cannot find a way to modify the standard Message (in the BPMN 2 toolbox) to add the three tags I want. I don't understand the help as it talks of editing the Profile. Where do I find the Profile for the Message element and how then do I edit it to add the Tags I want ?

I've spent  a good few hours looking, but without success (I have tried the Profile toolbox, but I didn't understand it or do the right thing) , so I am now hoping that my Sparxian experts will point me in the right direction !
« Last Edit: December 20, 2014, 02:44:48 am by ducatiross »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding tagged values to certain elements
« Reply #14 on: December 20, 2014, 02:52:34 am »
Look into this: http://community.sparxsystems.com/tutorials/552-24intro-to-creating-a-mdg-file

Note that applying a stereotype will only add tags automatically from V10 on. Before you need to explicitly synch TVs.

q.
« Last Edit: December 20, 2014, 03:15:22 am by qwerty »