Repository: juddi
Updated Branches:
  refs/heads/master e06b6c55f -> f367a947a


JUDDI-861 done


Project: http://git-wip-us.apache.org/repos/asf/juddi/repo
Commit: http://git-wip-us.apache.org/repos/asf/juddi/commit/f367a947
Tree: http://git-wip-us.apache.org/repos/asf/juddi/tree/f367a947
Diff: http://git-wip-us.apache.org/repos/asf/juddi/diff/f367a947

Branch: refs/heads/master
Commit: f367a947a7ae02a771358acc7e8c5d0826298b52
Parents: e06b6c5
Author: Alex <[email protected]>
Authored: Thu Jan 29 16:44:45 2015 -0500
Committer: Alex <[email protected]>
Committed: Thu Jan 29 16:44:45 2015 -0500

----------------------------------------------------------------------
 .../org/apache/juddi/api/impl/JUDDIApiImpl.java |   6 +-
 .../notify/USERFRIENDLYSMTPNotifier.java        | 116 +++++++++++++++++--
 .../src/main/resources/messages.properties      |   4 +-
 .../main/java/org/uddi/sub_v3/Subscription.java |   2 +
 4 files changed, 118 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/juddi/blob/f367a947/juddi-core/src/main/java/org/apache/juddi/api/impl/JUDDIApiImpl.java
----------------------------------------------------------------------
diff --git 
a/juddi-core/src/main/java/org/apache/juddi/api/impl/JUDDIApiImpl.java 
b/juddi-core/src/main/java/org/apache/juddi/api/impl/JUDDIApiImpl.java
index 3654d29..725f0f3 100644
--- a/juddi-core/src/main/java/org/apache/juddi/api/impl/JUDDIApiImpl.java
+++ b/juddi-core/src/main/java/org/apache/juddi/api/impl/JUDDIApiImpl.java
@@ -227,9 +227,10 @@ public class JUDDIApiImpl extends AuthenticatedService 
implements JUDDIApiPortTy
                         new 
ValidatePublish(publisher).validateDeletePublisher(em, body);
 
                         List<String> entityKeyList = body.getPublisherId();
+                        List<Publisher> deletedPubs = new 
ArrayList<Publisher>();
                         for (String entityKey : entityKeyList) {
                                 Publisher obj = 
em.find(org.apache.juddi.model.Publisher.class, entityKey);
-
+                                deletedPubs.add(obj);
                                 //get an authtoken for this publisher so that 
we can get its registeredInfo
                                 UDDISecurityImpl security = new 
UDDISecurityImpl();
                                 AuthToken authToken = 
security.getAuthToken(entityKey);
@@ -277,6 +278,9 @@ public class JUDDIApiImpl extends AuthenticatedService 
implements JUDDIApiPortTy
                         }
 
                         tx.commit();
+                        for (Publisher p: deletedPubs){
+                                
USERFRIENDLYSMTPNotifier.notifyAccountDeleted(new TemporaryMailContainer(null, 
p, (Publisher) publisher));
+                        }
                         long procTime = System.currentTimeMillis() - startTime;
                         serviceCounter.update(JUDDIQuery.DELETE_PUBLISHER,
                                 QueryStatus.SUCCESS, procTime);

http://git-wip-us.apache.org/repos/asf/juddi/blob/f367a947/juddi-core/src/main/java/org/apache/juddi/subscription/notify/USERFRIENDLYSMTPNotifier.java
----------------------------------------------------------------------
diff --git 
a/juddi-core/src/main/java/org/apache/juddi/subscription/notify/USERFRIENDLYSMTPNotifier.java
 
