A lot of refactoring to standardize object handling, exceptions and nulls
This commit is contained in:
parent
164064e98b
commit
aabd795656
|
@ -27,6 +27,7 @@ public class PortalEvent extends Event {
|
|||
private static String rootVOName;
|
||||
|
||||
public static final String TYPE = "portal";
|
||||
public static final String USER_ENTRY = "user";
|
||||
public static final String GROUP_ENTRY = "group";
|
||||
public static final String ROLE_ENTRY = "role";
|
||||
|
||||
|
@ -45,40 +46,31 @@ public class PortalEvent extends Event {
|
|||
}
|
||||
|
||||
public PortalEvent(String name) {
|
||||
super(name, TYPE, getRootVOName());
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
public PortalEvent(String name, User user) {
|
||||
this(name, getUserIdentifier(user));
|
||||
}
|
||||
|
||||
public PortalEvent(String name, String user) {
|
||||
super(name, TYPE, getRootVOName(), user);
|
||||
}
|
||||
|
||||
public PortalEvent(String name, User user, Map<String, String> data) {
|
||||
this(name, getUserIdentifier(user), data);
|
||||
}
|
||||
|
||||
public PortalEvent(String name, String user, Map<String, String> data) {
|
||||
super(name, TYPE, getRootVOName(), user, data);
|
||||
public PortalEvent(String name, Map<String, String> data) {
|
||||
super(name, TYPE, getRootVOName(), data);
|
||||
}
|
||||
|
||||
protected static String getRootVOName() {
|
||||
return rootVOName;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
public void setUser(User user) throws UserManagementSystemException, UserRetrievalFault {
|
||||
setUser(getUserIdentifier(user));
|
||||
}
|
||||
|
||||
protected static String getUserIdentifier(User user) {
|
||||
try {
|
||||
return USER_MANAGER.getUserById(user.getUserId()).getUsername();
|
||||
} catch (UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot get username for user: " + user, e);
|
||||
return null;
|
||||
}
|
||||
protected String getUserIdentifier(User user) throws UserManagementSystemException, UserRetrievalFault {
|
||||
return USER_MANAGER.getUserById(user.getUserId()).getUsername();
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
set(USER_ENTRY, user);
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return (String) get(USER_ENTRY);
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
|
|
|
@ -4,6 +4,8 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.gcube.portal.event.publisher.lr62.PortalEvent;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||
|
||||
import com.liferay.portal.model.User;
|
||||
|
||||
|
@ -14,8 +16,9 @@ public class ActionEvent extends PortalEvent {
|
|||
public static final String LOGIN_NAME = "login";
|
||||
public static final String LOGOUT_NAME = "logout";
|
||||
|
||||
private ActionEvent(String name, User user) {
|
||||
super(name, user);
|
||||
private ActionEvent(String name, User user) throws UserManagementSystemException, UserRetrievalFault {
|
||||
super(name);
|
||||
setUser(user);
|
||||
}
|
||||
|
||||
public static ActionEvent newLoginEvent(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
@ -23,7 +26,12 @@ public class ActionEvent extends PortalEvent {
|
|||
if (log.isDebugEnabled()) {
|
||||
log.debug("Sending login event for user: " + user.getScreenName());
|
||||
}
|
||||
return new ActionEvent(LOGIN_NAME, user);
|
||||
try {
|
||||
return new ActionEvent(LOGIN_NAME, user);
|
||||
} catch (UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot create action event for user: " + user, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ActionEvent newLogoutEvent(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
@ -31,7 +39,12 @@ public class ActionEvent extends PortalEvent {
|
|||
if (log.isDebugEnabled()) {
|
||||
log.debug("Sending logut event for user: " + user.getScreenName());
|
||||
}
|
||||
return new ActionEvent(LOGOUT_NAME, user);
|
||||
try {
|
||||
return new ActionEvent(LOGOUT_NAME, user);
|
||||
} catch (UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot create action event for user: " + user, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,9 +9,6 @@ public class SimpleActionEvent extends PortalEvent {
|
|||
public static final String STARTUP_NAME = "startup";
|
||||
public static final String SHUTDOWN_NAME = "shutdown";
|
||||
|
||||
public static final String LOGIN_NAME = "login";
|
||||
public static final String LOGOUT_NAME = "logout";
|
||||
|
||||
public static final String IDS_ENTRY = "ids";
|
||||
|
||||
private SimpleActionEvent(String name, String[] ids) {
|
||||
|
|
|
@ -34,4 +34,4 @@ public class GroupEvent extends PortalModelListenerEvent<Group> {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,21 +1,30 @@
|
|||
package org.gcube.portal.event.publisher.lr62.model;
|
||||
|
||||
import com.liferay.portal.ModelListenerException;
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.model.Group;
|
||||
|
||||
public class GroupEventPublisher extends AbstractEventPublisherBaseModelListener<Group> {
|
||||
|
||||
protected static final Log log = LogFactoryUtil.getLog(GroupEventPublisher.class);
|
||||
|
||||
public GroupEventPublisher() {
|
||||
super();
|
||||
log.info("New GroupEventPublisher instance created");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterCreate(Group group) throws ModelListenerException {
|
||||
if (group.isSite()) {
|
||||
log.info("Created a site Group");
|
||||
GroupEvent groupEvent = GroupEvent.newCreatedEvent(group);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Group event is: " + groupEvent);
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Group event is: " + groupEvent);
|
||||
}
|
||||
publish(groupEvent);
|
||||
} else {
|
||||
log.info("Created a non-site Group");
|
||||
} else if (log.isDebugEnabled()) {
|
||||
log.debug("Created a non-site Group");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,8 +37,8 @@ public class GroupEventPublisher extends AbstractEventPublisherBaseModelListener
|
|||
log.debug("Group event is: " + groupEvent);
|
||||
}
|
||||
publish(groupEvent);
|
||||
} else {
|
||||
log.info("Deleted a non-site Group");
|
||||
} else if (log.isDebugEnabled()) {
|
||||
log.debug("Deleted a non-site Group");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,54 +46,38 @@ public class GroupEventPublisher extends AbstractEventPublisherBaseModelListener
|
|||
|
||||
@Override
|
||||
public void onAfterRemove(Group group) throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterAddAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterRemoveAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterUpdate(Group group) throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeAddAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeCreate(Group group) throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeRemoveAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeUpdate(Group group) throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.gcube.vomanagement.usermanagement.RoleManager;
|
|||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||
|
||||
|
@ -34,23 +35,19 @@ public class PortalModelListenerEvent<T extends BaseModel<T>> extends PortalEven
|
|||
setModelClassName(baseModel.getModelClassName());
|
||||
}
|
||||
|
||||
public PortalModelListenerEvent(String name, User user, T baseModel) {
|
||||
super(name, user);
|
||||
public PortalModelListenerEvent(String name, User user, T baseModel)
|
||||
throws UserManagementSystemException, UserRetrievalFault {
|
||||
|
||||
super(name);
|
||||
setUser(user);
|
||||
setModelClassName(baseModel.getModelClassName());
|
||||
}
|
||||
|
||||
public PortalModelListenerEvent(String name, String user, T baseModel) {
|
||||
super(name, user);
|
||||
setModelClassName(baseModel.getModelClassName());
|
||||
}
|
||||
public PortalModelListenerEvent(String name, Map<String, String> data, User user, T baseModel)
|
||||
throws UserManagementSystemException, UserRetrievalFault {
|
||||
|
||||
public PortalModelListenerEvent(String name, String user, Map<String, String> data, T baseModel) {
|
||||
super(name, user, data);
|
||||
setModelClassName(baseModel.getModelClassName());
|
||||
}
|
||||
|
||||
public PortalModelListenerEvent(String name, User user, Map<String, String> data, T baseModel) {
|
||||
super(name, user, data);
|
||||
super(name, data);
|
||||
setUser(user);
|
||||
setModelClassName(baseModel.getModelClassName());
|
||||
}
|
||||
|
||||
|
@ -58,7 +55,7 @@ public class PortalModelListenerEvent<T extends BaseModel<T>> extends PortalEven
|
|||
setGroup(getGroupIdentifier(group));
|
||||
}
|
||||
|
||||
protected static String getGroupIdentifier(Group group) throws PortalException, SystemException {
|
||||
protected String getGroupIdentifier(Group group) throws PortalException, SystemException {
|
||||
try {
|
||||
return URLEncoder.encode(GROUP_MANAGER.getInfrastructureScope(group.getGroupId()), "UTF-8");
|
||||
} catch (UnsupportedEncodingException | UserManagementSystemException | GroupRetrievalFault e) {
|
||||
|
@ -71,7 +68,7 @@ public class PortalModelListenerEvent<T extends BaseModel<T>> extends PortalEven
|
|||
setRole(getRoleIdentifier(role));
|
||||
}
|
||||
|
||||
protected static String getRoleIdentifier(Role role) throws PortalException, SystemException {
|
||||
protected String getRoleIdentifier(Role role) throws PortalException, SystemException {
|
||||
try {
|
||||
return ROLE_MANAGER.getRole(role.getRoleId()).getRoleName();
|
||||
} catch (UserManagementSystemException | RoleRetrievalFault e) {
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package org.gcube.portal.event.publisher.lr62.model;
|
||||
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
import com.liferay.portal.model.Group;
|
||||
import com.liferay.portal.model.User;
|
||||
|
||||
public class UserEvent extends PortalModelListenerEvent<User> {
|
||||
|
@ -9,16 +15,55 @@ public class UserEvent extends PortalModelListenerEvent<User> {
|
|||
public static final String CREATED_NAME = "user_created";
|
||||
public static final String DELETED_NAME = "user_deleted";
|
||||
|
||||
private UserEvent(String name, User user) {
|
||||
public static final String UG_CREATED_NAME = "user-group_created";
|
||||
public static final String UG_DELETED_NAME = "user-group_deleted";
|
||||
|
||||
private UserEvent(String name, User user) throws UserManagementSystemException, UserRetrievalFault {
|
||||
super(name, user, user);
|
||||
}
|
||||
|
||||
private UserEvent(String name, User user, Group group)
|
||||
throws PortalException, SystemException, UserManagementSystemException, UserRetrievalFault {
|
||||
|
||||
this(name, user);
|
||||
setGroup(group);
|
||||
}
|
||||
|
||||
public static UserEvent newCreatedEvent(User user) {
|
||||
return new UserEvent(CREATED_NAME, user);
|
||||
try {
|
||||
return new UserEvent(CREATED_NAME, user);
|
||||
} catch (UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot create event from User model object", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static UserEvent newDeletedEvent(User user) {
|
||||
return new UserEvent(DELETED_NAME, user);
|
||||
try {
|
||||
return new UserEvent(DELETED_NAME, user);
|
||||
} catch (UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot create event from User model object", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static UserEvent newCreatedEvent(User user, Group group) {
|
||||
try {
|
||||
return new UserEvent(UG_CREATED_NAME, user, group);
|
||||
} catch (PortalException | SystemException | UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot create event from one model object", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static UserEvent newDeletedEvent(User user, Group group) {
|
||||
try {
|
||||
return new UserEvent(UG_DELETED_NAME, user, group);
|
||||
} catch (PortalException | SystemException | UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot create event from one model object", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,30 @@
|
|||
package org.gcube.portal.event.publisher.lr62.model;
|
||||
|
||||
import com.liferay.portal.ModelListenerException;
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.model.Group;
|
||||
import com.liferay.portal.model.User;
|
||||
import com.liferay.portal.service.GroupLocalServiceUtil;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
|
||||
public class UserEventPublisher extends AbstractEventPublisherBaseModelListener<User> {
|
||||
|
||||
protected static final Log log = LogFactoryUtil.getLog(UserEventPublisher.class);
|
||||
|
||||
public UserEventPublisher() {
|
||||
super();
|
||||
log.info("New UserEventPublisher instance created");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterCreate(User user) throws ModelListenerException {
|
||||
log.info("New user created");
|
||||
UserEvent userEvent = UserEvent.newCreatedEvent(user);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("User event is: " + userEvent);
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("User event is: " + userEvent);
|
||||
}
|
||||
publish(userEvent);
|
||||
}
|
||||
|
@ -19,19 +33,98 @@ public class UserEventPublisher extends AbstractEventPublisherBaseModelListener<
|
|||
public void onBeforeRemove(User user) throws ModelListenerException {
|
||||
log.info("User removed");
|
||||
UserEvent userEvent = UserEvent.newDeletedEvent(user);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("User event is: " + userEvent);
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("User event is: " + userEvent);
|
||||
}
|
||||
publish(userEvent);
|
||||
}
|
||||
|
||||
/* Uninteresting model events */
|
||||
|
||||
@Override
|
||||
public void onAfterAddAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
|
||||
if (Group.class.getName().equals(associationClassName)) {
|
||||
log.info("User has been associated to a group");
|
||||
User user = getUser((Long) classPK);
|
||||
Group group = getGroup((Long) associationClassPK);
|
||||
if (user != null && group != null) {
|
||||
if (group.isSite()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Target group is a site: " + group.getName());
|
||||
}
|
||||
UserEvent userEvent = UserEvent.newCreatedEvent(user, group);
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("User event is: " + userEvent);
|
||||
}
|
||||
publish(userEvent);
|
||||
} else if (log.isDebugEnabled()) {
|
||||
log.debug("Target group is not a site");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Uninteresting association with: " + associationClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeRemoveAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
|
||||
if (Group.class.getName().equals(associationClassName)) {
|
||||
log.info("User has been associated to a group");
|
||||
User user = getUser((Long) classPK);
|
||||
Group group = getGroup((Long) associationClassPK);
|
||||
if (user != null && group != null) {
|
||||
if (group.isSite()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Target group is a site: " + group.getName());
|
||||
}
|
||||
UserEvent userEvent = UserEvent.newDeletedEvent(user, group);
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("User event is: " + userEvent);
|
||||
}
|
||||
publish(userEvent);
|
||||
} else if (log.isDebugEnabled()) {
|
||||
log.debug("Target group is not a site");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Uninteresting association removal with: " + associationClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected User getUser(Long userPK) {
|
||||
User user = null;
|
||||
try {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Getting user object idetified by pk: " + userPK);
|
||||
}
|
||||
user = UserLocalServiceUtil.getUser(userPK);
|
||||
} catch (PortalException | SystemException e) {
|
||||
logger.error("Cannot get user with pk: " + userPK, e);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
protected Group getGroup(Long groupPK) {
|
||||
Group group = null;
|
||||
try {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Getting group object idetified by pk: " + groupPK);
|
||||
}
|
||||
group = GroupLocalServiceUtil.getGroup((Long) groupPK);
|
||||
} catch (PortalException | SystemException e) {
|
||||
logger.error("Cannot get group with pk: " + groupPK, e);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
/* Uninteresting model events */
|
||||
|
||||
@Override
|
||||
public void onAfterRemove(User user) throws ModelListenerException {
|
||||
}
|
||||
|
@ -54,11 +147,6 @@ public class UserEventPublisher extends AbstractEventPublisherBaseModelListener<
|
|||
public void onBeforeCreate(User user) throws ModelListenerException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeRemoveAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeUpdate(User user) throws ModelListenerException {
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.gcube.portal.event.publisher.lr62.model;
|
||||
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
import com.liferay.portal.model.Group;
|
||||
|
@ -15,9 +18,9 @@ public class UserGroupRoleEvent extends PortalModelListenerEvent<UserGroupRole>
|
|||
public static final String DELETED_NAME = "user-group-role_deleted";
|
||||
|
||||
private UserGroupRoleEvent(String name, UserGroupRole userGroupRole, User user, Group group, Role role)
|
||||
throws PortalException, SystemException {
|
||||
throws PortalException, SystemException, UserManagementSystemException, UserRetrievalFault {
|
||||
|
||||
super(name, user.getScreenName(), userGroupRole);
|
||||
super(name, user, userGroupRole);
|
||||
setGroup(group);
|
||||
setRole(role);
|
||||
}
|
||||
|
@ -25,7 +28,7 @@ public class UserGroupRoleEvent extends PortalModelListenerEvent<UserGroupRole>
|
|||
public static UserGroupRoleEvent newCreatedEvent(UserGroupRole userGroupRole, User user, Group group, Role role) {
|
||||
try {
|
||||
return new UserGroupRoleEvent(CREATED_NAME, userGroupRole, user, group, role);
|
||||
} catch (PortalException | SystemException e) {
|
||||
} catch (PortalException | SystemException | UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot create event from model object", e);
|
||||
return null;
|
||||
}
|
||||
|
@ -34,10 +37,10 @@ public class UserGroupRoleEvent extends PortalModelListenerEvent<UserGroupRole>
|
|||
public static UserGroupRoleEvent newDeletedEvent(UserGroupRole userGroupRole, User user, Group group, Role role) {
|
||||
try {
|
||||
return new UserGroupRoleEvent(DELETED_NAME, userGroupRole, user, group, role);
|
||||
} catch (PortalException | SystemException e) {
|
||||
} catch (PortalException | SystemException | UserManagementSystemException | UserRetrievalFault e) {
|
||||
log.error("Cannot create event from model object", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,13 +1,23 @@
|
|||
package org.gcube.portal.event.publisher.lr62.model;
|
||||
|
||||
import com.liferay.portal.ModelListenerException;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
import com.liferay.portal.kernel.exception.SystemException;
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.model.Group;
|
||||
import com.liferay.portal.model.UserGroupRole;
|
||||
|
||||
public class UserGroupRoleEventPublisher extends AbstractEventPublisherBaseModelListener<UserGroupRole> {
|
||||
|
||||
protected static final Log log = LogFactoryUtil.getLog(UserGroupRoleEventPublisher.class);
|
||||
|
||||
public UserGroupRoleEventPublisher() {
|
||||
super();
|
||||
log.info("New UserGroupRoleEventPublisher instance created");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterCreate(UserGroupRole userGroupRole) throws ModelListenerException {
|
||||
try {
|
||||
|
@ -15,15 +25,14 @@ public class UserGroupRoleEventPublisher extends AbstractEventPublisherBaseModel
|
|||
if (group.isSite()) {
|
||||
log.info("Created a site user's group role");
|
||||
UserGroupRoleEvent event = UserGroupRoleEvent.newCreatedEvent(userGroupRole, userGroupRole.getUser(),
|
||||
group,
|
||||
userGroupRole.getRole());
|
||||
group, userGroupRole.getRole());
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Event is: " + event);
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Event is: " + event);
|
||||
}
|
||||
publish(event);
|
||||
} else {
|
||||
log.info("Created a non-site user's group role");
|
||||
} else if (log.isDebugEnabled()) {
|
||||
log.debug("Created a non-site user's group role");
|
||||
}
|
||||
} catch (PortalException | SystemException e) {
|
||||
log.error("Cannot get related model objects", e);
|
||||
|
@ -37,10 +46,15 @@ public class UserGroupRoleEventPublisher extends AbstractEventPublisherBaseModel
|
|||
Group group = userGroupRole.getGroup();
|
||||
if (group.isSite()) {
|
||||
log.info("Deleted a site user's group role");
|
||||
publish(UserGroupRoleEvent.newDeletedEvent(userGroupRole, userGroupRole.getUser(), group,
|
||||
userGroupRole.getRole()));
|
||||
} else {
|
||||
log.info("Deleted a non-site user's group role");
|
||||
UserGroupRoleEvent event = UserGroupRoleEvent.newDeletedEvent(userGroupRole, userGroupRole.getUser(),
|
||||
group, userGroupRole.getRole());
|
||||
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Event is: " + event);
|
||||
}
|
||||
publish(event);
|
||||
} else if (log.isDebugEnabled()) {
|
||||
log.debug("Deleted a non-site user's group role");
|
||||
}
|
||||
} catch (PortalException | SystemException e) {
|
||||
log.error("Cannot get related model objects", e);
|
||||
|
@ -52,53 +66,37 @@ public class UserGroupRoleEventPublisher extends AbstractEventPublisherBaseModel
|
|||
@Override
|
||||
public void onAfterAddAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterRemove(UserGroupRole userGroupRole) throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterRemoveAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterUpdate(UserGroupRole userGroupRole) throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeAddAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeCreate(UserGroupRole userGroupRole) throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeRemoveAssociation(Object classPK, String associationClassName, Object associationClassPK)
|
||||
throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeUpdate(UserGroupRole userGroupRole) throws ModelListenerException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue