mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 13:35:44 +01:00
Introduce ManagerDaoAdapter for create and modify
This commit is contained in:
@@ -43,6 +43,7 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.ManagerDaoAdapter;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.TransformFilter;
|
||||
import sonia.scm.search.SearchRequest;
|
||||
@@ -84,6 +85,10 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
public DefaultGroupManager(GroupDAO groupDAO)
|
||||
{
|
||||
this.groupDAO = groupDAO;
|
||||
this.managerDaoAdapter = new ManagerDaoAdapter<>(
|
||||
groupDAO,
|
||||
GroupNotFoundException::new,
|
||||
GroupAlreadyExistsException::new);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -101,46 +106,23 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param group
|
||||
*
|
||||
* @throws GroupException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public Group create(Group group) throws GroupException
|
||||
{
|
||||
public Group create(Group group) throws GroupException {
|
||||
String type = group.getType();
|
||||
|
||||
if (Util.isEmpty(type))
|
||||
{
|
||||
if (Util.isEmpty(type)) {
|
||||
group.setType(groupDAO.getType());
|
||||
}
|
||||
|
||||
String name = group.getName();
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("create group {} of type {}", name,
|
||||
group.getType());
|
||||
}
|
||||
|
||||
GroupPermissions.create().check();
|
||||
|
||||
if (groupDAO.contains(name))
|
||||
{
|
||||
throw new GroupAlreadyExistsException(name);
|
||||
}
|
||||
logger.info("create group {} of type {}", group.getName(), group.getType());
|
||||
|
||||
removeDuplicateMembers(group);
|
||||
group.setCreationDate(System.currentTimeMillis());
|
||||
fireEvent(HandlerEventType.BEFORE_CREATE, group);
|
||||
groupDAO.add(group);
|
||||
fireEvent(HandlerEventType.CREATE, group);
|
||||
return group;
|
||||
|
||||
return managerDaoAdapter.create(
|
||||
group,
|
||||
GroupPermissions::create,
|
||||
newGroup -> fireEvent(HandlerEventType.BEFORE_CREATE, newGroup),
|
||||
newGroup -> fireEvent(HandlerEventType.CREATE, newGroup)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,31 +177,18 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void modify(Group group) throws GroupException
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("modify group {} of type {}", group.getName(),
|
||||
group.getType());
|
||||
}
|
||||
public void modify(Group group) throws GroupException {
|
||||
logger.info("modify group {} of type {}", group.getName(), group.getType());
|
||||
|
||||
String name = group.getName();
|
||||
GroupPermissions.modify().check(name);
|
||||
|
||||
Group notModified = groupDAO.get(name);
|
||||
if (notModified != null)
|
||||
{
|
||||
removeDuplicateMembers(group);
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, group, notModified);
|
||||
group.setLastModified(System.currentTimeMillis());
|
||||
group.setCreationDate(notModified.getCreationDate());
|
||||
groupDAO.modify(group);
|
||||
fireEvent(HandlerEventType.MODIFY, group, notModified);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new GroupNotFoundException();
|
||||
}
|
||||
managerDaoAdapter.modify(
|
||||
group,
|
||||
GroupPermissions::modify,
|
||||
notModified -> {
|
||||
removeDuplicateMembers(group);
|
||||
fireEvent(HandlerEventType.BEFORE_MODIFY, group, notModified);
|
||||
},
|
||||
notModified -> fireEvent(HandlerEventType.MODIFY, group, notModified)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -458,4 +427,5 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
|
||||
/** Field description */
|
||||
private GroupDAO groupDAO;
|
||||
private final ManagerDaoAdapter<Group, GroupException> managerDaoAdapter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user