diff options
author | rescobar | 2011-08-10 03:28:05 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2011-08-10 03:28:05 +0000 |
commit | f135d5263a3d0c5597e8a48f43ac9a8dc50ec1f8 (patch) | |
tree | c5fca6e4ec7272f1f78af0d4e064f356ed4c4180 /plugins/org.eclipse.osee.mail | |
parent | 34711e00d3a815754426b86248b5d90d5c0f9902 (diff) | |
download | org.eclipse.osee-f135d5263a3d0c5597e8a48f43ac9a8dc50ec1f8.tar.gz org.eclipse.osee-f135d5263a3d0c5597e8a48f43ac9a8dc50ec1f8.tar.xz org.eclipse.osee-f135d5263a3d0c5597e8a48f43ac9a8dc50ec1f8.zip |
feature[bgz_348148]: Update mail service to use callables
Diffstat (limited to 'plugins/org.eclipse.osee.mail')
7 files changed, 198 insertions, 36 deletions
diff --git a/plugins/org.eclipse.osee.mail/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.mail/META-INF/MANIFEST.MF index 914e6c3e001..b0f27ed4b79 100644 --- a/plugins/org.eclipse.osee.mail/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.mail/META-INF/MANIFEST.MF @@ -10,7 +10,6 @@ Import-Package: javax.activation, javax.mail.event;version="1.4.1", javax.mail.internet;version="1.4.1", javax.xml.bind.annotation, - org.eclipse.osee.framework.core.operation, org.eclipse.osee.framework.jdk.core.util, org.eclipse.osee.framework.jdk.core.util.windows, org.osgi.framework diff --git a/plugins/org.eclipse.osee.mail/build.properties b/plugins/org.eclipse.osee.mail/build.properties index 987480095e1..fc412f6afa1 100644 --- a/plugins/org.eclipse.osee.mail/build.properties +++ b/plugins/org.eclipse.osee.mail/build.properties @@ -3,6 +3,4 @@ output.. = bin/ bin.includes = META-INF/,\ . additional.bundles = javax.mail.glassfish,\ - org.eclipse.osee.framework.core,\ - org.eclipse.core.runtime,\ org.eclipse.osee.framework.jdk.core diff --git a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailEventUtil.java b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailEventUtil.java index f8dcf65165a..c92209507d8 100644 --- a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailEventUtil.java +++ b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailEventUtil.java @@ -10,13 +10,14 @@ *******************************************************************************/ package org.eclipse.osee.mail; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Map; import javax.mail.Address; import javax.mail.Message; -import javax.mail.MessagingException; import javax.mail.event.TransportEvent; +import org.eclipse.osee.mail.SendMailStatus.MailStatus; /** * @author Roberto E. Escobar @@ -27,6 +28,56 @@ public final class MailEventUtil { // Utility } + public static void loadStatus(SendMailStatus status, TransportEvent event) { + MailStatus eventStatus = toStatus(event); + status.add(eventStatus); + } + + public static MailStatus toStatus(TransportEvent event) { + MailStatus status = new MailStatus(); + status.setVerified(true); + Message message = event.getMessage(); + String uuid; + try { + String[] header = message.getHeader(MailConstants.MAIL_UUID_HEADER); + uuid = header.length == 0 ? "-1" : header[0]; + } catch (Exception ex) { + uuid = ex.getMessage(); + } + status.setUuid(uuid); + try { + Date sentDate = message.getSentDate(); + status.setDateSent(sentDate); + } catch (Exception ex) { + // Do nothing + } + String subject; + try { + subject = message.getSubject(); + } catch (Exception ex) { + subject = ex.getMessage(); + } + status.setSubject(subject); + + try { + addAddress(status.getFromAddress(), message.getFrom()); + } catch (Exception ex) { + // + } + addAddress(status.getInvalidAddress(), event.getInvalidAddresses()); + addAddress(status.getSentAddress(), event.getValidSentAddresses()); + addAddress(status.getUnsentAddress(), event.getValidUnsentAddresses()); + return status; + } + + private static void addAddress(Collection<String> data, Address... addresses) { + if (addresses != null) { + for (Address address : addresses) { + data.add(address.toString()); + } + } + } + public static Map<String, String> createTransportEventData(TransportEvent event) { Map<String, String> data = new HashMap<String, String>(); Message message = event.getMessage(); @@ -35,27 +86,27 @@ public final class MailEventUtil { try { String[] header = message.getHeader(MailConstants.MAIL_UUID_HEADER); uuid = header.length == 0 ? "-1" : header[0]; - } catch (MessagingException ex) { + } catch (Exception ex) { uuid = ex.getMessage(); } data.put(MailConstants.MAIL_UUID, uuid); try { Date sentDate = message.getSentDate(); data.put(MailConstants.MAIL_DATE_SENT, String.valueOf(sentDate.getTime())); - } catch (MessagingException ex) { + } catch (Exception ex) { // Do nothing } String subject; try { subject = message.getSubject(); - } catch (MessagingException ex) { + } catch (Exception ex) { subject = ex.getMessage(); } data.put(MailConstants.MAIL_SUBJECT, subject); try { addAddress(data, MailConstants.MAIL_FROM_ADDRESS, message.getFrom()); - } catch (MessagingException ex) { + } catch (Exception ex) { data.put(MailConstants.MAIL_FROM_ADDRESS, ex.getMessage()); } addAddress(data, MailConstants.MAIL_INVALID_ADDRESS, event.getInvalidAddresses()); diff --git a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailMessage.java b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailMessage.java index f96170dccc6..49f273f9ac4 100644 --- a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailMessage.java +++ b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailMessage.java @@ -10,13 +10,15 @@ *******************************************************************************/ package org.eclipse.osee.mail; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; +import java.util.List; import javax.activation.DataHandler; import javax.activation.DataSource; -import javax.xml.bind.annotation.XmlAttachmentRef; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; /** * @author Roberto E. Escobar @@ -34,8 +36,8 @@ public class MailMessage { @XmlElement private final Collection<String> recepientAddresses = new LinkedHashSet<String>(); - @XmlAttachmentRef - private final Collection<DataHandler> attachments = new LinkedHashSet<DataHandler>(); + @XmlTransient + private final List<DataHandler> attachments = new ArrayList<DataHandler>(); public void setId(String id) { this.id = id; @@ -79,6 +81,7 @@ public class MailMessage { this.recepientAddresses.addAll(recipientAddress); } + @XmlElement public Collection<DataHandler> getAttachments() { return attachments; } diff --git a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailService.java b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailService.java index 9c5d1417681..bd7893b76b3 100644 --- a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailService.java +++ b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/MailService.java @@ -11,13 +11,15 @@ package org.eclipse.osee.mail; import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; /** * @author Roberto E. Escobar */ public interface MailService { - List<SendMailOperation> createSendOp(MailMessage... emails); + List<Callable<SendMailStatus>> createSendCalls(long waitForStatus, TimeUnit unit, MailMessage... emails); MailServiceConfig getConfiguration(); diff --git a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/SendMailOperation.java b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/SendMailOperation.java deleted file mode 100644 index 29e0578ca42..00000000000 --- a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/SendMailOperation.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.mail; - -import javax.mail.event.TransportListener; -import org.eclipse.osee.framework.core.operation.IOperation; - -/** - * @author Roberto E. Escobar - */ -public interface SendMailOperation extends IOperation { - - void addListener(TransportListener listener); - - void removeListener(TransportListener listener); -} diff --git a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/SendMailStatus.java b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/SendMailStatus.java new file mode 100644 index 00000000000..3810b8757a6 --- /dev/null +++ b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/SendMailStatus.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.mail; + +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Roberto E. Escobar + */ +@XmlRootElement +public class SendMailStatus { + + private final Set<MailStatus> entries = new HashSet<MailStatus>(); + + public void add(MailStatus newStatus) { + entries.add(newStatus); + } + + @XmlElement + public Collection<MailStatus> getEntries() { + return entries; + } + + @XmlRootElement + public static class MailStatus { + + private String uuid; + private String subject; + private Date dateSent; + private boolean verified; + + private final Set<String> fromAddress = new HashSet<String>(); + private final Set<String> invalidAddress = new HashSet<String>(); + private final Set<String> sentAddress = new HashSet<String>(); + private final Set<String> unsentAddress = new HashSet<String>(); + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public void setDateSent(Date dateSent) { + this.dateSent = dateSent; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getUuid() { + return uuid; + } + + public Date getDateSent() { + return dateSent; + } + + public String getSubject() { + return subject; + } + + public boolean isVerified() { + return verified; + } + + public void setVerified(boolean verified) { + this.verified = verified; + } + + @XmlElement + public Set<String> getFromAddress() { + return fromAddress; + } + + @XmlElement + public Set<String> getInvalidAddress() { + return invalidAddress; + } + + @XmlElement + public Set<String> getSentAddress() { + return sentAddress; + } + + @XmlElement + public Set<String> getUnsentAddress() { + return unsentAddress; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MailStatus other = (MailStatus) obj; + if (uuid == null) { + if (other.uuid != null) { + return false; + } + } else if (!uuid.equals(other.uuid)) { + return false; + } + return true; + } + } + +} |