To implement your own listener, you just need to extend some existing listener classes. These classes define hooks that are invoked before or after operations are performed on the organization model.
To listen to user changes, you need to extend org.exoplatform.services.organization.UserEventListener.
public class MyUserListener extends UserEventListener {
public void preSave(User user, boolean isNew) throws Exception {
System.out.println("Before " + (isNew?"creating":"updating") + " user " + user.getUserName());
}
public void postSave(User user, boolean isNew) throws Exception {
System.out.println("After user " + user.getUserName() + (isNew?" created":" updated"));
}
public void preDelete(User user) throws Exception {
System.out.println("Before deleting user " + user.getUserName());
}
public void postDelete(User user) throws Exception {
System.out.println("After deleting user " + user.getUserName());
}
public void preSetEnabled(User user) throws Exception {
System.out.println("Before enabling/disabling user " + user.getUserName());
}
public void postSetEnabled(User user) throws Exception {
System.out.println("After enabling/disabling user " + user.getUserName());
}
}
To listen to group changes, you need to extend org.exoplatform.services.organization.GroupEventListener:
public class MyGroupListener extends GroupEventListener {
public void preSave(Group group, boolean isNew) throws Exception {
System.out.println("Before " + (isNew?"creating":"updating") + " group " + group.getName());
}
public void postSave(Group group, boolean isNew) throws Exception {
System.out.println("After group " + group.getName() + (isNew?" created":" updated"));
}
public void preDelete(Group group) throws Exception {
System.out.println("Before deleting group " + group.getName());
}
public void postDelete(Group group) throws Exception {
System.out.println("After deleting group " + group.getName());
}
}
To listen to membership changes, you need to extend org.exoplatform.services.organization.MembershipEventListener:
public class MyMembershipListener extends MembershipEventListener {
public void preSave(Membership membership, boolean isNew) throws Exception {
System.out.println("Before " + (isNew?"creating":"updating") + " membership.");
}
public void postSave(Membership membership, boolean isNew) throws Exception {
System.out.println("After membership " + (isNew?" created":" updated"));
}
public void preDelete(Membership membership) throws Exception {
System.out.println("Before deleting membership");
}
public void postDelete(Membership membership) throws Exception {
System.out.println("After deleting membership");
}
}