KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > api > engine > scheduling > hibernate > PersistentReportJobMailNotification


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.api.engine.scheduling.hibernate;
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import com.jaspersoft.jasperserver.api.engine.scheduling.domain.ReportJob;
30 import com.jaspersoft.jasperserver.api.engine.scheduling.domain.ReportJobMailNotification;
31
32 /**
33  * @author Lucian Chirita (lucianc@users.sourceforge.net)
34  * @version $Id: PersistentReportJobMailNotification.java 3550 2006-06-06 18:47:26Z lucian $
35  */

36 public class PersistentReportJobMailNotification {
37     
38     private long id;
39     private int version;
40     private List JavaDoc recipients;
41     private String JavaDoc subject;
42     private String JavaDoc messageText;
43     private byte resultSendType;
44
45     public PersistentReportJobMailNotification() {
46         version = ReportJob.VERSION_NEW;
47     }
48     
49     public long getId() {
50         return id;
51     }
52
53     public void setId(long id) {
54         this.id = id;
55     }
56
57     public int getVersion() {
58         return version;
59     }
60
61     public void setVersion(int version) {
62         this.version = version;
63     }
64
65     public String JavaDoc getMessageText() {
66         return messageText;
67     }
68
69     public void setMessageText(String JavaDoc messageText) {
70         this.messageText = messageText;
71     }
72
73     public byte getResultSendType() {
74         return resultSendType;
75     }
76
77     public void setResultSendType(byte resultSendType) {
78         this.resultSendType = resultSendType;
79     }
80
81     public String JavaDoc getSubject() {
82         return subject;
83     }
84
85     public void setSubject(String JavaDoc subject) {
86         this.subject = subject;
87     }
88
89     public List JavaDoc getRecipients() {
90         return recipients;
91     }
92
93     public void setRecipients(List JavaDoc toAddresses) {
94         this.recipients = toAddresses;
95     }
96
97     public void copyFrom(ReportJobMailNotification mailNotification) {
98         copyRecipientsFrom(mailNotification);
99         setSubject(mailNotification.getSubject());
100         setMessageText(mailNotification.getMessageText());
101         setResultSendType(mailNotification.getResultSendType());
102     }
103
104     protected void copyRecipientsFrom(ReportJobMailNotification mailNotification) {
105         List JavaDoc newRecipients = new ArrayList JavaDoc();
106         collectRecipients(newRecipients, mailNotification.getToAddresses(), PersistentReportJobMailRecipient.TYPE_TO);
107         collectRecipients(newRecipients, mailNotification.getCcAddresses(), PersistentReportJobMailRecipient.TYPE_CC);
108         collectRecipients(newRecipients, mailNotification.getBccAddresses(), PersistentReportJobMailRecipient.TYPE_BCC);
109         setRecipients(newRecipients);
110     }
111
112     protected void collectRecipients(List JavaDoc recipientsList, List JavaDoc addresses, byte type) {
113         if (addresses != null && !addresses.isEmpty()) {
114             for (Iterator JavaDoc it = addresses.iterator(); it.hasNext();) {
115                 String JavaDoc address = (String JavaDoc) it.next();
116                 PersistentReportJobMailRecipient recipient = new PersistentReportJobMailRecipient();
117                 recipient.setType(type);
118                 recipient.setAddress(address);
119                 recipientsList.add(recipient);
120             }
121         }
122     }
123
124     public ReportJobMailNotification toClient() {
125         ReportJobMailNotification mail = new ReportJobMailNotification();
126         mail.setId(getId());
127         mail.setVersion(getVersion());
128         copyAddressesTo(mail);
129         mail.setSubject(getSubject());
130         mail.setMessageText(getMessageText());
131         mail.setResultSendType(getResultSendType());
132         return mail;
133     }
134
135     protected void copyAddressesTo(ReportJobMailNotification mail) {
136         Map JavaDoc collectedAddresses = new HashMap JavaDoc();
137         collectedAddresses.put(new Byte JavaDoc(PersistentReportJobMailRecipient.TYPE_TO), new ArrayList JavaDoc());
138         collectedAddresses.put(new Byte JavaDoc(PersistentReportJobMailRecipient.TYPE_BCC), new ArrayList JavaDoc());
139         collectedAddresses.put(new Byte JavaDoc(PersistentReportJobMailRecipient.TYPE_CC), new ArrayList JavaDoc());
140         
141         for (Iterator JavaDoc it = getRecipients().iterator(); it.hasNext();) {
142             PersistentReportJobMailRecipient recipient = (PersistentReportJobMailRecipient) it.next();
143             ((List JavaDoc) collectedAddresses.get(new Byte JavaDoc(recipient.getType()))).add(recipient.getAddress());
144         }
145         
146         mail.setToAddresses((List JavaDoc) collectedAddresses.get(new Byte JavaDoc(PersistentReportJobMailRecipient.TYPE_TO)));
147         mail.setCcAddresses((List JavaDoc) collectedAddresses.get(new Byte JavaDoc(PersistentReportJobMailRecipient.TYPE_CC)));
148         mail.setBccAddresses((List JavaDoc) collectedAddresses.get(new Byte JavaDoc(PersistentReportJobMailRecipient.TYPE_BCC)));
149     }
150
151     public boolean isNew() {
152         return getVersion() == ReportJob.VERSION_NEW;
153     }
154
155 }
156
Popular Tags