Changes for page Communication between models
Last modified by Erik Bakker on 2024/09/05 14:00
From version 14.1
edited by Erik Bakker
on 2022/07/28 10:28
on 2022/07/28 10:28
Change comment:
There is no comment for this version
To version 5.2
edited by Erik Bakker
on 2022/07/26 08:16
on 2022/07/26 08:16
Change comment:
Update document after refactoring.
Summary
-
Page properties (3 modified, 0 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 - Communicationbetween models1 +expert-create-your-transformations-xpath-expert - Default language
-
... ... @@ -1,1 +1,0 @@ 1 -en - Content
-
... ... @@ -1,80 +1,93 @@ 1 1 {{container}}{{container layoutStyle="columns"}}((( 2 - In alow-codeplatformlike eMagiz,you wanttopreventsingcustomscripting asmuchaspossible.However,sometimes inpractice,youencountersituationsthatcannot berealizedwith thestandardtoolboxrovided within theplatform. Asa result, weoffertheoption touseaGroovyscriptinhesesituationschieveheesired solution. In this microlearning, we will lookat whereyou canuse a Groovyscriptand discuss thekeyconsiderationswhen implementingaGroovyscriptwithin yourmodel.2 +Within the crash course, we already explained XPath conceptually. In that same microlearning, we also looked at some more uncomplicated cases of using XPath within your transformation. If you need to brush up on that knowledge, please check out this [microlearning](crashcourse-platform-create-transformation-xpath-basic.md). In the intermediate microlearning on this subject, we built upon that knowledge. Please check out this [microlearning](intermediate-create-your-transformations-xpath-intermediate.md) if you need a refresher on that. In this microlearning, we will build upon that knowledge and look at some concrete, practical examples that could be useful in your project. 3 3 4 4 Should you have any questions, please get in touch with [[academy@emagiz.com>>mailto:academy@emagiz.com]]. 5 5 6 +* Last update: October 25th, 2021 7 +* Required reading time: 6 minutes 8 + 6 6 == 1. Prerequisites == 7 7 8 -* Expert knowledge of the eMagiz platform 11 +* Advanced knowledge of the eMagiz platform 12 +* [[XPath Basic>>doc:Main.eMagiz Academy.Microlearnings.Crash Course.Crash Course Platform.crashcourse-platform-create-transformation-xpath-basic.WebHome||target="blank"]] 13 +* [[XPath Intermediate>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level.Create your transformations.intermediate-create-your-transformations-xpath-intermediate.WebHome||target="blank"]] 9 9 15 + 10 10 == 2. Key concepts == 11 11 12 -This microlearning focuses on groovy scripts. A groovy script is a pieceofcode written in the groovylanguagethat allows you to extendthe platform's functionality beyond themere useof the components supplied viahe flow designer.18 +This microlearning focuses on more complex XPath operations. 13 13 14 -* Groovy scripts should be viewed as an extension that can be used in fringe cases, not as a standard best practice 15 -* When a groovy script becomes so complex that you are programming, you should consider alternatives to the solution 16 -* Groovy scripts can be used in a filter, transformation, and as part of a standard executor 17 -* Groovy scripts should be well documented as they are though to read for most of our community members 18 -* There is no guarantee from eMagiz that Groovy scripts within models keep working in newer versions of the platform 20 +With XPath Advanced, we mean learning that XPath options are complex but could benefit you in your daily work. 19 19 20 - ==3.Groovyscript==22 +Some of the more complex XPath options are: 21 21 22 -In a low-code platform like eMagiz, you want to prevent using custom scripting as much as possible. However, sometimes in practice, you encounter situations that cannot be realized with the standard toolbox provided within the platform. As a result, we offer the option to use a Groovy script in these situations to achieve the desired solution. In this microlearning, we will look at where you can use a Groovy script and discuss the key considerations when implementing a Groovy script within your model. 24 +* dateTime calculation 25 +* Filter list 26 +* XPath on JSON 27 +* SpEL notation for XPath 23 23 24 -=== 3.1 Implementation in Create === 25 25 26 -To implement a groovy script in Create, you first need to consider what your Groovy script should do. Then, within the flow designer, there are five components available that can handle a Groovy script. 27 - 28 -* In case you want the Groovy script to filter out messages, you should implement the Groovy script in a "standard filter" component. 29 -* If you want your Groovy script to always transform your message from a certain format into another format, you should consider using a "standard transformer" component. 30 -* The "standard service activator" is your friend if you need an optional output. So, for example, when you want to do some transformation and check whether a message can continue, you can use the "standard service activator" and have an optional output. 31 -* When you want to split your message based on a Groovy script, you should use the "standard splitter." 32 -* If you want to route messages based on a Groovy script, you should use the "standard router." 33 33 34 - {{warning}}Notethatin practice, we mainly see use cases for the"standard serviceactivator" and the"standardtransformation." {{/warning}}31 +== 3. XPath Advanced == 35 35 36 - [[image:Main.Images.Microlearning.WebHome@expert-data-handling-groovy-script-available-components.png]]33 +Within the crash course, we already explained XPath conceptually. In that same microlearning, we also looked at some more uncomplicated cases of using XPath within your transformation. If you need to brush up on that knowledge, please check out this [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Crash Course.Crash Course Platform.crashcourse-platform-create-transformation-xpath-basic.WebHome||target="blank"]]. In the intermediate microlearning on this subject, we built upon that knowledge. Please check out this [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level.Create your transformations.intermediate-create-your-transformations-xpath-intermediate.WebHome||target="blank"]] if you need a refresher on that. In this microlearning, we will build upon that knowledge and look at some concrete, practical examples that could be useful in your project. 37 37 38 - Regardlessof thecomponentyouchoose, you always needto select the"Groovy script" option andreference the Groovy resource available on the flow level you want to use within the component.35 +Some of the more complex XPath options are: 39 39 40 -[[image:Main.Images.Microlearning.WebHome@expert-data-handling-groovy-script-groovy-configuration.png]] 37 +* dateTime calculation 38 +* Filter list 39 +* XPath on JSON 40 +* SpEL notation for XPath 41 41 42 - {{info}}Asyoucan see inthehelp text when selecting the"resource"attribute, you need to make sure that the Groovy script isuploaded within the contextof your flow.{{/info}}42 +=== 3.1 dateTime calculation === 43 43 44 - Afteryouhave the componentinsuch awaythat the correctGroovyscriptis called, youaredone with thecomponent'sconfigurationndcantesttheflowusingflowtesting.44 +Sometimes we see that a dateTime calculation is needed within a transformation to determine a specific action. As these calculations are not natively supported within the eMagiz platform, you need to use XPath's functionality to calculate the new valid date (or dateTime). 45 45 46 - ===3.2Key considerations ===46 +The XPath standard offers several functions to calculate with dateTime values. The two most used options are dayTimeDuration and yearMonthDuration. With the help of the dayTimeDuration, you can add, subtract, multiple, or divide seconds, minutes, hours, and days regarding the original value. The yearMonthDuration works similarly but then for months and years. An example of such an XPath is: <xsl:value-of xmlns:xs="http://www.w3.org/2001/XMLSchema" select="CDM:StartDate + xs:dayTimeDuration('P1D') * xs:yearMonthDuration('P1M')"/>. In this example, XPath adds one day and subtracts one month from the input date. Note that making this work requires the additional namespace to be defined. Therefore you need a custom snippet within your transformation or a custom transformation to make this work. Furthermore, note that the P1D and P1M could also be filled with the help of parameters to make them dynamic in nature. 47 47 48 -* To make some groovy scripts work, you need to upload (third-party) Java libraries that are not packaged on default by eMagiz 49 -* To make some groovy scripts work, you need to reference Java libraries via a standard header enricher or as a dummy variable 50 -* The store consists of several groovy scripts that might be of use to you 51 -* Groovy scripts should be viewed as an extension that can be used in fringe cases, not as a standard best practice 52 -* When a groovy script becomes so complex that you are programming, you should consider alternatives to the solution 53 -* Groovy scripts can be used in a filter, transformation, and as part of a standard executor 54 -* Groovy scripts should be well documented as they are though to read for most of our community members 55 -* There is no guarantee from eMagiz that Groovy scripts within models keep working in newer versions of the platform 48 +Some examples that we saw during the years: 56 56 50 +* https://my.emagiz.com/p/question/172825635700358186 51 +* https://my.emagiz.com/p/question/172825635700352588 52 + 53 +=== 3.2 Filter list === 54 + 55 +Sometimes you have a large message which contains a certain list within it. However, logic dictates that you can only send the message if at least one entry in the list for which attribute A is filled and attribute B equals type C. To make that happen in XPath, we first need to navigate to the list within the message. As we previously learned, there are two options to do so. One is to use // to navigate to the entity somewhere in the tree directly. The other is to start at the root and walk the tree from there. In this example, we use the latter. That results in the following XPath example: /root/list[attributeB = 'type C']/attributeA !=''. With this XPath, you filter the list on the specified check and subsequently check whether one of those entries that remains has an attributeA which is filled in. 56 + 57 +=== 3.3 XPath on JSON === 58 + 59 +With the release of build number .50, we expanded our offering on JSON messages to resemble much of the functionality we previously offered for XML messages. As a result, you can use XPath expressions on JSON messages within the following components (related to XPath): 60 + 61 +* XPath header enricher 62 +* XPath transformer 63 +* XPath router 64 + 65 +To activate the functionality, simply link the JSON source factory support object to one of these components to achieve the desired result. For more information, check out: https://emagiz.github.io/docs/release-notes/build50. 66 + 67 +=== 3.4 SpEL notation for XPath === 68 + 69 +Sometimes you want to perform an XPath operation but store the header via a standard message header enricher component. As a result, you need a valid SpEL expression to help you in this cause. To do so, you need to know the correct notation for an XPath expression when using the SpEL language. An example of the correct notation is: #xpath(payload,'/root/entity/attribute') 70 + 57 57 == 4. Assignment == 58 58 59 - TrytoimplementacomponentthatreferencesaGroovyscript andseewhether the flowcan be tested.60 -This assignment can be completed with the help of the(Academy) project you created/used in the previous assignment.73 +Check out which of the XPaths we have discussed today can be found within your project. 74 +This assignment can be completed within the (Academy) project you created/used in the previous assignment. 61 61 62 62 == 5. Key takeaways == 63 63 64 -* To make some groovy scripts work, you need to upload (third-party) Java libraries that are not packaged on default by eMagiz 65 -* To make some groovy scripts work, you need to reference Java libraries via a standard header enricher or as a dummy variable 66 -* The store consists of several groovy scripts that might be of use to you 67 -* Groovy scripts should be viewed as an extension that can be used in fringe cases, not as a standard best practice 68 -* When a groovy script becomes so complex that you are programming, you should consider alternatives to the solution 69 -* Groovy scripts can be used in a filter, transformation, and as part of a standard executor 70 -* Groovy scripts should be well documented as they are though to read for most of our community members 71 -* There is no guarantee from eMagiz that Groovy scripts within models keep working in newer versions of the platform 78 +Some of the more complex XPath options are: 72 72 80 +* dateTime calculation 81 +* Filter list 82 +* XPath on JSON 83 +* SpEL notation for XPath 84 + 73 73 == 6. Suggested Additional Readings == 74 74 75 -If you are interested in this topic and want more information, please read the help text provided by eMagiz and read the following link: 76 -* https://www.tutorialspoint.com/groovy/index.htm 87 +If you are interested in this topic and want more information on it, please read the help text provided by eMagiz and read more information on the following link: 77 77 89 +* https://www.w3schools.com/xml/xpath_intro.asp 90 + 78 78 == 7. Silent demonstration video == 79 79 80 80 As this is more of theoretical microlearning, there is no video accompanying the microlearning.)))((({{toc/}}))){{/container}}{{/container}}