diff --git a/CHANGELOG.md b/CHANGELOG.md index 6af3873..94d1e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + # Changelog for "event-publisher-portal" +## [v1.1.0-SNAPSHOT] +Added new event publisher for new created `Role`s having "`site`" type (#20896) + ## [v1.0.0] - First release (#19461) - - -This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). \ No newline at end of file diff --git a/pom.xml b/pom.xml index c753de4..f451435 100644 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,21 @@ + 4.0.0 + maven-parent org.gcube.tools 1.1.0 + org.gcube.portal event-publisher-hook + 1.1.0-SNAPSHOT war - 1.0.0 + 6.2.5 6.2.10.12 @@ -20,11 +24,13 @@ /Users/themaxx/Development/Server/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext /Users/themaxx/Development/Server/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps/ROOT - - scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git - scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git - https://code-repo.d4science.org/gCubeSystem/${project.artifactId} - + + + scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git + scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git + https://code-repo.d4science.org/gCubeSystem/${project.artifactId} + + @@ -36,6 +42,7 @@ + @@ -61,6 +68,7 @@ + org.gcube.common diff --git a/src/main/java/org/gcube/portal/event/publisher/lr62/model/RoleEvent.java b/src/main/java/org/gcube/portal/event/publisher/lr62/model/RoleEvent.java new file mode 100644 index 0000000..0a8aeb4 --- /dev/null +++ b/src/main/java/org/gcube/portal/event/publisher/lr62/model/RoleEvent.java @@ -0,0 +1,37 @@ +package org.gcube.portal.event.publisher.lr62.model; + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.model.Role; + +public class RoleEvent extends PortalModelListenerEvent { + + private static final long serialVersionUID = 3939268094440017646L; + + public static final String CREATED_NAME = "role_created"; +// public static final String DELETED_NAME = "role_deleted"; + + private RoleEvent(String name, Role role) throws PortalException, SystemException { + super(name, role); + setRole(role); + } + + public static RoleEvent newCreatedEvent(Role role) { + try { + return new RoleEvent(CREATED_NAME, role); + } catch (PortalException | SystemException e) { + log.error("Cannot create event from Role model object", e); + return null; + } + } + +// public static RoleEvent newDeletedEvent(Role role) { +// try { +// return new RoleEvent(DELETED_NAME, role); +// } catch (PortalException | SystemException e) { +// log.error("Cannot create event from Role model object", e); +// return null; +// } +// } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portal/event/publisher/lr62/model/RoleEventPublisher.java b/src/main/java/org/gcube/portal/event/publisher/lr62/model/RoleEventPublisher.java new file mode 100644 index 0000000..d1d3e02 --- /dev/null +++ b/src/main/java/org/gcube/portal/event/publisher/lr62/model/RoleEventPublisher.java @@ -0,0 +1,75 @@ +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.Role; +import com.liferay.portal.model.RoleConstants; + +public class RoleEventPublisher extends AbstractEventPublisherBaseModelListener { + + protected static final Log log = LogFactoryUtil.getLog(RoleEventPublisher.class); + + public RoleEventPublisher() { + super(); + log.info("New RoleEventPublisher instance created"); + } + + @Override + public void onAfterCreate(Role role) throws ModelListenerException { + if (role.getType() == RoleConstants.TYPE_SITE) { + log.info("Created a new role having site type"); + RoleEvent event = RoleEvent.newCreatedEvent(role); + + if (log.isTraceEnabled()) { + log.trace("Event is: " + event); + } + publish(event); + } else if (log.isDebugEnabled()) { + log.debug("Created a non-site type role: " + role.getName()); + } + } + + /* Uninteresting model events */ + + @Override + public void onBeforeRemove(Role role) throws ModelListenerException { + } + + @Override + public void onAfterAddAssociation(Object classPK, String associationClassName, Object associationClassPK) + throws ModelListenerException { + } + + @Override + public void onAfterRemove(Role role) throws ModelListenerException { + } + + @Override + public void onAfterRemoveAssociation(Object classPK, String associationClassName, Object associationClassPK) + throws ModelListenerException { + } + + @Override + public void onAfterUpdate(Role role) throws ModelListenerException { + } + + @Override + public void onBeforeAddAssociation(Object classPK, String associationClassName, Object associationClassPK) + throws ModelListenerException { + } + + @Override + public void onBeforeCreate(Role role) throws ModelListenerException { + } + + @Override + public void onBeforeRemoveAssociation(Object classPK, String associationClassName, Object associationClassPK) + throws ModelListenerException { + } + + @Override + public void onBeforeUpdate(Role role) throws ModelListenerException { + } + +} diff --git a/src/main/resources/portal.properties b/src/main/resources/portal.properties index 6e2d3d6..a20b0a0 100644 --- a/src/main/resources/portal.properties +++ b/src/main/resources/portal.properties @@ -1,13 +1,12 @@ -value.object.listener.com.liferay.portal.model.User=org.gcube.portal.event.publisher.lr62.model.UserEventPublisher value.object.listener.com.liferay.portal.model.Group=org.gcube.portal.event.publisher.lr62.model.GroupEventPublisher -#value.object.listener.com.liferay.portal.model.UserGroup=org.gcube.portal.event.publisher.lr62.model.UserGroupEventPublisher -#value.object.listener.com.liferay.portal.model.UserGroupGroupRole=org.gcube.portal.event.publisher.lr62.model.UserGroupGroupRoleEventPublisher +value.object.listener.com.liferay.portal.model.Role=org.gcube.portal.event.publisher.lr62.model.RoleEventPublisher +value.object.listener.com.liferay.portal.model.User=org.gcube.portal.event.publisher.lr62.model.UserEventPublisher value.object.listener.com.liferay.portal.model.UserGroupRole=org.gcube.portal.event.publisher.lr62.model.UserGroupRoleEventPublisher login.events.post=org.gcube.portal.event.publisher.lr62.action.PostLoginAction logout.events.pre=org.gcube.portal.event.publisher.lr62.action.PreLogoutAction #servlet.session.destroy.events= -#global.startup.events is not hook-able but they should be configured in main portal*.properties -#global.shutdown.events is not hook-able but they should be configured in main portal*.properties +#global.startup.events are not hook-able but they should be configured in main portal*.properties +#global.shutdown.events are not hook-able but they should be configured in main portal*.properties application.startup.events=org.gcube.portal.event.publisher.lr62.action.StartupAction application.shutdown.events=org.gcube.portal.event.publisher.lr62.action.ShutdownAction # shutdown event is never called. See issue at https://issues.liferay.com/browse/LPS-11613 \ No newline at end of file