OCLOperators transform
No edit summary
(Automatically adding template at the end of the page.)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
object.transform(viewmodelname, <destination object>) uses the viewmodel to transform information from <object> into the <destination object>. Returns True if transform is full.
object.transform(viewmodelname, <destination object>) uses the ViewModel to transform information from <object> into the <destination object>. Returns True if the transform is full. The transform operator takes the object as the root of the ViewModel specified and uses the ViewModel as a template to copy and create a new structure of objects.
The transform operator takes the object as the root of the viewmodel specified and use the viewmodel as a template to copy and create a new structure of objects.


Usually a false return value, i.e. not a full transform, are due to that the destination attribute could not be found or that the destination attribute is read-only. Currently there is no log available to pinpoint exactly why false is returned.
Usually, a false return value, i.e. not a full transform, is due to the fact that the destination attribute could not be found or is read-only. Currently, there is no log available to pinpoint exactly why false is returned. Read about duck-typing below for hints on what is incorrect in your transformation.


=== Example of how to use ===
=== Example of How to Use It ===
Often when sending an email you need to "collect" information from many objects to find all the information needed to create an outgoing email.
Often, when sending an email, you need to "collect" information from many objects to find all the information needed to create an outgoing email.


Using this model of an email queue lets see how objects of the OutgoingEmail and EmailAttachment can be created using transform.
Using this model of an email queue, let's see how objects of the OutgoingEmail and EmailAttachment can be created using transform.


[[File:EmailQueueClassDiagram.png|761x761px]]
[[File:EmailQueueClassDiagram.png|696x696px]]


This viewmodel and transform will fill in the OutgoingEmail and EmailAttachment by name-matching each attribute and link from the "Självfaktura" onto OutgoingEmail.
This ViewModel and transform will fill in the OutgoingEmail and EmailAttachment by name-matching each attribute and link from the "Självfaktura" onto OutgoingEmail.


[[File:TransformViewmodelForEmail.png|768x768px]]
[[File:TransformViewmodelForEmail.png|768x768px]]


(please note the "trick" self->asSet because we need an list, not a link to fill in "EmailAttachments" multi-link and Självfaktura only contains an attribute "Pdf")
(Please note the "trick" self->asSet because we need a list, not a link to fill in the "EmailAttachments" multi-link and Självfaktura only contains an attribute "Pdf".)


This is the EAL code in the "Send" action on "Självfaktura". Create the OutgoingEmail object and call transform to fill it in. If the transform isn't full (some attributes wasn't stored), we back out by removing the newly created oe object.
This is the EAL code in the "Send" action on "Självfaktura". Create the OutgoingEmail object and call transform to fill it in. If the transform isn't full (some attributes weren't stored), we back out by removing the newly created <code>oe</code> object.


  let oe = OutgoingEmail.create in
  let oe = OutgoingEmail.create in
Line 27: Line 26:
   endif
   endif
  )
  )
For completeness, this is the serverside viewmodel that sends email and thus empties the queue.
For completeness, this is the serverside ViewModel that sends emails and thus empties the queue.


[[File:ViewmodelForSendingEmail.png|447x447px]]
[[File:ViewmodelForSendingEmail.png|447x447px]]


=== Duck Typing ===
=== Duck Typing ===
Transforming objects over the class border based on similarities - as transform does - is often refered to as [[wikipedia:Duck_typing|Duck Typing]]. In MDriven the ViewModel is used as a vehicle to facilitate a type safe way to the duck type transform. The ViewModel editor has a property to enable you to typecheck your transform in design time during normal model validation:
Transforming objects over the class border based on similarities - as transform does - is often referred to as [[wikipedia:Duck_typing|Duck Typing]]. In MDriven, the ViewModel is used as a vehicle to facilitate a type-safe way to the duck type transform. The ViewModel Editor has a property to enable you to type-check your transform in design time during normal model validation:
[[File:2019-11-03 19h15 37.png|none|thumb|1193x1193px]]
[[File:2019-11-03 19h15 37.png|none|thumb|1193x1193px]]
[[Category:OCLOperators]]
{{Edited|July|12|2024}}

Latest revision as of 15:43, 10 February 2024

object.transform(viewmodelname, <destination object>) uses the ViewModel to transform information from <object> into the <destination object>. Returns True if the transform is full. The transform operator takes the object as the root of the ViewModel specified and uses the ViewModel as a template to copy and create a new structure of objects.

Usually, a false return value, i.e. not a full transform, is due to the fact that the destination attribute could not be found or is read-only. Currently, there is no log available to pinpoint exactly why false is returned. Read about duck-typing below for hints on what is incorrect in your transformation.

Example of How to Use It

Often, when sending an email, you need to "collect" information from many objects to find all the information needed to create an outgoing email.

Using this model of an email queue, let's see how objects of the OutgoingEmail and EmailAttachment can be created using transform.

EmailQueueClassDiagram.png

This ViewModel and transform will fill in the OutgoingEmail and EmailAttachment by name-matching each attribute and link from the "Självfaktura" onto OutgoingEmail.

TransformViewmodelForEmail.png

(Please note the "trick" self->asSet because we need a list, not a link to fill in the "EmailAttachments" multi-link and Självfaktura only contains an attribute "Pdf".)

This is the EAL code in the "Send" action on "Självfaktura". Create the OutgoingEmail object and call transform to fill it in. If the transform isn't full (some attributes weren't stored), we back out by removing the newly created oe object.

let oe = OutgoingEmail.create in
(
  if self.transform('TR_SjälvfakturaSkickaPDF', oe) then
    true
  else
    oe.Delete
  endif
)

For completeness, this is the serverside ViewModel that sends emails and thus empties the queue.

ViewmodelForSendingEmail.png

Duck Typing

Transforming objects over the class border based on similarities - as transform does - is often referred to as Duck Typing. In MDriven, the ViewModel is used as a vehicle to facilitate a type-safe way to the duck type transform. The ViewModel Editor has a property to enable you to type-check your transform in design time during normal model validation:

2019-11-03 19h15 37.png
This page was edited 93 days ago on 02/10/2024. What links here