Thursday, October 27, 2016

Importing Java Libraries in DataWeave and MEL

Last but not least, we are going to define a global function that imports different libraries and can be used via DataWeave, isn’t this cool! :-)
First of all, we need to define our global function. In this example we are going to calculate the number of days of one month provided as a parameter. We will make use of Calendar and SimpleDateFormat libraries.
<configuration doc:name="Configuration">
  <expression-language>
      <global-functions>
          def dayOfTheMonth(date){
          
              import java.util.Calendar;
              import java.text.SimpleDateFormat;
              
              cal = Calendar.getInstance();
              sdf = new SimpleDateFormat('yyyyMMdd');
              cal.setTime(sdf.parse(date));
              
              return cal.getActualMaximum(Calendar.DAY_OF_MONTH).toString();
          }
      </global-functions>
  </expression-language>
</configuration>

Our new function is ready to be used! We can now use a MEL expression or include our function in Dataweave!
MEL:   #[dayOfTheMonth(‘20151027’)]
DataWeave:   day: dayOfTheMonth(‘20140302’)

7 comments:

  1. I would not have been certified in my favourite IT certification if I would not have sought help from Pass4sure Juniper dumps. This PDF short study material made is quick and easy to prepare for my final exam. I found almost the same question in Juniper questions and answer that were faced in final test. If you are interested in Juniper exam then you must prepare from Dumpspass4sure.

    ReplyDelete

  2. very nice & informative video for mulesoft folks...you can also visit https://www.goformule.com for mulesoft tutorials

    ReplyDelete
  3. It is amazing to visit your site. Thanks for sharing this information, this is useful to me...
    Mulesoft Training in Hyderabad
    Mulesoft Online Training

    ReplyDelete