Author Topic: Transform issues  (Read 14386 times)

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Transform issues
« on: January 26, 2019, 02:46:52 am »
I am writing a transform template and have 2 questions:

1) how to remove the suffix of a name.

The following code works
Code: [Select]
%if elemType != "Class" and elemType != "Interface" and elemType != "Enumeration"%
%endTemplate%

%elemType%
{
%TRANSFORM_REFERENCE("Class")%
stereotype = "Blah"
 
name=%qt%%CONVERT_NAME(className, "Underscored", "Ht( )Ht")%%qt%
 
}
%list="Connector" @separator="\n"%

But the code I really need is but it throws an error on
Code: [Select]
name=%qt%%REPLACE(className, "_oplog", " ")%%qt%
Code: [Select]
%if elemType != "Class" and elemType != "Interface" and elemType != "Enumeration"%
%endTemplate%

%elemType%
{
%TRANSFORM_REFERENCE("Class")%
stereotype = "Logical Data Entity"
 
name=%qt%%REPLACE(className, "_oplog", " ")%%qt%
name=%qt%%CONVERT_NAME(className, "Underscored", "Ht( )Ht")%%qt%
 
}
%list="Connector" @separator="\n"%

2) What transform do I need to write to create a relationship between what is being transform and the transformation result - i.e., between the class being transformed and the class resulting from the transformation.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Transform issues
« Reply #1 on: January 29, 2019, 09:40:09 am »
1) The only odd thing I see is that you're generating a name twice. I suspect you want something like this
Code: [Select]
$name=%REPLACE(className, "_oplog", " ")%
name=%qt%%CONVERT_NAME($name, "Underscored", "Ht( )Ht")%%qt%

2) https://sparxsystems.com/enterprise_architect_user_guide/14.0/model_domains/transform_connectors.html

Quote
This script creates a Dependency from a Class created in a transformation, to the Class it was transformed from:

Code: [Select]
Dependency
{
%TRANSFORM_REFERENCE("SourceDependency",classGUID)%
stereotype="transformedFrom"
Source
{
%TRANSFORM_REFERENCE("Class",classGUID)%
}
Target
{
GUID=%qt%%classGUID%%qt%
}
}

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Re: Transform issues
« Reply #2 on: January 29, 2019, 08:09:27 pm »
1) The only odd thing I see is that you're generating a name twice. I suspect you want something like this
Code: [Select]
$name=%REPLACE(className, "_oplog", " ")%
name=%qt%%CONVERT_NAME($name, "Underscored", "Ht( )Ht")%%qt%
This is indeed what I am trying to do but I am still getting an error, the error reads:

There was an error parsing on line [nn].
Unexpected symbol: [class name] - "_oplog"

It is weird, it appears as if
Code: [Select]
$name=%REPLACE(className, "_oplog", " ")% works as expected but
Code: [Select]
name=%qt%%CONVERT_NAME($name, "Underscored", "Ht( )Ht")%%qt% fails.

I must be missing something obvious.

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Re: Transform issues
« Reply #3 on: February 08, 2019, 05:50:29 am »
My mistake, I ended up with
Code: [Select]
$name = %qt%%REPLACE(className, "_oplog", "")%%qt%
name=%CONVERT_NAME($name, "Underscored", "Ht( )Ht")%

Instead of

Code: [Select]
$name=%REPLACE(className, "_oplog", " ")%
name=%qt%%CONVERT_NAME($name, "Underscored", "Ht( )Ht")%%qt%

Sparx EA does not like this at all.

I do have a 3 additional questions:
1) Is there are online reference on how this very Sparxish language is supposed to work?

I have written an Attribute transformation, it works fine but:
2) how can I transform the attribute stereotype or remove it altogether?
3) can I write a statement like:
Code: [Select]
$name = %qt%%CONVERT_NAME($name, "Underscored", "Ht( )Ht")%%qt%

if $name contains "id" replace "id" with "ID"

if $name="Oid" then replace "Old" with "OID"

and so on

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Transform issues
« Reply #4 on: February 08, 2019, 10:45:11 am »
1) Look for transform templates and code generation templates in the help.
2) Add "stereotype" to the TRANSFORM_CURRENT. Each argument added prevents it from copying the original value for that field.
Code: [Select]
%TRANSFORM_CURRENT("scope","type","stereotype")%3)Yes, you can do a replace on the result of a previous one. (btw. Did you want to repliace _oplog with a space, or did you want to remove it?)
Code: [Select]
$name=%REPLACE(className, "_oplog", "")%
$name=%REPLACE($name, "id", "ID")%
$name=%REPLACE($name, "Oid", "OID")%

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Re: Transform issues
« Reply #5 on: February 26, 2019, 07:45:35 pm »
This works nicely :). Thank you for the tips.

I have noticed the following behaviour: if I transform a class with a transformation template and later change/tweak the transformation template, when I transform again a class that has been transformed before Sparx EA updates correctly the class resulting from the previous transformation. Is this intended functionality or one of the many undocumented things Sparx EA does?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Transform issues
« Reply #6 on: February 27, 2019, 09:50:04 am »
In your template you have %TRANSFORM_REFERENCE("Class")%. That generates the binding so that synchronization can occur. EA doesn't care if changes are because of the template changing or the original class changing.

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Re: Transform issues
« Reply #7 on: September 14, 2019, 01:22:05 am »
Sorry to bring this topic back to the top of the forum. I have been writing some transformations with a colleague and everything works fine except for the usual annoying problem.

We have the following model structure:

Model (root)
----A(package)
--------B (package)

We have written a template to transform B (or individual elements in package B) into package C, with "C" being the package name specific in the "File" macro.

Model (root)
----A(package)
--------B (package)
--------C (transformed package)

The elements are transformed correctly but whatever we do, we always end up with wrong package structure, we end up with

