package com.itms.resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Vector;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.itms.bo.EmailSchedularBO;
import com.itms.dao.VException;
public class EmailSchedular implements Job{
static final Logger _log=Logger.getLogger(com.itms.resource.EmailSchedular.class);
static ResourceBundle szResBundl = ResourceBundle.getBundle("com/itms/resource/mailProperties");
String message = szResBundl.getString("MESSAGE_EMAIL_SCHEDULAR");
String subject= szResBundl.getString("SUBJECT_EMAIL_SCHEDULAR");
EmailSchedularBO szMailJob7DaysBO;
HashMap szHmap=null;
HashMap szMap=null;
HashMap szMapW=null;
HashMap mailMap=null;
Vector szVec = null;
Vector szVec1 = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
java.util.Date utildate = new Date();
java.sql.Date sqlDate = new java.sql.Date(utildate.getTime());
Calendar calendar = Calendar.getInstance();
public void execute(JobExecutionContext jExeCtx) throws JobExecutionException {
// TODO Auto-generated method stub
System.out.println("<<< TestSchedular start >>> ");
try {
_
log.info("In MailJob7Days Schedular >> job method >> ");
System.out.println("In MailJob7Days Schedular >> job method >> ");
szMailJob7DaysBO = new EmailSchedularBO();
szHmap= new HashMap();
mailMap=new HashMap();
szMapW= new HashMap();
szMap= new HashMap();
szVec= new Vector();
szVec1= new Vector();
try{
System.out.println("Email schedular srart for sending Mail ... ");
String toDayDate=sqlDate+"";
System.out.println(toDayDate);
// szHmap.put("", "");
szVec = szMailJob7DaysBO.getApprovedPreClerance(szHmap);
System.out.println("szVec -- "+szVec.size() +" -- "+szVec1.size());
String userName ="";
String submittedDate="";
String itms ="";
// System.out.println(szMapW.get("RowNum") +" "+ szMapW.get("alldate"));
// System.out.println(szMap.get("EMAIL_ID")); //APPROVAL_DATE
for(int k=0;k<szVec.size();k++){
szMap = (HashMap) szVec.get(k);
System.out.println("szMap: : "+ szMap);
szVec1 =szMailJob7DaysBO.getWorkingDay(szMap);
System.out.println("szVec1== "+szVec1);
userName =(String) szMap.get("EMPLOYEE_NAME");
for(int i=0;i<szVec1.size();i++)
{
szMapW = (HashMap) szVec1.get(i);
System.out.println("alldate >> "+szMapW.get("alldate"));
}
submittedDate =(String) szMap.get("SUBMITTED_ON");
String date1 = submittedDate;
System.out.println("date1 >>"+date1);
String [] datePass1 = submittedDate.split(" ",0);
//System.out.println("datePass1 "+datePass1[0]);
itms =(String) szMap.get("PRE_ITMS_NO");
message = message.replaceAll("#USER#",userName);
message = message.replaceAll("#DATE#",datePass1[0]);
subject = subject.replaceAll("#ITMSNO#",itms);
subject = subject.replaceAll("#DATE#",datePass1[0]);
mailMap.put("ITMS_NO", itms);
mailMap.put("EMP_OS_NAME", userName);
mailMap.put("EMAIL_ID", szMap.get("EMAIL_ID"));
mailMap.put("MESSAGE", " ");
mailMap.put("CCEMAIL", " ");
mailMap.put("EMAIL_DATE", toDayDate);
String [] allDate1 = szMapW.get("alldate").toString().split(" ");
String dt = allDate1[0];
System.out.println(dt+" ================= dt >> " +toDayDate);
if(dt.equals(toDayDate)){
//EmailSend.sendEmail((String) szMap.get("EMAIL_ID"), "", subject, message);
szMailJob7DaysBO.insertEmailSchedular(mailMap);
}
}
}catch(Exception ex){
ex.printStackTrace();
System.out.println("MailJob7Days Exception >> "+ex);
} catch (VException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}