mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-27 22:40:19 +01:00
improve modification events to pass the item before it was modified to the subscriber
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
package sonia.scm;
|
||||
|
||||
import sonia.scm.event.HandlerEventBase;
|
||||
|
||||
/**
|
||||
* Extension to the {@link ModificationHandlerEvent}.
|
||||
*
|
||||
* @param <T> type of changed item
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.48
|
||||
*/
|
||||
public interface ModificationHandlerEvent<T> extends HandlerEventBase<T>
|
||||
{
|
||||
/**
|
||||
* Returns item, before it was modified.
|
||||
*
|
||||
* @return item before modification
|
||||
*/
|
||||
public T getItemBeforeModification();
|
||||
}
|
||||
@@ -90,21 +90,32 @@ public abstract class AbstractGroupManager implements GroupManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link GroupListener#onEvent(Group,sonia.scm.HandlerEvent)}
|
||||
* method of all registered listeners and send a {@link GroupEvent} to
|
||||
* the {@link ScmEventBus}.
|
||||
*
|
||||
* Creates a new {@link GroupEvent} and calls {@link #fireEvent(sonia.scm.group.GroupEvent)}.
|
||||
*
|
||||
* @param group group that has changed
|
||||
* @param event type of change event
|
||||
*/
|
||||
protected void fireEvent(Group group, HandlerEvent event)
|
||||
{
|
||||
fireEvent(new GroupEvent(group, event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link GroupListener#onEvent(Group,sonia.scm.HandlerEvent)}
|
||||
* method of all registered listeners and send a {@link GroupEvent} to
|
||||
* the {@link ScmEventBus}.
|
||||
*
|
||||
* @param event type of change event
|
||||
* @since 1.148
|
||||
*/
|
||||
protected void fireEvent(GroupEvent event)
|
||||
{
|
||||
for (GroupListener listener : listenerSet)
|
||||
{
|
||||
listener.onEvent(group, event);
|
||||
listener.onEvent(event.getItem(), event.getEventType());
|
||||
}
|
||||
|
||||
ScmEventBus.getInstance().post(new GroupEvent(group, event));
|
||||
ScmEventBus.getInstance().post(event);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -48,7 +48,7 @@ import sonia.scm.event.HandlerEventBase;
|
||||
* @since 1.23
|
||||
*/
|
||||
@Event
|
||||
public final class GroupEvent implements HandlerEventBase<Group>
|
||||
public class GroupEvent implements HandlerEventBase<Group>
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
package sonia.scm.group;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.ModificationHandlerEvent;
|
||||
|
||||
/**
|
||||
* Event which is fired whenever a group is modified.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.48
|
||||
*/
|
||||
public class GroupModificationEvent extends GroupEvent implements ModificationHandlerEvent<Group>
|
||||
{
|
||||
|
||||
private final Group itemBeforeModification;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link GroupModificationEvent}.
|
||||
*
|
||||
* @param item changed group
|
||||
* @param itemBeforeModification changed group before it was modified
|
||||
* @param eventType type of event
|
||||
*/
|
||||
public GroupModificationEvent(Group item, Group itemBeforeModification, HandlerEvent eventType)
|
||||
{
|
||||
super(item, eventType);
|
||||
this.itemBeforeModification = itemBeforeModification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getItemBeforeModification()
|
||||
{
|
||||
return itemBeforeModification;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -231,22 +231,34 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
||||
listenerSet.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link RepositoryEvent} and calls {@link #fireEvent(sonia.scm.repository.RepositoryEvent)}.
|
||||
*
|
||||
* @param repository changed repository
|
||||
* @param event event type
|
||||
*/
|
||||
protected void fireEvent(Repository repository, HandlerEvent event)
|
||||
{
|
||||
fireEvent(new RepositoryEvent(repository, event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link RepositoryListener#onEvent(Repository,sonia.scm.HandlerEvent)}
|
||||
* method of all registered listeners and send a {@link RepositoryEvent} to
|
||||
* the {@link ScmEventBus}.
|
||||
*
|
||||
* @param repository repository that has changed
|
||||
* @param event type of change event
|
||||
* @param event repository event
|
||||
*
|
||||
* @since 1.48
|
||||
*/
|
||||
protected void fireEvent(Repository repository, HandlerEvent event)
|
||||
protected void fireEvent(RepositoryEvent event)
|
||||
{
|
||||
for (RepositoryListener listener : listenerSet)
|
||||
{
|
||||
listener.onEvent(repository, event);
|
||||
listener.onEvent(event.getItem(), event.getEventType());
|
||||
}
|
||||
|
||||
ScmEventBus.getInstance().post(new RepositoryEvent(repository, event));
|
||||
ScmEventBus.getInstance().post(event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,7 @@ import sonia.scm.event.HandlerEventBase;
|
||||
* @since 1.23
|
||||
*/
|
||||
@Event
|
||||
public final class RepositoryEvent implements HandlerEventBase<Repository>
|
||||
public class RepositoryEvent implements HandlerEventBase<Repository>
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
package sonia.scm.repository;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.ModificationHandlerEvent;
|
||||
import sonia.scm.event.Event;
|
||||
|
||||
/**
|
||||
* Event which is fired whenever a repository is modified.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.48
|
||||
*/
|
||||
@Event
|
||||
public final class RepositoryModificationEvent extends RepositoryEvent implements ModificationHandlerEvent<Repository>
|
||||
{
|
||||
|
||||
private final Repository itemBeforeModification;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link RepositoryModificationEvent}.
|
||||
*
|
||||
* @param item changed repository
|
||||
* @param itemBeforeModification repository before it was modified
|
||||
* @param eventType event type
|
||||
*/
|
||||
public RepositoryModificationEvent(Repository item, Repository itemBeforeModification, HandlerEvent eventType)
|
||||
{
|
||||
super(item, eventType);
|
||||
this.itemBeforeModification = itemBeforeModification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository getItemBeforeModification()
|
||||
{
|
||||
return itemBeforeModification;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -90,21 +90,32 @@ public abstract class AbstractUserManager implements UserManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link UserListener#onEvent(User,sonia.scm.HandlerEvent)}
|
||||
* method of all registered listeners and send a {@link UserEvent} to
|
||||
* the {@link ScmEventBus}.
|
||||
* Creates a new {@link UserEvent} and calls {@link #fireEvent(sonia.scm.user.UserEvent)}.
|
||||
*
|
||||
* @param user user that has changed
|
||||
* @param event type of change event
|
||||
*/
|
||||
protected void fireEvent(User user, HandlerEvent event)
|
||||
{
|
||||
fireEvent(new UserEvent(user, event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link UserListener#onEvent(User,sonia.scm.HandlerEvent)}
|
||||
* method of all registered listeners and send a {@link UserEvent} to
|
||||
* the {@link ScmEventBus}.
|
||||
*
|
||||
* @param event user event
|
||||
* @since 1.48
|
||||
*/
|
||||
protected void fireEvent(UserEvent event)
|
||||
{
|
||||
for (UserListener listener : listenerSet)
|
||||
{
|
||||
listener.onEvent(user, event);
|
||||
listener.onEvent(event.getItem(), event.getEventType());
|
||||
}
|
||||
|
||||
ScmEventBus.getInstance().post(new UserEvent(user, event));
|
||||
ScmEventBus.getInstance().post(event);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -47,7 +47,7 @@ import sonia.scm.event.HandlerEventBase;
|
||||
* @since 1.23
|
||||
*/
|
||||
@Event
|
||||
public final class UserEvent implements HandlerEventBase<User>
|
||||
public class UserEvent implements HandlerEventBase<User>
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
package sonia.scm.user;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.ModificationHandlerEvent;
|
||||
import sonia.scm.event.Event;
|
||||
|
||||
/**
|
||||
* Event which is fired whenever a user is modified.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.48
|
||||
*/
|
||||
@Event
|
||||
public class UserModificationEvent extends UserEvent implements ModificationHandlerEvent<User>
|
||||
{
|
||||
|
||||
private final User itemBeforeModification;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link UserModificationEvent}.
|
||||
*
|
||||
* @param item changed user
|
||||
* @param itemBeforeModification changed user before it was modified
|
||||
* @param eventType type of event
|
||||
*/
|
||||
public UserModificationEvent(User item, User itemBeforeModification, HandlerEvent eventType)
|
||||
{
|
||||
super(item, eventType);
|
||||
this.itemBeforeModification = itemBeforeModification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getItemBeforeModification()
|
||||
{
|
||||
return itemBeforeModification;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user