Book a Demo

Author Topic: Custom MDA Transformation  (Read 3413 times)

bstoddart

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Custom MDA Transformation
« on: February 04, 2011, 01:25:59 am »
Hello,

This is my first attempt at creating a custom MDA transformation. First, I am creating a DDL transformation which should be pretty simple, but things are not working out quite right. What I am trying to do is set the attribute type based on attribute name suffix. For example, if the name ends with _Id, then the type is guid, if Indicator, then Boolean, etc.  You get the idea.  The type is not set in the PIM it is determined during the transform.

Here is a sample of the Attribute template...it is raw...just trying to get it to work.

%if attName == "Id"%
  PrimaryKey
  {
    Column
    {
      %TRANSFORM_CURRENT("type", "stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
      type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,"guid")%%qt%
    }
  }
  %else%
      $genType="_"+%attName%
      $genType=%qt%+%RIGHT($genType,2)%+%qt%
      %If $genType == "id"%
            Column
            {
              %TRANSFORM_CURRENT("type", "stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
              type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,"guid")%%qt%
            }
      %endIf%
      %if $genType == "or"%
            Column
            {
              %TRANSFORM_CURRENT("type", "stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
              type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,"Boolean")%%qt%
            }
      %endIf%
%endIf%


Here is what is produced in the intermediate file...

---------- DDL ----------
Package
{
  name="DDL"
  namespaceroot="true"
Table
{
  XRef{namespace="DDL" name="Table" source="{F74B34AE-E63A-4d00-BAFF-6E7B7E6FEA3C}"}
  notes=""
  scope="Public"
  multiplicity=""
  version="1.0"
  author="Bill"
  alias=""
  name="CodeList"
  complexity="1"
  concurrency=""
  persistence=""
  arguments=""
  phase="1.0"
  status="Proposed"
  visibility=""
  cardinality=""
  language="SQL Server 2008"
    PrimaryKey
  {
    Column
    {
      notes="Uniquely identifies a row in the table."
  scope="Public"
  container=""
  alias=""
  lowerbound="1"
  name="Id"
  default=""
  upperbound="1"
      type="uniqueidentifier"
    }
  }
  
      
      %If "or" == "id"%
            Column
            {
              notes=""
  scope="Public"
  container=""
  alias=""
  lowerbound="1"
  name="IsActiveIndicator"
  default=""
  upperbound="1"
              type="uniqueidentifier"
            }
      
      
}
}

The if statement seems to be correct, but it is being written instead of being executed.

Any ideas?
 :-/

Bill Stoddart



bstoddart

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Custom MDA Transformation
« Reply #1 on: February 04, 2011, 02:29:04 am »
this seems to work...not sure if it is optimal...

%if attName == "Id"%
  PrimaryKey
  {
    Column
    {
      %TRANSFORM_CURRENT("type", "stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
      type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,"guid")%%qt%
    }
  }
%endTemplate%
$isId = %qt%+%FIND(attName,"_Id")%+%qt%
$isIndicator = %qt%+%FIND(attName,"_Indicator")%+%qt%
$colName = %qt%+%REPLACE(attName,"_","")%+%qt%
%if $isId != "-1"%
      Column
      {
        %TRANSFORM_CURRENT("type", "stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
        type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,"guid")%%qt%
        name=$colName
      }
%elseIf $isIndicator != "-1"%
      Column
      {
        %TRANSFORM_CURRENT("type", "stereotype", "collection", "constant", "containment", "ordered", "static", "volatile")%
        type=%qt%%CONVERT_TYPE(genOptDefaultDatabase,"Boolean")%%qt%
        name=$colName
      }
%endIf%