mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
improve modification handler events by sending old and new items to eventbus
This commit is contained in:
187
scm-core/src/main/java/sonia/scm/event/AbstractHandlerEvent.java
Normal file
187
scm-core/src/main/java/sonia/scm/event/AbstractHandlerEvent.java
Normal file
@@ -0,0 +1,187 @@
|
||||
/**
|
||||
* Copyright (c) 2010, 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.event;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import sonia.scm.HandlerEventType;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link HandlerEvent}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class AbstractHandlerEvent<T> implements HandlerEvent<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param eventType
|
||||
* @param item
|
||||
*/
|
||||
public AbstractHandlerEvent(HandlerEventType eventType, T item)
|
||||
{
|
||||
this(eventType, item, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param eventType
|
||||
* @param item
|
||||
* @param oldItem
|
||||
*/
|
||||
public AbstractHandlerEvent(HandlerEventType eventType, T item, T oldItem)
|
||||
{
|
||||
this.eventType = eventType;
|
||||
this.item = item;
|
||||
this.oldItem = oldItem;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param obj
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final AbstractHandlerEvent<?> other = (AbstractHandlerEvent<?>) obj;
|
||||
|
||||
return Objects.equal(eventType, other.eventType)
|
||||
&& Objects.equal(item, other.item)
|
||||
&& Objects.equal(oldItem, other.oldItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hashCode(eventType, item, oldItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
//J-
|
||||
return Objects.toStringHelper(this)
|
||||
.add("eventType", eventType)
|
||||
.add("item", item)
|
||||
.add("oldItem", oldItem)
|
||||
.toString();
|
||||
//J+
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the type of the event.
|
||||
*
|
||||
*
|
||||
* @return type of the event
|
||||
*/
|
||||
@Override
|
||||
public HandlerEventType getEventType()
|
||||
{
|
||||
return eventType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns changed item.
|
||||
*
|
||||
*
|
||||
* @return changed item
|
||||
*/
|
||||
@Override
|
||||
public T getItem()
|
||||
{
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns old item or null. This method will always return null expect of
|
||||
* modification events.
|
||||
*
|
||||
*
|
||||
* @return old item or null
|
||||
*/
|
||||
@Override
|
||||
public T getOldItem()
|
||||
{
|
||||
return oldItem;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** event type */
|
||||
private final HandlerEventType eventType;
|
||||
|
||||
/** changed item */
|
||||
private final T item;
|
||||
|
||||
/** old item */
|
||||
private final T oldItem;
|
||||
}
|
||||
@@ -63,4 +63,15 @@ public interface HandlerEvent<T>
|
||||
* @return changed item
|
||||
*/
|
||||
public T getItem();
|
||||
|
||||
/**
|
||||
* Returns old item or null. This method returns always expect for
|
||||
* modification events.
|
||||
*
|
||||
*
|
||||
* @return old item or null
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public T getOldItem();
|
||||
}
|
||||
|
||||
@@ -38,8 +38,6 @@ package sonia.scm.group;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link GroupManager} implementations. This class
|
||||
* implements the listener methods of the {@link GroupManager} interface.
|
||||
@@ -52,11 +50,23 @@ public abstract class AbstractGroupManager implements GroupManager
|
||||
/**
|
||||
* Send a {@link GroupEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param group group that has changed
|
||||
* @param event type of change event
|
||||
* @param group group that has changed
|
||||
*/
|
||||
protected void fireEvent(Group group, HandlerEventType event)
|
||||
protected void fireEvent(HandlerEventType event, Group group)
|
||||
{
|
||||
ScmEventBus.getInstance().post(new GroupEvent(group, event));
|
||||
ScmEventBus.getInstance().post(new GroupEvent(event, group));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a {@link GroupEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param event type of change event
|
||||
* @param group group that has changed
|
||||
* @param oldGroup old group
|
||||
*/
|
||||
protected void fireEvent(HandlerEventType event, Group group, Group oldGroup)
|
||||
{
|
||||
ScmEventBus.getInstance().post(new GroupEvent(event, group, oldGroup));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,10 @@ package sonia.scm.group;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.event.AbstractHandlerEvent;
|
||||
import sonia.scm.event.Event;
|
||||
import sonia.scm.event.HandlerEvent;
|
||||
|
||||
/**
|
||||
* The GroupEvent is fired if a group object changes.
|
||||
@@ -48,72 +47,31 @@ import sonia.scm.event.HandlerEvent;
|
||||
* @since 1.23
|
||||
*/
|
||||
@Event
|
||||
public final class GroupEvent implements HandlerEvent<Group>
|
||||
public final class GroupEvent extends AbstractHandlerEvent<Group>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs new group event
|
||||
* Constructs a new group event.
|
||||
*
|
||||
*
|
||||
* @param group changed group
|
||||
* @param eventType type of the event
|
||||
* @param group changed group
|
||||
*/
|
||||
public GroupEvent(Group group, HandlerEventType eventType)
|
||||
public GroupEvent(HandlerEventType eventType, Group group)
|
||||
{
|
||||
this.group = group;
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
//J-
|
||||
return Objects.toStringHelper(this)
|
||||
.add("eventType", eventType)
|
||||
.add("group", group)
|
||||
.toString();
|
||||
//J+
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HandlerEventType getEventType()
|
||||
{
|
||||
return eventType;
|
||||
super(eventType, group);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Constructs a new group event.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @param eventType type of the event
|
||||
* @param group changed group
|
||||
* @param oldGroup old group
|
||||
*/
|
||||
@Override
|
||||
public Group getItem()
|
||||
public GroupEvent(HandlerEventType eventType, Group group, Group oldGroup)
|
||||
{
|
||||
return group;
|
||||
super(eventType, group, oldGroup);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** event type */
|
||||
private final HandlerEventType eventType;
|
||||
|
||||
/** changed group */
|
||||
private final Group group;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
||||
*
|
||||
* @param event event to be fired
|
||||
*/
|
||||
@Override
|
||||
public void fireHookEvent(RepositoryHookEvent event)
|
||||
{
|
||||
AssertUtil.assertIsNotNull(event);
|
||||
@@ -83,12 +84,26 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
||||
/**
|
||||
* Send a {@link RepositoryEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param repository repository that has changed
|
||||
* @param event type of change event
|
||||
* @param repository repository that has changed
|
||||
* @param oldRepository old repository
|
||||
*/
|
||||
protected void fireEvent(Repository repository, HandlerEventType event)
|
||||
protected void fireEvent(HandlerEventType event, Repository repository,
|
||||
Repository oldRepository)
|
||||
{
|
||||
ScmEventBus.getInstance().post(new RepositoryEvent(repository, event));
|
||||
ScmEventBus.getInstance().post(new RepositoryEvent(event, repository,
|
||||
oldRepository));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a {@link RepositoryEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param event type of change event
|
||||
* @param repository repository that has changed
|
||||
*/
|
||||
protected void fireEvent(HandlerEventType event, Repository repository)
|
||||
{
|
||||
ScmEventBus.getInstance().post(new RepositoryEvent(event, repository));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -37,6 +38,7 @@ package sonia.scm.repository;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.event.AbstractHandlerEvent;
|
||||
import sonia.scm.event.Event;
|
||||
import sonia.scm.event.HandlerEvent;
|
||||
|
||||
@@ -47,72 +49,32 @@ import sonia.scm.event.HandlerEvent;
|
||||
* @since 1.23
|
||||
*/
|
||||
@Event
|
||||
public final class RepositoryEvent implements HandlerEvent<Repository>
|
||||
public final class RepositoryEvent extends AbstractHandlerEvent<Repository>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs new repository event
|
||||
* Constructs a new repository event.
|
||||
*
|
||||
*
|
||||
* @param repository changed repository
|
||||
* @param eventType type of the event
|
||||
* @param repository changed repository
|
||||
*/
|
||||
public RepositoryEvent(Repository repository, HandlerEventType eventType)
|
||||
public RepositoryEvent(HandlerEventType eventType, Repository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
//J-
|
||||
return Objects.toStringHelper(this)
|
||||
.add("eventType", eventType)
|
||||
.add("repository", repository)
|
||||
.toString();
|
||||
//J+
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HandlerEventType getEventType()
|
||||
{
|
||||
return eventType;
|
||||
super(eventType, repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Constructs a new repository event.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @param eventType type of the event
|
||||
* @param repository changed repository
|
||||
* @param oldRepository old repository
|
||||
*/
|
||||
@Override
|
||||
public Repository getItem()
|
||||
public RepositoryEvent(HandlerEventType eventType, Repository repository,
|
||||
Repository oldRepository)
|
||||
{
|
||||
return repository;
|
||||
super(eventType, repository, oldRepository);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** event type */
|
||||
private final HandlerEventType eventType;
|
||||
|
||||
/** changed repository */
|
||||
private final Repository repository;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,6 @@ package sonia.scm.user;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link UserManager} implementations. This class
|
||||
* implements the listener methods of the {@link UserManager} interface.
|
||||
@@ -50,14 +47,26 @@ import sonia.scm.event.ScmEventBus;
|
||||
public abstract class AbstractUserManager implements UserManager
|
||||
{
|
||||
|
||||
/**
|
||||
* Send a {@link UserEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param event type of change event
|
||||
* @param user user that has changed
|
||||
* @param oldUser old user
|
||||
*/
|
||||
protected void fireEvent(HandlerEventType event, User user, User oldUser)
|
||||
{
|
||||
ScmEventBus.getInstance().post(new UserEvent(event, user, oldUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a {@link UserEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param user user that has changed
|
||||
* @param event type of change event
|
||||
*/
|
||||
protected void fireEvent(User user, HandlerEventType event)
|
||||
protected void fireEvent(HandlerEventType event, User user)
|
||||
{
|
||||
ScmEventBus.getInstance().post(new UserEvent(user, event));
|
||||
ScmEventBus.getInstance().post(new UserEvent(event, user));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,15 +30,14 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.user;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.event.AbstractHandlerEvent;
|
||||
import sonia.scm.event.Event;
|
||||
import sonia.scm.event.HandlerEvent;
|
||||
|
||||
/**
|
||||
* The UserEvent is fired if a user object changes.
|
||||
@@ -47,72 +46,31 @@ import sonia.scm.event.HandlerEvent;
|
||||
* @since 1.23
|
||||
*/
|
||||
@Event
|
||||
public final class UserEvent implements HandlerEvent<User>
|
||||
public final class UserEvent extends AbstractHandlerEvent<User>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs new UserEvent.
|
||||
* Constructs a new user event.
|
||||
*
|
||||
*
|
||||
* @param eventType event type
|
||||
* @param user changed user
|
||||
*/
|
||||
public UserEvent(HandlerEventType eventType, User user)
|
||||
{
|
||||
super(eventType, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new user event.
|
||||
*
|
||||
*
|
||||
* @param eventType type of the event
|
||||
* @param user changed user
|
||||
* @param oldUser old user
|
||||
*/
|
||||
public UserEvent(User user, HandlerEventType eventType)
|
||||
public UserEvent(HandlerEventType eventType, User user, User oldUser)
|
||||
{
|
||||
this.user = user;
|
||||
this.eventType = eventType;
|
||||
super(eventType, user, oldUser);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
//J-
|
||||
return Objects.toStringHelper(this)
|
||||
.add("eventType", eventType)
|
||||
.add("user", user)
|
||||
.toString();
|
||||
//J+
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HandlerEventType getEventType()
|
||||
{
|
||||
return eventType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public User getItem()
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** type of the event */
|
||||
private final HandlerEventType eventType;
|
||||
|
||||
/** changed user */
|
||||
private final User user;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.apache.shiro.subject.Subject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.ManagerTestBase;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
@@ -263,23 +263,23 @@ public abstract class RepositoryManagerTestBase
|
||||
|
||||
repoManager.create(repository);
|
||||
assertRepositoriesEquals(repository, listener.preRepository);
|
||||
assertSame(HandlerEvent.BEFORE_CREATE, listener.preEvent);
|
||||
assertSame(HandlerEventType.BEFORE_CREATE, listener.preEvent);
|
||||
assertRepositoriesEquals(repository, listener.postRepository);
|
||||
assertSame(HandlerEvent.CREATE, listener.postEvent);
|
||||
assertSame(HandlerEventType.CREATE, listener.postEvent);
|
||||
|
||||
repository.setDescription("changed description");
|
||||
repoManager.modify(repository);
|
||||
assertRepositoriesEquals(repository, listener.preRepository);
|
||||
assertSame(HandlerEvent.BEFORE_MODIFY, listener.preEvent);
|
||||
assertSame(HandlerEventType.BEFORE_MODIFY, listener.preEvent);
|
||||
assertRepositoriesEquals(repository, listener.postRepository);
|
||||
assertSame(HandlerEvent.MODIFY, listener.postEvent);
|
||||
assertSame(HandlerEventType.MODIFY, listener.postEvent);
|
||||
|
||||
repoManager.delete(repository);
|
||||
|
||||
assertRepositoriesEquals(repository, listener.preRepository);
|
||||
assertSame(HandlerEvent.BEFORE_DELETE, listener.preEvent);
|
||||
assertSame(HandlerEventType.BEFORE_DELETE, listener.preEvent);
|
||||
assertRepositoriesEquals(repository, listener.postRepository);
|
||||
assertSame(HandlerEvent.DELETE, listener.postEvent);
|
||||
assertSame(HandlerEventType.DELETE, listener.postEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,13 +574,13 @@ public abstract class RepositoryManagerTestBase
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private HandlerEvent postEvent;
|
||||
private HandlerEventType postEvent;
|
||||
|
||||
/** Field description */
|
||||
private Repository postRepository;
|
||||
|
||||
/** Field description */
|
||||
private HandlerEvent preEvent;
|
||||
private HandlerEventType preEvent;
|
||||
|
||||
/** Field description */
|
||||
private Repository preRepository;
|
||||
|
||||
@@ -43,7 +43,7 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.TransformFilter;
|
||||
import sonia.scm.search.SearchRequest;
|
||||
@@ -138,9 +138,9 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
|
||||
removeDuplicateMembers(group);
|
||||
group.setCreationDate(System.currentTimeMillis());
|
||||
fireEvent(group, HandlerEvent.BEFORE_CREATE);
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, group);
|
||||
groupDAO.add(group);
|
||||
fireEvent(group, HandlerEvent.CREATE);
|
||||
fireEvent(HandlerEventType.CREATE, group);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,9 +167,9 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
|
||||
if (groupDAO.contains(name))
|
||||
{
|
||||
fireEvent(group, HandlerEvent.BEFORE_DELETE);
|
||||
fireEvent(HandlerEventType.BEFORE_DELETE, group);
|
||||
groupDAO.delete(group);
|
||||
fireEvent(group, HandlerEvent.DELETE);
|
||||
fireEvent(HandlerEventType.DELETE, group);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -184,9 +184,7 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
* @param context
|
||||
*/
|
||||
@Override
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
}
|
||||
public void init(SCMContextProvider context) {}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -210,13 +208,15 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
|
||||
String name = group.getName();
|
||||
|
||||
if (groupDAO.contains(name))
|
||||
Group oldGroup = groupDAO.get(name);
|
||||
|
||||
if (oldGroup != null)
|
||||
{
|
||||
removeDuplicateMembers(group);
|
||||
group.setLastModified(System.currentTimeMillis());
|
||||
fireEvent(group, HandlerEvent.BEFORE_MODIFY);
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, group, oldGroup);
|
||||
groupDAO.modify(group);
|
||||
fireEvent(group, HandlerEvent.MODIFY);
|
||||
fireEvent(HandlerEventType.MODIFY, group, oldGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ArgumentIsInvalidException;
|
||||
import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
@@ -105,7 +105,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
||||
* @param keyGenerator
|
||||
* @param repositoryDAO
|
||||
* @param handlerSet
|
||||
* @param preProcessorUtil
|
||||
*/
|
||||
@Inject
|
||||
public DefaultRepositoryManager(ScmConfiguration configuration,
|
||||
@@ -187,9 +186,9 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
||||
getHandler(repository).create(repository);
|
||||
}
|
||||
|
||||
fireEvent(repository, HandlerEvent.BEFORE_CREATE);
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, repository);
|
||||
repositoryDAO.add(repository);
|
||||
fireEvent(repository, HandlerEvent.CREATE);
|
||||
fireEvent(HandlerEventType.CREATE, repository);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,17 +236,16 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
||||
|
||||
if (repositoryDAO.contains(repository))
|
||||
{
|
||||
fireEvent(repository, HandlerEvent.BEFORE_DELETE);
|
||||
fireEvent(HandlerEventType.BEFORE_DELETE, repository);
|
||||
getHandler(repository).delete(repository);
|
||||
repositoryDAO.delete(repository);
|
||||
fireEvent(HandlerEventType.DELETE, repository);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RepositoryNotFoundException(
|
||||
"repository ".concat(repository.getName()).concat(" not found"));
|
||||
}
|
||||
|
||||
fireEvent(repository, HandlerEvent.DELETE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,9 +271,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
||||
* @param context
|
||||
*/
|
||||
@Override
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
}
|
||||
public void init(SCMContextProvider context) {}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -298,24 +294,23 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
||||
|
||||
AssertUtil.assertIsValid(repository);
|
||||
|
||||
Repository notModifiedRepository = repositoryDAO.get(repository.getType(),
|
||||
Repository oldRepository = repositoryDAO.get(repository.getType(),
|
||||
repository.getName());
|
||||
|
||||
if (notModifiedRepository != null)
|
||||
if (oldRepository != null)
|
||||
{
|
||||
assertIsOwner(notModifiedRepository);
|
||||
fireEvent(repository, HandlerEvent.BEFORE_MODIFY);
|
||||
assertIsOwner(oldRepository);
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, repository, oldRepository);
|
||||
repository.setLastModified(System.currentTimeMillis());
|
||||
getHandler(repository).modify(repository);
|
||||
repositoryDAO.modify(repository);
|
||||
fireEvent(HandlerEventType.MODIFY, repository, oldRepository);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RepositoryNotFoundException(
|
||||
"repository ".concat(repository.getName()).concat(" not found"));
|
||||
}
|
||||
|
||||
fireEvent(repository, HandlerEvent.MODIFY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.apache.shiro.SecurityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.group.GroupEvent;
|
||||
import sonia.scm.store.ConfigurationEntryStore;
|
||||
@@ -132,7 +132,7 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
|
||||
//J-
|
||||
ScmEventBus.getInstance().post(
|
||||
new StoredAssignedPermissionEvent(HandlerEvent.CREATE, sap)
|
||||
new StoredAssignedPermissionEvent(HandlerEventType.CREATE, sap)
|
||||
);
|
||||
//J+
|
||||
|
||||
@@ -152,7 +152,7 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
store.remove(permission.getId());
|
||||
//J-
|
||||
ScmEventBus.getInstance().post(
|
||||
new StoredAssignedPermissionEvent(HandlerEvent.CREATE, permission)
|
||||
new StoredAssignedPermissionEvent(HandlerEventType.CREATE, permission)
|
||||
);
|
||||
//J+
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
@Subscribe
|
||||
public void handleEvent(final UserEvent event)
|
||||
{
|
||||
if (event.getEventType() == HandlerEvent.DELETE)
|
||||
if (event.getEventType() == HandlerEventType.DELETE)
|
||||
{
|
||||
deletePermissions(new Predicate<AssignedPermission>()
|
||||
{
|
||||
@@ -209,7 +209,7 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
@Subscribe
|
||||
public void handleEvent(final GroupEvent event)
|
||||
{
|
||||
if (event.getEventType() == HandlerEvent.DELETE)
|
||||
if (event.getEventType() == HandlerEventType.DELETE)
|
||||
{
|
||||
deletePermissions(new Predicate<AssignedPermission>()
|
||||
{
|
||||
@@ -243,7 +243,7 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
|
||||
//J-
|
||||
ScmEventBus.getInstance().post(
|
||||
new StoredAssignedPermissionEvent(HandlerEvent.CREATE, permission)
|
||||
new StoredAssignedPermissionEvent(HandlerEventType.CREATE, permission)
|
||||
);
|
||||
//J+
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ import org.apache.shiro.subject.SimplePrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.group.GroupManager;
|
||||
@@ -121,9 +121,8 @@ public class ScmRealm extends AuthorizingRealm
|
||||
*/
|
||||
@Inject
|
||||
public ScmRealm(ScmConfiguration configuration,
|
||||
LoginAttemptHandler loginAttemptHandler,
|
||||
AuthorizationCollector collector,UserManager userManager,
|
||||
GroupManager groupManager, UserDAO userDAO,
|
||||
LoginAttemptHandler loginAttemptHandler, AuthorizationCollector collector,
|
||||
UserManager userManager, GroupManager groupManager, UserDAO userDAO,
|
||||
AuthenticationManager authenticator, RepositoryManager manager,
|
||||
Provider<HttpServletRequest> requestProvider,
|
||||
Provider<HttpServletResponse> responseProvider)
|
||||
@@ -150,8 +149,6 @@ public class ScmRealm extends AuthorizingRealm
|
||||
setPermissionResolver(new RepositoryPermissionResolver());
|
||||
}
|
||||
|
||||
private final LoginAttemptHandler loginAttemptHandler;
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -198,6 +195,7 @@ public class ScmRealm extends AuthorizingRealm
|
||||
else
|
||||
{
|
||||
loginAttemptHandler.onUnsuccessfulAuthentication(authToken, result);
|
||||
|
||||
throw new AccountException("authentication failed");
|
||||
}
|
||||
|
||||
@@ -257,9 +255,10 @@ public class ScmRealm extends AuthorizingRealm
|
||||
user.setCreationDate(System.currentTimeMillis());
|
||||
|
||||
// TODO find a better way
|
||||
UserEventHack.fireEvent(userManager, user, HandlerEvent.BEFORE_CREATE);
|
||||
UserEventHack.fireEvent(userManager, HandlerEventType.BEFORE_CREATE,
|
||||
user);
|
||||
userDAO.add(user);
|
||||
UserEventHack.fireEvent(userManager, user, HandlerEvent.CREATE);
|
||||
UserEventHack.fireEvent(userManager, HandlerEventType.CREATE, user);
|
||||
}
|
||||
else if (logger.isErrorEnabled())
|
||||
{
|
||||
@@ -547,6 +546,9 @@ public class ScmRealm extends AuthorizingRealm
|
||||
/** Field description */
|
||||
private final GroupManager groupManager;
|
||||
|
||||
/** Field description */
|
||||
private final LoginAttemptHandler loginAttemptHandler;
|
||||
|
||||
/** Field description */
|
||||
private final Provider<HttpServletRequest> requestProvider;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.apache.shiro.subject.Subject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.TransformFilter;
|
||||
import sonia.scm.search.SearchRequest;
|
||||
@@ -179,9 +179,9 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
|
||||
AssertUtil.assertIsValid(user);
|
||||
user.setCreationDate(System.currentTimeMillis());
|
||||
fireEvent(user, HandlerEvent.BEFORE_CREATE);
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, user);
|
||||
userDAO.add(user);
|
||||
fireEvent(user, HandlerEvent.CREATE);
|
||||
fireEvent(HandlerEventType.CREATE, user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,9 +207,9 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
|
||||
if (userDAO.contains(name))
|
||||
{
|
||||
fireEvent(user, HandlerEvent.BEFORE_DELETE);
|
||||
fireEvent(HandlerEventType.BEFORE_DELETE, user);
|
||||
userDAO.delete(user);
|
||||
fireEvent(user, HandlerEvent.DELETE);
|
||||
fireEvent(HandlerEventType.DELETE, user);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -268,13 +268,15 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
|
||||
String name = user.getName();
|
||||
|
||||
if (userDAO.contains(name))
|
||||
User oldUser = userDAO.get(name);
|
||||
|
||||
if (oldUser != null)
|
||||
{
|
||||
AssertUtil.assertIsValid(user);
|
||||
user.setLastModified(System.currentTimeMillis());
|
||||
fireEvent(user, HandlerEvent.BEFORE_MODIFY);
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, user, oldUser);
|
||||
userDAO.modify(user);
|
||||
fireEvent(user, HandlerEvent.MODIFY);
|
||||
fireEvent(HandlerEventType.MODIFY, user, oldUser);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ package sonia.scm.user;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.HandlerEventType;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -71,15 +71,15 @@ public final class UserEventHack
|
||||
* @param user
|
||||
* @param event
|
||||
*/
|
||||
public static void fireEvent(UserManager userManager, User user,
|
||||
HandlerEvent event)
|
||||
public static void fireEvent(UserManager userManager, HandlerEventType event,
|
||||
User user)
|
||||
{
|
||||
AbstractUserManager abstractUserManager =
|
||||
getAbstractUserManager(userManager);
|
||||
|
||||
if (abstractUserManager != null)
|
||||
{
|
||||
abstractUserManager.fireEvent(user, event);
|
||||
abstractUserManager.fireEvent(event, user);
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserEvent;
|
||||
|
||||
@@ -101,7 +101,7 @@ public class GuavaScmEventBusTest extends AbstractTestBase
|
||||
}
|
||||
});
|
||||
|
||||
eventBus.post(new UserEvent(new User("test"), HandlerEvent.CREATE));
|
||||
eventBus.post(new UserEvent(HandlerEventType.CREATE, new User("test")));
|
||||
|
||||
assertNotEquals(thread, currentThread);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.HandlerEventType;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -118,7 +118,7 @@ public class UserEventHackTest
|
||||
*/
|
||||
private void fireEvent(UserManager u)
|
||||
{
|
||||
UserEventHack.fireEvent(u, new User(), HandlerEvent.CREATE);
|
||||
UserEventHack.fireEvent(u, HandlerEventType.CREATE, new User());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,8 +129,8 @@ public class UserEventHackTest
|
||||
*/
|
||||
private void verify(int count)
|
||||
{
|
||||
verifier.verify(userManager, calls(count)).fireEvent(any(User.class),
|
||||
any(HandlerEvent.class));
|
||||
verifier.verify(userManager,
|
||||
calls(count)).fireEvent(any(HandlerEventType.class), any(User.class));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user