Author Topic: XSD transformation: attribute mapping  (Read 9811 times)

Guillaume

  • EA User
  • **
  • Posts: 629
  • Karma: +18/-0
    • View Profile
    • www.umlchannel.com
XSD transformation: attribute mapping
« on: February 10, 2016, 07:58:07 pm »
Hi,

I'm looking into XSD related EA features to identify the most efficient way to achieve the following: define a UML class to transform to an XSD model, and generate the schema (XSD or JSON file) with the Schema Composer.
I can't figure out the mapping of attribute types between UML and XSD ; is there any information available on this?

I created UML classes with Language = None ; this does not seem to be appropriate since the number of attribute types is limited.
e.g. I'd like to define a UML class with an attribute which will transform in an XSD element "Year" of type xs:gYear.

Thanks
Guillaume
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8204
  • Karma: +193/-23
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XSD transformation: attribute mapping
« Reply #1 on: February 10, 2016, 08:11:58 pm »
Hi Guillaume,

I had the same issue, and I finally sorted it out using a post-processing script I ran after the transformation.

Geert

Guillaume

  • EA User
  • **
  • Posts: 629
  • Karma: +18/-0
    • View Profile
    • www.umlchannel.com
Re: XSD transformation: attribute mapping
« Reply #2 on: February 11, 2016, 12:19:04 am »
Hi Geert,

Thanks for the information. Your VB library looks very interesting.
I ran some tests with the post-processing script which provides some good examples of improving EA XSD transformation.
Whilst EA is great at being customised to achieve the expected result, I'm trying to figure out the logic behind EA XSD support with the aim to identify exactly the areas that need to be improved (with scripts or Sparx EA enhancements).

- UML to XSD model transformation mostly leads to XSDComplexType classes with unstereotyped attributes which type is copied as is from the UML model (PIM) e.g int, string, boolean
   Note: before transforming a PIM to a PSM model, aggregation links need to be replaced with directed associations.
   Inheritance links seem to be supported, although Rodrigo suggests in his blog blog to create XSD Choices (this should be supported in Sparx EA transformation scripts perhaps via an option to create XSDChoices for inheritance. Alternatively a script can be used to achieve this)
   --> Feature request 1
   
- Once the transformation has been carried out, results are shown in a class diagram
   Note: there is an XML Schema toolbox in EA which should IMHO be displayed with this diagram. However there doesn't seem to be any diagram type associated with this toolbox in EA (should be added by Sparx).
   --> Feature request 2

- Attributes are not stereotyped. However when you use the XML Schema toolbox, you notice that XSD elements and XSD attributes can be defined. Advantage is to have access to XML Schema primitive data types. So it would appear more suitable to get XSDElement stereotyped attributes as a result of EA XSD transformation.
   --> Feature request 3

- Once the XML Schema model is completed, XSD or JSON files can be generated using the Schema Composer. This tool provides the advantage of letting you create several profiles from the same model if needed, where a selection can be carried out on what needs to be included for a message.
   Note: XSDElement and XSDAttribute attributes are not properly supported when the XSD file is generated i.e. the data type is missing
   In the following example, attribute1 is stereotyped XSDAttribute with the string type, and element1 is stereotypedXSDElement with the string type

   <xs:complexType name="Product">
   <xs:sequence>
      <xs:element name="attribute1" minOccurs="1" maxOccurs="1" type=""/>
         <xs:element name="element1" minOccurs="1" maxOccurs="1" type=""/>
         <xs:element name="name" minOccurs="1" maxOccurs="1" type="xs:string"/>         
      </xs:sequence>
   </xs:complexType>


Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Rodrigo Nascimento

  • EA User
  • **
  • Posts: 33
  • Karma: +3/-0
    • View Profile
Re: XSD transformation: attribute mapping
« Reply #3 on: February 12, 2016, 08:48:05 am »
Hello Chaps!

Here is my humble contribution to this interesting topic...

UML to XSD model transformation

I believe that customising the XSD Transformation Template should solve all your problems. I'm not an expert in this area as I'm not that familiar with the 'Intermediary Language', but I've done a few customisation for problems similar to yours. Starting with the Classes, the only 2 XSD types that are mapped in the default template are XSDComplexType and enumeration. Here is the extract from the XSD Class template:

Code: [Select]
name=%qt%%className%%qt%
%if classStereotype=="enumeration"%
  stereotype="enumeration"
