Hi All Many of you where working in Endeca, will enable the Schedule Indexing, automatic Indexing and Waiting to See the Status of the indexing is Successful or not, will though to Trigger a Mail also after
the Indexing. This tutorial will give you a Detailed Information how to check the Status of the Indexing and Trigger Mail after that.
I am Writing This Blog Assuming that you are intersted to trigger a mail after every Scheduled Indexing .
Step 1:
Extend the Class SimpleIndexingAdmin
Step 2:
Override the Method performScheduledTask
@Override
public void performScheduledTask(Scheduler pScheduler, ScheduledJob pJob)
{
long startTime = System.currentTimeMillis();
long nextTime = pJob.getSchedule().getNextJobTime(startTime);
boolean status=Boolean.FALSE;
try {
if (pJob == this.mBaselineScheduledJob) {
status=indexBaseline();
}
else if (pJob == this.mPartialScheduledJob) {
status=indexPartial();
}
else
vlogError("Failed to find indexing job corresponding to {0}", new Object[] { pJob });
}
catch (IndexingException e) {
vlogError(e, "Error while executing scheduled job {0}", new Object[] { pJob.getJobName() });
long currentTime = System.currentTimeMillis();
boolean enoughTime = nextTime - currentTime - this.mRetryInMs > 2L * (currentTime - startTime);
if ((this.mRetryInMs > 0L) && (enoughTime)) {
try {
Thread.sleep(this.mRetryInMs);
vlogInfo(e, "Retrying scheduled job {0} after a failure", new Object[] { pJob.getJobName() });
if (pJob == this.mBaselineScheduledJob){
status=indexBaseline();
}
else if (pJob == this.mPartialScheduledJob){
status=indexPartial();
}
}
catch (IndexingException ee) {
vlogError(e, "Error while retrying scheduled job {0}", new Object[] { pJob.getJobName() });
}
catch (InterruptedException te) {
vlogError(e, "InterruptedException while while retrying scheduled job {0}", new Object[] { pJob.getJobName() });
}
}
else if ((this.mRetryInMs > 0L) && (!(enoughTime)))
vlogInfo(e, "Not retrying scheduled job {0} - too little time till the next scheduled run", new Object[] { pJob.getJobName() });
}
if (getEmailConfiguration().isEnableEmailServices()) {
@Override
public void performScheduledTask(Scheduler pScheduler, ScheduledJob pJob)
{
long startTime = System.currentTimeMillis();
long nextTime = pJob.getSchedule().getNextJobTime(startTime);
boolean status=Boolean.FALSE;
try {
if (pJob == this.mBaselineScheduledJob) {
status=indexBaseline();
}
else if (pJob == this.mPartialScheduledJob) {
status=indexPartial();
}
else
vlogError("Failed to find indexing job corresponding to {0}", new Object[] { pJob });
}
catch (IndexingException e) {
vlogError(e, "Error while executing scheduled job {0}", new Object[] { pJob.getJobName() });
long currentTime = System.currentTimeMillis();
boolean enoughTime = nextTime - currentTime - this.mRetryInMs > 2L * (currentTime - startTime);
if ((this.mRetryInMs > 0L) && (enoughTime)) {
try {
Thread.sleep(this.mRetryInMs);
vlogInfo(e, "Retrying scheduled job {0} after a failure", new Object[] { pJob.getJobName() });
if (pJob == this.mBaselineScheduledJob){
status=indexBaseline();
}
else if (pJob == this.mPartialScheduledJob){
status=indexPartial();
}
}
catch (IndexingException ee) {
vlogError(e, "Error while retrying scheduled job {0}", new Object[] { pJob.getJobName() });
}
catch (InterruptedException te) {
vlogError(e, "InterruptedException while while retrying scheduled job {0}", new Object[] { pJob.getJobName() });
}
}
else if ((this.mRetryInMs > 0L) && (!(enoughTime)))
vlogInfo(e, "Not retrying scheduled job {0} - too little time till the next scheduled run", new Object[] { pJob.getJobName() });
}
if (getEmailConfiguration().isEnableEmailServices()) {
getEmailConfiguration().sendAutomatedEmail(status);
}
}
Where getEmailConfiguration() is a GenericService class that will be acting as a Email Sender.
Step 3:
For this Tutorial am using the Template Email Sender that is coming as part of the ATG for sending the email.
Befor Going into Coding Part let us under stand the Basic Concepts.
TemplateEmailInfoImpl
/atg/scenario/DefaultTemplateEmailInfo is a component responsible for holding the Content of the Mail,
Of class TemplateEmailInfoImpl
TemplateEmailSender
/atg/userprofiling/email/TemplateEmailSender is a component responsible for the Sending the Emails.
you have to inject the component and call its
getTemplateEmailSender().sendEmailMessage(pTemplateEmailInfo, emailTo, true, false);
This method will send the email on the Successful trigger of Indexing .
public synchronized void sendAutomatedEmail(boolean pScuccess) {
if (isLoggingDebug()) {
logDebug("BEGIN:::sendEmail Method. ::");
}
if (pSuccess) {
pTemplateEmailInfo.setMessageTo(getEmailMessageTo());
emailTo[0] = pTemplateEmailInfo.getMessageTo();
pTemplateEmailInfo
.setMessageSubject(getSuccessSubjectMsg());
else {
pTemplateEmailInfo.setMessageTo(getEmailMessageTo());
emailTo[0] = pTemplateEmailInfo.getMessageTo();
pTemplateEmailInfo.setMessageSubject(getFailureSubjectMsg());
if (isLoggingDebug()) {
vlogDebug("Email sending Failure {0}",emailTo[0]);
}
}
try {
getTemplateEmailSender().sendEmailMessage(pTemplateEmailInfo, emailTo, true, false);
}catch(TemplateEmailException exp){
if (isLoggingError()) {
vlogError("Error in sending email from sendEndecaBaselineIndexingEmail", exp);
}
}
if (isLoggingDebug()) {
logDebug("END:::sendEmail Method. ::");
}
}
in the DefaultTemplateEmailInfo Define the Following for the Temaplate.It is Mandatory to Define the template Url. This is the JSP where we used to define the Content used to send.
Step 4:
$class=atg.userprofiling.email.TemplateEmailInfoImpl
contentProcessor=/atg/userprofiling/email/HtmlContentProcessor
templateURL=/email/mailtemplate.jsp
mailingName=Service-Email
fillFromTemplate=true
mailtemplate.jsp
<%@ taglib uri="/dspTaglib" prefix="dsp"%>
<%@ taglib uri="/dspELTaglib" prefix="dspel" %>
<%@ taglib uri="c" prefix="c"%>
<%@ taglib uri="fmt" prefix="fmt" %>
<dsp:page>
<div id="main">
Indexing process has completed.Please check the Status for more details.
</div>
</dsp:page>
Once if all is done then the Email will be triggered automatically.
Short and sweet post by Syed Ghouse. Keep it up and all the best for your future endeavor.
ReplyDeleteThanks,
Dilroz