upgrade spring, add javadoc, formatting
This commit is contained in:
parent
8ebed47574
commit
eb829bfa26
@ -20,7 +20,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class Application extends SpringBootServletInitializer {
|
||||
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
@ -31,7 +31,9 @@ public class Application extends SpringBootServletInitializer {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.boot.web.servlet.support.SpringBootServletInitializer#onStartup(javax.servlet.ServletContext)
|
||||
* @see
|
||||
* org.springframework.boot.web.servlet.support.SpringBootServletInitializer#
|
||||
* onStartup(javax.servlet.ServletContext)
|
||||
*/
|
||||
@Override
|
||||
public void onStartup(ServletContext servletContext) throws ServletException {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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> {
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
14
core/pom.xml
14
core/pom.xml
@ -7,7 +7,7 @@
|
||||
<artifactId>webstly-main</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<name>core</name>
|
||||
<artifactId>webstly-core</artifactId>
|
||||
|
||||
@ -56,6 +56,12 @@
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>31.1-jre</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
@ -64,7 +70,7 @@
|
||||
<dependency>
|
||||
<groupId>org.passay</groupId>
|
||||
<artifactId>passay</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -76,7 +82,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.66</version>
|
||||
<version>1.70</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -87,7 +93,7 @@
|
||||
<dependency>
|
||||
<groupId>javax.measure</groupId>
|
||||
<artifactId>unit-api</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<version>2.1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -42,13 +42,13 @@ public class PermissionManager implements UserDataProvider {
|
||||
* Gets the.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @return the list
|
||||
*/
|
||||
public List<Permission> get(Long target, String name) {
|
||||
if (target != null && StringUtils.hasText(name)) {
|
||||
return Lists.newArrayList(permissionRepository
|
||||
.findAll(qPermission.target.eq(target).and(qPermission.name.eq(name))));
|
||||
return Lists.newArrayList(
|
||||
permissionRepository.findAll(qPermission.target.eq(target).and(qPermission.name.eq(name))));
|
||||
}
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
@ -57,15 +57,14 @@ public class PermissionManager implements UserDataProvider {
|
||||
* Gets the not expires.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @return the not expires
|
||||
*/
|
||||
public List<Permission> getNotExpires(Long target, String name) {
|
||||
if (target != null && StringUtils.hasText(name)) {
|
||||
return Lists.newArrayList(permissionRepository
|
||||
.findAll(qPermission.target.eq(target).and(qPermission.name.eq(name))
|
||||
.and(qPermission.expires.after(Instant.now()).and(qPermission.starts
|
||||
.isNull().or(qPermission.starts.before(Instant.now()))))));
|
||||
return Lists.newArrayList(permissionRepository.findAll(qPermission.target.eq(target)
|
||||
.and(qPermission.name.eq(name)).and(qPermission.expires.after(Instant.now())
|
||||
.and(qPermission.starts.isNull().or(qPermission.starts.before(Instant.now()))))));
|
||||
}
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
@ -91,9 +90,9 @@ public class PermissionManager implements UserDataProvider {
|
||||
*/
|
||||
public List<Permission> getNotExpiresByTarget(Long target) {
|
||||
if (target != null) {
|
||||
return Lists.newArrayList(permissionRepository.findAll(qPermission.target.eq(target)
|
||||
.and(qPermission.expires.after(Instant.now()).and(qPermission.starts.isNull()
|
||||
.or(qPermission.starts.before(Instant.now()))))));
|
||||
return Lists.newArrayList(permissionRepository
|
||||
.findAll(qPermission.target.eq(target).and(qPermission.expires.after(Instant.now())
|
||||
.and(qPermission.starts.isNull().or(qPermission.starts.before(Instant.now()))))));
|
||||
}
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
@ -106,9 +105,9 @@ public class PermissionManager implements UserDataProvider {
|
||||
*/
|
||||
public List<Permission> getNotExpiresByName(String name) {
|
||||
if (name != null) {
|
||||
return Lists.newArrayList(permissionRepository.findAll(qPermission.name.eq(name)
|
||||
.and(qPermission.expires.after(Instant.now()).and(qPermission.starts.isNull()
|
||||
.or(qPermission.starts.before(Instant.now()))))));
|
||||
return Lists.newArrayList(
|
||||
permissionRepository.findAll(qPermission.name.eq(name).and(qPermission.expires.after(Instant.now())
|
||||
.and(qPermission.starts.isNull().or(qPermission.starts.before(Instant.now()))))));
|
||||
}
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
@ -121,8 +120,8 @@ public class PermissionManager implements UserDataProvider {
|
||||
*/
|
||||
public List<Permission> getNotExpiresByTargetIgnoreStart(Long target) {
|
||||
if (target != null) {
|
||||
return Lists.newArrayList(permissionRepository.findAll(
|
||||
qPermission.target.eq(target).and(qPermission.expires.after(Instant.now()))));
|
||||
return Lists.newArrayList(permissionRepository
|
||||
.findAll(qPermission.target.eq(target).and(qPermission.expires.after(Instant.now()))));
|
||||
}
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
@ -134,16 +133,16 @@ public class PermissionManager implements UserDataProvider {
|
||||
* @return true, if is full user
|
||||
*/
|
||||
public boolean isFullUser(Long target) {
|
||||
return permissionRepository.exists(qPermission.target.eq(target)
|
||||
.and(qPermission.addon.isFalse()).and(qPermission.expires.after(Instant.now()).and(
|
||||
qPermission.starts.isNull().or(qPermission.starts.before(Instant.now())))));
|
||||
return permissionRepository.exists(qPermission.target.eq(target).and(qPermission.addon.isFalse())
|
||||
.and(qPermission.expires.after(Instant.now())
|
||||
.and(qPermission.starts.isNull().or(qPermission.starts.before(Instant.now())))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for permission.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean hasPermission(Long target, String name) {
|
||||
@ -152,23 +151,21 @@ public class PermissionManager implements UserDataProvider {
|
||||
}
|
||||
|
||||
return target != null && permissionRepository.exists(qPermission.name.eq(name)
|
||||
.and(qPermission.target.eq(target))
|
||||
.and(qPermission.expires.after(Instant.now()).and(
|
||||
qPermission.starts.isNull().or(qPermission.starts.before(Instant.now())))));
|
||||
.and(qPermission.target.eq(target)).and(qPermission.expires.after(Instant.now())
|
||||
.and(qPermission.starts.isNull().or(qPermission.starts.before(Instant.now())))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param addon the addon
|
||||
* @param starts the starts
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param addon the addon
|
||||
* @param starts the starts
|
||||
* @param expires the expires
|
||||
* @return the permission
|
||||
*/
|
||||
public Permission create(Long target, String name, boolean addon, Instant starts,
|
||||
Instant expires) {
|
||||
public Permission create(Long target, String name, boolean addon, Instant starts, Instant expires) {
|
||||
Permission newPermission = new Permission();
|
||||
newPermission.setTarget(target);
|
||||
newPermission.setName(name);
|
||||
@ -186,11 +183,8 @@ public class PermissionManager implements UserDataProvider {
|
||||
* @return the permission
|
||||
*/
|
||||
public Permission update(Permission permission) {
|
||||
Assert.isTrue(permissionRepository.existsById(permission.getId()), "Permission '"
|
||||
+ permission.getName()
|
||||
+ "' for target + '"
|
||||
+ permission.getTarget()
|
||||
+ "' not exists!");
|
||||
Assert.isTrue(permissionRepository.existsById(permission.getId()),
|
||||
"Permission '" + permission.getName() + "' for target + '" + permission.getTarget() + "' not exists!");
|
||||
Permission updatePermission = permissionRepository.getById(permission.getId());
|
||||
updatePermission.setStarts(permission.getStarts());
|
||||
updatePermission.setExpires(permission.getExpires());
|
||||
@ -201,7 +195,7 @@ public class PermissionManager implements UserDataProvider {
|
||||
/**
|
||||
* Clone.
|
||||
*
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @param clone the clone
|
||||
* @return the list
|
||||
*/
|
||||
@ -210,11 +204,11 @@ public class PermissionManager implements UserDataProvider {
|
||||
|
||||
for (Permission permission : permissionRepository
|
||||
.findAll(qPermission.name.eq(name).and(qPermission.expires.after(Instant.now())))) {
|
||||
if (!permissionRepository.exists(
|
||||
qPermission.name.eq(clone).and(qPermission.target.eq(permission.getTarget()))
|
||||
if (!permissionRepository
|
||||
.exists(qPermission.name.eq(clone).and(qPermission.target.eq(permission.getTarget()))
|
||||
.and(qPermission.expires.goe(permission.getExpires())))) {
|
||||
permissions.add(create(permission.getTarget(), clone, permission.isAddon(),
|
||||
permission.getStarts(), permission.getExpires()));
|
||||
permissions.add(create(permission.getTarget(), clone, permission.isAddon(), permission.getStarts(),
|
||||
permission.getExpires()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,7 +219,7 @@ public class PermissionManager implements UserDataProvider {
|
||||
* Delete.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
*/
|
||||
public void delete(Long target, String name) {
|
||||
for (Permission permission : get(target, name)) {
|
||||
@ -254,14 +248,13 @@ public class PermissionManager implements UserDataProvider {
|
||||
/**
|
||||
* Apply item.
|
||||
*
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param answers the answers
|
||||
* @param starts the starts
|
||||
* @param starts the starts
|
||||
* @param expires the expires
|
||||
*/
|
||||
public void applyItem(Long target, Integer item, JsonArray answers, Instant starts,
|
||||
Instant expires) {
|
||||
public void applyItem(Long target, Integer item, JsonArray answers, Instant starts, Instant expires) {
|
||||
for (Permission permission : getForItem(target, item, answers, starts, expires)) {
|
||||
permissionRepository.save(permission);
|
||||
}
|
||||
@ -270,15 +263,14 @@ public class PermissionManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the for item.
|
||||
*
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param answers the answers
|
||||
* @param starts the starts
|
||||
* @param starts the starts
|
||||
* @param expires the expires
|
||||
* @return the for item
|
||||
*/
|
||||
public List<Permission> getForItem(Long target, Integer item, JsonArray answers, Instant starts,
|
||||
Instant expires) {
|
||||
public List<Permission> getForItem(Long target, Integer item, JsonArray answers, Instant starts, Instant expires) {
|
||||
List<Permission> permissions = Lists.newArrayList();
|
||||
for (PermissionMapping permissionMapping : permissionMappingManager.getAllByItem(item)) {
|
||||
for (String name : permissionMapping.getNames()) {
|
||||
@ -294,51 +286,42 @@ public class PermissionManager implements UserDataProvider {
|
||||
}
|
||||
|
||||
if (permissionMapping.isLifetimeRound()) {
|
||||
permissionStarts = InstantHelper.truncate(permissionStarts,
|
||||
permissionMapping.getLifetimeUnit());
|
||||
permissionStarts = InstantHelper.truncate(permissionStarts, permissionMapping.getLifetimeUnit());
|
||||
}
|
||||
|
||||
if (permissionsExpires == null) {
|
||||
permissionsExpires = InstantHelper.plus(
|
||||
permissionStarts == null ? Instant.now() : permissionStarts,
|
||||
permissionsExpires = InstantHelper.plus(permissionStarts == null ? Instant.now() : permissionStarts,
|
||||
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit());
|
||||
}
|
||||
|
||||
boolean additional = permissionMapping.isAddon();
|
||||
|
||||
for (JsonElement anwser : answers) {
|
||||
if (anwser.isJsonObject()
|
||||
&& anwser.getAsJsonObject().has("question_identifier")) {
|
||||
if (anwser.isJsonObject() && anwser.getAsJsonObject().has("question_identifier")) {
|
||||
if (StringUtils.hasText(permissionMapping.getStartsQuestion())
|
||||
&& permissionMapping.getStartsQuestion()
|
||||
.equals(anwser.getAsJsonObject().get("question_identifier")
|
||||
.getAsString())
|
||||
.equals(anwser.getAsJsonObject().get("question_identifier").getAsString())
|
||||
&& anwser.getAsJsonObject().has("answer")) {
|
||||
String dateTimeString = anwser.getAsJsonObject().get("answer")
|
||||
.getAsString();
|
||||
String dateTimeString = anwser.getAsJsonObject().get("answer").getAsString();
|
||||
if (StringUtils.hasText(dateTimeString)) {
|
||||
dateTimeString = dateTimeString.replace(" ", "T");
|
||||
permissionStarts = OffsetDateTime.parse(dateTimeString).toInstant();
|
||||
permissionsExpires = InstantHelper.plus(permissionStarts,
|
||||
permissionMapping.getLifetime(),
|
||||
permissionMapping.getLifetimeUnit());
|
||||
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit());
|
||||
additional = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(permissionMapping.getExpiresQuestion())
|
||||
&& permissionMapping.getExpiresQuestion()
|
||||
.equals(anwser.getAsJsonObject().get("question_identifier")
|
||||
.getAsString())
|
||||
.equals(anwser.getAsJsonObject().get("question_identifier").getAsString())
|
||||
&& anwser.getAsJsonObject().has("answer")) {
|
||||
String dateTimeString = anwser.getAsJsonObject().get("answer")
|
||||
.getAsString();
|
||||
String dateTimeString = anwser.getAsJsonObject().get("answer").getAsString();
|
||||
if (StringUtils.hasText(dateTimeString)) {
|
||||
dateTimeString = dateTimeString.replace(" ", "T");
|
||||
permissionsExpires = InstantHelper.plus(
|
||||
OffsetDateTime.parse(dateTimeString).toInstant(),
|
||||
permissionMapping.getLifetime(),
|
||||
permissionMapping.getLifetimeUnit());
|
||||
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit());
|
||||
additional = false;
|
||||
}
|
||||
}
|
||||
@ -372,18 +355,17 @@ public class PermissionManager implements UserDataProvider {
|
||||
permission.setStarts(permissionStarts);
|
||||
permission.setExpires(permissionsExpires);
|
||||
} else {
|
||||
if (permission.getStarts() != null
|
||||
&& permission.getStarts().isBefore(Instant.now())) {
|
||||
if (permission.getStarts() != null && permission.getStarts().isBefore(Instant.now())) {
|
||||
permission.setStarts(null);
|
||||
}
|
||||
|
||||
permission.setExpires(InstantHelper.plus(permission.getExpires(),
|
||||
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit()));
|
||||
permission.setExpires(InstantHelper.plus(permission.getExpires(), permissionMapping.getLifetime(),
|
||||
permissionMapping.getLifetimeUnit()));
|
||||
}
|
||||
|
||||
if (permissionMapping.isLifetimeRound()) {
|
||||
permission.setExpires(InstantHelper.truncate(permission.getExpires(),
|
||||
permissionMapping.getLifetimeUnit()));
|
||||
permission.setExpires(
|
||||
InstantHelper.truncate(permission.getExpires(), permissionMapping.getLifetimeUnit()));
|
||||
}
|
||||