1    package com.instantbank.component.job.model;
2    
3    import java.util.Collection;
4    import java.util.ArrayList;
5    import java.util.Hashtable;
6    import java.util.Iterator;
7    import java.io.Serializable;
8    import org.w3c.dom.Element;
9    import org.w3c.dom.Document;
10   import java.sql.Date;
11   
12   import com.instantbank.component.job.model.JobSELECTelement;
13   import com.instantbank.component.job.model.JobWHEREelement;
14   import com.instantbank.component.job.model.JobORDERelement;
15   
16   /**
17    * state Model of Job EJB
18    *
19    * @author Instant-bank (Consuelo Franky)
20    * @created October 2002
21    */
22   public class JobModel
23       implements Serializable {
24   
25     // ATTRIBUTES CORRESPONDING TO Job EJB state:
26   
27     // master attributes that can not be null:
28     /**
29      *  job Id: primary key
30      */
31     private Long jobId;
32     /**
33      *  current company
34      */
35     private String companyId;
36     /**
37      *  job name
38      */
39     private String name;
40     /**
41      *  job frequency
42      */
43     private String frequency;
44     /**
45      *  job status
46      */
47     private String status;
48     /**
49      *  activation date
50      */
51     private java.sql.Date activationDate;
52     /**
53      *  current user
54      */
55     private Long userId;
56     /**
57      * version (i.e. last changed date)
58      */
59     private java.sql.Date version;
60   
61     // master attributes that can be null (in the database):
62     /**
63      * template code associated to the job
64      */
65     private long templateCode;
66     /**
67      * queue type id (for future integration with Collections
68      */
69     private long queueTypeId;
70     /**
71      * job description
72      */
73     private String description;
74     /**
75      * sql text associated to the job
76      */
77     private String sqlText;
78     /**
79      *  last Execution date
80      */
81     private java.sql.Date lastExecutionDate;
82     /**
83      *  ftp Primary Id
84      */
85     private long ftpPrimaryId;
86     /**
87      *  ftp Alternate Id
88      */
89     private long ftpAlternateId;
90   
91     // detail attributes :
92     /**
93      * job SELECT collection: elements of type jobSELECTelement
94      */
95     private Collection jobSELECT;
96     /**
97      * job WHERE collection:  elements of type jobWHEREelement
98      */
99     private Collection jobWHERE;
100  
101    /**
102     * job ORDER collection:  elements of type jobORDERelement
103     *it is assumed that the set of jobORDER elements
104     *is the same set of jobSELECT elements
105     */
106    private Collection jobORDER;
107  
108  
109    /**
110     *  empty Constructor.
111     */
112    public JobModel() { }
113  
114  
115    /**
116     *  full Constructor.
117     *
118     * @param jobId identifier of job (primary key)
119     * @param companyId current company
120     * @param name job name
121     * @param frequency job frequency
122     * @param status job status
123     * @param activationDate job activation date
124     * @param ftpPrimaryId a ftp location id of the company
125     * @param ftpAlternateId an alternate ftp location id of the company
126     * @param userId current user
127     * @param version job version (last update date)
128     * @param templateCode code of template associated to job
129     * @param queueTypeId queue type id associated to job
130     *                          (not used; reserved for future integration
131     *                           with Collections subsystem)
132     * @param description job description
133     * @param sqlText sql text for selecting database tuples
134     *                          corresponding to the job
135     * @param lastExecutionDate job last execution date
136     * @param jobSELECT job SELECT elements
137     * @param jobWHERE job WHERE elements
138     * @param jobORDER job ORDER elements
139     */
140    public JobModel
141      (Long jobId, String companyId, String name, String frequency,
142       String status, Date activationDate, long ftpPrimaryId,
143       long ftpAlternateId, Long userId, java.sql.Date version,
144       long templateCode, long queueTypeId, String description,
145       String sqlText, Date lastExecutionDate,
146       Collection jobSELECT, Collection jobWHERE, Collection jobORDER) {
147  
148      this.jobId = jobId;
149      this.companyId = companyId;
150      this.name = name;
151      this.frequency = frequency;
152      this.status = status;
153      this.activationDate = activationDate;
154      this.ftpPrimaryId = ftpPrimaryId;
155      this.ftpAlternateId = ftpAlternateId;
156      this.userId = userId;
157      this.version = version;
158      this.templateCode = templateCode;
159      this.queueTypeId = queueTypeId;
160      this.description = description;
161      this.sqlText = sqlText;
162      this.lastExecutionDate = lastExecutionDate;
163      this.jobSELECT = jobSELECT;
164      this.jobWHERE = jobWHERE;
165      this.jobORDER = jobORDER;
166    }
167  
168    // GET METHODS ON ATTRIBUTES:
169  
170    /**
171     *  Getter method for jobId
172     *
173     * @return jobId value
174     */
175    public Long getJobId() {
176      return jobId;
177    }
178  
179  
180    /**
181     *  Getter method for companyId
182     *
183     * @return companyId value
184     */
185    public String getCompanyId() {
186      return companyId;
187    }
188  
189  
190    /**
191     *  Getter method for name
192     *
193     * @return name value
194     */
195    public String getName() {
196      return name;
197    }
198  
199  
200    /**
201     *  Getter method for frequency
202     *
203     * @return frequency value
204     */
205    public String getFrequency() {
206      return frequency;
207    }
208  
209  
210    /**
211     *  Getter method for status
212     *
213     * @return status value
214     */
215    public String getStatus() {
216      return status;
217    }
218  
219  
220    /**
221     *  Getter method for activationDate
222     *
223     * @return activationDate value
224     */
225    public Date getActivationDate() {
226      return activationDate;
227    }
228  
229  
230    /**
231     *  Getter method for ftpPrimaryId
232     *
233     * @return ftpPrimaryId value
234     */
235    public long getFtpPrimaryId() {
236      return ftpPrimaryId;
237    }
238  
239  
240    /**
241     *  Getter method for ftpAlternateId
242     *
243     * @return ftpAlternateId value
244     */
245    public long getFtpAlternateId() {
246      return ftpAlternateId;
247    }
248  
249  
250    /**
251     *  Getter method for version
252     *
253     * @return version value
254     */
255    public java.sql.Date getVersion() {
256      return version;
257    }
258  
259  
260    /**
261     *  Getter method for userId
262     *
263     * @return userId value
264     */
265    public Long getUserId() {
266      return userId;
267    }
268  
269  
270    /**
271     *  Getter method for templateCode
272     *
273     * @return templateCode value
274     */
275    public long getTemplateCode() {
276      return templateCode;
277    }
278  
279  
280    /**
281     *  Getter method for queueTypeId
282     *
283     * @return queueTypeId value
284     */
285    public long getQueueTypeId() {
286      return queueTypeId;
287    }
288  
289  
290    /**
291     *  Getter method for description
292     *
293     * @return description value
294     */
295    public String getDescription() {
296      return description;
297    }
298  
299  
300    /**
301     *  Getter method for lastExecutionDate
302     *
303     * @return lastExecutionDate value
304     */
305    public java.sql.Date getLastExecutionDate() {
306      return lastExecutionDate;
307    }
308  
309  
310    /**
311     *  Getter method for sqlText
312     *
313     * @return sqlText value
314     */
315    public String getSqlText() {
316      return sqlText;
317    }
318  
319  
320    /**
321     *  Getter method for jobSELECT
322     *
323     * @return jobSELECT value
324     */
325    public Collection getJobSELECT() {
326      return jobSELECT;
327    }
328  
329  
330    /**
331     *  Getter method for jobWHERE
332     *
333     * @return jobWHERE value
334     */
335    public Collection getJobWHERE() {
336      return jobWHERE;
337    }
338  
339  
340    /**
341     *  Getter method for jobORDER returning a Collection
342     *
343     * @return jobORDER value
344     */
345    public Collection getJobORDER() {
346      return jobORDER;
347    }
348  
349  
350    /**
351     *  Getter method for jobORDER returning a Hashtable
352     *
353     * @return value of jobORDER in Hashtable form
354     */
355    public Hashtable getJobORDERtable() {
356      ArrayList jobORDERarray = (ArrayList)this.jobORDER;
357      if(jobORDERarray == null) {
358        return null;
359      }
360  
361      Hashtable jobORDERhashtable = new Hashtable();
362      for(int i = 0; i < jobORDERarray.size(); i++) {
363        JobORDERelement element = (JobORDERelement)jobORDERarray.get(i);
364        jobORDERhashtable.put(new Long(element.getFieldId()), element);
365      }
366      return jobORDERhashtable;
367    }
368  
369  
370    // SET METHODS ON ATTRIBUTES :
371  
372    /**
373     *  Setter method on jobId
374     *
375     * @param jobId The new jobId value
376     */
377    public void setJobId(Long jobId) {  // used by JobEJB and JobDAO
378      this.jobId = jobId;
379    }
380  
381  
382    /**
383     *  Setter method on version
384     *
385     * @param version The new version value
386     */
387    public void setVersion(java.sql.Date version) {  // used by JobDAO
388      this.version = version;
389    }
390  
391  
392    /**
393     *  Setter method on description
394     *
395     * @param description The new description value
396     */
397    public void setDescription(String description) {
398      this.description = description;
399    }
400  
401  
402    /**
403     *  Setter method on ftpPrimaryId
404     *
405     * @param ftpPrimaryId The new version value
406     */
407    public void setFtpPrimaryId(long ftpPrimaryId) {
408      this.ftpPrimaryId = ftpPrimaryId;
409    }
410  
411  
412    /**
413     *  Setter method on ftpAlternateId
414     *
415     * @param ftpAlternateId The new version value
416     */
417    public void setFtpAlternateId(long ftpAlternateId) {
418      this.ftpAlternateId = ftpAlternateId;
419    }
420  
421  
422    /**
423     *  Setter method on jobSELECT
424     *
425     * @param jobSELECT The new jobSELECT value
426     */
427    public void setJobSELECT(Collection jobSELECT) {  // used by JobDAO
428      this.jobSELECT = jobSELECT;
429    }
430  
431  
432    /**
433     *  Setter method on jobWHERE
434     *
435     * @param jobWHERE The new jobWHERE value
436     */
437    public void setJobWHERE(Collection jobWHERE) {  // used by JobDAO
438      this.jobWHERE = jobWHERE;
439    }
440  
441  
442    /**
443     *  Setter method on jobORDER
444     *
445     * @param jobORDER The new jobORDER value
446     */
447    public void setJobORDER(Collection jobORDER) {  // used by JobDAO
448      this.jobORDER = jobORDER;
449    }
450  
451  
452    /**
453     *  Setter method on sqlText
454     *
455     * @param sqlText The new sqlText value
456     */
457    public void setSqlText(String sqlText) {  // used by JobEJB
458      this.sqlText = sqlText;
459    }
460  
461  
462    /**
463     *  Setter method on templateCode
464     *
465     * @param templateCode The new templateCode value
466     */
467    public void setTemplateCode(long templateCode) {  // used by JobEJB
468      this.templateCode = templateCode;
469    }
470  
471  
472    /**
473     *  Setter method on master set of attributes.
474     *
475     * @param jobId identifier of job (primary key)
476     * @param companyId current company
477     * @param name job name
478     * @param frequency job frequency
479     * @param status job status
480     * @param activationDate job activation date
481     * @param ftpPrimaryId a ftp location id of the company
482     * @param ftpAlternateId an alternate ftp location id of the company
483     * @param userId current user
484     * @param version job version (last update date)
485     * @param templateCode code of template associated to job
486     * @param queueTypeId queue type id associated to job
487     *                          (not used; reserved for future integration
488     *                           with Collections subsystem)
489     * @param description job description
490     * @param sqlText sql text for selecting database tuples
491     *                          corresponding to the job
492     * @param lastExecutionDate job last execution date (letters generation)
493     */
494    public void setMaster
495      (Long jobId, String companyId, String name, String frequency,
496       String status, Date activationDate, long ftpPrimaryId,
497       long ftpAlternateId, Long userId, Date version,
498       long templateCode, long queueTypeId, String description,
499       String sqlText, Date lastExecutionDate) {
500  
501      this.jobId = jobId;
502      this.companyId = companyId;
503      this.name = name;
504      this.frequency = frequency;
505      this.status = status;
506      this.activationDate = activationDate;
507      this.ftpPrimaryId = ftpPrimaryId;
508      this.ftpAlternateId = ftpAlternateId;
509      this.userId = userId;
510      this.version = version;
511      this.templateCode = templateCode;
512      this.queueTypeId = queueTypeId;
513      this.description = description;
514      this.sqlText = sqlText;
515      this.lastExecutionDate = lastExecutionDate;
516    }
517  
518  
519    // OTHER METHODS :
520  
521    /**
522     *  Textual representation of JobModel
523     *
524     * @return associated text
525     */
526    public String toString() {
527      String ret = null;
528      ret = "jobId = " + jobId + "\n";
529      ret += "companyId = " + companyId + "\n";
530      ret += "name = " + name + "\n";
531      ret += "frequency = " + frequency + "\n";
532      ret += "status = " + status + "\n";
533      ret += "activationDate = " + activationDate + "\n";
534      ret += "ftpPrimaryId = " + ftpPrimaryId + "\n";
535      ret += "ftpAlternateId = " + ftpAlternateId + "\n";
536      ret += "userId = " + userId + "\n";
537      ret += "version = " + version + "\n";
538      ret += "templateCode = " + templateCode + "\n";
539      ret += "queueTypeId = " + queueTypeId + "\n";
540      ret += "description = " + description + "\n";
541      ret += "sqlText = " + sqlText + "\n";
542  
543      Iterator it;
544      it = (jobSELECT != null) ? jobSELECT.iterator() : null;
545      while((it != null) && it.hasNext()) {
546        JobSELECTelement item = (JobSELECTelement)it.next();
547        ret += "JobSELECT item = " + item.toString() + "\n";
548      }
549      it = (jobWHERE != null) ? jobWHERE.iterator() : null;
550      while((it != null) && it.hasNext()) {
551        JobWHEREelement item = (JobWHEREelement)it.next();
552        ret += "JobWHERE item = " + item.toString() + "\n";
553      }
554      it = (jobORDER != null) ? jobORDER.iterator() : null;
555      while((it != null) && it.hasNext()) {
556        JobORDERelement item = (JobORDERelement)it.next();
557        ret += "JobORDER item = " + item.toString() + "\n";
558      }
559      return ret;
560    }
561  
562  
563    /**
564     *  XML representation of JobModel
565     *
566     * @param doc Description of the Parameter
567     * @return associated XML text
568     */
569    public Element toXml(Document doc) {
570      Element root = doc.createElement("Job");
571      root.setAttribute("Id", jobId.toString());
572  
573      Element node = null;
574  
575      node = doc.createElement("CompanyId");
576      node.appendChild(doc.createTextNode(companyId));
577      root.appendChild(node);
578  
579      node = doc.createElement("Name");
580      node.appendChild(doc.createTextNode(name));
581      root.appendChild(node);
582  
583      node = doc.createElement("Frequency");
584      node.appendChild(doc.createTextNode(frequency));
585      root.appendChild(node);
586  
587      node = doc.createElement("Status");
588      node.appendChild(doc.createTextNode(status));
589      root.appendChild(node);
590  
591      node = doc.createElement("ActivationDate");
592      node.appendChild(doc.createTextNode(activationDate.toString()));
593      root.appendChild(node);
594  
595      node = doc.createElement("FtpPrimaryId");
596      node.appendChild(doc.createTextNode(String.valueOf(ftpPrimaryId)));
597      root.appendChild(node);
598  
599      node = doc.createElement("FtpAlternateId");
600      node.appendChild(doc.createTextNode(String.valueOf(ftpAlternateId)));
601      root.appendChild(node);
602  
603      node = doc.createElement("UserId");
604      node.appendChild(doc.createTextNode(userId.toString()));
605      root.appendChild(node);
606  
607      node = doc.createElement("Version");
608      node.appendChild(doc.createTextNode(version.toString()));
609      root.appendChild(node);
610  
611      node = doc.createElement("TemplateCode");
612      node.appendChild(doc.createTextNode(String.valueOf(templateCode)));
613      root.appendChild(node);
614  
615      node = doc.createElement("QueueTypeId");
616      node.appendChild(doc.createTextNode(String.valueOf(queueTypeId)));
617      root.appendChild(node);
618  
619      node = doc.createElement("Description");
620      node.appendChild(doc.createTextNode(description));
621      root.appendChild(node);
622  
623      node = doc.createElement("SqlText");
624      node.appendChild(doc.createTextNode(sqlText));
625      root.appendChild(node);
626  
627      for(Iterator it = jobSELECT.iterator(); it.hasNext(); ) {
628        root.appendChild(((JobSELECTelement)it.next()).toXml(doc));
629      }
630      for(Iterator it = jobWHERE.iterator(); it.hasNext(); ) {
631        root.appendChild(((JobWHEREelement)it.next()).toXml(doc));
632      }
633      for(Iterator it = jobORDER.iterator(); it.hasNext(); ) {
634        root.appendChild(((JobORDERelement)it.next()).toXml(doc));
635      }
636      return root;
637    }
638  
639  
640    /**
641     * Copies a JobModel value to attributes of this instance
642     *
643     * @param other input JobModel value
644     */
645    public void copy(JobModel other) {
646      this.jobId = other.jobId;
647      this.companyId = other.companyId;
648      this.name = other.name;
649      this.frequency = other.frequency;
650      this.status = other.status;
651      this.activationDate = other.activationDate;
652      this.ftpPrimaryId = other.ftpPrimaryId;
653      this.ftpAlternateId = other.ftpAlternateId;
654      this.userId = other.userId;
655      this.version = other.version;
656      this.templateCode = other.templateCode;
657      this.queueTypeId = other.queueTypeId;
658      this.description = other.description;
659      this.sqlText = other.sqlText;
660      this.jobSELECT = other.jobSELECT;
661      this.jobWHERE = other.jobWHERE;
662      this.jobORDER = other.jobORDER;
663    }
664  }
665  
666