package com.example;
import org.onehippo.cms7.event.HippoEvent;
import org.onehippo.cms7.services.eventbus.Subscribe;
import org.onehippo.repository.events.HippoWorkflowEvent;
public class MyListener {
@Subscribe
public void handleEvent(HippoEvent event) {
if (HippoEventConstants.CATEGORY_WORKFLOW.equals(event.category())) {
HippoWorkflowEvent workflowEvent = new HippoWorkflowEvent(event);
if ("publish".equals(workflowEvent.methodName())) {
System.out.println("document " + workflowEvent.handleUuid() +
" was published");
}
}
}
}
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at http://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.
package com.myCompany.hippo.cms.modules; import javax.jcr.RepositoryException;import javax.jcr.Session;import org.onehippo.cms7.services.HippoServiceRegistry;import org.onehippo.repository.modules.DaemonModule;import org.onehippo.repository.modules.ProvidesService;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.myCompany.hippo.cms.modules.PublicationEventListener;import org.onehippo.cms7.services.eventbus.HippoEventBus;
@ProvidesService(types = PublicationEventListener.class)public class PublicationListenerModule implements DaemonModule { static final Logger log = LoggerFactory.getLogger(PublicationListenerModule.class); static Session session = null; private PublicationEventListener listener; @Override public void initialize(final Session session) throws RepositoryException { listener = new PublicationEventListener(); HippoServiceRegistry.registerService(listener, HippoEventBus.class); } @Override public void shutdown() { HippoServiceRegistry.unregisterService(listener, HippoEventBus.class); }}
package com.myCompany.hippo.cms.modules;
import org.onehippo.cms7.event.HippoEvent;import org.onehippo.cms7.event.HippoEventConstants;import org.onehippo.cms7.services.eventbus.Subscribe;import org.onehippo.repository.events.HippoWorkflowEvent;import java.util.List;
import com.myCompany.hippo.cms.utils.EmailUtil;
public class PublicationEventListener {
@Subscribe public void handleEvent(HippoEvent event) { if (HippoEventConstants.CATEGORY_WORKFLOW.equals(event.category())) { HippoWorkflowEvent workflowEvent = new HippoWorkflowEvent(event);
List argList = workflowEvent.arguments(); boolean isScheduled = false; String messageContent = (""); String messageSubject = ("");
//EVENT: Publication if ("publish".equals(workflowEvent.methodName())) {
//Determine if published immediately or scheduled for future publication //Published events will have null in the in arglist, scheduled events will have the date of publication if (argList!=null){ isScheduled = true; }
if (isScheduled){ messageSubject = ("--NOTIFICATION OF SCHEDULED PUBLICATION--"); messageContent = ("\n" + "--NOTIFICATION OF SCHEDULED PUBLICATION-- \n DOCUMENT: " + workflowEvent.subjectPath() + "\n Has been scheduled to be published on: " + argList + " by \"" + workflowEvent.user() + "\"" + "\n");
System.out.println(messageContent); } else{ messageSubject = ("--NOTIFICATION OF PUBLICATION--"); messageContent =("\n" + "--NOTIFICATION OF PUBLICATION-- \n DOCUMENT: " + workflowEvent.subjectPath() + "\n Was published by: \"" + workflowEvent.user() + "\" \n On: " + new java.util.Date() + "\n"); System.out.println(messageContent); } }
//EVENT: Depublication else if ("depublish".equals(workflowEvent.methodName())){ //Determine if depublished immediately or scheduled for future depublication //Depublished events will have null in the in arglist, scheduled events will have the date of depublication if (argList!=null){ isScheduled = true; }
if (isScheduled){ System.out.println("\n" + "--NOTIFICATION OF SCHEDULED DEPUBLICATION-- \n DOCUMENT: " + workflowEvent.subjectPath() + "\n Has been scheduled to be depublished on: " + argList + " by \"" + workflowEvent.user() + "\"" + "\n"); } else{ System.out.println("\n" + "--NOTIFICATION OF DEPUBLICATION-- \n DOCUMENT: " + workflowEvent.subjectPath() + "\n Was depublished by: \"" + workflowEvent.user() + "\" \n On: " + new java.util.Date() + "\n"); } }
//EVENT: Request for publication else if ("requestPublication".equals(workflowEvent.methodName())) { //Determine if request is for immediate publication or scheduled future publication if (argList!=null){ isScheduled = true; }
if (isScheduled){ System.out.println("\n" + "--NOTIFICATION OF SCHEDULED PUBLICATION REQUEST-- \n DOCUMENT: " + workflowEvent.subjectPath() + "\n Has been requested for scheduled publication on: " + argList + " by \"" + workflowEvent.user() + "\"" + "\n"); } else{ System.out.println("\n" + "--NOTIFICATION OF PUBLICATION REQUEST-- \n DOCUMENT: " + workflowEvent.subjectPath() + "\n Has been requested for publication by: \"" + workflowEvent.user() + "\" \n On: " + new java.util.Date() + "\n"); } }
//EVENT: Request for depublication else if ("requestDepublication".equals(workflowEvent.methodName())) { //Determine if request is for immediate depublication or scheduled future depublication if (argList!=null){ isScheduled = true; }
if (isScheduled){ System.out.println("\n" + "--NOTIFICATION OF SCHEDULED DEPUBLICATION REQUEST-- \n DOCUMENT: " + workflowEvent.subjectPath() + "\n Has been requested for scheduled depublication on: " + argList + " by \"" + workflowEvent.user() + "\"" + "\n"); } else{ System.out.println("\n" + "--NOTIFICATION OF DEPUBLICATION REQUEST-- \n DOCUMENT: " + workflowEvent.subjectPath() + "\n Has been requested for depublication by: \"" + workflowEvent.user() + "\" \n On: " + new java.util.Date() + "\n"); } } //EVENT: Publication/depublication request has been accepted else if ("acceptRequest".equals(workflowEvent.methodName())) { System.out.println("\n" + "--NOTIFICATION OF PUBLICATION/DEPUBLICATION REQUEST ACCEPTANCE--" + "\n The request for the publication/depublication of DOCUMENT: " + workflowEvent.subjectPath() + "\n Has been accepted by \"" + workflowEvent.user() + "\"\n On: " + new java.util.Date() + "\n"); }
//EVENT: Publication/depublication request has been rejected else if ("rejectRequest".equals(workflowEvent.methodName())) { System.out.println("\n" + "--NOTIFICATION OF PUBLICATION/DEPUBLICATION REQUEST REJECTION--" + "\n The request for the publication/depublication of DOCUMENT: " + workflowEvent.subjectPath() + "\n Has been rejected by \"" + workflowEvent.user() + "\"\n On: " + new java.util.Date() + "\n"); }
//EVENT: Publication/depublication request was cancelled else if ("cancelRequest".equals(workflowEvent.methodName())) { System.out.println("\n" + "--NOTIFICATION OF PUBLICATION/DEPUBLICATION REQUEST CANCELLATION--" + "\n The request for the publication/depublication of DOCUMENT: " + workflowEvent.subjectPath() + "\n Has been canceled by \"" + workflowEvent.user() + "\"\n On: " + new java.util.Date() + "\n"); } else{ System.out.println("EVENT TRIGGERED: " + workflowEvent.methodName()); } //send email EmailUtil.SendEmail(messageContent, messageSubject); } }
}
package com.myCompany.hippo.cms.utils;
import java.util.*;import javax.mail.*;import javax.mail.internet.*;
public class EmailUtil{ public static void SendEmail(String content, String subject) { // Recipient's email ID needs to be mentioned. String to = "Firstname...@myCompany.com";
// Sender's email ID needs to be mentioned String from = "Firstname...@myCompany.com";
// Assuming you are sending email from localhost String host = "extrelay.myCompany.com";
// Get system properties Properties properties = new Properties();
// Setup mail server properties.setProperty("mail.host", host);
// Get the default Session object. Session session = Session.getDefaultInstance(properties, null);
try{ // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session);
// Set From: header field of the header. message.setFrom(new InternetAddress(from));
// Set To: header field of the header. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
// Set Subject: header field message.setSubject(subject);
// Now set the actual message message.setText(content);
// Send message Transport.send(message); System.out.println("Sent message successfully...."); }catch (MessagingException mex) { mex.printStackTrace(); } }}
Under hippo:configuration ->
hippo: modules
Add this node:
<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="eventlistenermodule" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hipposys:module</sv:value>
</sv:property>
<sv:property sv:name="hipposys:className" sv:type="String">
<sv:value>com.myCompany.hippo.cms.modules.PublicationListenerModule</sv:value>
</sv:property>
</sv:node>
--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at http://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.