upgrade spring, add javadoc, formatting
This commit is contained in:
@@ -108,52 +108,49 @@ public class BorrowItemManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @param search the search
|
||||
* @param search the search
|
||||
* @return the page
|
||||
*/
|
||||
public Page<BorrowItem> get(int page, int size, String sortBy, boolean descending,
|
||||
String search) {
|
||||
public Page<BorrowItem> get(int page, int size, String sortBy, boolean descending, String search) {
|
||||
|
||||
if (StringUtils.hasText(search)) {
|
||||
return borrowItemRepository.findAll(
|
||||
qBorrowItem.name.contains(search).or(qBorrowItem.description.contains(search)),
|
||||
PageRequest.of(page, size, descending ? Sort.by(sortBy).descending()
|
||||
: Sort.by(sortBy).ascending()));
|
||||
return borrowItemRepository
|
||||
.findAll(qBorrowItem.name.contains(search).or(qBorrowItem.description.contains(search)), PageRequest
|
||||
.of(page, size, descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
}
|
||||
|
||||
return borrowItemRepository.findAll(PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
return borrowItemRepository.findAll(
|
||||
PageRequest.of(page, size, descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the for user.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param userId the user id
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @param search the search
|
||||
* @param search the search
|
||||
* @return the for user
|
||||
*/
|
||||
public Page<BorrowItem> getForUser(Long userId, int page, int size, String sortBy,
|
||||
boolean descending, String search) {
|
||||
public Page<BorrowItem> getForUser(Long userId, int page, int size, String sortBy, boolean descending,
|
||||
String search) {
|
||||
|
||||
BooleanBuilder query = new BooleanBuilder();
|
||||
|
||||
query.and(qBorrowItem.owner.eq(userId));
|
||||
|
||||
if (StringUtils.hasText(search)) {
|
||||
query.and(
|
||||
qBorrowItem.name.contains(search).or(qBorrowItem.description.contains(search)));
|
||||
query.and(qBorrowItem.name.contains(search).or(qBorrowItem.description.contains(search)));
|
||||
}
|
||||
|
||||
return borrowItemRepository.findAll(query.getValue(), PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
return borrowItemRepository.findAll(query.getValue(),
|
||||
PageRequest.of(page, size, descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,10 +162,10 @@ public class BorrowItemManager implements UserDataProvider {
|
||||
public BorrowItem save(BorrowItem borrowItem) {
|
||||
|
||||
if (borrowItem.getId() != null && !borrowItem.getId().equals(0L)) {
|
||||
borrowItemManualSlotRepository.deleteAll(borrowItemManualSlotRepository
|
||||
.findAll(qBorrowItemManualSlot.item.eq(borrowItem.getId())));
|
||||
borrowItemPeriodSlotRepository.deleteAll(borrowItemPeriodSlotRepository
|
||||
.findAll(qBorrowItemPeriodSlot.item.eq(borrowItem.getId())));
|
||||
borrowItemManualSlotRepository.deleteAll(
|
||||
borrowItemManualSlotRepository.findAll(qBorrowItemManualSlot.item.eq(borrowItem.getId())));
|
||||
borrowItemPeriodSlotRepository.deleteAll(
|
||||
borrowItemPeriodSlotRepository.findAll(qBorrowItemPeriodSlot.item.eq(borrowItem.getId())));
|
||||
}
|
||||
|
||||
List<? extends BorrowItemSlot> slots = borrowItem.getSlots();
|
||||
@@ -216,12 +213,11 @@ public class BorrowItemManager implements UserDataProvider {
|
||||
* @param borrowItem the borrow item
|
||||
*/
|
||||
public void delete(BorrowItem borrowItem) {
|
||||
borrowItemManualSlotRepository.deleteAll(borrowItemManualSlotRepository
|
||||
.findAll(qBorrowItemManualSlot.item.eq(borrowItem.getId())));
|
||||
borrowItemPeriodSlotRepository.deleteAll(borrowItemPeriodSlotRepository
|
||||
.findAll(qBorrowItemPeriodSlot.item.eq(borrowItem.getId())));
|
||||
borrowRequestRepository.deleteAll(
|
||||
borrowRequestRepository.findAll(qBorrowRequest.item.eq(borrowItem.getId())));
|
||||
borrowItemManualSlotRepository
|
||||
.deleteAll(borrowItemManualSlotRepository.findAll(qBorrowItemManualSlot.item.eq(borrowItem.getId())));
|
||||
borrowItemPeriodSlotRepository
|
||||
.deleteAll(borrowItemPeriodSlotRepository.findAll(qBorrowItemPeriodSlot.item.eq(borrowItem.getId())));
|
||||
borrowRequestRepository.deleteAll(borrowRequestRepository.findAll(qBorrowRequest.item.eq(borrowItem.getId())));
|
||||
|
||||
borrowItemRepository.delete(borrowItem);
|
||||
}
|
||||
@@ -233,8 +229,7 @@ public class BorrowItemManager implements UserDataProvider {
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
BorrowItem borrowItem = get(id);
|
||||
Assert.notNull(borrowItem, "Invalid borrow item id: "
|
||||
+ id);
|
||||
Assert.notNull(borrowItem, "Invalid borrow item id: " + id);
|
||||
delete(borrowItem);
|
||||
}
|
||||
|
||||
@@ -244,12 +239,8 @@ public class BorrowItemManager implements UserDataProvider {
|
||||
* @param borrowItem the borrow item
|
||||
*/
|
||||
public void notifyOwner(BorrowItem borrowItem) {
|
||||
Assert.isTrue(
|
||||
borrowItem.getEmailNotification() != null
|
||||
&& borrowItem.getEmailNotification().booleanValue(),
|
||||
"Email notification not enabled for '"
|
||||
+ borrowItem.getId()
|
||||
+ "'!");
|
||||
Assert.isTrue(borrowItem.getEmailNotification() != null && borrowItem.getEmailNotification().booleanValue(),
|
||||
"Email notification not enabled for '" + borrowItem.getId() + "'!");
|
||||
String email = borrowItem.getEmail();
|
||||
|
||||
if (!StringUtils.hasText(email)) {
|
||||
@@ -276,8 +267,7 @@ public class BorrowItemManager implements UserDataProvider {
|
||||
public List<UserData> getUserData(Long userId) {
|
||||
List<UserData> result = Lists.newArrayList();
|
||||
|
||||
Iterator<BorrowItem> items = borrowItemRepository.findAll(qBorrowItem.owner.eq(userId))
|
||||
.iterator();
|
||||
Iterator<BorrowItem> items = borrowItemRepository.findAll(qBorrowItem.owner.eq(userId)).iterator();
|
||||
while (items.hasNext()) {
|
||||
result.add(items.next());
|
||||
}
|
||||
@@ -290,8 +280,7 @@ public class BorrowItemManager implements UserDataProvider {
|
||||
*/
|
||||
@Override
|
||||
public void purgeUserData(Long userId) {
|
||||
Iterator<BorrowItem> items = borrowItemRepository.findAll(qBorrowItem.owner.eq(userId))
|
||||
.iterator();
|
||||
Iterator<BorrowItem> items = borrowItemRepository.findAll(qBorrowItem.owner.eq(userId)).iterator();
|
||||
while (items.hasNext()) {
|
||||
delete(items.next());
|
||||
}
|
||||
|
||||
@@ -68,69 +68,65 @@ public class BorrowRequestManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the for user.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param userId the user id
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @return the for user
|
||||
*/
|
||||
public Page<BorrowRequest> getForUser(Long userId, int page, int size, String sortBy,
|
||||
boolean descending) {
|
||||
return borrowRequestRepository.findAll(qBorrowRequest.user.eq(userId), PageRequest.of(page,
|
||||
size, descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
public Page<BorrowRequest> getForUser(Long userId, int page, int size, String sortBy, boolean descending) {
|
||||
return borrowRequestRepository.findAll(qBorrowRequest.user.eq(userId),
|
||||
PageRequest.of(page, size, descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the for user and status.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param status the status
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param userId the user id
|
||||
* @param status the status
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @return the for user and status
|
||||
*/
|
||||
public Page<BorrowRequest> getForUserAndStatus(Long userId, BorrowRequestStatus status,
|
||||
int page, int size, String sortBy, boolean descending) {
|
||||
return borrowRequestRepository.findAll(
|
||||
qBorrowRequest.user.eq(userId).and(qBorrowRequest.status.eq(status)),
|
||||
PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
public Page<BorrowRequest> getForUserAndStatus(Long userId, BorrowRequestStatus status, int page, int size,
|
||||
String sortBy, boolean descending) {
|
||||
return borrowRequestRepository.findAll(qBorrowRequest.user.eq(userId).and(qBorrowRequest.status.eq(status)),
|
||||
PageRequest.of(page, size, descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the for owner.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param userId the user id
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @return the for owner
|
||||
*/
|
||||
public Page<BorrowRequest> getForOwner(Long userId, int page, int size, String sortBy,
|
||||
boolean descending) {
|
||||
return borrowRequestRepository.findAllByOwner(userId, PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
public Page<BorrowRequest> getForOwner(Long userId, int page, int size, String sortBy, boolean descending) {
|
||||
return borrowRequestRepository.findAllByOwner(userId,
|
||||
PageRequest.of(page, size, descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the for owner and status.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param status the status
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param userId the user id
|
||||
* @param status the status
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @return the for owner and status
|
||||
*/
|
||||
public Page<BorrowRequest> getForOwnerAndStatus(Long userId, BorrowRequestStatus status,
|
||||
int page, int size, String sortBy, boolean descending) {
|
||||
return borrowRequestRepository.findAllByOwnerAndStatus(userId, status, PageRequest.of(page,
|
||||
size, descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
public Page<BorrowRequest> getForOwnerAndStatus(Long userId, BorrowRequestStatus status, int page, int size,
|
||||
String sortBy, boolean descending) {
|
||||
return borrowRequestRepository.findAllByOwnerAndStatus(userId, status,
|
||||
PageRequest.of(page, size, descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +161,7 @@ public class BorrowRequestManager implements UserDataProvider {
|
||||
* Creates the code.
|
||||
*
|
||||
* @param borrowRequest the borrow request
|
||||
* @param issuer the issuer
|
||||
* @param issuer the issuer
|
||||
* @return the signed JWT
|
||||
* @throws JOSEException the JOSE exception
|
||||
*/
|
||||
@@ -207,8 +203,7 @@ public class BorrowRequestManager implements UserDataProvider {
|
||||
|
||||
JwtKey jwtKey = jwtKeyManager.getLatest(JWT_BORROW_KEY_NAME, true);
|
||||
|
||||
JWSHeader.Builder headerBuilder = new JWSHeader.Builder(
|
||||
jwtKeyManager.getJwsAlgorithm(jwtKey));
|
||||
JWSHeader.Builder headerBuilder = new JWSHeader.Builder(jwtKeyManager.getJwsAlgorithm(jwtKey));
|
||||
headerBuilder.keyID(jwtKey.getKeyID());
|
||||
headerBuilder.type(JOSEObjectType.JWT);
|
||||
|
||||
@@ -222,7 +217,7 @@ public class BorrowRequestManager implements UserDataProvider {
|
||||
*
|
||||
* @param jwt the jwt
|
||||
* @return true, if successful
|
||||
* @throws JOSEException the JOSE exception
|
||||
* @throws JOSEException the JOSE exception
|
||||
* @throws ParseException the parse exception
|
||||
*/
|
||||
public boolean verify(SignedJWT jwt) throws JOSEException, ParseException {
|
||||
@@ -233,9 +228,7 @@ public class BorrowRequestManager implements UserDataProvider {
|
||||
|
||||
JwtKey jwtKey = jwtKeyManager.getByKeyID(jwt.getHeader().getKeyID());
|
||||
if (jwtKey == null) {
|
||||
throw new KeySourceException("No key found for given KeyID! ("
|
||||
+ jwt.getHeader().getKeyID()
|
||||
+ ")");
|
||||
throw new KeySourceException("No key found for given KeyID! (" + jwt.getHeader().getKeyID() + ")");
|
||||
}
|
||||
|
||||
if (jwt.getJWTClaimsSet() == null) {
|
||||
@@ -259,14 +252,13 @@ public class BorrowRequestManager implements UserDataProvider {
|
||||
@Override
|
||||
public List<UserData> getUserData(Long userId) {
|
||||
List<UserData> result = Lists.newArrayList();
|
||||
Iterator<BorrowRequest> userRequests = borrowRequestRepository
|
||||
.findAll(qBorrowRequest.user.eq(userId)).iterator();
|
||||
Iterator<BorrowRequest> userRequests = borrowRequestRepository.findAll(qBorrowRequest.user.eq(userId))
|
||||
.iterator();
|
||||
while (userRequests.hasNext()) {
|
||||
result.add(userRequests.next());
|
||||
}
|
||||
|
||||
Iterator<BorrowRequest> ownerRequests = borrowRequestRepository.findAllByOwner(userId)
|
||||
.iterator();
|
||||
Iterator<BorrowRequest> ownerRequests = borrowRequestRepository.findAllByOwner(userId).iterator();
|
||||
while (ownerRequests.hasNext()) {
|
||||
result.add(ownerRequests.next());
|
||||
}
|
||||
@@ -279,14 +271,13 @@ public class BorrowRequestManager implements UserDataProvider {
|
||||
*/
|
||||
@Override
|
||||
public void purgeUserData(Long userId) {
|
||||
Iterator<BorrowRequest> userRequests = borrowRequestRepository
|
||||
.findAll(qBorrowRequest.user.eq(userId)).iterator();
|
||||
Iterator<BorrowRequest> userRequests = borrowRequestRepository.findAll(qBorrowRequest.user.eq(userId))
|
||||
.iterator();
|
||||
while (userRequests.hasNext()) {
|
||||
delete(userRequests.next());
|
||||
}
|
||||
|
||||
Iterator<BorrowRequest> ownerRequests = borrowRequestRepository.findAllByOwner(userId)
|
||||
.iterator();
|
||||
Iterator<BorrowRequest> ownerRequests = borrowRequestRepository.findAllByOwner(userId).iterator();
|
||||
while (ownerRequests.hasNext()) {
|
||||
delete(ownerRequests.next());
|
||||
}
|
||||
|
||||
@@ -46,19 +46,18 @@ public class BorrowItemController extends BaseController {
|
||||
/**
|
||||
* Gets the borrow items.
|
||||
*
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param sortParameter the sort parameter
|
||||
* @param descParameter the desc parameter
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param sortParameter the sort parameter
|
||||
* @param descParameter the desc parameter
|
||||
* @param searchParameter the search parameter
|
||||
* @param ownerParameter the owner parameter
|
||||
* @param ownerParameter the owner parameter
|
||||
* @return the borrow items
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping
|
||||
public Page<BorrowItem> getBorrowItems(@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter, @RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
||||
@RequestParam("search") Optional<String> searchParameter,
|
||||
@RequestParam("owner") Optional<Boolean> ownerParameter) {
|
||||
@@ -71,17 +70,15 @@ public class BorrowItemController extends BaseController {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
borrowItems = borrowItemManager.getForUser(getCurrentUserId(), pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false), searchParameter.orElse(null));
|
||||
sizeParameter.orElse(10), sortParameter.orElse("id"), descParameter.orElse(false),
|
||||
searchParameter.orElse(null));
|
||||
} else {
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(),
|
||||
BorrowPermissions.BORROW_REQUESTS)
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_REQUESTS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
borrowItems = borrowItemManager.get(pageParameter.orElse(0), sizeParameter.orElse(10),
|
||||
sortParameter.orElse("id"), descParameter.orElse(false),
|
||||
searchParameter.orElse(null));
|
||||
sortParameter.orElse("id"), descParameter.orElse(false), searchParameter.orElse(null));
|
||||
}
|
||||
|
||||
for (BorrowItem borrowItem : borrowItems.getContent()) {
|
||||
|
||||
@@ -66,19 +66,17 @@ public class BorrowRequestController extends BaseController {
|
||||
/**
|
||||
* Gets the borrow requests.
|
||||
*
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param sortParameter the sort parameter
|
||||
* @param descParameter the desc parameter
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param sortParameter the sort parameter
|
||||
* @param descParameter the desc parameter
|
||||
* @param ownerParameter the owner parameter
|
||||
* @return the borrow requests
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping
|
||||
public Page<BorrowRequest> getBorrowRequests(
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
public Page<BorrowRequest> getBorrowRequests(@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter, @RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
||||
@RequestParam("owner") Optional<Boolean> ownerParameter) {
|
||||
|
||||
@@ -89,18 +87,15 @@ public class BorrowRequestController extends BaseController {
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
borrowRequests = borrowRequestManager.getForOwner(getCurrentUserId(),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false));
|
||||
borrowRequests = borrowRequestManager.getForOwner(getCurrentUserId(), pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("id"), descParameter.orElse(false));
|
||||
} else {
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(),
|
||||
BorrowPermissions.BORROW_REQUESTS)
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_REQUESTS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
borrowRequests = borrowRequestManager.getForUser(getCurrentUserId(),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false));
|
||||
borrowRequests = borrowRequestManager.getForUser(getCurrentUserId(), pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("id"), descParameter.orElse(false));
|
||||
}
|
||||
|
||||
for (BorrowRequest borrowRequest : borrowRequests.getContent()) {
|
||||
@@ -153,8 +148,7 @@ public class BorrowRequestController extends BaseController {
|
||||
}
|
||||
|
||||
if (borrowRequest.getId() == null || borrowRequest.getId().equals(0L)) {
|
||||
if (borrowItem.getEmailNotification() != null
|
||||
&& borrowItem.getEmailNotification().booleanValue()) {
|
||||
if (borrowItem.getEmailNotification() != null && borrowItem.getEmailNotification().booleanValue()) {
|
||||
borrowItemManager.notifyOwner(borrowItem);
|
||||
}
|
||||
}
|
||||
@@ -212,7 +206,7 @@ public class BorrowRequestController extends BaseController {
|
||||
/**
|
||||
* Gets the code.
|
||||
*
|
||||
* @param id the id
|
||||
* @param id the id
|
||||
* @param request the request
|
||||
* @return the code
|
||||
*/
|
||||
@@ -230,12 +224,9 @@ public class BorrowRequestController extends BaseController {
|
||||
|
||||
String issuer = jwtBorrowIssuer;
|
||||
if (!StringUtils.hasText(issuer)) {
|
||||
issuer = request.getScheme()
|
||||
+ "://"
|
||||
+ request.getServerName();
|
||||
issuer = request.getScheme() + "://" + request.getServerName();
|
||||
if (request.getServerPort() != 443 && request.getServerPort() != 80) {
|
||||
issuer += ":"
|
||||
+ request.getServerPort();
|
||||
issuer += ":" + request.getServerPort();
|
||||
}
|
||||
}
|
||||
try {
|
||||
@@ -250,21 +241,19 @@ public class BorrowRequestController extends BaseController {
|
||||
* Verfiy.
|
||||
*
|
||||
* @param serialized the serialized
|
||||
* @param request the request
|
||||
* @param response the response
|
||||
* @param request the request
|
||||
* @param response the response
|
||||
* @return the object
|
||||
*/
|
||||
@PostMapping("verify")
|
||||
public Object verfiy(@RequestBody String serialized, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
public Object verfiy(@RequestBody String serialized, HttpServletRequest request, HttpServletResponse response) {
|
||||
try {
|
||||
SignedJWT signedJwt = SignedJWT.parse(serialized);
|
||||
Errors errors = new RequestBodyErrors(signedJwt);
|
||||
borrowJwtValidator.validate(signedJwt, errors);
|
||||
if (errors.hasErrors()) {
|
||||
if (errors.getGlobalErrors().isEmpty()) {
|
||||
throw new EntityResponseStatusException(errors.getAllErrors(),
|
||||
HttpStatus.PRECONDITION_FAILED);
|
||||
throw new EntityResponseStatusException(errors.getAllErrors(), HttpStatus.PRECONDITION_FAILED);
|
||||
} else {
|
||||
throw new EntityResponseStatusException(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
+9
-18
@@ -48,13 +48,11 @@ public class BorrowItemValidator implements Validator {
|
||||
errors.rejectValue("availability", "REQUIRED");
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(borrowItem.getUrl())
|
||||
&& !urlValidator.isValid(borrowItem.getUrl())) {
|
||||
if (StringUtils.hasText(borrowItem.getUrl()) && !urlValidator.isValid(borrowItem.getUrl())) {
|
||||
errors.rejectValue("url", "INVALID_URL");
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(borrowItem.getEmail())
|
||||
&& !emailValidator.isValid(borrowItem.getEmail())) {
|
||||
if (StringUtils.hasText(borrowItem.getEmail()) && !emailValidator.isValid(borrowItem.getEmail())) {
|
||||
errors.rejectValue("email", "INVALID_EMAIL");
|
||||
}
|
||||
|
||||
@@ -64,18 +62,15 @@ public class BorrowItemValidator implements Validator {
|
||||
errors.rejectValue("maxDuration", "INVALID");
|
||||
}
|
||||
|
||||
if (borrowItem.getAvailability() != null && borrowItem.getSlots() != null
|
||||
&& !borrowItem.getSlots().isEmpty()) {
|
||||
if (borrowItem.getAvailability() != null && borrowItem.getSlots() != null && !borrowItem.getSlots().isEmpty()) {
|
||||
for (BorrowItemSlot borrowItemSlot : borrowItem.getSlots()) {
|
||||
switch (borrowItem.getAvailability()) {
|
||||
case MANUAL:
|
||||
if (borrowItemSlot instanceof BorrowItemManualSlot) {
|
||||
BorrowItemManualSlot borrowItemManualSlot = (BorrowItemManualSlot) borrowItemSlot;
|
||||
if (borrowItemManualSlot.getStart() == null
|
||||
|| borrowItemManualSlot.getEnd() == null) {
|
||||
if (borrowItemManualSlot.getStart() == null || borrowItemManualSlot.getEnd() == null) {
|
||||
errors.rejectValue("slots", "MISSING_DATES");
|
||||
} else if (borrowItemManualSlot.getStart()
|
||||
.isAfter(borrowItemManualSlot.getEnd())) {
|
||||
} else if (borrowItemManualSlot.getStart().isAfter(borrowItemManualSlot.getEnd())) {
|
||||
errors.rejectValue("slots", "INVALID_DATES");
|
||||
}
|
||||
}
|
||||
@@ -83,18 +78,14 @@ public class BorrowItemValidator implements Validator {
|
||||
case PERIOD:
|
||||
if (borrowItemSlot instanceof BorrowItemPeriodSlot) {
|
||||
BorrowItemPeriodSlot borrowItemPeriodSlot = (BorrowItemPeriodSlot) borrowItemSlot;
|
||||
if (borrowItemPeriodSlot.getStartDay() == null
|
||||
|| borrowItemPeriodSlot.getStartTime() == null
|
||||
if (borrowItemPeriodSlot.getStartDay() == null || borrowItemPeriodSlot.getStartTime() == null
|
||||
|| borrowItemPeriodSlot.getEndDay() == null
|
||||
|| borrowItemPeriodSlot.getEndTime() == null) {
|
||||
errors.rejectValue("slots", "MISSING_DATES");
|
||||
} else if (borrowItemPeriodSlot.getStartDay()
|
||||
.compareTo(borrowItemPeriodSlot.getEndDay()) > 0) {
|
||||
} else if (borrowItemPeriodSlot.getStartDay().compareTo(borrowItemPeriodSlot.getEndDay()) > 0) {
|
||||
errors.rejectValue("slots", "INVALID_DAY");
|
||||
} else if (borrowItemPeriodSlot.getStartDay()
|
||||
.compareTo(borrowItemPeriodSlot.getEndDay()) == 0
|
||||
&& borrowItemPeriodSlot.getStartTime()
|
||||
.isAfter(borrowItemPeriodSlot.getEndTime())) {
|
||||
} else if (borrowItemPeriodSlot.getStartDay().compareTo(borrowItemPeriodSlot.getEndDay()) == 0
|
||||
&& borrowItemPeriodSlot.getStartTime().isAfter(borrowItemPeriodSlot.getEndTime())) {
|
||||
errors.rejectValue("slots", "INVALID_TIME");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -111,8 +111,7 @@ public class BorrowJwtValidator implements Validator {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!BorrowRequestStatus.valueOf(claims.getStringClaim("status"))
|
||||
.equals(BorrowRequestStatus.ACCEPTED)) {
|
||||
if (!BorrowRequestStatus.valueOf(claims.getStringClaim("status")).equals(BorrowRequestStatus.ACCEPTED)) {
|
||||
errors.rejectValue("status", "INVALID");
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
|
||||
+14
-12
@@ -66,6 +66,13 @@ public class BorrowRequestValidator implements Validator {
|
||||
validateTime(borrowRequest, borrowItem, errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate time.
|
||||
*
|
||||
* @param borrowRequest the borrow request
|
||||
* @param borrowItem the borrow item
|
||||
* @param errors the errors
|
||||
*/
|
||||
public void validateTime(BorrowRequest borrowRequest, BorrowItem borrowItem, Errors errors) {
|
||||
if (borrowRequest.getStarts() == null) {
|
||||
errors.rejectValue("starts", "REQUIRED");
|
||||
@@ -77,16 +84,14 @@ public class BorrowRequestValidator implements Validator {
|
||||
return;
|
||||
}
|
||||
|
||||
borrowRequest
|
||||
.setStarts(InstantHelper.truncate(borrowRequest.getStarts(), ChronoUnit.SECONDS));
|
||||
borrowRequest.setStarts(InstantHelper.truncate(borrowRequest.getStarts(), ChronoUnit.SECONDS));
|
||||
borrowRequest.setEnds(InstantHelper.truncate(borrowRequest.getEnds(), ChronoUnit.SECONDS));
|
||||
|
||||
// expiry + start
|
||||
if (borrowRequest.getStarts().isAfter(borrowRequest.getEnds())
|
||||
|| borrowRequestRepository.exists(qBorrowRequest.item.eq(borrowRequest.getItem())
|
||||
// exlude self
|
||||
.and(qBorrowRequest.id
|
||||
.ne(borrowRequest.getId() == null ? -1L : borrowRequest.getId()))
|
||||
.and(qBorrowRequest.id.ne(borrowRequest.getId() == null ? -1L : borrowRequest.getId()))
|
||||
// accepted
|
||||
.and(qBorrowRequest.status.eq(BorrowRequestStatus.ACCEPTED))
|
||||
// expires after start
|
||||
@@ -96,8 +101,8 @@ public class BorrowRequestValidator implements Validator {
|
||||
errors.rejectValue("starts", "ALREADY_USED");
|
||||
errors.rejectValue("ends", "ALREADY_USED");
|
||||
} else {
|
||||
if (borrowItem.getMinDuration() != null && borrowItem.getMinDuration().compareTo(
|
||||
Duration.between(borrowRequest.getEnds(), borrowRequest.getStarts())) > 0) {
|
||||
if (borrowItem.getMinDuration() != null && borrowItem.getMinDuration()
|
||||
.compareTo(Duration.between(borrowRequest.getEnds(), borrowRequest.getStarts())) > 0) {
|
||||
errors.rejectValue("starts", "TOO_SHORT");
|
||||
errors.rejectValue("ends", "TOO_SHORT");
|
||||
} else if (borrowItem.getMaxDuration() != null
|
||||
@@ -119,12 +124,10 @@ public class BorrowRequestValidator implements Validator {
|
||||
for (BorrowItemSlot borrowItemSlot : borrowItem.getSlots()) {
|
||||
if (borrowItemSlot instanceof BorrowItemManualSlot) {
|
||||
BorrowItemManualSlot borrowItemManualSlot = (BorrowItemManualSlot) borrowItemSlot;
|
||||
if (borrowRequest.getStarts()
|
||||
.compareTo(borrowItemManualSlot.getStart()) >= 0) {
|
||||
if (borrowRequest.getStarts().compareTo(borrowItemManualSlot.getStart()) >= 0) {
|
||||
validStart = true;
|
||||
}
|
||||
if (borrowRequest.getEnds()
|
||||
.compareTo(borrowItemManualSlot.getEnd()) <= 0) {
|
||||
if (borrowRequest.getEnds().compareTo(borrowItemManualSlot.getEnd()) <= 0) {
|
||||
validEnd = true;
|
||||
}
|
||||
if (validStart && validEnd) {
|
||||
@@ -140,8 +143,7 @@ public class BorrowRequestValidator implements Validator {
|
||||
BorrowItemPeriodSlot borrowItemPeriodSlot = (BorrowItemPeriodSlot) borrowItemSlot;
|
||||
if (borrowRequest.getStarts().atZone(ZoneOffset.UTC).getDayOfWeek()
|
||||
.compareTo(borrowItemPeriodSlot.getStartDay()) >= 0
|
||||
&& LocalTime
|
||||
.ofInstant(borrowRequest.getStarts(), ZoneOffset.UTC)
|
||||
&& LocalTime.ofInstant(borrowRequest.getStarts(), ZoneOffset.UTC)
|
||||
.compareTo(borrowItemPeriodSlot.getStartTime()) >= 0) {
|
||||
validStart = true;
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,6 +13,6 @@ import de.bstly.we.borrow.model.BorrowItemManualSlot;
|
||||
* The Interface BorrowItemManualSlotRepository.
|
||||
*/
|
||||
@Repository
|
||||
public interface BorrowItemManualSlotRepository extends JpaRepository<BorrowItemManualSlot, Long>,
|
||||
QuerydslPredicateExecutor<BorrowItemManualSlot> {
|
||||
public interface BorrowItemManualSlotRepository
|
||||
extends JpaRepository<BorrowItemManualSlot, Long>, QuerydslPredicateExecutor<BorrowItemManualSlot> {
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,6 +13,6 @@ import de.bstly.we.borrow.model.BorrowItemPeriodSlot;
|
||||
* The Interface BorrowItemPeriodSlotRepository.
|
||||
*/
|
||||
@Repository
|
||||
public interface BorrowItemPeriodSlotRepository extends JpaRepository<BorrowItemPeriodSlot, Long>,
|
||||
QuerydslPredicateExecutor<BorrowItemPeriodSlot> {
|
||||
public interface BorrowItemPeriodSlotRepository
|
||||
extends JpaRepository<BorrowItemPeriodSlot, Long>, QuerydslPredicateExecutor<BorrowItemPeriodSlot> {
|
||||
}
|
||||
|
||||
@@ -13,6 +13,5 @@ import de.bstly.we.borrow.model.BorrowItem;
|
||||
* The Interface BorrowItemRepository.
|
||||
*/
|
||||
@Repository
|
||||
public interface BorrowItemRepository
|
||||
extends JpaRepository<BorrowItem, Long>, QuerydslPredicateExecutor<BorrowItem> {
|
||||
public interface BorrowItemRepository extends JpaRepository<BorrowItem, Long>, QuerydslPredicateExecutor<BorrowItem> {
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface BorrowRequestRepository
|
||||
/**
|
||||
* Find all by owner.
|
||||
*
|
||||
* @param owner the owner
|
||||
* @param owner the owner
|
||||
* @param pageable the pageable
|
||||
* @return the page
|
||||
*/
|
||||
@@ -43,13 +43,13 @@ public interface BorrowRequestRepository
|
||||
/**
|
||||
* Find all by owner and status.
|
||||
*
|
||||
* @param owner the owner
|
||||
* @param status the status
|
||||
* @param owner the owner
|
||||
* @param status the status
|
||||
* @param pageable the pageable
|
||||
* @return the page
|
||||
*/
|
||||
@Query("SELECT request FROM BorrowRequest request INNER JOIN BorrowItem as item ON request.item = item.id WHERE item.owner = :owner AND request.status = :status")
|
||||
Page<BorrowRequest> findAllByOwnerAndStatus(@Param("owner") Long owner,
|
||||
@Param("status") BorrowRequestStatus status, Pageable pageable);
|
||||
Page<BorrowRequest> findAllByOwnerAndStatus(@Param("owner") Long owner, @Param("status") BorrowRequestStatus status,
|
||||
Pageable pageable);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user