Skip to content

Commit

Permalink
Merge pull request #10250 from dotCMS/issue-10198-notify-doubleevent
Browse files Browse the repository at this point in the history
#10198 now if the action is save, just save event is triggered. If th…
  • Loading branch information
jgambarios committed Dec 2, 2016
2 parents 4b8b3a6 + 0c8d5bb commit 45a87fc
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 7 deletions.
Expand Up @@ -11,6 +11,7 @@
* <li>A file change: <b>SAVE_FILE_ASSET, UPDATE_FILE_ASSET, ARCHIVE_FILE_ASSET, UN_ARCHIVE_FILE_ASSET, DELETE_FILE_ASSET, PUBLISH_FILE_ASSET, UN_PUBLISH_FILE_ASSET</b>.</li>
* <li>A file change: <b>SAVE_LINK, UPDATE_LINK, ARCHIVE_LINK, UN_ARCHIVE_LINK, MOVE_LINK, COPY_LINK, DELETE_LINK, PUBLISH_LINK, UN_PUBLISH_LINK</b>.</li>
* <li>A file change: <b>MOVE_FOLDER, COPY_FOLDER, MOVE_FILE_ASSET, COPY_FILE_ASSET, MOVE_PAGE_ASSET, COPY_PAGE_ASSET</b>.</li>
* <li>When a session is created or destroyed: <b>SESSION_CREATED, SESSION_DESTROYED</b>.</li>
* </ul>
* <p>
* The idea behind this class is to map a type of event with different possible
Expand Down Expand Up @@ -73,6 +74,9 @@ public enum SystemEventType {
COPY_FILE_ASSET,
MOVE_PAGE_ASSET,
COPY_PAGE_ASSET,


SESSION_CREATED,
SESSION_DESTROYED,

UPDATE_PORTLET_LAYOUTS,
}
46 changes: 45 additions & 1 deletion dotCMS/src/main/java/com/dotcms/listeners/SessionMonitor.java
Expand Up @@ -12,6 +12,11 @@
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.dotcms.api.system.event.*;
import com.dotcms.repackage.org.exolab.castor.types.Date;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.WebKeys;

/**
Expand All @@ -22,6 +27,20 @@
*/
public class SessionMonitor implements ServletRequestListener,
HttpSessionAttributeListener, HttpSessionListener {


private final SystemEventsAPI systemEventsAPI;

public SessionMonitor() {

this (APILocator.getSystemEventsAPI());
}

public SessionMonitor(final SystemEventsAPI systemEventsAPI) {

this.systemEventsAPI = systemEventsAPI;
}


// this will hold all logged in users
private Map<String, String> sysUsers = new ConcurrentHashMap<String, String>();
Expand Down Expand Up @@ -67,7 +86,21 @@ public void attributeRemoved(HttpSessionBindingEvent event) {
public void attributeReplaced(HttpSessionBindingEvent event) {
}

public void sessionCreated(HttpSessionEvent event) {
public void sessionCreated(final HttpSessionEvent event) {

/*final String userId = (String) event.getSession().getAttribute("USER_ID");
if (userId != null) {
try {
Logger.debug(this, "Triggering a session created event");
this.systemEventsAPI.push(new SystemEvent
(SystemEventType.SESSION_CREATED, new Payload(new Date())));
} catch (DotDataException e) {
Logger.debug(this, "Could not sent the session created event" + e.getMessage(), e);
}
}*/
}

public void sessionDestroyed(HttpSessionEvent event) {
Expand All @@ -77,6 +110,17 @@ public void sessionDestroyed(HttpSessionEvent event) {
sysUsers.remove(id);
userSessions.remove(id);
sysUsersAddress.remove(id);

try {

Logger.debug(this, "Triggering a session destroyed event");

this.systemEventsAPI.push(new SystemEvent
(SystemEventType.SESSION_DESTROYED, new Payload(new Date(), Visibility.USER, userId)));
} catch (DotDataException e) {

Logger.debug(this, "Could not sent the session destroyed event" + e.getMessage(), e);
}
}
}

Expand Down
Expand Up @@ -1369,7 +1369,8 @@ public Map<String,Object> saveContent(List<String> formData, boolean isAutoSave,

try {

newInode = contentletWebAPI.saveContent(contentletFormData,isAutoSave,isCheckin,user);
// if it is save and publish, the save event must be not generagted
newInode = contentletWebAPI.saveContent(contentletFormData,isAutoSave,isCheckin,user, !publish);

Contentlet contentlet = (Contentlet) contentletFormData.get(WebKeys.CONTENTLET_EDIT);

Expand Down
Expand Up @@ -12,9 +12,33 @@
*/
public interface ContentletWebAPI {

/**
* Saves the formData info, in addition sends an event if generateSaveEvent param is true.
* @param formData
* @param isAutoSave
* @param isCheckin
* @param user
* @param generateSaveEvent
* @return
* @throws Exception
*/
String saveContent(Map<String,Object> formData, boolean isAutoSave,boolean isCheckin,User user, boolean generateSaveEvent)
throws Exception;


/**
* Saves the formData info, in addition sends an event
* @param formData
* @param isAutoSave
* @param isCheckin
* @param user
* @return
* @throws Exception
*/
String saveContent(Map<String,Object> formData, boolean isAutoSave,boolean isCheckin,User user)
throws Exception;


/**
* Validates the new/modified page taken into account the following
* criteria:
Expand Down
Expand Up @@ -111,13 +111,25 @@ public ContentletWebAPIImpl() {

contentletSystemEventUtil = ContentletSystemEventUtil.getInstance();
}

/*
* (non-Javadoc)
* @see com.dotmarketing.portlets.contentlet.business.web.ContentletWebAPI#saveContent(java.util.Map, boolean, boolean, com.liferay.portal.model.User)
* This funtion works similar to EditContentletAction cmd = Constants.ADD
*/
public String saveContent(Map<String, Object> contentletFormData,
boolean isAutoSave, boolean isCheckin,User user) throws DotContentletValidationException,Exception {
boolean isAutoSave, boolean isCheckin,User user) throws DotContentletValidationException,Exception {

return this.saveContent(contentletFormData, isAutoSave, isCheckin, user, true);
}

/*
* (non-Javadoc)
* @see com.dotmarketing.portlets.contentlet.business.web.ContentletWebAPI#saveContent(java.util.Map, boolean, boolean, com.liferay.portal.model.User)
* This funtion works similar to EditContentletAction cmd = Constants.ADD
*/
public String saveContent(Map<String, Object> contentletFormData,
boolean isAutoSave, boolean isCheckin,User user, final boolean generateSaveEvent) throws DotContentletValidationException,Exception {

HttpServletRequest req =WebContextFactory.get().getHttpServletRequest();

Expand Down Expand Up @@ -186,10 +198,13 @@ public String saveContent(Map<String, Object> contentletFormData,
throw ae;
}

if(autocommit)
HibernateUtil.commitTransaction();
if(autocommit) {
HibernateUtil.commitTransaction();
}

contentletSystemEventUtil.pushSaveEvent(cont, isNew);
if (generateSaveEvent) {
contentletSystemEventUtil.pushSaveEvent(cont, isNew);
}

contentletFormData.put("cache_control", "0");

Expand Down

0 comments on commit 45a87fc

Please sign in to comment.