add lombok to clean codebase

This commit is contained in:
2025-11-09 18:40:38 +01:00
parent 8d9b10bace
commit c27e68caf0
88 changed files with 704 additions and 7787 deletions
+7
View File
@@ -111,5 +111,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
@@ -4,10 +4,14 @@
package de.bstly.we.controller.model;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
/**
* The Class ItemModel.
*/
@Getter
@Setter
public class ItemModel {
private Map<String, String> name;
@@ -22,31 +26,4 @@ public class ItemModel {
return name;
}
/**
* Sets the name.
*
* @param name the name
*/
public void setName(Map<String, String> name) {
this.name = name;
}
/**
* Gets the secret.
*
* @return the secret
*/
public String getSecret() {
return secret;
}
/**
* Sets the secret.
*
* @param secret the new secret
*/
public void setSecret(String secret) {
this.secret = secret;
}
}
@@ -7,49 +7,16 @@ import java.util.List;
import de.bstly.we.model.PermissionMapping;
import de.bstly.we.model.QuotaMapping;
import lombok.Getter;
import lombok.Setter;
/**
* The Class ItemResultModel.
*/
@Getter
@Setter
public class ItemResultModel {
private List<PermissionMapping> permissionMappings;
private List<QuotaMapping> quotaMappings;
/**
* Gets the permission mappings.
*
* @return the permission mappings
*/
public List<PermissionMapping> getPermissionMappings() {
return permissionMappings;
}
/**
* Sets the permission mappings.
*
* @param permissionMappings the new permission mappings
*/
public void setPermissionMappings(List<PermissionMapping> permissionMappings) {
this.permissionMappings = permissionMappings;
}
/**
* Gets the quota mappings.
*
* @return the quota mappings
*/
public List<QuotaMapping> getQuotaMappings() {
return quotaMappings;
}
/**
* Sets the quota mappings.
*
* @param quotaMappings the new quota mappings
*/
public void setQuotaMappings(List<QuotaMapping> quotaMappings) {
this.quotaMappings = quotaMappings;
}
}
@@ -3,48 +3,17 @@
*/
package de.bstly.we.controller.model;
import lombok.Getter;
import lombok.Setter;
/**
* The Class LoginModel.
*/
@Getter
@Setter
public class LoginModel {
private String username;
private String password;
/**
* Gets the username.
*
* @return the username
*/
public String getUsername() {
return username;
}
/**
* Sets the username.
*
* @param username the new username
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Gets the password.
*
* @return the password
*/
public String getPassword() {
return password;
}
/**
* Sets the password.
*
* @param password the new password
*/
public void setPassword(String password) {
this.password = password;
}
}
@@ -4,12 +4,16 @@
package de.bstly.we.controller.model;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
/**
* The Class PagesResult.
*
* @param <T> the generic type
*/
@Getter
@Setter
public class PagesResult<T extends Object> {
private List<T> result;
@@ -27,85 +31,4 @@ public class PagesResult<T extends Object> {
return result;
}
/**
* Sets the result.
*
* @param result the new result
*/
public void setResult(List<T> result) {
this.result = result;
}
/**
* Gets the size.
*
* @return the size
*/
public int getSize() {
return size;
}
/**
* Sets the size.
*
* @param size the new size
*/
public void setSize(int size) {
this.size = size;
}
/**
* Gets the page.
*
* @return the page
*/
public int getPage() {
return page;
}
/**
* Sets the page.
*
* @param page the new page
*/
public void setPage(int page) {
this.page = page;
}
/**
* Gets the total elements.
*
* @return the total elements
*/
public int getTotalElements() {
return totalElements;
}
/**
* Sets the total elements.
*
* @param totalElements the new total elements
*/
public void setTotalElements(int totalElements) {
this.totalElements = totalElements;
}
/**
* Gets the total pages.
*
* @return the total pages
*/
public int getTotalPages() {
return totalPages;
}
/**
* Sets the total pages.
*
* @param totalPages the new total pages
*/
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
}
@@ -3,66 +3,18 @@
*/
package de.bstly.we.controller.model;
import lombok.Getter;
import lombok.Setter;
/**
* The Class PasswordModel.
*/
@Getter
@Setter
public class PasswordModel {
private String old;
private String password;
private String password2;
/**
* Gets the old.
*
* @return the old
*/
public String getOld() {
return old;
}
/**
* Sets the old.
*
* @param old the new old
*/
public void setOld(String old) {
this.old = old;
}
/**
* Gets the password.
*
* @return the password
*/
public String getPassword() {
return password;
}
/**
* Sets the password.
*
* @param password the new password
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Gets the password 2.
*
* @return the password 2
*/
public String getPassword2() {
return password2;
}
/**
* Sets the password 2.
*
* @param password2 the new password 2
*/
public void setPassword2(String password2) {
this.password2 = password2;
}
}
@@ -3,29 +3,15 @@
*/
package de.bstly.we.controller.model;
import lombok.Getter;
import lombok.Setter;
/**
* The Class PasswordResetModel.
*/
@Getter
@Setter
public class PasswordResetModel extends PasswordModel {
private String token;
/**
* Gets the token.
*
* @return the token
*/
public String getToken() {
return token;
}
/**
* Sets the token.
*
* @param token the new token
*/
public void setToken(String token) {
this.token = token;
}
}
@@ -6,10 +6,14 @@ package de.bstly.we.controller.model;
import java.util.Map;
import org.springframework.http.HttpMethod;
import lombok.Getter;
import lombok.Setter;
/**
* The Class PretixRequest.
*/
@Getter
@Setter
public class PretixRequest {
private String path;
@@ -17,43 +21,7 @@ public class PretixRequest {
private Map<String, String> queryParameters;
private Object payload;
/**
* Gets the path.
*
* @return the path
*/
public String getPath() {
return path;
}
/**
* Sets the path.
*
* @param path the new path
*/
public void setPath(String path) {
this.path = path;
}
/**
* Gets the method.
*
* @return the method
*/
public HttpMethod getMethod() {
return method;
}
/**
* Sets the method.
*
* @param method the new method
*/
public void setMethod(HttpMethod method) {
this.method = method;
}
/**
/**
* Gets the query parameters.
*
* @return the query parameters
@@ -62,31 +30,4 @@ public class PretixRequest {
return queryParameters;
}
/**
* Sets the query parameters.
*
* @param queryParameters the query parameters
*/
public void setQueryParameters(Map<String, String> queryParameters) {
this.queryParameters = queryParameters;
}
/**
* Gets the payload.
*
* @return the payload
*/
public Object getPayload() {
return payload;
}
/**
* Sets the payload.
*
* @param payload the new payload
*/
public void setPayload(Object payload) {
this.payload = payload;
}
}
@@ -6,68 +6,18 @@ package de.bstly.we.controller.model;
import java.util.List;
import de.bstly.we.model.UserProfileField;
import lombok.Getter;
import lombok.Setter;
/**
* The Class ProfileModel.
*/
@Getter
@Setter
public class ProfileModel {
private String username;
private List<String> aliases;
private List<UserProfileField> profileFields;
/**
* Gets the username.
*
* @return the username
*/
public String getUsername() {
return username;
}
/**
* Sets the username.
*
* @param username the new username
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Gets the aliases.
*
* @return the aliases
*/
public List<String> getAliases() {
return aliases;
}
/**
* Sets the aliases.
*
* @param aliases the new aliases
*/
public void setAliases(List<String> aliases) {
this.aliases = aliases;
}
/**
* Gets the profile fields.
*
* @return the profile fields
*/
public List<UserProfileField> getProfileFields() {
return profileFields;
}
/**
* Sets the profile fields.
*
* @param profileFields the new profile fields
*/
public void setProfileFields(List<UserProfileField> profileFields) {
this.profileFields = profileFields;
}
}
@@ -3,60 +3,20 @@
*/
package de.bstly.we.controller.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
/**
* The Class SecondFactorProviderModel.
*/
@Getter
@Setter
@AllArgsConstructor
public class SecondFactorProviderModel {
private String id;
private boolean request;
/**
* Instantiates a new second factor provider model.
*
* @param id the id
* @param request the request
*/
public SecondFactorProviderModel(String id, boolean request) {
super();
this.id = id;
this.request = request;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(String id) {
this.id = id;
}
/**
* Checks if is request.
*
* @return true, if is request
*/
public boolean isRequest() {
return request;
}
/**
* Sets the request.
*
* @param request the new request
*/
public void setRequest(boolean request) {
this.request = request;
}
}
@@ -11,10 +11,14 @@ import de.bstly.we.model.Quota;
import de.bstly.we.model.QuotaMapping;
import de.bstly.we.model.UserProfileField;
import de.bstly.we.model.UserStatus;
import lombok.Getter;
import lombok.Setter;
/**
* The Class UserModel.
*/
@Getter
@Setter
public class UserModel extends PasswordModel {
private String username;
@@ -25,149 +29,4 @@ public class UserModel extends PasswordModel {
private UserStatus status;
private String token;
private List<UserProfileField> profileFields;
/**
* Gets the username.
*
* @return the username
*/
public String getUsername() {
return username;
}
/**
* Sets the username.
*
* @param username the new username
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Gets the permissions.
*
* @return the permissions
*/
public List<Permission> getPermissions() {
return permissions;
}
/**
* Sets the permissions.
*
* @param permissions the new permissions
*/
public void setPermissions(List<Permission> permissions) {
this.permissions = permissions;
}
/**
* Gets the permission mappings.
*
* @return the permission mappings
*/
public List<PermissionMapping> getPermissionMappings() {
return permissionMappings;
}
/**
* Sets the permission mappings.
*
* @param permissionMappings the new permission mappings
*/
public void setPermissionMappings(List<PermissionMapping> permissionMappings) {
this.permissionMappings = permissionMappings;
}
/**
* Gets the quotas.
*
* @return the quotas
*/
public List<Quota> getQuotas() {
return quotas;
}
/**
* Sets the quotas.
*
* @param quotas the new quotas
*/
public void setQuotas(List<Quota> quotas) {
this.quotas = quotas;
}
/**
* Gets the quota mappings.
*
* @return the quota mappings
*/
public List<QuotaMapping> getQuotaMappings() {
return quotaMappings;
}
/**
* Sets the quota mappings.
*
* @param quotaMappings the new quota mappings
*/
public void setQuotaMappings(List<QuotaMapping> quotaMappings) {
this.quotaMappings = quotaMappings;
}
/**
* Gets the status.
*
* @return the status
*/
public UserStatus getStatus() {
return status;
}
/**
* Sets the status.
*
* @param status the new status
*/
public void setStatus(UserStatus status) {
this.status = status;
}
/**
* Gets the token.
*
* @return the token
*/
public String getToken() {
return token;
}
/**
* Sets the token.
*
* @param token the new token
*/
public void setToken(String token) {
this.token = token;
}
/**
* Gets the profile fields.
*
* @return the profile fields
*/
public List<UserProfileField> getProfileFields() {
return profileFields;
}
/**
* Sets the profile fields.
*
* @param profileFields the new profile fields
*/
public void setProfileFields(List<UserProfileField> profileFields) {
this.profileFields = profileFields;
}
}
@@ -6,10 +6,14 @@ package de.bstly.we.event;
import org.springframework.context.ApplicationEvent;
import de.bstly.we.model.AbstractModel;
import lombok.Getter;
import lombok.Setter;
/**
* The Class AbstractModelEvent.
*/
@Getter
@Setter
public class AbstractModelEvent extends ApplicationEvent {
/**
@@ -20,52 +24,10 @@ public class AbstractModelEvent extends ApplicationEvent {
private AbstractModelEventType type;
private AbstractModel model;
/**
* Instantiates a new abstract model event.
*
* @param type the type
* @param model the model
*/
public AbstractModelEvent(AbstractModelEventType type, AbstractModel model) {
super(model);
this.type = type;
this.model = model;
}
/**
* Gets the type.
*
* @return the type
*/
public AbstractModelEventType getType() {
return type;
}
/**
* Sets the type.
*
* @param type the new type
*/
public void setType(AbstractModelEventType type) {
this.type = type;
}
/**
* Gets the model.
*
* @return the model
*/
public AbstractModel getModel() {
return model;
}
/**
* Sets the model.
*
* @param model the new model
*/
public void setModel(AbstractModel model) {
this.model = model;
}
}
@@ -11,12 +11,16 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
/**
* The Class Permission.
*/
@Entity
@Table(name = "permissions")
@Getter
@Setter
public class Permission implements UserData {
@Id
@@ -34,112 +38,4 @@ public class Permission implements UserData {
@Column(name = "expires")
private Instant expires;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the target.
*
* @return the target
*/
public Long getTarget() {
return target;
}
/**
* Sets the target.
*
* @param target the new target
*/
public void setTarget(Long target) {
this.target = target;
}
/**
* Checks if is addon.
*
* @return true, if is addon
*/
public boolean isAddon() {
return addon;
}
/**
* Sets the addon.
*
* @param addon the new addon
*/
public void setAddon(boolean addon) {
this.addon = addon;
}
/**
* Gets the starts.
*
* @return the starts
*/
public Instant getStarts() {
return starts;
}
/**
* Sets the starts.
*
* @param starts the new starts
*/
public void setStarts(Instant starts) {
this.starts = starts;
}
/**
* Gets the expires.
*
* @return the expires
*/
public Instant getExpires() {
return expires;
}
/**
* Sets the expires.
*
* @param expires the new expires
*/
public void setExpires(Instant expires) {
this.expires = expires;
}
}
@@ -19,12 +19,16 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
/**
* The Class PermissionMapping.
*/
@Entity
@Table(name = "permission_mappings")
@Getter
@Setter
public class PermissionMapping {
public static final ChronoUnit DEFAULT_LIFETIME_UNIT = ChronoUnit.DAYS;
@@ -58,222 +62,6 @@ public class PermissionMapping {
@Column(name = "expires_question")
private String expiresQuestion;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the product.
*
* @return the product
*/
public String getProduct() {
return product;
}
/**
* Sets the product.
*
* @param product the new product
*/
public void setProduct(String product) {
this.product = product;
}
/**
* Gets the item.
*
* @return the item
*/
public Integer getItem() {
return item;
}
/**
* Sets the item.
*
* @param item the new item
*/
public void setItem(Integer item) {
this.item = item;
}
/**
* Gets the names.
*
* @return the names
*/
public Set<String> getNames() {
return names;
}
/**
* Sets the names.
*
* @param names the new names
*/
public void setNames(Set<String> names) {
this.names = names;
}
/**
* Checks if is addon.
*
* @return true, if is addon
*/
public boolean isAddon() {
return addon;
}
/**
* Sets the addon.
*
* @param addon the new addon
*/
public void setAddon(boolean addon) {
this.addon = addon;
}
/**
* Gets the lifetime.
*
* @return the lifetime
*/
public Long getLifetime() {
return lifetime;
}
/**
* Sets the lifetime.
*
* @param lifetime the new lifetime
*/
public void setLifetime(Long lifetime) {
this.lifetime = lifetime;
}
/**
* Gets the lifetime unit.
*
* @return the lifetime unit
*/
public ChronoUnit getLifetimeUnit() {
return lifetimeUnit;
}
/**
* Sets the lifetime unit.
*
* @param lifetimeUnit the new lifetime unit
*/
public void setLifetimeUnit(ChronoUnit lifetimeUnit) {
this.lifetimeUnit = lifetimeUnit;
}
/**
* Checks if is lifetime round.
*
* @return true, if is lifetime round
*/
public boolean isLifetimeRound() {
return lifetimeRound;
}
/**
* Sets the lifetime round.
*
* @param lifetimeRound the new lifetime round
*/
public void setLifetimeRound(boolean lifetimeRound) {
this.lifetimeRound = lifetimeRound;
}
/**
* Gets the starts.
*
* @return the starts
*/
public Instant getStarts() {
return starts;
}
/**
* Sets the starts.
*
* @param starts the new starts
*/
public void setStarts(Instant starts) {
this.starts = starts;
}
/**
* Gets the expires.
*
* @return the expires
*/
public Instant getExpires() {
return expires;
}
/**
* Sets the expires.
*
* @param expires the new expires
*/
public void setExpires(Instant expires) {
this.expires = expires;
}
/**
* Gets the starts question.
*
* @return the starts question
*/
public String getStartsQuestion() {
return startsQuestion;
}
/**
* Sets the starts question.
*
* @param startsQuestion the new starts question
*/
public void setStartsQuestion(String startsQuestion) {
this.startsQuestion = startsQuestion;
}
/**
* Gets the expires question.
*
* @return the expires question
*/
public String getExpiresQuestion() {
return expiresQuestion;
}
/**
* Sets the expires question.
*
* @param expiresQuestion the new expires question
*/
public void setExpiresQuestion(String expiresQuestion) {
this.expiresQuestion = expiresQuestion;
}
/**
* The Class ChronoUnitConverter.
*/
@@ -9,12 +9,16 @@ import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
/**
* The Class PersistentLogin.
*/
@Entity
@Table(name = "persistent_logins")
@Getter
@Setter
public class PersistentLogin {
@Column(name = "username", length = 64, nullable = false)
@@ -27,76 +31,4 @@ public class PersistentLogin {
@Column(name = "last_used", nullable = false)
private Instant last_used;
/**
* Gets the username.
*
* @return the username
*/
public String getUsername() {
return username;
}
/**
* Sets the username.
*
* @param username the new username
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Gets the series.
*
* @return the series
*/
public String getSeries() {
return series;
}
/**
* Sets the series.
*
* @param series the new series
*/
public void setSeries(String series) {
this.series = series;
}
/**
* Gets the token.
*
* @return the token
*/
public String getToken() {
return token;
}
/**
* Sets the token.
*
* @param token the new token
*/
public void setToken(String token) {
this.token = token;
}
/**
* Gets the last used.
*
* @return the last used
*/
public Instant getLast_used() {
return last_used;
}
/**
* Sets the last used.
*
* @param last_used the new last used
*/
public void setLast_used(Instant last_used) {
this.last_used = last_used;
}
}
+4 -108
View File
@@ -9,12 +9,16 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
/**
* The Class Quota.
*/
@Entity
@Table(name = "quotas")
@Getter
@Setter
public class Quota implements UserData {
@Id
@@ -32,112 +36,4 @@ public class Quota implements UserData {
@Column(name = "disposable", columnDefinition = "boolean default false")
private boolean disposable;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the target.
*
* @return the target
*/
public Long getTarget() {
return target;
}
/**
* Sets the target.
*
* @param target the new target
*/
public void setTarget(Long target) {
this.target = target;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the value.
*
* @return the value
*/
public long getValue() {
return value;
}
/**
* Sets the value.
*
* @param value the new value
*/
public void setValue(long value) {
this.value = value;
}
/**
* Gets the unit.
*
* @return the unit
*/
public String getUnit() {
return unit;
}
/**
* Sets the unit.
*
* @param unit the new unit
*/
public void setUnit(String unit) {
this.unit = unit;
}
/**
* Checks if is disposable.
*
* @return true, if is disposable
*/
public boolean isDisposable() {
return disposable;
}
/**
* Sets the disposable.
*
* @param disposable the new disposable
*/
public void setDisposable(boolean disposable) {
this.disposable = disposable;
}
}
@@ -14,12 +14,16 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
/**
* The Class QuotaMapping.
*/
@Entity
@Table(name = "quota_mappings")
@Getter
@Setter
public class QuotaMapping {
@Id
@@ -42,149 +46,4 @@ public class QuotaMapping {
private boolean append;
@Column(name = "disposable", columnDefinition = "boolean default false")
private boolean disposable;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the products.
*
* @return the products
*/
public Set<String> getProducts() {
return products;
}
/**
* Sets the products.
*
* @param products the new products
*/
public void setProducts(Set<String> products) {
this.products = products;
}
/**
* Gets the items.
*
* @return the items
*/
public Set<Integer> getItems() {
return items;
}
/**
* Sets the items.
*
* @param items the new items
*/
public void setItems(Set<Integer> items) {
this.items = items;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the value.
*
* @return the value
*/
public long getValue() {
return value;
}
/**
* Sets the value.
*
* @param value the new value
*/
public void setValue(long value) {
this.value = value;
}
/**
* Gets the unit.
*
* @return the unit
*/
public String getUnit() {
return unit;
}
/**
* Sets the unit.
*
* @param unit the new unit
*/
public void setUnit(String unit) {
this.unit = unit;
}
/**
* Checks if is append.
*
* @return true, if is append
*/
public boolean isAppend() {
return append;
}
/**
* Sets the append.
*
* @param append the new append
*/
public void setAppend(boolean append) {
this.append = append;
}
/**
* Checks if is disposable.
*
* @return true, if is disposable
*/
public boolean isDisposable() {
return disposable;
}
/**
* Sets the disposable.
*
* @param disposable the new disposable
*/
public void setDisposable(boolean disposable) {
this.disposable = disposable;
}
}
@@ -7,12 +7,16 @@ import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
/**
* The Class SystemProfileField.
*/
@Entity
@Table(name = "system_profile_fields")
@Getter
@Setter
public class SystemProfileField {
@Id
@@ -23,58 +27,4 @@ public class SystemProfileField {
@Column(name = "unique_value", columnDefinition = "boolean default false")
private boolean uniqueValue;
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the type.
*
* @return the type
*/
public ProfileFieldType getType() {
return type;
}
/**
* Sets the type.
*
* @param type the new type
*/
public void setType(ProfileFieldType type) {
this.type = type;
}
/**
* Checks if is unique value.
*
* @return true, if is unique value
*/
public boolean isUniqueValue() {
return uniqueValue;
}
/**
* Sets the unique value.
*
* @param uniqueValue the new unique value
*/
public void setUniqueValue(boolean uniqueValue) {
this.uniqueValue = uniqueValue;
}
}
@@ -8,12 +8,20 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* The Class SystemProperty.
*/
@Entity
@Table(name = "system_properties")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SystemProperty {
@Id
@@ -23,59 +31,4 @@ public class SystemProperty {
@Column(name = "value", length = 100000)
private String value;
/**
* Instantiates a new system property.
*/
public SystemProperty() {
super();
}
/**
* Instantiates a new system property.
*
* @param key the key
* @param value the value
*/
public SystemProperty(String key, String value) {
super();
this.key = key;
this.value = value;
}
/**
* Gets the key.
*
* @return the key
*/
public String getKey() {
return key;
}
/**
* Sets the key.
*
* @param key the new key
*/
public void setKey(String key) {
this.key = key;
}
/**
* Gets the value.
*
* @return the value
*/
public String getValue() {
return value;
}
/**
* Sets the value.
*
* @param value the new value
*/
public void setValue(String value) {
this.value = value;
}
}
+4 -125
View File
@@ -12,12 +12,16 @@ import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
/**
* The Class User.
*/
@Entity
@Table(name = "users", uniqueConstraints = @UniqueConstraint(columnNames = { "username" }))
@Getter
@Setter
public class User implements UserData {
@Id
@@ -38,129 +42,4 @@ public class User implements UserData {
@Column(name = "reset_token")
private String resetToken;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the username.
*
* @return the username
*/
public String getUsername() {
return username;
}
/**
* Sets the username.
*
* @param username the new username
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Gets the password hash.
*
* @return the password hash
*/
public String getPasswordHash() {
return passwordHash;
}
/**
* Sets the password hash.
*
* @param passwordHash the new password hash
*/
public void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
/**
* Checks if is disabled.
*
* @return true, if is disabled
*/
public boolean isDisabled() {
return disabled;
}
/**
* Sets the disabled.
*
* @param disabled the new disabled
*/
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
/**
* Checks if is locked.
*
* @return true, if is locked
*/
public boolean isLocked() {
return locked;
}
/**
* Sets the locked.
*
* @param locked the new locked
*/
public void setLocked(boolean locked) {
this.locked = locked;
}
/**
* Gets the status.
*
* @return the status
*/
public UserStatus getStatus() {
return status;
}
/**
* Sets the status.
*
* @param status the new status
*/
public void setStatus(UserStatus status) {
this.status = status;
}
/**
* Gets the reset token.
*
* @return the reset token
*/
public String getResetToken() {
return resetToken;
}
/**
* Sets the reset token.
*
* @param resetToken the new reset token
*/
public void setResetToken(String resetToken) {
this.resetToken = resetToken;
}
}
@@ -10,12 +10,16 @@ import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.Getter;
import lombok.Setter;
/**
* The Class UserAlias.
*/
@Entity
@Table(name = "aliases", uniqueConstraints = @UniqueConstraint(columnNames = { "alias" }))
@Getter
@Setter
public class UserAlias implements UserData {
@Id
@@ -29,76 +33,4 @@ public class UserAlias implements UserData {
@Column(name = "visibility", nullable = false)
private Visibility visibility = Visibility.PROTECTED;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the target.
*
* @return the target
*/
public Long getTarget() {
return target;
}
/**
* Sets the target.
*
* @param target the new target
*/
public void setTarget(Long target) {
this.target = target;
}
/**
* Gets the alias.
*
* @return the alias
*/
public String getAlias() {
return alias;
}
/**
* Sets the alias.
*
* @param alias the new alias
*/
public void setAlias(String alias) {
this.alias = alias;
}
/**
* Gets the visibility.
*
* @return the visibility
*/
public Visibility getVisibility() {
return visibility;
}
/**
* Sets the visibility.
*
* @param visibility the new visibility
*/
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
}
@@ -10,12 +10,16 @@ import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.Getter;
import lombok.Setter;
/**
* The Class UserDomain.
*/
@Entity
@Table(name = "domains", uniqueConstraints = @UniqueConstraint(columnNames = { "domain" }))
@Getter
@Setter
public class UserDomain implements UserData {
@Id
@@ -33,111 +37,4 @@ public class UserDomain implements UserData {
@Column(name = "validated", columnDefinition = "boolean default false")
private boolean validated;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the target.
*
* @return the target
*/
public Long getTarget() {
return target;
}
/**
* Sets the target.
*
* @param target the new target
*/
public void setTarget(Long target) {
this.target = target;
}
/**
* Gets the domain.
*
* @return the domain
*/
public String getDomain() {
return domain;
}
/**
* Sets the domain.
*
* @param domain the new domain
*/
public void setDomain(String domain) {
this.domain = domain;
}
/**
* Gets the visibility.
*
* @return the visibility
*/
public Visibility getVisibility() {
return visibility;
}
/**
* Sets the visibility.
*
* @param visibility the new visibility
*/
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
/**
* Gets the secret.
*
* @return the secret
*/
public String getSecret() {
return secret;
}
/**
* Sets the secret.
*
* @param secret the new secret
*/
public void setSecret(String secret) {
this.secret = secret;
}
/**
* Checks if is validated.
*
* @return true, if is validated
*/
public boolean isValidated() {
return validated;
}
/**
* Sets the validated.
*
* @param validated the new validated
*/
public void setValidated(boolean validated) {
this.validated = validated;
}
}
@@ -5,6 +5,7 @@ package de.bstly.we.model;
import java.io.Serializable;
import de.bstly.we.model.UserProfileField.UserProfileFieldId;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@@ -12,8 +13,8 @@ import jakarta.persistence.IdClass;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import de.bstly.we.model.UserProfileField.UserProfileFieldId;
import lombok.Getter;
import lombok.Setter;
/**
* The Class UserProfileField.
@@ -21,6 +22,8 @@ import de.bstly.we.model.UserProfileField.UserProfileFieldId;
@Entity
@IdClass(UserProfileFieldId.class)
@Table(name = "profile_fields", uniqueConstraints = @UniqueConstraint(columnNames = { "target", "name" }))
@Getter
@Setter
public class UserProfileField implements UserData {
@Id
@@ -32,7 +35,7 @@ public class UserProfileField implements UserData {
@Column(name = "value", nullable = true)
private String value;
@Lob
@Column(name = "blob_value", nullable = true, length = 100000)
@Column(name = "blob_value", nullable = true, length = 100000)
private String blob;
@Column(name = "type", nullable = false)
private ProfileFieldType type;
@@ -41,135 +44,11 @@ public class UserProfileField implements UserData {
@Column(name = "order_index", nullable = true)
private Integer index = 0;
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the target.
*
* @return the target
*/
public Long getTarget() {
return target;
}
/**
* Sets the target.
*
* @param target the new target
*/
public void setTarget(Long target) {
this.target = target;
}
/**
* Gets the value.
*
* @return the value
*/
public String getValue() {
return value;
}
/**
* Sets the value.
*
* @param value the new value
*/
public void setValue(String value) {
this.value = value;
}
/**
* Gets the blob.
*
* @return the blob
*/
public String getBlob() {
return blob;
}
/**
* Sets the blob.
*
* @param blob the new blob
*/
public void setBlob(String blob) {
this.blob = blob;
}
/**
* Gets the type.
*
* @return the type
*/
public ProfileFieldType getType() {
return type;
}
/**
* Sets the type.
*
* @param type the new type
*/
public void setType(ProfileFieldType type) {
this.type = type;
}
/**
* Gets the visibility.
*
* @return the visibility
*/
public Visibility getVisibility() {
return visibility;
}
/**
* Sets the visibility.
*
* @param visibility the new visibility
*/
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
/**
* Gets the index.
*
* @return the index
*/
public Integer getIndex() {
return index;
}
/**
* Sets the index.
*
* @param index the new index
*/
public void setIndex(Integer index) {
this.index = index;
}
/**
* The Class UserProfileFieldId.
*/
@Getter
@Setter
public static class UserProfileFieldId implements Serializable {
/**
@@ -179,42 +58,6 @@ public class UserProfileField implements UserData {
private Long target;
private String name;
/**
* Gets the target.
*
* @return the target
*/
public Long getTarget() {
return target;
}
/**
* Sets the target.
*
* @param target the new target
*/
public void setTarget(Long target) {
this.target = target;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/*
* @see java.lang.Object#equals(java.lang.Object)
*/
@@ -15,12 +15,16 @@ import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.Getter;
import lombok.Setter;
/**
* The Class UserTotp.
*/
@Entity
@Table(name = "user_totps", uniqueConstraints = @UniqueConstraint(columnNames = { "target" }))
@Getter
@Setter
public class UserTotp implements SecondFactor {
@Id
@@ -37,112 +41,4 @@ public class UserTotp implements SecondFactor {
@CollectionTable(name = "user_totps_recovery_codes")
private List<String> recoveryCodes;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the target.
*
* @return the target
*/
public Long getTarget() {
return target;
}
/**
* Sets the target.
*
* @param target the new target
*/
public void setTarget(Long target) {
this.target = target;
}
/**
* Checks if is enabled.
*
* @return true, if is enabled
*/
public boolean isEnabled() {
return enabled;
}
/**
* Sets the enabled.
*
* @param enabled the new enabled
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* Gets the secret.
*
* @return the secret
*/
public String getSecret() {
return secret;
}
/**
* Sets the secret.
*
* @param secret the new secret
*/
public void setSecret(String secret) {
this.secret = secret;
}
/**
* Gets the qr data.
*
* @return the qr data
*/
public String getQrData() {
return qrData;
}
/**
* Sets the qr data.
*
* @param qrData the new qr data
*/
public void setQrData(String qrData) {
this.qrData = qrData;
}
/**
* Gets the recovery codes.
*
* @return the recovery codes
*/
public List<String> getRecoveryCodes() {
return recoveryCodes;
}
/**
* Sets the recovery codes.
*
* @param recoveryCodes the new recovery codes
*/
public void setRecoveryCodes(List<String> recoveryCodes) {
this.recoveryCodes = recoveryCodes;
}
}
@@ -9,12 +9,16 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
/**
* The Class VoucherMapping.
*/
@Entity
@Table(name = "voucher_mappings")
@Getter
@Setter
public class VoucherMapping {
@Id
@@ -30,94 +34,4 @@ public class VoucherMapping {
@Column(name = "free", columnDefinition = "boolean default false")
private boolean free;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the quota.
*
* @return the quota
*/
public String getQuota() {
return quota;
}
/**
* Sets the quota.
*
* @param quota the new quota
*/
public void setQuota(String quota) {
this.quota = quota;
}
/**
* Gets the voucher.
*
* @return the voucher
*/
public int getVoucher() {
return voucher;
}
/**
* Sets the voucher.
*
* @param voucher the new voucher
*/
public void setVoucher(int voucher) {
this.voucher = voucher;
}
/**
* Checks if is free.
*
* @return true, if is free
*/
public boolean isFree() {
return free;
}
/**
* Sets the free.
*
* @param free the new free
*/
public void setFree(boolean free) {
this.free = free;
}
}
@@ -7,10 +7,14 @@ import java.util.Collection;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import lombok.Getter;
import lombok.Setter;
/**
* The Class LocalUserDetails.
*/
@Getter
@Setter
public class LocalUserDetails extends User {
/**
@@ -36,36 +40,4 @@ public class LocalUserDetails extends User {
this.alias = alias;
}
/**
* Gets the user id.
*
* @return the user id
*/
public Long getUserId() {
return userId;
}
/**
* Sets the user id.
*
* @param userId the new user id
*/
public void setUserId(Long userId) {
this.userId = userId;
}
/**
* @return the alias
*/
public String getAlias() {
return alias;
}
/**
* @param alias the alias to set
*/
public void setAlias(String alias) {
this.alias = alias;
}
}
@@ -1,8 +1,11 @@
package de.bstly.we.businesslogic;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
@@ -11,7 +14,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@@ -23,273 +25,289 @@ import com.google.gson.JsonArray;
import de.bstly.we.model.Permission;
import de.bstly.we.model.PermissionMapping;
import de.bstly.we.model.QPermission;
import de.bstly.we.repository.PermissionRepository;
@ExtendWith(MockitoExtension.class)
class PermissionManagerTest {
@Mock
private PermissionRepository permissionRepository;
@Mock
private PermissionRepository permissionRepository;
@Mock
private PermissionMappingManager permissionMappingManager;
@Mock
private PermissionMappingManager permissionMappingManager;
@InjectMocks
private PermissionManager permissionManager;
@InjectMocks
private PermissionManager permissionManager;
private static final Long TARGET_USER_ID = 1L;
private static final Integer TEST_ITEM_ID = 1;
private static final String ROLE_MEMBER = "ROLE_MEMBER";
private static final Long TARGET_USER_ID = 1L;
private static final Integer TEST_ITEM_ID = 1;
private static final String ROLE_MEMBER = "ROLE_MEMBER";
@Test
void testGetForItem_NewAddonPermission_CreatesNewWhenNoExisting() {
// Given
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
// No existing permissions
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList());
@Test
void testGetForItem_NewAddonPermission_CreatesNewWhenNoExisting() {
// Given
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// No existing permissions
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList());
// Then
assertEquals(1, result.size());
Permission permission = result.get(0);
assertEquals(TARGET_USER_ID, permission.getTarget());
assertEquals(ROLE_MEMBER, permission.getName());
assertTrue(permission.isAddon()); // Should be addon since no existing permission found
// Should create new permission with 1 year from current time: March 15, 2025 + 1 year = March 15, 2026
Instant expectedExpiry = Instant.parse("2026-03-15T10:00:00Z");
assertEquals(expectedExpiry, permission.getExpires());
}
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
@Test
void testGetForItem_AddonExtendsValidPermission_Simple() {
// Given - existing valid permission that expires on June 15, 2025
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
Instant existingExpiry = Instant.parse("2025-06-15T10:00:00Z"); // 3 months in the future
Permission existingPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, existingExpiry);
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(existingPermission));
// Then
assertEquals(1, result.size());
Permission permission = result.get(0);
assertEquals(TARGET_USER_ID, permission.getTarget());
assertEquals(ROLE_MEMBER, permission.getName());
assertTrue(permission.isAddon()); // Should be addon since no existing permission found
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission extendedPermission = result.get(0);
assertEquals(existingPermission, extendedPermission); // Should be the same object (extended)
// Should extend by exactly 1 year from current expiry: June 15, 2025 + 1 year = June 15, 2026
Instant expectedExpiry = Instant.parse("2026-06-15T10:00:00Z");
assertEquals(expectedExpiry, extendedPermission.getExpires());
assertEquals(TARGET_USER_ID, extendedPermission.getTarget());
assertEquals(ROLE_MEMBER, extendedPermission.getName());
}
@Test
void testGetForItem_AddonExtendsExpiredPermission_SimpleCase() {
// Given - existing permission that expired on February 15, 2025 (1 month ago from March 15)
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
Instant expiredDate = Instant.parse("2025-02-15T10:00:00Z"); // Expired exactly 1 month ago
Permission expiredPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, expiredDate);
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(expiredPermission));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission extendedPermission = result.get(0);
assertEquals(expiredPermission, extendedPermission); // Should be the same object (extended)
// Should extend by exactly 1 year from original expiry: Feb 15, 2025 + 1 year = Feb 15, 2026
Instant expectedExpiry = Instant.parse("2026-02-15T10:00:00Z");
assertEquals(expectedExpiry, extendedPermission.getExpires());
assertTrue(extendedPermission.getExpires().isAfter(currentTime)); // Should be in the future
}
@Test
void testGetForItem_AddonExtendsLongExpiredPermission_CatchesUp() {
// Given - permission that expired 2 years ago (Dec 31, 2023, applied in Nov 2025)
Instant currentTime = Instant.parse("2025-02-09T10:00:00Z");
Instant longExpiredDate = Instant.parse("2023-12-31T23:59:59Z");
Permission longExpiredPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, longExpiredDate);
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(longExpiredPermission));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission extendedPermission = result.get(0);
assertEquals(longExpiredPermission, extendedPermission); // Should be the same object (extended)
// Should "catch up" to future: 2023-12-31 -> 2024-12-31 -> 2025-12-31 (first future date)
Instant expectedExpiry = Instant.parse("2025-12-31T23:59:59Z");
assertEquals(expectedExpiry, extendedPermission.getExpires());
assertTrue(extendedPermission.getExpires().isAfter(currentTime)); // Should be in the future
}
@Test
void testGetForItem_AddonExtendsNonExpiredPermission_CatchesUp() {
// Given - permission that expired 2 years ago (Dec 31, 2023, applied in Nov 2025)
Instant currentTime = Instant.parse("2025-02-09T10:00:00Z");
Instant expiredDate = Instant.parse("2025-12-31T23:59:59Z");
Permission existingPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, expiredDate);
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(existingPermission));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission extendedPermission = result.get(0);
assertEquals(existingPermission, extendedPermission); // Should be the same object (extended)
// Should "catch up" to future: 2025-12-31 -> 2026-12-31 (first future date)
Instant expectedExpiry = Instant.parse("2026-12-31T23:59:59Z");
assertEquals(expectedExpiry, extendedPermission.getExpires());
assertTrue(extendedPermission.getExpires().isAfter(currentTime)); // Should be in the future
}
@Test
void testGetForItem_AddonSelectsLatestExpiringPermission() {
// Given - multiple existing permissions with different expiry dates
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
Permission permission1 = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, Instant.parse("2025-06-23T10:00:00Z")); // 100 days
Permission permission2 = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, Instant.parse("2025-10-01T10:00:00Z")); // 200 days (latest)
Permission permission3 = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, Instant.parse("2025-05-04T10:00:00Z")); // 50 days
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 6L, ChronoUnit.MONTHS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(permission1, permission2, permission3));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission selectedPermission = result.get(0);
assertEquals(permission2, selectedPermission); // Should select the one with latest expiry (Oct 1, 2025)
// Should extend by 6 months from latest expiry: Oct 1, 2025 + 6 months = April 1, 2026
Instant expectedExpiry = Instant.parse("2026-04-01T10:00:00Z");
assertEquals(expectedExpiry, selectedPermission.getExpires());
assertEquals(TARGET_USER_ID, selectedPermission.getTarget());
assertEquals(ROLE_MEMBER, selectedPermission.getName());
}
@Test
void testGetForItem_NonAddonCreatesNewPermission() {
// Given
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
PermissionMapping nonAddonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, false); // Not addon
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(nonAddonMapping));
// Existing permission exists but should be ignored since this is not an addon
Permission existingPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, Instant.parse("2025-06-23T10:00:00Z"));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(existingPermission));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission newPermission = result.get(0);
assertNotEquals(existingPermission, newPermission); // Should be a new permission object
assertEquals(TARGET_USER_ID, newPermission.getTarget());
assertEquals(ROLE_MEMBER, newPermission.getName());
assertFalse(newPermission.isAddon()); // Should not be addon
// Should create new permission with 1 year from current time: March 15, 2025 + 1 year = March 15, 2026
Instant expectedExpiry = Instant.parse("2026-03-15T10:00:00Z");
assertEquals(expectedExpiry, newPermission.getExpires());
}
@Test
void testGetForItem_MultiplePermissionNames() {
// Given - mapping with multiple permission names
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
Set<String> permissionNames = new HashSet<>(Arrays.asList("ROLE_MEMBER", "ROLE_SPECIAL"));
PermissionMapping multiMapping = createPermissionMapping(permissionNames, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(multiMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList()); // No existing permissions
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(2, result.size());
// Should have both permission names
Set<String> resultNames = new HashSet<>();
for (Permission p : result) {
resultNames.add(p.getName());
assertEquals(TARGET_USER_ID, p.getTarget());
assertTrue(p.isAddon());
// Should create new permission with 1 year from current time: March 15, 2025 +
// 1 year = March 15, 2026
Instant expectedExpiry = Instant.parse("2026-03-15T10:00:00Z");
assertEquals(expectedExpiry, permission.getExpires());
}
assertEquals(permissionNames, resultNames);
}
// Helper methods
private Permission createPermission(Long target, String name, boolean addon, Instant starts, Instant expires) {
Permission permission = new Permission();
permission.setTarget(target);
permission.setName(name);
permission.setAddon(addon);
permission.setStarts(starts);
permission.setExpires(expires);
return permission;
}
@Test
void testGetForItem_AddonExtendsValidPermission_Simple() {
// Given - existing valid permission that expires on June 15, 2025
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
Instant existingExpiry = Instant.parse("2025-06-15T10:00:00Z"); // 3 months in the future
Permission existingPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null,
existingExpiry);
private PermissionMapping createAddonPermissionMapping(String permissionName, Long lifetime, ChronoUnit unit, boolean isAddon) {
Set<String> names = new HashSet<>();
names.add(permissionName);
return createPermissionMapping(names, lifetime, unit, isAddon);
}
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(existingPermission));
private PermissionMapping createPermissionMapping(Set<String> names, Long lifetime, ChronoUnit unit, boolean isAddon) {
PermissionMapping mapping = new PermissionMapping();
mapping.setItem(TEST_ITEM_ID);
mapping.setNames(names);
mapping.setLifetime(lifetime);
mapping.setLifetimeUnit(unit);
mapping.setAddon(isAddon);
mapping.setLifetimeRound(false);
return mapping;
}
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission extendedPermission = result.get(0);
assertEquals(existingPermission, extendedPermission); // Should be the same object (extended)
// Should extend by exactly 1 year from current expiry: June 15, 2025 + 1 year =
// June 15, 2026
Instant expectedExpiry = Instant.parse("2026-06-15T10:00:00Z");
assertEquals(expectedExpiry, extendedPermission.getExpires());
assertEquals(TARGET_USER_ID, extendedPermission.getTarget());
assertEquals(ROLE_MEMBER, extendedPermission.getName());
}
@Test
void testGetForItem_AddonExtendsExpiredPermission_SimpleCase() {
// Given - existing permission that expired on February 15, 2025 (1 month ago
// from March 15)
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
Instant expiredDate = Instant.parse("2025-02-15T10:00:00Z"); // Expired exactly 1 month ago
Permission expiredPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, expiredDate);
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(expiredPermission));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission extendedPermission = result.get(0);
assertEquals(expiredPermission, extendedPermission); // Should be the same object (extended)
// Should extend by exactly 1 year from original expiry: Feb 15, 2025 + 1 year =
// Feb 15, 2026
Instant expectedExpiry = Instant.parse("2026-02-15T10:00:00Z");
assertEquals(expectedExpiry, extendedPermission.getExpires());
assertTrue(extendedPermission.getExpires().isAfter(currentTime)); // Should be in the future
}
@Test
void testGetForItem_AddonExtendsLongExpiredPermission_CatchesUp() {
// Given - permission that expired 2 years ago (Dec 31, 2023, applied in Nov
// 2025)
Instant currentTime = Instant.parse("2025-02-09T10:00:00Z");
Instant longExpiredDate = Instant.parse("2023-12-31T23:59:59Z");
Permission longExpiredPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null,
longExpiredDate);
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(longExpiredPermission));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission extendedPermission = result.get(0);
assertEquals(longExpiredPermission, extendedPermission); // Should be the same object (extended)
// Should "catch up" to future: 2023-12-31 -> 2024-12-31 -> 2025-12-31 (first
// future date)
Instant expectedExpiry = Instant.parse("2025-12-31T23:59:59Z");
assertEquals(expectedExpiry, extendedPermission.getExpires());
assertTrue(extendedPermission.getExpires().isAfter(currentTime)); // Should be in the future
}
@Test
void testGetForItem_AddonExtendsNonExpiredPermission_CatchesUp() {
// Given - permission that expired 2 years ago (Dec 31, 2023, applied in Nov
// 2025)
Instant currentTime = Instant.parse("2025-02-09T10:00:00Z");
Instant expiredDate = Instant.parse("2025-12-31T23:59:59Z");
Permission existingPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null, expiredDate);
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(existingPermission));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission extendedPermission = result.get(0);
assertEquals(existingPermission, extendedPermission); // Should be the same object (extended)
// Should "catch up" to future: 2025-12-31 -> 2026-12-31 (first future date)
Instant expectedExpiry = Instant.parse("2026-12-31T23:59:59Z");
assertEquals(expectedExpiry, extendedPermission.getExpires());
assertTrue(extendedPermission.getExpires().isAfter(currentTime)); // Should be in the future
}
@Test
void testGetForItem_AddonSelectsLatestExpiringPermission() {
// Given - multiple existing permissions with different expiry dates
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
Permission permission1 = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null,
Instant.parse("2025-06-23T10:00:00Z")); // 100 days
Permission permission2 = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null,
Instant.parse("2025-10-01T10:00:00Z")); // 200 days (latest)
Permission permission3 = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null,
Instant.parse("2025-05-04T10:00:00Z")); // 50 days
PermissionMapping addonMapping = createAddonPermissionMapping(ROLE_MEMBER, 6L, ChronoUnit.MONTHS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(addonMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(permission1, permission2, permission3));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission selectedPermission = result.get(0);
assertEquals(permission2, selectedPermission); // Should select the one with latest expiry (Oct 1, 2025)
// Should extend by 6 months from latest expiry: Oct 1, 2025 + 6 months = April
// 1, 2026
Instant expectedExpiry = Instant.parse("2026-04-01T10:00:00Z");
assertEquals(expectedExpiry, selectedPermission.getExpires());
assertEquals(TARGET_USER_ID, selectedPermission.getTarget());
assertEquals(ROLE_MEMBER, selectedPermission.getName());
}
@Test
void testGetForItem_NonAddonCreatesNewPermission() {
// Given
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
PermissionMapping nonAddonMapping = createAddonPermissionMapping(ROLE_MEMBER, 1L, ChronoUnit.YEARS,
false); // Not addon
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(nonAddonMapping));
// Existing permission exists but should be ignored since this is not an addon
Permission existingPermission = createPermission(TARGET_USER_ID, ROLE_MEMBER, false, null,
Instant.parse("2025-06-23T10:00:00Z"));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList(existingPermission));
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(1, result.size());
Permission newPermission = result.get(0);
assertNotEquals(existingPermission, newPermission); // Should be a new permission object
assertEquals(TARGET_USER_ID, newPermission.getTarget());
assertEquals(ROLE_MEMBER, newPermission.getName());
assertFalse(newPermission.isAddon()); // Should not be addon
// Should create new permission with 1 year from current time: March 15, 2025 +
// 1 year = March 15, 2026
Instant expectedExpiry = Instant.parse("2026-03-15T10:00:00Z");
assertEquals(expectedExpiry, newPermission.getExpires());
}
@Test
void testGetForItem_MultiplePermissionNames() {
// Given - mapping with multiple permission names
Instant currentTime = Instant.parse("2025-03-15T10:00:00Z");
Set<String> permissionNames = new HashSet<>(Arrays.asList("ROLE_MEMBER", "ROLE_SPECIAL"));
PermissionMapping multiMapping = createPermissionMapping(permissionNames, 1L, ChronoUnit.YEARS, true);
when(permissionMappingManager.getAllByItem(TEST_ITEM_ID)).thenReturn(Arrays.asList(multiMapping));
when(permissionRepository.findAll(any(com.querydsl.core.types.Predicate.class), any(Sort.class)))
.thenReturn(Arrays.asList()); // No existing permissions
// When
List<Permission> result = permissionManager.getForItem(TARGET_USER_ID, TEST_ITEM_ID, new JsonArray(),
currentTime, null);
// Then
assertEquals(2, result.size());
// Should have both permission names
Set<String> resultNames = new HashSet<>();
for (Permission p : result) {
resultNames.add(p.getName());
assertEquals(TARGET_USER_ID, p.getTarget());
assertTrue(p.isAddon());
}
assertEquals(permissionNames, resultNames);
}
// Helper methods
private Permission createPermission(Long target, String name, boolean addon, Instant starts, Instant expires) {
Permission permission = new Permission();
permission.setTarget(target);
permission.setName(name);
permission.setAddon(addon);
permission.setStarts(starts);
permission.setExpires(expires);
return permission;
}
private PermissionMapping createAddonPermissionMapping(String permissionName, Long lifetime, ChronoUnit unit,
boolean isAddon) {
Set<String> names = new HashSet<>();
names.add(permissionName);
return createPermissionMapping(names, lifetime, unit, isAddon);
}
private PermissionMapping createPermissionMapping(Set<String> names, Long lifetime, ChronoUnit unit,
boolean isAddon) {
PermissionMapping mapping = new PermissionMapping();
mapping.setItem(TEST_ITEM_ID);
mapping.setNames(names);
mapping.setLifetime(lifetime);
mapping.setLifetimeUnit(unit);
mapping.setAddon(isAddon);
mapping.setLifetimeRound(false);
return mapping;
}
}