b/juddi-core/src/main/java/org/apache/juddi/subscription/notify/USERFRIENDLYSMTPNotifier.java
index 443e102..521f47e 100644
--- 
a/juddi-core/src/main/java/org/apache/juddi/subscription/notify/USERFRIENDLYSMTPNotifier.java
+++ 
b/juddi-core/src/main/java/org/apache/juddi/subscription/notify/USERFRIENDLYSMTPNotifier.java
@@ -75,10 +75,12 @@ public class USERFRIENDLYSMTPNotifier extends SMTPNotifier {
 
         public static void notifySubscriptionDeleted(TemporaryMailContainer 
container) {
                 try {
-                        Publisher publisher=container.getPublisher();
+                        Publisher publisher = container.getPublisher();
                         Publisher deletedBy = container.getDeletedBy();
                         Subscription obj = container.getObj();
-                                
+                        String emailaddress = publisher.getEmailAddress();
+                        if (emailaddress==null || 
emailaddress.trim().equals(""))
+                                return;
                         Properties properties = new Properties();
                         Session session = null;
                         String mailPrefix = 
AppConfig.getConfiguration().getString(Property.JUDDI_EMAIL_PREFIX, 
Property.DEFAULT_JUDDI_EMAIL_PREFIX);
@@ -92,7 +94,7 @@ public class USERFRIENDLYSMTPNotifier extends SMTPNotifier {
                                         properties.put(key, 
System.getProperty(mailPrefix + key));
                                 }
                         }
-                        String emailaddress = publisher.getEmailAddress();
+
                         boolean auth = 
(properties.getProperty("mail.smtp.auth", "false")).equalsIgnoreCase("true");
                         if (auth) {
                                 final String username = 
properties.getProperty("mail.smtp.user");
@@ -137,7 +139,7 @@ public class USERFRIENDLYSMTPNotifier extends SMTPNotifier {
                         Address[] to = {address};
                         message.setRecipients(RecipientType.TO, to);
                         message.setFrom(new 
InternetAddress(properties.getProperty("mail.smtp.from", "jUDDI")));
-                                //Hello %s,<br><br>Your subscription UDDI 
subscription was deleted. Attached is what the subscription was. It was deleted 
by %s, %s at %s. This node is %s
+                        //Hello %s,<br><br>Your subscription UDDI subscription 
was deleted. Attached is what the subscription was. It was deleted by %s, %s at 
%s. This node is %s
                         //maybe nice to use a template rather then sending raw 
xml.
                         org.uddi.sub_v3.Subscription api = new 
org.uddi.sub_v3.Subscription();
                         MappingModelToApi.mapSubscription(obj, api);
@@ -146,15 +148,17 @@ public class USERFRIENDLYSMTPNotifier extends 
SMTPNotifier {
 
                         MimeBodyPart content = new MimeBodyPart();
                         String msg_content = 
ResourceConfig.getGlobalMessage("notifications.smtp.subscriptionDeleted");
-                        SimpleDateFormat sdf = new 
SimpleDateFormat("yyyy-MM-ddTkk:mm:ssZ");
-//Hello %s,<br><br>Your subscription UDDI subscription was deleted. Attached 
is what the subscription was. It was deleted by %s, %s at %s. This node is %s
+                        SimpleDateFormat sdf = new 
SimpleDateFormat("yyyy-MM-dd kk:mm:ssZ");
+//Hello %s, %s<br><br>Your subscription UDDI subscription was deleted. 
Attached is what the subscription was. It was deleted by %s, %s at %s. This 
node is %s.
                         msg_content = String.format(msg_content,
                                 
StringEscapeUtils.escapeHtml(publisher.getPublisherName()),
                                 
StringEscapeUtils.escapeHtml(publisher.getAuthorizedName()),
                                 
StringEscapeUtils.escapeHtml(deletedBy.getPublisherName()),
                                 
StringEscapeUtils.escapeHtml(deletedBy.getAuthorizedName()),
                                 StringEscapeUtils.escapeHtml(sdf.format(new 
Date())),
-                                
StringEscapeUtils.escapeHtml(AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID,
 "(unknown node id!)"))
+                                
StringEscapeUtils.escapeHtml(AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID,
 "(unknown node id!)")),
+                                
AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL, "(unknown 
url)"),
+                                
AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL_SECURE, 
"(unknown url)")
                         );
 
                         content.setContent(msg_content, "text/html; 
charset=UTF-8;");
@@ -171,7 +175,103 @@ public class USERFRIENDLYSMTPNotifier extends 
SMTPNotifier {
                         Transport.send(message);
 
                 } catch (Throwable t) {
-                        log.error(t);
+                        log.error("Error sending email!" + t.getMessage(), t);
+                }
+        }
+
+        public static void notifyAccountDeleted(TemporaryMailContainer 
container) {
+                try {
+                        Publisher publisher = container.getPublisher();
+                        Publisher deletedBy = container.getDeletedBy();
+                        String emailaddress = publisher.getEmailAddress();
+                        if (emailaddress==null || 
emailaddress.trim().equals(""))
+                                return;
+                        Properties properties = new Properties();
+                        Session session = null;
+                        String mailPrefix = 
AppConfig.getConfiguration().getString(Property.JUDDI_EMAIL_PREFIX, 
Property.DEFAULT_JUDDI_EMAIL_PREFIX);
+                        if (!mailPrefix.endsWith(".")) {
+                                mailPrefix = mailPrefix + ".";
+                        }
+                        for (String key : mailProps) {
+                                if 
(AppConfig.getConfiguration().containsKey(mailPrefix + key)) {
+                                        properties.put(key, 
AppConfig.getConfiguration().getProperty(mailPrefix + key));
+                                } else if (System.getProperty(mailPrefix + 
key) != null) {
+                                        properties.put(key, 
System.getProperty(mailPrefix + key));
+                                }
+                        }
+                        
+                        boolean auth = 
(properties.getProperty("mail.smtp.auth", "false")).equalsIgnoreCase("true");
+                        if (auth) {
+                                final String username = 
properties.getProperty("mail.smtp.user");
+                                String pwd = 
properties.getProperty("mail.smtp.password");
+                                //decrypt if possible
+                                if 
(properties.getProperty("mail.smtp.password" + Property.ENCRYPTED_ATTRIBUTE, 
"false").equalsIgnoreCase("true")) {
+                                        try {
+                                                pwd = 
CryptorFactory.getCryptor().decrypt(pwd);
+                                        } catch (NoSuchPaddingException ex) {
+                                                log.error("Unable to decrypt 
settings", ex);
+                                        } catch (NoSuchAlgorithmException ex) {
+                                                log.error("Unable to decrypt 
settings", ex);
+                                        } catch 
(InvalidAlgorithmParameterException ex) {
+                                                log.error("Unable to decrypt 
settings", ex);
+                                        } catch (InvalidKeyException ex) {
+                                                log.error("Unable to decrypt 
settings", ex);
+                                        } catch (IllegalBlockSizeException ex) 
{
+                                                log.error("Unable to decrypt 
settings", ex);
+                                        } catch (BadPaddingException ex) {
+                                                log.error("Unable to decrypt 
settings", ex);
+                                        }
+                                }
+                                final String password = pwd;
+                                log.debug("SMTP username = " + username + " 
from address = " + emailaddress);
+                                Properties eMailProperties = properties;
+                                eMailProperties.remove("mail.smtp.user");
+                                eMailProperties.remove("mail.smtp.password");
+                                session = Session.getInstance(properties, new 
javax.mail.Authenticator() {
+                                        protected PasswordAuthentication 
getPasswordAuthentication() {
+                                                return new 
PasswordAuthentication(username, password);
+                                        }
+                                });
+                        } else {
+                                Properties eMailProperties = properties;
+                                eMailProperties.remove("mail.smtp.user");
+                                eMailProperties.remove("mail.smtp.password");
+                                session = Session.getInstance(eMailProperties);
+                        }
+
+                        MimeMessage message = new MimeMessage(session);
+                        InternetAddress address = new 
InternetAddress(emailaddress);
+                        Address[] to = {address};
+                        message.setRecipients(RecipientType.TO, to);
+                        message.setFrom(new 
InternetAddress(properties.getProperty("mail.smtp.from", "jUDDI")));
+                                //Hello %s,<br><br>Your subscription UDDI 
subscription was deleted. Attached is what the subscription was. It was deleted 
by %s, %s at %s. This node is %s
+
+                        Multipart mp = new MimeMultipart();
+
+                        MimeBodyPart content = new MimeBodyPart();
+                        String msg_content = 
ResourceConfig.getGlobalMessage("notifications.smtp.accountDeleted");
+                        SimpleDateFormat sdf = new 
SimpleDateFormat("yyyy-MM-dd kk:mm:ssZ");
+//Hello %s, %s,<br><br>Your account has been deleted by %s, %s at %s. This 
node is %s.
+                        msg_content = String.format(msg_content,
+                                
StringEscapeUtils.escapeHtml(publisher.getPublisherName()),
+                                
StringEscapeUtils.escapeHtml(publisher.getAuthorizedName()),
+                                
StringEscapeUtils.escapeHtml(deletedBy.getPublisherName()),
+                                
StringEscapeUtils.escapeHtml(deletedBy.getAuthorizedName()),
+                                StringEscapeUtils.escapeHtml(sdf.format(new 
Date())),
+                                
StringEscapeUtils.escapeHtml(AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID,
 "(unknown node id!)")),
+                                
AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL, "(unknown 
url)"),
+                                
AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL_SECURE, 
"(unknown url)")
+                        );
+
+                        content.setContent(msg_content, "text/html; 
charset=UTF-8;");
+                        mp.addBodyPart(content);
+
+                        message.setContent(mp);
+                        
message.setSubject(ResourceConfig.getGlobalMessage("notifications.smtp.accountDeleted.subject"));
+                        Transport.send(message);
+
+                } catch (Throwable t) {
+                        log.error("Error sending email!" + t.getMessage(), t);
                 }
         }
 

http://git-wip-us.apache.org/repos/asf/juddi/blob/f367a947/juddi-core/src/main/resources/messages.properties
----------------------------------------------------------------------
diff --git a/juddi-core/src/main/resources/messages.properties 
b/juddi-core/src/main/resources/messages.properties
index a417c0d..1db74f8 100644
--- a/juddi-core/src/main/resources/messages.properties
+++ b/juddi-core/src/main/resources/messages.properties
@@ -282,7 +282,9 @@ notifications.smtp.default.subject=UDDI Subscription 
Notification for subscripti
 
 notifications.smtp.userfriendly.subject=UDDI Subscription Notification for 
subscription 
 notifications.smtp.userfriendly.body=Hello %s,<br><br>You are currently 
registered to receive subscription updates in the UDDI Node <b>%s</b> for %s. A 
change was registered that triggered an update notification to be sent. The 
attachment contains the XML containing the details of the 
change.<br><br><b>Summary of changes</b>: <br><br>%s
-notifications.smtp.subscriptionDeleted=Hello %s,<br><br>Your subscription UDDI 
subscription was deleted. Attached is what the subscription was. It was deleted 
by %s, %s at %s. This node is %s
+notifications.smtp.subscriptionDeleted=Hello %s, %s,<br><br>Your UDDI 
subscription was deleted. Attached is what the subscription was. It was deleted 
by %s, %s at %s. This node is %s.<br><br><a href="%s">Non-secure web 
site</a><br><a href="%s">Secure web site</a>
+notifications.smtp.accountDeleted=Hello %s, %s,<br><br>Your account has been 
deleted by %s, %s at %s. This node is %s.<br><br><a href="%s">Non-secure web 
site</a><br><a href="%s">Secure web site</a>
+notifications.smtp.accountDeleted.subject=UDDI Account Management
 #username
 #node
 #search results or a specific item

http://git-wip-us.apache.org/repos/asf/juddi/blob/f367a947/uddi-ws/src/main/java/org/uddi/sub_v3/Subscription.java
----------------------------------------------------------------------
diff --git a/uddi-ws/src/main/java/org/uddi/sub_v3/Subscription.java 
b/uddi-ws/src/main/java/org/uddi/sub_v3/Subscription.java
index ac418c5..17952c5 100644
--- a/uddi-ws/src/main/java/org/uddi/sub_v3/Subscription.java
+++ b/uddi-ws/src/main/java/org/uddi/sub_v3/Subscription.java
@@ -24,6 +24,7 @@ import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.datatype.Duration;
@@ -169,6 +170,7 @@ Durations</i>.</p>
     "maxEntities",
     "expiresAfter"
 })
+@XmlRootElement
 public class Subscription implements Serializable{
        @XmlTransient
        private static final long serialVersionUID = -1016771256986173140L;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to