The TIBCO Platform is a real-time, composable data platform that will bring together an evolving set of your TIBCO solutions - and it's available now!
A chart showing the TIBCO Platform vision
Jump to content
Articles
Read more about TIBCO use cases, product features, capabilities and more
  • TIBCO Flogo for TIBCO BusinessWorks Developers - Iteration


    JenVay Chong

    Preface

    The TIBCO Flogo for TIBCO BusinessWorks Developers series of articles aims to familiarize BusinessWorks developers with TIBCO Flogo in order to better utilize these complementary technologies. Each article is focused on a specific key common behavior or feature that is often used in a BusinessWorks project. It takes that common behavior and replicates that in Flogo. 

    Iteration

    In this article, we will take a look at iterations. There are multiple different iteration types within BusinessWorks that are commonly used. We will touch on each of these. 

    Group-While-True

    This is the iteration behavior of While-True enclosed within a group. What this does is the activities within the group will repeat its execution as long as the condition is true. Do note that there is another similar iteration behavior called Repeat-Until-True which is basically an invert of the While-True thereby we will not be classifying this as a separate behavior.

    This behavior is coded as illustrated below.

    BW5 

    WVBhyMVjUspiCZOGmgsYgE4VYsNq8TrDR49-li5cdM-kMIQRoCvjp0NxoPycAfkjFoGc7ohK-0Y4naYu5psDQbMcwGjIrwtgIfXiCyoFsCmzppFFLMV4U-QeQz9igFXDg3lqR8GYE87xs5gws7tXwMY

    BW6/CE

    1UJncr0Y7zAF-n1_bDOPJeQm9Ah4OlnO61B_ojZmYsHR0XwJLcPIwwzTzvFJa78qTlcYvObAnABMNAdKtjlkpI7Rrox9AZxsOvbxM-o6rNGGIOWSZ1L3IwQv-DYvunBaaEHPbH9SJpDm69dDf9zZV9o

    To do this in Flogo, we use the Loop configuration of the activity. Most of the activities inside Flogo support looping in this manner. Inside this configuration, you will set the Type to “Repeat while true” and provide the condition to repeat execution of the specific activities. 

    One thing to note though is the evaluation of the condition and the index of the iteration. 

    In BusinessWorks, the evaluation happens at the start of the group and the index starts at 1. This means that in order to execute 3 times, my condition will need to evaluate the index to be less than or equal to 3. 

    In Flogo, the evaluation happens at the end of the activity. Additionally, the index starts at 0. This means that in order to replicate the exact same behavior as the example in BW, we would need to evaluate the condition to be less than 2 as shown below and compensate for the logging of the “Iteration: <<number>>” message by adding 1 to the index as shown below. Other than this, the behavior of the BW application is completely replicated in the Flogo application. 

    Flogo

    VQx8jiLw0Ul8W-DOz-A4L_9RRiLusTHE1lxTjaHdkSdpuZsK1GWURkXZEvU4yZXaEJbaZvUfhdcZJ0WEJcxR2rwfF8Zuxh_5kkvuf2oJv8-0slL8OpXfoVGqXHNLbqTdO-Mmga-K3LBDywcreFec-Dc

     

    rwUdpHEsOWyVWvAJXQbVEa5SpkKMmvrIP515-vtoRV-cjxuCaPVBgJ9Ieow82SmuJl7p-i1D0G8XqWN_MQts0OrQrTQXXqb_d8cQXh3Xa3BWSkaKMKl678OKRB0M7YK1TKnooXe0KUyyqjEJnhCkGY8

     

    Group-While-True With Multiple Activities

    One might ask that if the loop is within the Activity in Flogo, how do we then replicate the behavior of a loop that contains multiple activities in BusinessWorks. For this scenario, we use the below. You can see that we have two activities inside the group that is iterating. Each activity is executed once before the loop repeats.

    BW5

    JO5Abk-ByscSCH-coXWdKmGd1Ya0KiqeI0rSRneLrKxKQTSpgHGmKgK_Hp4JJUfWxGHa1sVPtehsyIZaP3ww2kpyuhb8pvS4KiKqvwvWIP_Q_4WdA6J4sw_20AMxOlAmIM9HwaIvPoZctpWOw1aJIHw

    BW6/CE

    iMX2vVdbyA-DQtzzKzYMciuxpSMymHG4dijuWX8X8Fy6qrp3xic2u-uyym0CvxRQ0zOG9zbkYW4_5gZXa1H1S2ZBro1PqMzq4GEH6t7tXmQhj5Q8_rGTWVBqnFrNhGZ0knpip6aN4AOkY_EnCbpWZ1s

    To accomplish this in Flogo, we use a subflow. A subflow is similar to a subprocess in BusinessWorks. Within this subflow, you put all the activities you want to iterate in sequence.

    xJ0AnxO6qpIjORMTX4_rTfaiotvPuEVHPmCtoi2RTR3y2ed9sX50tJUc2L-urDgh1FqpvtXJgSQkM5SNdc9py7-ACOktjIhLznxvB9dIQzYFtrhwBxQSs6OnfBB8u100gMllYTrqLP1i4h_IAgkKT9o

    Then we have a main flow which uses the Start A Subflow activity to execute the subflow. We then configure the iteration in the loop subtab like the previous Flogo example taking into account the same adjustment needed based on the conditional evaluation and index in Flogo. Any data needed for the subflow is passed in during this call.

    7O68pPq1rakg6xNiYY8oN4rKc1K5d04q7nN9b0agO-IT9jx0UHa9_Pq4_eGkA5B8ODvVbYjFInaAHxJIMmXcFJKnVwHcyoDXeWS3r0xflHAllhh8c_Lo_GJRoV-gDNuUT_dkobDAC7IcRiOj0UH6Nv4

     

    HvBk4fZIzrt1UWyv8ko5lBTxzZlsSb1HVF0gMbDbaf6W3koBgFCkrw4wqY19zQt_HEMpjjffHn7lvVK-Q2nNBhKT4xsgap0sm6tq6dJEwhJObWDjzurCohGdGfiafbaVVG5Sk2VX1y_1VYkGPVztniM

    Group-Iterate

    Another type of iteration typically used in BusinessWorks is the iteration based on data elements. For this example, we have a repeating schema which houses customer names. We would want to iterate through the customers in the group and print out each name. The implementation of this for BusinessWorks is shown below.

    BW5 

    WdcrO8vTSvrKsbd6gyc3LiYLqAyDclUJPj92voEjr2XYvr-QW_c_z4ixuZ7raibx0tMz0MJjWjCwzIwnwoiNCIHPxhGED6M6KWZdUFx_pyQr_2Fr-ajsRw0VjMZS8qDn5mdJ0PRVbLN-364Dr9VjVcs

    pzd7Lyy86fTN5LCxrazr75mj62DGvbpVNYwC7cOAkjnmIl6psxMCb6fFSlVKvxkBbMu0h8EXfweoRp_IheAvfxo-LeLF3nogDPyUGUmh9AxLwgn4xF65kHRLp12hPxnUPB0XMPVuwpwkxMlWGIOWo8g

    BW6/CE

    qPxqspR5ZnxL31kZN7hH5awD5jPyBrtZxvcNxIehGyrOvqd7a2lvBhRUEg9-gswtTFN1eV81vq2Be2RtRAHH85YQQFBm6MUcJxqrjGZePB26PwmA-OKEWCTnl2JSpKuc8n05USieSgMAQt6X2Fv7NVo

     

    kc0V5H2GaG4BvoE7SmrYa8amIAlq7Jde1KdgQwUetxuvH5qMg2kI0gHFbMwasBuqHWaqA9JTICBdlnNglVk7Bg8RPUV-vkpfdjMmj01tWLC8b_mzIcAgHJJ-dDOGMTZqUsI4E7tkSMo6kxpPra0zdN4

    To do this in Flogo is relatively simple. We also have a mapper which we pre-create a repeating schema just like BusinessWorks.

    fg6lSJRc4uREQF-N7pjt_BDPIw9iM02Tvc5Hbl19iep8nPmTtusfXseVHIVpFOXehpAoMHCo5EiJjhUjini4R0nZ1_4VEYm6f54oVcdF5jBT_gomvWCOVI2mibVE2jODhFdJjLNc7xRm-kiPctA4Gd8

    We also use the Loop configuration of the activity to achieve this iteration. To iterate on the repeating data element, select the type as Iterate and provide the repeating element as the iterator element. Just like in BusinessWorks, you will be able to drag this from the “Available Data” section into the configuration text box. In the screenshot below, you can see that element is the $activity[RepeatingSchema].output.root dragged from Available data > RepeatingSchema > output > root. Notice the root element has an “Arr” icon which indicates an array repeating element.

    orUwSnBIOpiPCywAYkmoJv6tu3jS0Lv1w0GxDhs51XwI0Rvvh_KaAAgHdmB6nVS6ims67cWoQ_1LMP4YjO1cdkXPiNs9IzCpfo9mrxuik-oMSvrbMEmeU99PIChkgl1E8yY7ZRDihUxdhtDMzBvY3gc

    We can then map the iterator data value from the $iteration object in the Available data section for use in the iteration.

    tqx3PRj6uGdn-dg2AS6RIl2eSD7qj6aXI-3qm2reRnZNiHdc4q1SPWtZb3GvVa47V3AoRvHxLHBaZkpaIF1k5dNvQBq80ycas1xBWBHO4tTrE4RpeEw_xH_ctFm5LRrCeS5P6xF_v5YMpnwnTstcHEk

    Group-Repeat-On-Error-Until-True

    There is another common iteration activity called Repeat-On-Error-Until-True. What this does is if there is an exception in the group, it will repeat execution of activities in the group up to a certain number of times as long as the exception continues. After the retry is exhausted, it will then propagate the exception upwards to the parent. 

    BW5 

    PSxB__RB4E9rK5SPJk3Wi06iEpniYTO3rl1LakSV38PoMDu0R3UQUq6pk-BSMNKe1UP3nK7jIhiT6-HzUpyBTsFO5Iq0cSqicLfAEFS6yX-Tm82YvRXKLFV_VnVhpROtXVnQqaQ3mfP9moopX6bD0pY

    BW6/CE

    GUheI7qSQvNB9oH5AmxJKr47LidIBAD_UTHDwh6TMWTQ0ql9T3dZvxLvV2ZmE8BQoIIL63ZiH4AcJHhjDwAzNhs5G6jrC-htMo72Rp4Jeu1hZ4x3KJTnr_530mPnsmMXWDC-QmEi6iw9znYMh4axGn0

    Flogo approached this a little differently compared to BusinessWorks. It does not provide a repeat on error for all the activities. This is because when an exception happens to an activity, not all exceptions are correctable but re-executing it. So, this function is only provided to activities that could be potentially corrected by re-execution. 

    One such activity is the InvokeRESTService. In this example, a fake URL is used and a timeout for this invocation is set to 1000 milliseconds. Then we configure the Retry On Error with a count of 3 and an wait interval of 5000 milliseconds. 

    q_KyfDMlONbH0aTQVNhkO1qnxaY41kv1YDtHOFSEtNT03df-ZYwL7TNSzg7awaVbS-yYE9qoaLLwWQzFIaTsUJ8arZ7IVTLnyAVZZuZoAI3k_GZYzKAO0Fb4YaC411m_I54rVGnLTwZxRf6qoE3EJ8w

    brMdaKNkP6a3bfFztaF4Au8es5qFm_J8TVkFgFslT-tvSivkm1nB87e3cfwrH4gqwOhdqjlN6mlKeVN90tB2BusA_Ogvsi5WZqIanOO6pJKyRJPWMlPRGyvRds1uCdNA19xoGDtMM0f_RKBq8thfakQ

     

    fuJ21sY_ewh5DL70alxc5m7x3laGSoaXaLGqdFtdJtmWMklhBmmjwJmGCOnTlUcqU8b9lAc49je5jYUtj-G-jgwRQkuRIvXd1I8E81vpdWwKdSYpasT8w7K1AhMVMRY8QAHW1ZNRaxiLGGcX-l67FHA

    In running this, we observed that the activity retried itself 3 times on failure. After the third failure, it propagates the exception to the parent just like BusinessWorks does.

    ZbL_UusYz12UtvnhQrbGKG1qMheF_9_maGToK0CKhL1KGfTvkUW4IKwvLbSlHWBed8PakQuuzCvPsdix-IXd2a62nLnLWJ_yrAnwf5VEBmVJI96VKVanVH2jPAbv5DHxBynQcbOWPesm5gG5IRQ9U5U

    For-Each-Mapping

    The For-Each-Mapping iteration happens within the Mapper in BusinessWorks. This facilitates mapping of complex schemas from one to another. 

    BW5 

    07632fYSmQ7PVR9WnfqbCmh7Ko8OfMYDSpda1gY9SqaVac_3Hzs2yUfDojv3M-NOnpRSkVhV2Sqhj-5wdZmqMXd2h8tqi_JuXk2e8wJkq2zXcR0fH16ZEYJA7FquNSsDjYgaHQZF1pETZABQAWE9xTs

    BW6/CE

    A-HugRvf8bq9si7In-8YPSn3eNcMrteGY3RCVa0rTu_oZ0Px7VjnlNVFeHIOqfXKPb0iwOewwn06pad-412EyadOSQw9CX57ub6DrGx2uXjyBsfymEUupaswcNfLi4o6wofvfWiveFNl9kghgTFooGE

    To achieve this in Flogo, we can use a similar method within the Flogo Mapper to iterate through the repeating element and mapping the repeat element over to the new schema.

    mW2cUNwMzbBxxM0Afyq74MqXf7_ni0F5x7sZ9TdUg56fhPD98Fii4lLv0xrtC82MBI6xTOcST3v2K2nl7XfQTZQ4iKjHJbAY1ZuP0EpTTv9idC0Y5dhWiJJ4gklDG94LdOkd-EtRAfpuN2F4mmVPXp0

     

    SUTPF7tpK_dVOMrDhv0P9nrgcD9OW4jPwTolLxIRSnh4tfXDGQvTPtc_iZpr0vl66wwggl_e7yWWvf0BEPuzrI1GA1l83ZtajH08ZKfseheQje3yAC1cu9pBXR3n1-xXkaXGTGnBoNfcTPv8rzG9Juk

    All three projects coded in BW 5.15.1, BWCE 2.9.1 and Flogo 2.24.0 using the Visual Studio Code Extension are provided below for your reference.

     

    BW_5_15_1-F4BWDev-Iteration.zip BWCE_2_9_1-F4BWDev-Iteration.zip Iteration.flogo


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...