1 21 package com.jaspersoft.jasperserver.api.engine.scheduling.hibernate; 22 23 import java.util.ArrayList ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 29 import com.jaspersoft.jasperserver.api.engine.scheduling.domain.ReportJob; 30 import com.jaspersoft.jasperserver.api.engine.scheduling.domain.ReportJobMailNotification; 31 32 36 public class PersistentReportJobMailNotification { 37 38 private long id; 39 private int version; 40 private List recipients; 41 private String subject; 42 private String 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 getMessageText() { 66 return messageText; 67 } 68 69 public void setMessageText(String 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 getSubject() { 82 return subject; 83 } 84 85 public void setSubject(String subject) { 86 this.subject = subject; 87 } 88 89 public List getRecipients() { 90 return recipients; 91 } 92 93 public void setRecipients(List 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 newRecipients = new ArrayList (); 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 recipientsList, List addresses, byte type) { 113 if (addresses != null && !addresses.isEmpty()) { 114 for (Iterator it = addresses.iterator(); it.hasNext();) { 115 String address = (String ) 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 collectedAddresses = new HashMap (); 137 collectedAddresses.put(new Byte (PersistentReportJobMailRecipient.TYPE_TO), new ArrayList ()); 138 collectedAddresses.put(new Byte (PersistentReportJobMailRecipient.TYPE_BCC), new ArrayList ()); 139 collectedAddresses.put(new Byte (PersistentReportJobMailRecipient.TYPE_CC), new ArrayList ()); 140 141 for (Iterator it = getRecipients().iterator(); it.hasNext();) { 142 PersistentReportJobMailRecipient recipient = (PersistentReportJobMailRecipient) it.next(); 143 ((List ) collectedAddresses.get(new Byte (recipient.getType()))).add(recipient.getAddress()); 144 } 145 146 mail.setToAddresses((List ) collectedAddresses.get(new Byte (PersistentReportJobMailRecipient.TYPE_TO))); 147 mail.setCcAddresses((List ) collectedAddresses.get(new Byte (PersistentReportJobMailRecipient.TYPE_CC))); 148 mail.setBccAddresses((List ) collectedAddresses.get(new Byte (PersistentReportJobMailRecipient.TYPE_BCC))); 149 } 150 151 public boolean isNew() { 152 return getVersion() == ReportJob.VERSION_NEW; 153 } 154 155 } 156 | Popular Tags |