Groovy

                                               

GroovyScriptProcedure

Groovy is a first-class scripting language on top of the JVM and to enable some rapid scripting and playing with the platform
Cronjob Scripting

Traditionally, creating a new cronjob was time-consuming and entailed many manual steps, for example, you had to create a new java class, take care of spring bean definition, rebuild the platform, restart the server and so on and so forth.

Using dynamic scripting, creating cronjobs becomes much easier and, most importantly, it can be done dynamically at runtime.
How It Works

Let’s look at some basic concepts:

  • Script – the item type where the script content is stored (a separate deployment table)
  • ScriptingJob- a new ServicelayerJob item, which contains additionally the scriptURI (consequently, the stored script can be found at runtime from different locations (classpath, db and also Email Notification like(Email id,Mail template,Notificaton process,…)
  • ScriptingJobPerformable- the spring bean assigned to every ScriptingJob instance; it implements the usual perform() method (like for any other cronjob). This is where the “scripted” cronjob logic is executed.

You can execute the cronjob by java API (CronjobService.perfom(Cronjob)) or by defining a trigger. The execution will be delegated to the ScriptingJobPerfomable.

Step1: Script
Define a Script
Creating groovy Script Based on Client requirment in Groovy Web Console .It Contains all necessary libraries and tools to use Groovy as programming language for your extension. This extension is a required dependency for your new extension.

INSERT_UPDATE Script; code[unique=true];content
;<PromotionDuplicateGroovyScript>;println ‘hello groovy! ‘

1
(OR) Imorting Scripting:
root: hmc->console->Scripting Languages->Browse->Import Script File
Name:PromotionDuplicateGroovyScript(Name of Script Code Unique Identifier)
Type:groovy

2

ii)once you loaded the script file assign Name of Script Code Unique Identifier then import the file

3
iii)After imported file Sucessfully the Script Stored under Scripts Repostry->Groovy-><Name of the ScriptFile>

4
we can load,delete,edit and save the script for future references.
You can see this script info under hmc->Scripting->Script

5

we can edit your script content throw hmc also under Scripting ->Scripts->ScriptName

6
Step2:ScriptingJob

Use the impex import console to import the following:

INSERT_UPDATE ScriptingJob; code[unique=true];scriptURI
;PromotionDuplicateGroovyScriptJob;model://PromotionDuplicateGroovyScript
This stores your ScriptingJob (aptly named PromotionDuplicateGroovyScript) in the database. Regarding the scriptURI, if you want to point to a script stored in database, you canuse the convention: model://myscriptreference
You can see this under
hmc->Scripting->ScriptingJobs

7ii)Open ScriptingJobs-> PromotionDuplicateGroovyScriptJob->Advance attributes
Notification:

  • Send notification after processing: YES(After exceted script send the notification mail)
  • Email address: abc@xyz.com(Mention multiple email address by comma(,) separated )
  • Email template: Mention the email render notification template it will be used to generate report for email body information

Email template

Mention the email render notification template it will be used to generate report for email body information
we can edit email body information below URI
GOTO hmc->System->Output Documents->Comunication Template->futuregroup_groovy_Script_Email_Body

8

Step:3 ScriptingJobPerformable
Define a CronJob
Use the impex import console to import the following:
INSERT_UPDATE CronJob; code[unique=true];job(code);singleExecutable;sessionLanguage(isocode)

;FGPromotionDuplicateGroovyScriptCronJob;PromotionDuplicateGroovyScript;true;en

This stores the new cronjob holding the reference to our previously defined job
root: hmc–>System->CronJobs->FGPromotionDuplicateGroovyScriptCronJob

11
ii)Create the trigger on daily bases so it will run automatically as per trigger time

12
Note: Local.Properties
Mentioning below attributes are generic we can edit for feture reference
groovyScript.directory.sava.data= /data/bbbuildfiles/b5/groovyData/Data_

This is used to taking the back up files in below mention directory for feture references:
/data/bbbuildfiles/b5/groovyData/Data_<ScriptingJobName_dd/MM/yyyy.xls>

groovyScript.email.subject=Daily Report for

This is used for email subject descriptive and provide the reader with a reason to explore your message further

Daily Report for <ScriptingJobName>