Page 1 of 1

Changing ID of Element Model

PostPosted: Mon Mar 06, 2006 11:14 am
by Raul Lorenzo
Hi,

I need to change the ID of an element with setID() method but always get
an IlegalStateException. I need to change the ID of an element because I
am developing a plugin which imports information from a database, so i
need to know its primary key to manage updates of model to import again
to MagicDraw per example.
How could I do to setID work?

or

Could be available another element property to store the primary key?
(In this way I think setID shouldn´t be called).

Re: Changing ID of Element Model

PostPosted: Wed Mar 08, 2006 4:39 am
by Tomas Pugzlys
Hello,

ID of the model element is not mutable.

>Could be available another element property to store the primary key

You may store your primary key in the model element comment
by using methods:
ModelHelper.setComment(element, commentBody)
ModelHelper.getComment(Element element)

Comments are used for user documentation.
So storing your database id maybe not always appropriate.

Another way to create some model element that caries database id info.
For classifiers you may create attribute with name "id" and default
value containing database id.

The most universal and correct way would be to use tagged values.

The following steps:
1.Create your custom stereotype with name "databaseEntity".
2.Create tagged definition property in stereotype with name "id" and
assign type string.
3.Apply "databaseEntity" stereotype and create id tagged value for model
element.

Feel free to contact us, if you have any implementation questions.

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363- IV, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple

nntp://news.nomagic.com/nomagic.products.magicdrawuml.openapi wrote:
> Hi,
>
> I need to change the ID of an element with setID() method but always get
> an IlegalStateException. I need to change the ID of an element because I
> am developing a plugin which imports information from a database, so i
> need to know its primary key to manage updates of model to import again
> to MagicDraw per example.
> How could I do to setID work?
>
> or
>
> Could be available another element property to store the primary key?
> (In this way I think setID shouldn´t be called).
>
>


Re: Changing ID of Element Model

PostPosted: Wed Mar 08, 2006 6:23 am
by Raul Lorenzo
I attached the code I use to create the element model. I hope helps a
bit more.


Raul Lorenzo escribió:
> Hi,
>
> I need to change the ID of an element with setID() method but always get
> an IlegalStateException. I need to change the ID of an element because I
> am developing a plugin which imports information from a database, so i
> need to know its primary key to manage updates of model to import again
> to MagicDraw per example.
> How could I do to setID work?
>
> or
>
> Could be available another element property to store the primary key?
> (In this way I think setID shouldn´t be called).


Re: Changing ID of Element Model

PostPosted: Wed Mar 08, 2006 11:18 am
by Raul Lorenzo
Tomas Pugzlys escribió:
> Hello,
>
> ID of the model element is not mutable.
>
>>Could be available another element property to store the primary key
>
> You may store your primary key in the model element comment
> by using methods:
> ModelHelper.setComment(element, commentBody)
> ModelHelper.getComment(Element element)
>
> Comments are used for user documentation.
> So storing your database id maybe not always appropriate.
>
> Another way to create some model element that caries database id info.
> For classifiers you may create attribute with name "id" and default
> value containing database id.
>
> The most universal and correct way would be to use tagged values.
>
> The following steps:
> 1.Create your custom stereotype with name "databaseEntity".
> 2.Create tagged definition property in stereotype with name "id" and
> assign type string.
> 3.Apply "databaseEntity" stereotype and create id tagged value for model
> element.
>
> Feel free to contact us, if you have any implementation questions.
>
> Regards,
Hi,

I create the stereotype, create the property for the stereotype; but I
don´t understand how to create the id tagged value for each element I need.

I use the code I attached to do that.
1 is implemented by Crear_StereoTipo method
2 is implemented by Crear_Propiedad method
3 should be implemented by Crear_Actor method but is incomplete and
doesn`t work.

How do I complete this to do it work?

Thanks about your good help.

Re: Changing ID of Element Model

PostPosted: Thu Mar 09, 2006 7:42 am
by Tomas Pugzlys
Hello,

Just to make it clear.
Stereotype and property needs to be created only once.

Crear_Actor method will have the following code:
...

//Establece el nombre del paquete
actor_sistema.setName(name_actor);
Stereotype stereotype = StereotypesHelper.getStereotype(estereotipo_name);
StereotypesHelper.addStereotype(nameSetter, stereotype);
StereotypesHelper.setStereotypePropertyValue(actor_sistema, stereotype,
property_name, OID);
...

Crear_Propiedad method will have the following code:
...
propiedad.setName(property_name);
DataType stringDataType =
ModelHelper.findElementInCollection(project.getDataTypes().getOwnedElement(),
"String");
propiedad.setType(stringDataType);
//Call to ModelElementsManager AddElement method.
...

In order to get the tagged value use
StereotypesHelper.getStereotypePropertyValue(Element element, Stereotype
stereotype, String propertyName).

If it is more convenient to work with tagged values as strings
use StereotypesHelper.getStereotypePropertyValueAsString(...) with the
same parameters.

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363- IV, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple


Re: Changing ID of Element Model

PostPosted: Thu Mar 09, 2006 10:17 am
by Raul Lorenzo
Hello,

I got that works!!!, Thanks for your help

Raul

Tomas Pugzlys escribió:
> Hello,
>
> Just to make it clear.
> Stereotype and property needs to be created only once.

....