Model (root)
----A(package)
--------B (package)
--------C (package)
-----------B (transformed package)

To sum up the second B package is redundant.

Code on the "File" macro
Code: [Select]
Package
{
name="C"

%list="Namespace" @separator="\n\n" @indent="  "%
}

Code in the "Namespace" macro
Code: [Select]
%if packagePath == ""%

%list="Class" @separator="\n"%
%endTemplate%

Package
{
  %TRANSFORM_CURRENT()%

%list="Class" @separator="\n" @indent="  "%
}
« Last Edit: September 16, 2019, 04:31:30 am by Modesto Vega »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Transform issues
« Reply #8 on: September 16, 2019, 09:31:02 am »
If you don't want the origin namespace generated, don't create one in your Namespace template.

Code: [Select]
%list="Class" @separator="\n"%
Or, if there's any chance your source could contain a deeper structure in the future...

Code: [Select]
%if packagePath == ""%
%list="Class" @separator="\n"%
%endTemplate%

%list="Namespace" @separator="\n\n" @indent=""%
%list="Class" @separator="\n" @indent=""%

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Re: Transform issues
« Reply #9 on: September 16, 2019, 06:58:12 pm »
Or, if there's any chance your source could contain a deeper structure in the future...

Code: [Select]
%if packagePath == ""%
%list="Class" @separator="\n"%
%endTemplate%

%list="Namespace" @separator="\n\n" @indent=""%
%list="Class" @separator="\n" @indent=""%

This code in our Namespace works without a deeper structure but does not work with a deeper package structure. It transforms

Model (root)
----A(package)
--------B (package)

Correctly into (with "C" being the package name specific in the "File" macro).

Model (root)
----A(package)
--------B (package)
--------C (transformed package)

But does not transform

Model (root)
----A(package)
--------B (package)
----------B1 (package)
------------B1a (package)
------------B1b (package)

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Re: Transform issues
« Reply #10 on: September 17, 2019, 02:07:39 am »
One other question, is it possible to write a transform for the Class macro that checks if a class has attributes and transform it only, and only if, it has attributes?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Transform issues
« Reply #11 on: September 17, 2019, 08:55:18 am »
This code in our Namespace works without a deeper structure but does not work with a deeper package structure.
Sorry, you need to list child namespaces in the empty packagePath option too, which means there's no conditional behavior at all.
Code: [Select]
%list="Namespace" @separator="\n\n" @indent=""%
%list="Class" @separator="\n" @indent=""%

One other question, is it possible to write a transform for the Class macro that checks if a class has attributes and transform it only, and only if, it has attributes?
Put this at the top of your class template.
Code: [Select]
$atts=%list="Attribute" @separator="\n" @indent="  "%
%if $atts==""%
%endTemplate%

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Re: Transform issues
« Reply #12 on: September 18, 2019, 01:00:03 am »
Put this at the top of your class template.
Code: [Select]
$atts=%list="Attribute" @separator="\n" @indent="  "%
%if $atts==""%
%endTemplate%
This works fine, thanks for your help.

Sorry, you need to list child namespaces in the empty packagePath option too, which means there's no conditional behavior at all.
Code: [Select]
%list="Namespace" @separator="\n\n" @indent=""%
%list="Class" @separator="\n" @indent=""%

I don't understand this, the following namespace code variations do not transform sub-packages
Code: [Select]
%if packagePath == ""%
%list="Namespace" @separator="\n\n" @indent=""%
%list="Class" @separator="\n" @indent=""%
%endTemplate%

%list="Namespace" @separator="\n\n" @indent=""%
%list="Class" @separator="\n" @indent=""%

Code: [Select]
%if packagePath != ""%
%list="Namespace" @separator="\n\n" @indent=""%
%list="Class" @separator="\n" @indent=""%
%endTemplate%

%list="Namespace" @separator="\n\n" @indent=""%
%list="Class" @separator="\n" @indent=""%

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Transform issues
« Reply #13 on: September 18, 2019, 10:55:31 am »
If you're wanting to generate a flat copy of the contents of nested namespaces, copy the ddl templates.

File
Code: [Select]
Package
{
  name="DDL"
  namespaceroot="true"
%list="Namespace" @separator="\n\n" @indent="  "%
}

Namespace
Code: [Select]
%list="Namespace" @separator="\n\n"%
%list="Class" @separator="\n\n"%

If you're wanting to include the packages, just not the first one. Go back to the starting namespace template and mark that top package as a namespace root.

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1080
  • Karma: +28/-8
    • View Profile
Re: Transform issues
« Reply #14 on: September 19, 2019, 12:56:43 am »
Almost there, this is a bit more painful than expected. The following code works, it creates a more complex package structure in almost all cases as long as "Include child packages" is specified in the dialog - please not the emphasis as this is very important.

File
Code: [Select]
%list="Namespace" @separator="\n\n"%
%list="Class" @separator="\n\n"%

Namespace
Code: [Select]
$transformedPkgNm = %REPLACE(packageName, "P", "L")%

Package
{
namespaceroot="true"
name = %qt%$transformedPkgNm%qt%

%list="Namespace" @separator="\n\n"%
%list="Class" @separator="\n\n"%

}

There 2 things that need addressing and something I do not understand:
  • namespaceroot="true" does not appear to do anything, we get the same behaviour in both v13 and v15
  • the transform appears to behave differently in v13 and v15, in v13 it works fine but in v15 it also transforms the parent package - i.e., no matter what we do in v15 transformation p2 on a model\p1\p2 structure always copies p1 but in v13 it does not.
  • somehow I was expecting to be able to create a (traceability) matrix but I cannot which is leading me to think that a Trace is not created between original and transform elements (I am not referring to the Trace functionality under Design in the ribbon).