%else%
  stereotype="XSDcomplexType"
%endIf%

I never had to use stereotypes for the attributes, as the most important for me has been the rules to translate the PIM attribute types to XSD types. In order to create this mapping, you can customise the following part of the XSD Attribute template:

Code: [Select]
name=%qt%%attName%%qt%
  scope="Public"
 %if attType=="Date" or attType=="DateYear" or attType=="DateCalendar"%
  type="xs:dateTime"
 %elseIf attType=="Time"%
  type="xs:time"
 %elseIf attType=="Decimal"%
  type="xs:decimal"
 %elseIf attType=="Integer"%
  type="xs:integer"
 %else%
  type="xs:string"

You could also do the same for stereotypes if required.

Regarding the inheritance/generalisation/specialisation, there is a new functionality on schema composer in v12.1 that enables the specialisations of a specific generalised class to be realised as a XSD choice. Check this page of the user guide for more information:

http://goo.gl/1Wqe0R

Although this is a great feature that I've been waiting, it has some bugs that I've already reported. I can post some information in the respective forum area if you guys are interested.

XSD Schema Toolbox

For this one, I will use a traditional phrase from most of the IT support people: "It is working on my machine"  ;D

Attributes are not stereotyped

GOTO my first point. ;)

Other considerations

Regarding the physicalisation of the models as JSON or XSD format, I've been doing few tests and believe that (unless you use exactly the same structure for both formats) they should be treated as 2 different PSMs. The main reason is that XSDs are usually related to coarse grained functionalities (i.e. backend systems integration services, ETL) or persistence storages (i.e. databases), and JSON related to more fine grained functionalities (i.e. APIs, microservices). Therefore, the latter usually demands a flatter structure.

Please let me know if it makes sense or if I misinterpreted any of your points.

Regards,
Rodrigo


« Last Edit: February 12, 2016, 07:46:55 pm by Rodrigo Nascimento »
Please check my blog for more EA related articles!

http://connection.rnascimento.com

Guillaume

  • EA User
  • **
  • Posts: 629
  • Karma: +18/-0
    • View Profile
    • www.umlchannel.com
Re: XSD transformation: attribute mapping
« Reply #4 on: February 15, 2016, 10:24:58 pm »
Hi Rodrigo,

Thanks about your advice; it's really useful  :)
I managed to apply transformationnrules on the attributes type and stereotype, as well as on the connectors (aggregations are replaced with directed associations).
I still have to test the Schema Composer handling of inheritance.

I will post details on what I came up with via an article once I've fully tested my templates and reviewed with colleagues.

Note: I noticed that EA stores hidden associations between the original and the transformed class (t_xref). Where it wouldn't be difficult to add a script or addin to find related elements based on this, it would make more sense that this relation can be used via an EA built-in feature.

Cheers,
Guillaume
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Rodrigo Nascimento

  • EA User
  • **
  • Posts: 33
  • Karma: +3/-0
    • View Profile
Re: XSD transformation: attribute mapping
« Reply #5 on: February 15, 2016, 10:46:10 pm »
I'm glad it was useful!

I believe that the hidden associations you are talking about is actually the traceability between PIM and PSM. All the transformed classes have the link back to the original ones. You can see this relationship in the traceability window, just click on the transformed class and you will see the relationship under "transformed from".

When you update your PIM model and transform to a specific PSM (i.e. XSD), Sparx uses this relationship to check if the class already exists (to be updated) or if it is a new one (to be created).

Does it make sense?

Cheers,
Rod
Please check my blog for more EA related articles!

http://connection.rnascimento.com

Guillaume

  • EA User
  • **
  • Posts: 629
  • Karma: +18/-0
    • View Profile
    • www.umlchannel.com
Re: XSD transformation: attribute mapping
« Reply #6 on: February 16, 2016, 07:48:10 pm »
Hi Rodrigo,

Thanks for the hint about the Traceability view.

I modified the XSD model transformation template to achieve most of the enhancements I was after.
The only remaining issue I have so far is to do with inheritance support in the Schema Composer.

The following article summarises the work I carried (custom MDA template is available to download): http://goo.gl/hjqXEJ

Please let me know what you think, and if you have any suggestion on inheritance links.

