mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 21:45:43 +01:00
Create NotFoundExceptions with id fields
This commit is contained in:
@@ -52,7 +52,7 @@ public class GroupNotFoundException extends GroupException
|
|||||||
* Constructs a new GroupNotFoundException.
|
* Constructs a new GroupNotFoundException.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public GroupNotFoundException() {
|
public GroupNotFoundException(Group group) {
|
||||||
super("group does not exist");
|
super("group " + group.getName() + " does not exist");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ public class RepositoryNotFoundException extends RepositoryException
|
|||||||
* error detail message.
|
* error detail message.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public RepositoryNotFoundException() {
|
public RepositoryNotFoundException(Repository repository) {
|
||||||
super("repository does not exist");
|
super("repository " + repository.getName() + "/" + repository.getNamespace() + " does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepositoryNotFoundException(String repositoryId) {
|
public RepositoryNotFoundException(String repositoryId) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class UserNotFoundException extends UserException
|
|||||||
* Constructs a new UserNotFoundException.
|
* Constructs a new UserNotFoundException.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public UserNotFoundException() {
|
public UserNotFoundException(User user) {
|
||||||
super("user does not exist");
|
super("user " + user.getName() + " does not exist");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,19 +9,17 @@ import java.util.function.Supplier;
|
|||||||
public class ManagerDaoAdapter<T extends ModelObject, E extends Exception> {
|
public class ManagerDaoAdapter<T extends ModelObject, E extends Exception> {
|
||||||
|
|
||||||
private final GenericDAO<T> dao;
|
private final GenericDAO<T> dao;
|
||||||
private final Supplier<E> notFoundException;
|
private final Function<T, E> notFoundException;
|
||||||
private final Function<T, E> alreadyExistsException;
|
private final Function<T, E> alreadyExistsException;
|
||||||
|
|
||||||
public ManagerDaoAdapter(GenericDAO<T> dao, Supplier<E> notFoundException, Function<T, E> alreadyExistsException) {
|
public ManagerDaoAdapter(GenericDAO<T> dao, Function<T, E> notFoundException, Function<T, E> alreadyExistsException) {
|
||||||
this.dao = dao;
|
this.dao = dao;
|
||||||
this.notFoundException = notFoundException;
|
this.notFoundException = notFoundException;
|
||||||
this.alreadyExistsException = alreadyExistsException;
|
this.alreadyExistsException = alreadyExistsException;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void modify(T object, Function<T, PermissionCheck> permissionCheck, AroundHandler<T, E> beforeUpdate, AroundHandler<T, E> afterUpdate) throws E {
|
public void modify(T object, Function<T, PermissionCheck> permissionCheck, AroundHandler<T, E> beforeUpdate, AroundHandler<T, E> afterUpdate) throws E {
|
||||||
String name = object.getId();
|
T notModified = dao.get(object.getId());
|
||||||
|
|
||||||
T notModified = dao.get(name);
|
|
||||||
if (notModified != null) {
|
if (notModified != null) {
|
||||||
permissionCheck.apply(notModified).check();
|
permissionCheck.apply(notModified).check();
|
||||||
AssertUtil.assertIsValid(object);
|
AssertUtil.assertIsValid(object);
|
||||||
@@ -35,7 +33,7 @@ public class ManagerDaoAdapter<T extends ModelObject, E extends Exception> {
|
|||||||
|
|
||||||
afterUpdate.handle(notModified);
|
afterUpdate.handle(notModified);
|
||||||
} else {
|
} else {
|
||||||
throw notFoundException.get();
|
throw notFoundException.apply(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public class DefaultGroupManager extends AbstractGroupManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new GroupNotFoundException();
|
throw new GroupNotFoundException(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ public class DefaultGroupManager extends AbstractGroupManager
|
|||||||
|
|
||||||
if (fresh == null)
|
if (fresh == null)
|
||||||
{
|
{
|
||||||
throw new GroupNotFoundException();
|
throw new GroupNotFoundException(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
fresh.copyProperties(group);
|
fresh.copyProperties(group);
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
|||||||
repositoryDAO.delete(repository);
|
repositoryDAO.delete(repository);
|
||||||
fireEvent(HandlerEventType.DELETE, repository);
|
fireEvent(HandlerEventType.DELETE, repository);
|
||||||
} else {
|
} else {
|
||||||
throw new RepositoryNotFoundException();
|
throw new RepositoryNotFoundException(repository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
|||||||
if (fresh != null) {
|
if (fresh != null) {
|
||||||
fresh.copyProperties(repository);
|
fresh.copyProperties(repository);
|
||||||
} else {
|
} else {
|
||||||
throw new RepositoryNotFoundException();
|
throw new RepositoryNotFoundException(repository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ public class DefaultUserManager extends AbstractUserManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new UserNotFoundException();
|
throw new UserNotFoundException(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +249,7 @@ public class DefaultUserManager extends AbstractUserManager
|
|||||||
|
|
||||||
if (fresh == null)
|
if (fresh == null)
|
||||||
{
|
{
|
||||||
throw new UserNotFoundException();
|
throw new UserNotFoundException(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
fresh.copyProperties(user);
|
fresh.copyProperties(user);
|
||||||
|
|||||||
Reference in New Issue
Block a user