Added new event publisher for new created `Role`s having "`site`" type (requested by #20896)

master
Mauro Mugnaini 3 years ago
parent 3859f04d4e
commit e7ce536e0e

@ -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).

@ -1,17 +1,21 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
<relativePath />
</parent>
<groupId>org.gcube.portal</groupId>
<artifactId>event-publisher-hook</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<version>1.0.0</version>
<properties>
<liferay.version>6.2.5</liferay.version>
<liferay.maven.plugin.version>6.2.10.12</liferay.maven.plugin.version>
@ -20,11 +24,13 @@
<liferay.app.server.lib.global.dir>/Users/themaxx/Development/Server/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext</liferay.app.server.lib.global.dir>
<liferay.app.server.portal.dir>/Users/themaxx/Development/Server/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps/ROOT</liferay.app.server.portal.dir>
</properties>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
@ -36,6 +42,7 @@
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
@ -61,6 +68,7 @@
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.gcube.common</groupId>

@ -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<Role> {
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;
// }
// }
}

@ -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<Role> {
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 {
}
}

@ -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
Loading…
Cancel
Save