Cheers,
Guillaume
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8204
  • Karma: +193/-23
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XSD transformation: attribute mapping
« Reply #7 on: February 16, 2016, 08:18:56 pm »
Guillaume,

I'm currently working with another client on a similar track: define service definitions from the EA model.
I developed a schema composer add-in in order to generate a subset model that contains the selections in from the schema composer.
From this subset model we use another add-in (developed by someone else) to generate the XSD's for the messages and the WSDL.

In the subset we flatten generalizations by only retaining the lowest level.

See http://bellekens.com/ecdm-message-composer/ for more details.

Geert

Guillaume

  • EA User
  • **
  • Posts: 629
  • Karma: +18/-0
    • View Profile
    • www.umlchannel.com
Re: XSD transformation: attribute mapping
« Reply #8 on: February 18, 2016, 08:37:21 pm »
Thanks for the advice Geert.

I noticed that XSDAttributes-stereotyped attributes are generated as XSD elements e.g. with attribute1 below.
   <xs:complexType name="Product">
      <xs:sequence>
         <xs:element name="attribute1" type="xs:string"/>

Is this something that can be resolved via a custom Schema Addin?
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8204
  • Karma: +193/-23
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XSD transformation: attribute mapping
« Reply #9 on: February 18, 2016, 08:42:49 pm »
Yes, you could create a schema composer add-in that generates the XSD , or you could create a subset model and use the standard XSD generation, or you could create an add-in to generate your XSD starting from the subset model.

The last option is what we chose at this particular client because it allows the most flexibility (but also requires quite some work)

Geert

Rodrigo Nascimento

  • EA User
  • **
  • Posts: 33
  • Karma: +3/-0
    • View Profile
Re: XSD transformation: attribute mapping
« Reply #10 on: February 19, 2016, 12:23:41 am »
This is a good point for reflexion...

As Geert said, the add-in will allow you to customise the way you generate subset models or files. I like the idea of generating subset models from your PSM XSD models as it gives you the flexibility to make adjustments to the model at the physical level (i.e. flattening the schema, merging classes...) without affecting the XSD "logical model" (PSM). The main trade-off is that this approach results in the management of three different models (PIM, PSM and "physical") instead of two (PIM and PSM).



 
Please check my blog for more EA related articles!

http://connection.rnascimento.com

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8204
  • Karma: +193/-23
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XSD transformation: attribute mapping
« Reply #11 on: February 19, 2016, 12:36:43 am »
We even do it differently

At one client we have
- PIM Common/Canonical Model (contains several standard framework models)
- PIM Service Model (contains the definition of the service, interfaces, operations and messages)
- PIM Message Model (cherry picked from the PIM Common Model using the schema composer, and duplicated in a subset using the ECDM Message Composer addin)
- XSD/WSDL files (created using another add-in directly from the PIM message model)

Geert

Rodrigo Nascimento

  • EA User
  • **
  • Posts: 33
  • Karma: +3/-0
    • View Profile
Re: XSD transformation: attribute mapping
« Reply #12 on: February 19, 2016, 01:27:46 am »
Was there any particular reason for not following Sparx functionalities for the MDA approach?

PIM -> PSM -> code generation

I found it very useful as I can use the MDA Transformation Templates to translate my PIM to different PSM models.
Please check my blog for more EA related articles!

http://connection.rnascimento.com

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8204
  • Karma: +193/-23
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: XSD transformation: attribute mapping
« Reply #13 on: February 19, 2016, 04:59:12 am »
I haven't decided, but this client had looked at the MDA templates stuff and found it not flexible enough.

I haven't done too much work with MDA transformation templates, but I could not tell them wrong. My experience wasn't entirely pleasant  :-\

The advantage of skipping the PSM model is that it is one less model to maintain.

Geert

Guillaume

  • EA User
  • **
  • Posts: 629
  • Karma: +18/-0
    • View Profile
    • www.umlchannel.com
Re: XSD transformation: attribute mapping
« Reply #14 on: February 19, 2016, 07:08:26 pm »
Interesting views.. food for thoughts  ;)

For my current context, I created a Schema Addin (having looked at Sparx sample + Rodrigo's article) and managed to create XSD Attribute in the XSD file.
So I have an amended MDA template to generate the XML Schema PSM from the PIM, and a addin to generate the appropriate XSD from the PSM.

This approach is going to be suggested to 2 dev teams; hopefully this will be useful.

Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com