Review - Adds reason for RuntimeException & extends REST docs

This commit is contained in:
Johannes Schnatterer
2018-07-03 16:18:44 +02:00
parent 0aa2326818
commit 4a49068b4a
3 changed files with 16 additions and 9 deletions

View File

@@ -577,6 +577,9 @@ public abstract class AbstractManagerResource<T extends ModelObject,
return items; return items;
} }
// We have to handle IntrospectionException here, because it's a checked exception
// It shouldn't occur really - so creating a new unchecked exception would be over-engineered here
@SuppressWarnings("squid:S00112")
private void checkSortByField(String sortBy) { private void checkSortByField(String sortBy) {
try { try {
BeanInfo info = Introspector.getBeanInfo(type); BeanInfo info = Introspector.getBeanInfo(type);
@@ -589,17 +592,17 @@ public abstract class AbstractManagerResource<T extends ModelObject,
} }
} }
protected PageResult<T> fetchPage(String sortby, boolean desc, int pageNumber, protected PageResult<T> fetchPage(String sortBy, boolean desc, int pageNumber,
int pageSize) { int pageSize) {
AssertUtil.assertPositive(pageNumber); AssertUtil.assertPositive(pageNumber);
AssertUtil.assertPositive(pageSize); AssertUtil.assertPositive(pageSize);
if (Util.isEmpty(sortby)) { if (Util.isEmpty(sortBy)) {
// replace with something useful // replace with something useful
sortby = "id"; sortBy = "id";
} }
return manager.getPage(createComparator(sortby, desc), pageNumber, pageSize); return manager.getPage(createComparator(sortBy, desc), pageNumber, pageSize);
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------

View File

@@ -43,9 +43,10 @@ public class GroupCollectionResource {
* Returns all groups for a given page number with a given page size (default page size is {@value DEFAULT_PAGE_SIZE}). * Returns all groups for a given page number with a given page size (default page size is {@value DEFAULT_PAGE_SIZE}).
* *
* <strong>Note:</strong> This method requires "group" privilege. * <strong>Note:</strong> This method requires "group" privilege.
*
* @param page the number of the requested page * @param page the number of the requested page
* @param pageSize the page size (default page size is {@value DEFAULT_PAGE_SIZE}) * @param pageSize the page size (default page size is {@value DEFAULT_PAGE_SIZE})
* @param sortBy sort parameter * @param sortBy sort parameter (if empty - undefined sorting)
* @param desc sort direction desc or aesc * @param desc sort direction desc or aesc
*/ */
@GET @GET
@@ -54,6 +55,7 @@ public class GroupCollectionResource {
@TypeHint(GroupDto[].class) @TypeHint(GroupDto[].class)
@StatusCodes({ @StatusCodes({
@ResponseCode(code = 200, condition = "success"), @ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 400, condition = "\"sortBy\" field unknown"),
@ResponseCode(code = 401, condition = "not authenticated / invalid credentials"), @ResponseCode(code = 401, condition = "not authenticated / invalid credentials"),
@ResponseCode(code = 403, condition = "not authorized, the current user does not have the \"group\" privilege"), @ResponseCode(code = 403, condition = "not authorized, the current user does not have the \"group\" privilege"),
@ResponseCode(code = 500, condition = "internal server error") @ResponseCode(code = 500, condition = "internal server error")

View File

@@ -43,9 +43,10 @@ public class UserCollectionResource {
* Returns all users for a given page number with a given page size (default page size is {@value DEFAULT_PAGE_SIZE}). * Returns all users for a given page number with a given page size (default page size is {@value DEFAULT_PAGE_SIZE}).
* *
* <strong>Note:</strong> This method requires "user" privilege. * <strong>Note:</strong> This method requires "user" privilege.
*
* @param page the number of the requested page * @param page the number of the requested page
* @param pageSize the page size (default page size is {@value DEFAULT_PAGE_SIZE}) * @param pageSize the page size (default page size is {@value DEFAULT_PAGE_SIZE})
* @param sortBy sort parameter * @param sortBy sort parameter (if empty - undefined sorting)
* @param desc sort direction desc or asc * @param desc sort direction desc or asc
*/ */
@GET @GET
@@ -54,6 +55,7 @@ public class UserCollectionResource {
@TypeHint(UserDto[].class) @TypeHint(UserDto[].class)
@StatusCodes({ @StatusCodes({
@ResponseCode(code = 200, condition = "success"), @ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 400, condition = "\"sortBy\" field unknown"),
@ResponseCode(code = 401, condition = "not authenticated / invalid credentials"), @ResponseCode(code = 401, condition = "not authenticated / invalid credentials"),
@ResponseCode(code = 403, condition = "not authorized, the current user does not have the \"user\" privilege"), @ResponseCode(code = 403, condition = "not authorized, the current user does not have the \"user\" privilege"),
@ResponseCode(code = 500, condition = "internal server error") @ResponseCode(code = 500, condition = "internal server error")