added userdata, email to lowercase

This commit is contained in:
2021-10-28 11:51:22 +02:00
parent 2af3b8cd63
commit 67a66e3cb9
17 changed files with 366 additions and 104 deletions
@@ -3,6 +3,7 @@
*/
package de.bstly.we.borrow.businesslogic;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,15 +29,17 @@ import de.bstly.we.borrow.repository.BorrowItemManualSlotRepository;
import de.bstly.we.borrow.repository.BorrowItemPeriodSlotRepository;
import de.bstly.we.borrow.repository.BorrowItemRepository;
import de.bstly.we.borrow.repository.BorrowRequestRepository;
import de.bstly.we.businesslogic.UserDataProvider;
import de.bstly.we.businesslogic.UserManager;
import de.bstly.we.email.businesslogic.EmailManager;
import de.bstly.we.model.User;
import de.bstly.we.model.UserData;
/**
* The Class BorrowItemManager.
*/
@Component
public class BorrowItemManager {
public class BorrowItemManager implements UserDataProvider {
@Autowired
private BorrowItemRepository borrowItemRepository;
@@ -252,4 +255,40 @@ public class BorrowItemManager {
// TODO: send email
}
/*
* @see de.bstly.we.businesslogic.UserDataProvider#getId()
*/
@Override
public String getId() {
return "borrow-items";
}
/*
* @see de.bstly.we.businesslogic.UserDataProvider#getUserData(java.lang.Long)
*/
@Override
public List<UserData> getUserData(Long userId) {
List<UserData> result = Lists.newArrayList();
Iterator<BorrowItem> items = borrowItemRepository.findAll(qBorrowItem.owner.eq(userId))
.iterator();
while (items.hasNext()) {
result.add(items.next());
}
return result;
}
/*
* @see de.bstly.we.businesslogic.UserDataProvider#purgeUserData(java.lang.Long)
*/
@Override
public void purgeUserData(Long userId) {
Iterator<BorrowItem> items = borrowItemRepository.findAll(qBorrowItem.owner.eq(userId))
.iterator();
while (items.hasNext()) {
delete(items.next());
}
}
}
@@ -6,6 +6,8 @@ package de.bstly.we.borrow.businesslogic;
import java.text.ParseException;
import java.time.Instant;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -14,6 +16,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import com.beust.jcommander.internal.Lists;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JOSEObjectType;
import com.nimbusds.jose.JWSHeader;
@@ -26,16 +29,18 @@ import de.bstly.we.borrow.model.BorrowRequest;
import de.bstly.we.borrow.model.BorrowRequestStatus;
import de.bstly.we.borrow.model.QBorrowRequest;
import de.bstly.we.borrow.repository.BorrowRequestRepository;
import de.bstly.we.businesslogic.UserDataProvider;
import de.bstly.we.businesslogic.UserManager;
import de.bstly.we.jwt.businesslogic.JwtKeyManager;
import de.bstly.we.jwt.model.JwtKey;
import de.bstly.we.model.User;
import de.bstly.we.model.UserData;
/**
* The Class BorrowRequestManager.
*/
@Component
public class BorrowRequestManager {
public class BorrowRequestManager implements UserDataProvider {
@Autowired
private BorrowRequestRepository borrowRequestRepository;
@@ -63,10 +68,10 @@ public class BorrowRequestManager {
/**
* 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
*/
@@ -79,11 +84,11 @@ public class BorrowRequestManager {
/**
* Gets the for user and stauts.
*
* @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 stauts
*/
@@ -98,10 +103,10 @@ public class BorrowRequestManager {
/**
* 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
*/
@@ -114,11 +119,11 @@ public class BorrowRequestManager {
/**
* 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
*/
@@ -160,7 +165,7 @@ public class BorrowRequestManager {
* 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
*/
@@ -217,7 +222,7 @@ public class BorrowRequestManager {
*
* @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 {
@@ -239,4 +244,51 @@ public class BorrowRequestManager {
return jwt.verify(jwtKeyManager.createVerfifier(jwtKey));
}
/*
* @see de.bstly.we.businesslogic.UserDataProvider#getId()
*/
@Override
public String getId() {
return "borrow-requests";
}
/*
* @see de.bstly.we.businesslogic.UserDataProvider#getUserData(java.lang.Long)
*/
@Override
public List<UserData> getUserData(Long userId) {
List<UserData> result = Lists.newArrayList();
Iterator<BorrowRequest> userRequests = borrowRequestRepository
.findAll(qBorrowRequest.user.eq(userId)).iterator();
while (userRequests.hasNext()) {
result.add(userRequests.next());
}
Iterator<BorrowRequest> ownerRequests = borrowRequestRepository.findAllByOwner(userId)
.iterator();
while (ownerRequests.hasNext()) {
result.add(ownerRequests.next());
}
return result;
}
/*
* @see de.bstly.we.businesslogic.UserDataProvider#purgeUserData(java.lang.Long)
*/
@Override
public void purgeUserData(Long userId) {
Iterator<BorrowRequest> userRequests = borrowRequestRepository
.findAll(qBorrowRequest.user.eq(userId)).iterator();
while (userRequests.hasNext()) {
delete(userRequests.next());
}
Iterator<BorrowRequest> ownerRequests = borrowRequestRepository.findAllByOwner(userId)
.iterator();
while (ownerRequests.hasNext()) {
delete(ownerRequests.next());
}
}
}
@@ -19,13 +19,15 @@ import javax.persistence.Transient;
import com.fasterxml.jackson.annotation.JsonInclude;
import de.bstly.we.model.UserData;
/**
* The Class BorrowItem.
*/
@Entity
@Table(name = "borrow_items")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class BorrowItem {
public class BorrowItem implements UserData {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -16,12 +16,14 @@ import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;
import de.bstly.we.model.UserData;
/**
* The Class BorrowRequest.
*/
@Entity
@Table(name = "borrow_requests")
public class BorrowRequest {
public class BorrowRequest implements UserData {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -24,7 +24,17 @@ public interface BorrowRequestRepository
/**
* Find all by owner.
*
* @param owner the owner
* @param owner the owner
* @param pageable the pageable
* @return the page
*/
@Query("SELECT request FROM BorrowRequest request INNER JOIN BorrowItem item ON request.item = item.id WHERE item.owner = :owner")
Iterable<BorrowRequest> findAllByOwner(@Param("owner") Long owner);
/**
* Find all by owner.
*
* @param owner the owner
* @param pageable the pageable
* @return the page
*/
@@ -34,8 +44,8 @@ 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
*/