new voucher system + jdoc

This commit is contained in:
2021-10-06 15:25:13 +02:00
parent 456332f24e
commit 442bdb4996
234 changed files with 4793 additions and 2737 deletions
@@ -32,8 +32,7 @@ import de.bstly.we.urlshortener.model.ShortenedUrl;
import de.bstly.we.urlshortener.repository.ShortenedUrlRepository;
/**
* @author _bastler@bstly.de
*
* The Class ShortenedUrlManager.
*/
@Component
public class ShortenedUrlManager implements SmartInitializingSingleton, UserDataProvider {
@@ -57,9 +56,9 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
public static final String SYSTEM_PROPERTY_URL_SHORTENER_NOT_FOUND = "urlShortener.notFoundRedirect";
public static final String SYSTEM_PROPERTY_URL_SHORTENER_PASSWORD = "urlShortener.passwordRedirect";
/*
* @see org.springframework.beans.factory.SmartInitializingSingleton#
* afterSingletonsInstantiated()
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
*/
@Override
public void afterSingletonsInstantiated() {
@@ -84,31 +83,34 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
}
/**
*
* @param code
* @return
* Gets the.
*
* @param code the code
* @return the shortened url
*/
public ShortenedUrl get(String code) {
return shortenedUrlRepository.findById(code).orElse(null);
}
/**
*
* @param userId
* @return
* Gets the all by owner.
*
* @param userId the user id
* @return the all by owner
*/
public List<ShortenedUrl> getAllByOwner(Long userId) {
return Lists.newArrayList(shortenedUrlRepository.findAll(qShortenedUrl.owner.eq(userId)));
}
/**
*
* @param page
* @param size
* @param sortBy
* @param descending
* @param search
* @return
* Gets the.
*
* @param page the page
* @param size the size
* @param sortBy the sort by
* @param descending the descending
* @param search the search
* @return the page
*/
public Page<ShortenedUrl> get(int page, int size, String sortBy, boolean descending,
String search) {
@@ -126,14 +128,15 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
}
/**
*
* @param userId
* @param page
* @param size
* @param sortBy
* @param descending
* @param search
* @return
* Gets the for user id.
*
* @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
* @return the for user id
*/
public Page<ShortenedUrl> getForUserId(Long userId, int page, int size, String sortBy,
boolean descending, String search) {
@@ -156,14 +159,17 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
}
/**
*
* @param owner
* @param url
* @param code
* @param expires
* @param password
* @param quota
* @return
* Creates the.
*
* @param owner the owner
* @param url the url
* @param note the note
* @param code the code
* @param expires the expires
* @param password the password
* @param queryParameters the query parameters
* @param quota the quota
* @return the shortened url
*/
public ShortenedUrl create(Long owner, String url, String note, String code, Instant expires,
String password, boolean queryParameters, boolean quota) {
@@ -210,9 +216,10 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
}
/**
*
* @param shortenedUrl
* @return
* Save.
*
* @param shortenedUrl the shortened url
* @return the shortened url
*/
public ShortenedUrl save(ShortenedUrl shortenedUrl) {
@@ -225,9 +232,10 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
}
/**
*
* @param shortenedUrl
* @param quota
* Delete.
*
* @param shortenedUrl the shortened url
* @param quota the quota
*/
public void delete(ShortenedUrl shortenedUrl, boolean quota) {
if (quota) {
@@ -246,9 +254,10 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
}
/**
*
* @param owner
* @param quota
* Delete all.
*
* @param owner the owner
* @param quota the quota
*/
public void deleteAll(Long owner, boolean quota) {
List<ShortenedUrl> shortenedUrls = Lists
@@ -259,6 +268,7 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
}
}
/*
* @see de.bstly.we.businesslogic.UserDataProvider#getId()
*/
@@ -267,6 +277,7 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
return "shortend-urls";
}
/*
* @see de.bstly.we.businesslogic.UserDataProvider#getUserData(java.lang.Long)
*/
@@ -279,6 +290,7 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
return result;
}
/*
* @see de.bstly.we.businesslogic.UserDataProvider#purgeUserData(java.lang.Long)
*/
@@ -290,7 +302,7 @@ public class ShortenedUrlManager implements SmartInitializingSingleton, UserData
}
/**
*
* Clear or update shortened urls.
*/
@Scheduled(cron = "0 */5 * * * *")
public void clearOrUpdateShortenedUrls() {
@@ -4,8 +4,7 @@
package de.bstly.we.urlshortener.businesslogic;
/**
* @author _bastler@bstly.de
*
* The Interface ShortenedUrlPermissions.
*/
public interface ShortenedUrlPermissions {
public static final String URL_SHORTENER = "url_shortener";
@@ -4,8 +4,7 @@
package de.bstly.we.urlshortener.businesslogic;
/**
* @author _bastler@bstly.de
*
* The Interface ShortenedUrlQuotas.
*/
public interface ShortenedUrlQuotas {
@@ -44,8 +44,7 @@ import de.bstly.we.urlshortener.controller.validation.ShortenedUrlModelValidator
import de.bstly.we.urlshortener.model.ShortenedUrl;
/**
* @author _bastler@bstly.de
*
* The Class ShortenedUrlController.
*/
@RestController
@RequestMapping("/url/shortener")
@@ -65,11 +64,13 @@ public class ShortenedUrlController extends BaseController {
private ShortenedUrlModelValidator shortenedUrlModelValidator;
/**
*
* @param code
* @param request
* @param response
* @throws IOException
* Gets the shortened url link.
*
* @param code the code
* @param request the request
* @param response the response
* @return the shortened url link
* @throws IOException Signals that an I/O exception has occurred.
*/
@GetMapping("/{code}")
public void getShortenedUrlLink(@PathVariable("code") String code, HttpServletRequest request,
@@ -104,12 +105,14 @@ public class ShortenedUrlController extends BaseController {
}
/**
*
* @param code
* @param password
* @param request
* @param response
* @throws IOException
* Gets the protected shortened url link.
*
* @param code the code
* @param password the password
* @param request the request
* @param response the response
* @return the protected shortened url link
* @throws IOException Signals that an I/O exception has occurred.
*/
@PostMapping("/{code}")
public void getProtectedShortenedUrlLink(@PathVariable("code") String code,
@@ -159,11 +162,12 @@ public class ShortenedUrlController extends BaseController {
}
/**
*
* @param shortenedUrl
* @param request
* @param response
* @throws IOException
* Send valid redirect.
*
* @param shortenedUrl the shortened url
* @param request the request
* @param response the response
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void sendValidRedirect(ShortenedUrl shortenedUrl, HttpServletRequest request,
HttpServletResponse response) throws IOException {
@@ -184,9 +188,10 @@ public class ShortenedUrlController extends BaseController {
}
/**
*
* @param code
* @return
* Gets the shortened url.
*
* @param code the code
* @return the shortened url
*/
@PreAuthorize("isAuthenticated()")
@GetMapping("/model/{code}")
@@ -211,8 +216,14 @@ public class ShortenedUrlController extends BaseController {
}
/**
*
* @return
* Gets the shortened urls.
*
* @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
* @return the shortened urls
*/
@PreAuthorize("isAuthenticated()")
@GetMapping
@@ -234,9 +245,10 @@ public class ShortenedUrlController extends BaseController {
}
/**
*
* @param shortenedUrlModel
* @return
* Creates the shortened url.
*
* @param shortenedUrlModel the shortened url model
* @return the shortened url
*/
@PreAuthorize("isAuthenticated()")
@PostMapping
@@ -268,9 +280,10 @@ public class ShortenedUrlController extends BaseController {
}
/**
*
* @param shortenedUrlModel
* @return
* Update shortened url.
*
* @param shortenedUrlModel the shortened url model
* @return the shortened url
*/
@PreAuthorize("isAuthenticated()")
@PatchMapping
@@ -333,8 +346,9 @@ public class ShortenedUrlController extends BaseController {
}
/**
*
* @param id
* Delete shortened url.
*
* @param code the code
*/
@PreAuthorize("isAuthenticated()")
@DeleteMapping("/{code}")
@@ -24,8 +24,7 @@ import de.bstly.we.urlshortener.businesslogic.ShortenedUrlManager;
import de.bstly.we.urlshortener.model.ShortenedUrl;
/**
* @author _bastler@bstly.de
*
* The Class ShortenedUrlManagementController.
*/
@RestController
@RequestMapping("/url/shortener/manage")
@@ -35,8 +34,12 @@ public class ShortenedUrlManagementController extends BaseController {
private ShortenedUrlManager shortenedUrlManager;
/**
*
* @return
* Gets the shortened urls.
*
* @param pageParameter the page parameter
* @param sizeParameter the size parameter
* @param searchParameter the search parameter
* @return the shortened urls
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping
@@ -49,9 +52,10 @@ public class ShortenedUrlManagementController extends BaseController {
}
/**
*
* @param shortenedUrl
* @return
* Creates the or update shortened url.
*
* @param shortenedUrl the shortened url
* @return the shortened url
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@PostMapping
@@ -60,8 +64,10 @@ public class ShortenedUrlManagementController extends BaseController {
}
/**
*
* @param id
* Delete shortened url.
*
* @param code the code
* @param quota the quota
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@DeleteMapping("/{code}")
@@ -77,8 +83,10 @@ public class ShortenedUrlManagementController extends BaseController {
}
/**
*
* @param owner
* Delete all.
*
* @param owner the owner
* @param quota the quota
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@DeleteMapping("/all/{owner}")
@@ -6,8 +6,7 @@ package de.bstly.we.urlshortener.controller.model;
import java.time.Instant;
/**
* @author _bastler@bstly.de
*
* The Class ShortenedUrlModel.
*/
public class ShortenedUrlModel {
@@ -22,6 +21,8 @@ public class ShortenedUrlModel {
private boolean newPassword;
/**
* Gets the code.
*
* @return the code
*/
public String getCode() {
@@ -29,27 +30,35 @@ public class ShortenedUrlModel {
}
/**
* @param code the code to set
* Sets the code.
*
* @param code the new code
*/
public void setCode(String code) {
this.code = code;
}
/**
* @return the newCode
* Gets the new code.
*
* @return the new code
*/
public String getNewCode() {
return newCode;
}
/**
* @param newCode the newCode to set
* Sets the new code.
*
* @param newCode the new new code
*/
public void setNewCode(String newCode) {
this.newCode = newCode;
}
/**
* Gets the url.
*
* @return the url
*/
public String getUrl() {
@@ -57,13 +66,17 @@ public class ShortenedUrlModel {
}
/**
* @param url the url to set
* Sets the url.
*
* @param url the new url
*/
public void setUrl(String url) {
this.url = url;
}
/**
* Gets the note.
*
* @return the note
*/
public String getNote() {
@@ -71,13 +84,17 @@ public class ShortenedUrlModel {
}
/**
* @param note the note to set
* Sets the note.
*
* @param note the new note
*/
public void setNote(String note) {
this.note = note;
}
/**
* Gets the expires.
*
* @return the expires
*/
public Instant getExpires() {
@@ -85,13 +102,17 @@ public class ShortenedUrlModel {
}
/**
* @param expires the expires to set
* Sets the expires.
*
* @param expires the new expires
*/
public void setExpires(Instant expires) {
this.expires = expires;
}
/**
* Gets the password.
*
* @return the password
*/
public String getPassword() {
@@ -99,49 +120,63 @@ public class ShortenedUrlModel {
}
/**
* @param password the password to set
* Sets the password.
*
* @param password the new password
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the password2
* Gets the password 2.
*
* @return the password 2
*/
public String getPassword2() {
return password2;
}
/**
* @param password2 the password2 to set
* Sets the password 2.
*
* @param password2 the new password 2
*/
public void setPassword2(String password2) {
this.password2 = password2;
}
/**
* @return the queryParameters
* Checks if is query parameters.
*
* @return true, if is query parameters
*/
public boolean isQueryParameters() {
return queryParameters;
}
/**
* @param queryParameters the queryParameters to set
* Sets the query parameters.
*
* @param queryParameters the new query parameters
*/
public void setQueryParameters(boolean queryParameters) {
this.queryParameters = queryParameters;
}
/**
* @return the newPassword
* Checks if is new password.
*
* @return true, if is new password
*/
public boolean isNewPassword() {
return newPassword;
}
/**
* @param newPassword the newPassword to set
* Sets the new password.
*
* @param newPassword the new new password
*/
public void setNewPassword(boolean newPassword) {
this.newPassword = newPassword;
@@ -16,8 +16,7 @@ import de.bstly.we.urlshortener.businesslogic.ShortenedUrlManager;
import de.bstly.we.urlshortener.controller.model.ShortenedUrlModel;
/**
* @author _bastler@bstly.de
*
* The Class ShortenedUrlModelValidator.
*/
@Component
public class ShortenedUrlModelValidator implements Validator {
@@ -27,6 +26,7 @@ public class ShortenedUrlModelValidator implements Validator {
private UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES);
protected static final String codePart = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\\\.[A-Z0-9_!#$%&'*+/=?`{|}~^-]+)*$";
/*
* @see org.springframework.validation.Validator#supports(java.lang.Class)
*/
@@ -35,9 +35,9 @@ public class ShortenedUrlModelValidator implements Validator {
return clazz.isAssignableFrom(ShortenedUrlModel.class);
}
/*
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
* @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
*/
@Override
public void validate(Object target, Errors errors) {
@@ -23,8 +23,7 @@ import de.bstly.we.model.AbstractModel;
import de.bstly.we.model.UserData;
/**
* @author _bastler@bstly.de
*
* The Class ShortenedUrl.
*/
@Entity
@Table(name = "shortened_urls")
@@ -51,6 +50,8 @@ public class ShortenedUrl implements UserData, AbstractModel {
private boolean hasPassword;
/**
* Gets the code.
*
* @return the code
*/
public String getCode() {
@@ -58,13 +59,17 @@ public class ShortenedUrl implements UserData, AbstractModel {
}
/**
* @param code the code to set
* Sets the code.
*
* @param code the new code
*/
public void setCode(String code) {
this.code = code;
}
/**
* Gets the owner.
*
* @return the owner
*/
public Long getOwner() {
@@ -72,13 +77,17 @@ public class ShortenedUrl implements UserData, AbstractModel {
}
/**
* @param owner the owner to set
* Sets the owner.
*
* @param owner the new owner
*/
public void setOwner(Long owner) {
this.owner = owner;
}
/**
* Gets the url.
*
* @return the url
*/
public String getUrl() {
@@ -86,13 +95,17 @@ public class ShortenedUrl implements UserData, AbstractModel {
}
/**
* @param url the url to set
* Sets the url.
*
* @param url the new url
*/
public void setUrl(String url) {
this.url = url;
}
/**
* Gets the expires.
*
* @return the expires
*/
public Instant getExpires() {
@@ -100,27 +113,35 @@ public class ShortenedUrl implements UserData, AbstractModel {
}
/**
* @param expires the expires to set
* Sets the expires.
*
* @param expires the new expires
*/
public void setExpires(Instant expires) {
this.expires = expires;
}
/**
* @return the passwordHash
* Gets the password hash.
*
* @return the password hash
*/
public String getPasswordHash() {
return passwordHash;
}
/**
* @param passwordHash the passwordHash to set
* Sets the password hash.
*
* @param passwordHash the new password hash
*/
public void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
/**
* Gets the link.
*
* @return the link
*/
public String getLink() {
@@ -128,13 +149,17 @@ public class ShortenedUrl implements UserData, AbstractModel {
}
/**
* @param link the link to set
* Sets the link.
*
* @param link the new link
*/
public void setLink(String link) {
this.link = link;
}
/**
* Gets the note.
*
* @return the note
*/
public String getNote() {
@@ -142,28 +167,36 @@ public class ShortenedUrl implements UserData, AbstractModel {
}
/**
* @param note the note to set
* Sets the note.
*
* @param note the new note
*/
public void setNote(String note) {
this.note = note;
}
/**
* @return the queryParameters
* Checks if is query parameters.
*
* @return true, if is query parameters
*/
public boolean isQueryParameters() {
return queryParameters;
}
/**
* @param queryParameters the queryParameters to set
* Sets the query parameters.
*
* @param queryParameters the new query parameters
*/
public void setQueryParameters(boolean queryParameters) {
this.queryParameters = queryParameters;
}
/**
* @return the hasPassword
* Checks if is checks for password.
*
* @return true, if is checks for password
*/
public boolean isHasPassword() {
return StringUtils.hasText(passwordHash);
@@ -10,9 +10,7 @@ import org.springframework.stereotype.Repository;
import de.bstly.we.urlshortener.model.ShortenedUrl;
/**
*
* @author _bastler@bstly.de
*
* The Interface ShortenedUrlRepository.
*/
@Repository
public interface ShortenedUrlRepository