1 64 65 70 package com.jcorporate.expresso.ext.job; 71 72 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 73 import com.jcorporate.expresso.core.job.Job; 74 import com.jcorporate.expresso.core.security.User; 75 import com.jcorporate.expresso.ext.dbobj.DownloadLog; 76 import com.jcorporate.expresso.services.dbobj.Event; 77 import com.jcorporate.expresso.services.dbobj.JobQueue; 78 import com.jcorporate.expresso.services.dbobj.JobQueueParam; 79 import org.apache.log4j.Logger; 80 81 import javax.servlet.ServletException ; 82 import java.util.Enumeration ; 83 import java.util.Hashtable ; 84 import java.util.Iterator ; 85 86 87 93 public class SendNotice 94 extends Job { 95 private static final String thisClass = SendNotice.class.getName() + "."; 96 private static Logger log = Logger.getLogger("expresso.services.job.SendNotice");; 97 98 101 public SendNotice() { 102 super(); 103 addParameter("Subject", "Message Subject"); 104 addParameter("FileNumber", "File Number"); 105 addParameter("NoticeText", "Notice Text"); 106 } 107 108 114 private void errorNotify(String msg) { 115 String myName = (thisClass + "errorNotify()"); 116 117 try { 118 Event myEvent = new Event(getJobQueueEntry().getDataContext(), 119 "SYSERROR", 120 myName + 121 ":Unable to send notifications:" + msg + 122 " Job:" + getJobNumber() + " User:" + 123 getUser(), false); 124 } catch (Exception e) { 125 log.error(e); 126 } 127 } 128 129 134 public String getTitle() { 135 return ("Send Notices"); 136 } 137 138 141 public void run() { 142 super.run(); 143 144 String myName = (thisClass + "run()"); 145 146 try { 147 StringBuffer mailMsg = new StringBuffer (""); 148 JobQueue jq = getJobQueueEntry(); 149 String uid = jq.getField("ExpUid"); 150 String subject = jq.getParamValue("Subject"); 151 String fileNumber = jq.getParamValue("FileNumber"); 152 StringBuffer noticeTextBuffer = new StringBuffer (); 153 JobQueueParam jqp = new JobQueueParam(SecuredDBObject.SYSTEM_ACCOUNT); 154 jqp.setField("JobNumber", jq.getField("JobNumber")); 155 jqp.setField("ParamCode", "NoticeText%"); 156 157 JobQueueParam oneJqp = null; 158 159 for (Iterator je = jqp.searchAndRetrieveList("ParamNumber").iterator(); 160 je.hasNext();) { 161 oneJqp = (JobQueueParam) je.next(); 162 noticeTextBuffer.append(oneJqp.getField("ParamValue")); 163 noticeTextBuffer.append("\n"); 164 } 165 166 167 String noticeText = noticeTextBuffer.toString(); 168 169 if (fileNumber.equals("")) { 170 throw new ServletException (myName + 171 ":File number must not be " + 172 "blank"); 173 } 174 175 Hashtable h = new Hashtable (10); 176 User oneUser = new User(); 177 178 179 DownloadLog dll = new DownloadLog(SecuredDBObject.SYSTEM_ACCOUNT); 180 dll.setField("FileNumber", fileNumber); 181 182 DownloadLog oneDl = null; 183 184 for (Iterator e = dll.searchAndRetrieveList().iterator(); 185 e.hasNext();) { 186 oneDl = (DownloadLog) e.next(); 187 188 if (h.get(oneDl.getField("ExpUid")) == null) { 189 h.put(oneDl.getField("ExpUid"), oneDl.getField("ExpUid")); 190 } 191 } 192 193 int noticeCount = 0; 194 195 for (Enumeration e = h.keys(); e.hasMoreElements();) { 196 oneUser.clear(); 197 oneUser.setUid((String ) e.nextElement()); 198 199 if (oneUser.find()) { 200 mailMsg.append("Sending notice to " + 201 oneUser.getLoginName() + " (" + 202 oneUser.getUid() + ")\n"); 203 oneUser.notify(subject, noticeText); 204 noticeCount++; 205 } else { 206 mailMsg.append("Unable to find user '" + 207 oneDl.getField("ExpUid") + 208 " in user table"); 209 } 210 } 211 212 mailMsg.append("" + noticeCount + " Notifications Sent"); 213 oneUser.clear(); 214 oneUser.setUid(uid); 215 oneUser.retrieve(); 216 oneUser.notify("Sent Notifications", mailMsg.toString()); 217 if (log.isInfoEnabled()) { 218 log.info("Job completed - removing queue entry"); 219 } 220 finish("Send Notices Job Completed"); 221 } catch (Exception de) { 222 finish("Unable to Send Notices", de); 223 } 224 } 225 226 } 227 | Popular Tags |