|
- package altk.comm.engine;
-
- public class JobReport
- {
- private String broadcastId;
- private String launchRecordId;
- private String contactId;
- private String recordId; // id into table, e.g. call_record, sms_record, etc.
- private String jobStatus; // Note: not enum
- private String errorText;
- private long startTime;
- private String activityRecordIdParamName;
- private String xmlRootNodeName;
-
- protected JobReport()
- {
- }
-
- protected final void initBase(Job job, String broadcastId, String launchRecordId,
- String activityRecordIdParamName, String xmlRootNodeName)
- {
- if (broadcastId == null || broadcastId.length() == 0)
- {
- throw new IllegalArgumentException("JobReport given null or empty broadcastId");
- }
- if (launchRecordId == null || launchRecordId.length() == 0)
- {
- throw new IllegalArgumentException("JobReport given null or empty launchRecordId");
- }
-
- this.broadcastId = broadcastId;
- this.launchRecordId = launchRecordId;
- this.activityRecordIdParamName = activityRecordIdParamName;
- this.xmlRootNodeName = xmlRootNodeName;
- startTime = job.startTime;
- contactId = job.recipient.contact_id;
- recordId = job.recipient.activity_record_id;
- jobStatus = job.jobStatus.toString();
- errorText = job.errorText;
- }
-
- /**
- * Derived class may initialize its own attributes.
- * @param job
- */
- public void init(Job job)
- {
- }
-
- public String toString()
- {
- StringBuffer xml = new StringBuffer();
- appendXML(xml);
- return xml.toString();
- }
-
- public final StringBuffer appendXML(StringBuffer xml)
- {
- xml.append("<" + xmlRootNodeName + " broadcast_id=\"" + broadcastId
- + "\" launch_record_id=\"" + launchRecordId
- + "\" " + activityRecordIdParamName + "=\"" + recordId
- + "\" contact_id=\"" + contactId
- + "\" recipient_status=\"" + jobStatus + "\" >\r\n");
- xml.append("<start_time>" + startTime/1000 + "</start_time>\r\n");
- xml = appendSpecificXML(xml);
- if (errorText != null && errorText.length() > 0)
- {
- xml.append("<error_text>");
- xml.append(errorText.replaceAll("&", "&").replaceAll("<", "<"));
- xml.append("</error_text>\r\n");
- }
- xml.append("</" + xmlRootNodeName + ">");
- return xml;
-
- }
-
- /**
- * Append data to xml which is specific to the derived class. For example, email
- * address for EmailJobReport.
- * @param xml
- * @return
- */
- protected StringBuffer appendSpecificXML(StringBuffer xml)
- {
- return xml;
- }
-
- }
|