Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add Exception suffix for exception classes #34

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.regex.Pattern;

import com.fasterxml.jackson.annotation.JsonValue;
import com.sitepark.ies.userrepository.core.domain.exception.InvalidAnchor;
import com.sitepark.ies.userrepository.core.domain.exception.InvalidAnchorException;

/**
* <p>
Expand Down Expand Up @@ -76,16 +76,16 @@ public String getName() {
}

/**
* @throws InvalidAnchor
* @throws InvalidAnchorException
*/
private static void validate(String name) {

if (ONLY_NUMBERS_PATTERN.matcher(name).matches()) {
throw new InvalidAnchor(name, "Anchor must not only consist of numbers");
throw new InvalidAnchorException(name, "Anchor must not only consist of numbers");
}

if (!VALIDATOR_PATTERN.matcher(name).matches()) {
throw new InvalidAnchor(name, "Anchor contains Spaces");
throw new InvalidAnchorException(name, "Anchor contains Spaces");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.sitepark.ies.userrepository.core.domain.exception;

/**
* The <code>AccessDenied</code> exception is thrown when a user or
* The <code>AccessDeniedException</code> exception is thrown when a user or
* process is denied access to a resource or operation due to
* insufficient permissions or authorization.
*/
public class AccessDenied extends UserRepositoryException {
public class AccessDeniedException extends UserRepositoryException {
private static final long serialVersionUID = 1L;

public AccessDenied(String message) {
public AccessDeniedException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import java.time.OffsetDateTime;

/**
* The <code>AccessTokenExpired</code> exception is thrown when
* The <code>AccessTokenExpiredException</code> exception is thrown when
* an access token has expired and is no longer valid for
* authentication purposes.
*/
public class AccessTokenExpired extends AuthenticationFailed {
public class AccessTokenExpiredException extends AuthenticationFailedException {

private static final long serialVersionUID = 1L;

private final OffsetDateTime expiredAt;

public AccessTokenExpired(OffsetDateTime expiredAt) {
public AccessTokenExpiredException(OffsetDateTime expiredAt) {
super();
this.expiredAt = expiredAt;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.sitepark.ies.userrepository.core.domain.exception;

/**
* The <code>AccessTokenNotActive</code> exception is thrown
* The <code>AccessTokenNotActiveException</code> exception is thrown
* when an access token is not active, making
* it invalid for authentication.
*/
public class AccessTokenNotActive extends AuthenticationFailed {
public class AccessTokenNotActiveException extends AuthenticationFailedException {

private static final long serialVersionUID = 1L;

public AccessTokenNotActive() {
public AccessTokenNotActiveException() {
super();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.sitepark.ies.userrepository.core.domain.exception;

/**
* The <code>AccessTokenRevoked</code> exception is thrown when an access token has been
* The <code>AccessTokenRevokedException</code> exception is thrown when an access token has been
* explicitly revoked, rendering it unusable for authentication or authorization.
*/
public class AccessTokenRevoked extends AuthenticationFailed {
public class AccessTokenRevokedException extends AuthenticationFailedException {

private static final long serialVersionUID = 1L;

public AccessTokenRevoked() {
public AccessTokenRevokedException() {
super();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import com.sitepark.ies.userrepository.core.domain.entity.Anchor;

/**
* The <code>AnchorAlreadyExists</code> exception is thrown when attempting to create
* The <code>AnchorAlreadyExistsException</code> exception is thrown when attempting to create
* a new anchor that already exists, violating the uniqueness constraint for anchors.
*/
public class AnchorAlreadyExists extends UserRepositoryException {
public class AnchorAlreadyExistsException extends UserRepositoryException {

private static final long serialVersionUID = 1L;

private final Anchor anchor;

private final long owner;

public AnchorAlreadyExists(Anchor anchor, long owner) {
public AnchorAlreadyExistsException(Anchor anchor, long owner) {
super();
this.anchor = anchor;
this.owner = owner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import com.sitepark.ies.userrepository.core.domain.entity.Anchor;

/**
* The <code>AnchorNotFound</code> exception is thrown when an anchor cannot be found
* The <code>AnchorNotFoundException</code> exception is thrown when an anchor cannot be found
* or does not exist in the system, typically when trying to access or manipulate an
* anchor that is not present.
*/
public class AnchorNotFound extends UserRepositoryException {
public class AnchorNotFoundException extends UserRepositoryException {

private static final long serialVersionUID = 1L;

private final Anchor anchor;

public AnchorNotFound(Anchor anchor) {
public AnchorNotFoundException(Anchor anchor) {
super();
this.anchor = anchor;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.sitepark.ies.userrepository.core.domain.exception;

/**
* The <code>AuthenticationFailed</code> exception is thrown when an authentication
* The <code>AuthenticationFailedException</code> exception is thrown when an authentication
* process fails, indicating that the provided credentials are invalid or authentication
* was unsuccessful for some reason.
*/
public abstract class AuthenticationFailed extends UserRepositoryException {
public abstract class AuthenticationFailedException extends UserRepositoryException {
private static final long serialVersionUID = 1L;

public AuthenticationFailed() {
public AuthenticationFailedException() {
super();
}

public AuthenticationFailed(String msg) {
public AuthenticationFailedException(String msg) {
super(msg);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sitepark.ies.userrepository.core.domain.exception;

/**
* The <code>InvalidAccessTokenException</code> exception is thrown when an access token provided
* for authentication is invalid.
*/
public class InvalidAccessTokenException extends AuthenticationFailedException {

private static final long serialVersionUID = 1L;

public InvalidAccessTokenException(String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.sitepark.ies.userrepository.core.domain.exception;

/**
* The <code>InvalidAnchor</code> exception is thrown when an anchor provided as a reference
* The <code>InvalidAnchorException</code> exception is thrown when an anchor provided as a reference
* is invalid, not recognized, or does not conform to the expected format or criteria.
*/
public class InvalidAnchor extends UserRepositoryException {
public class InvalidAnchorException extends UserRepositoryException {

private final String name;

private static final long serialVersionUID = 1L;

public InvalidAnchor(String name, String message) {
public InvalidAnchorException(String name, String message) {
super(message);
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.sitepark.ies.userrepository.core.domain.exception;

/**
* The <code>LoginAlreadyExists</code> exception is thrown when attempting to create
* The <code>LoginAlreadyExistsException</code> exception is thrown when attempting to create
* a user with a login or username that already exists in the system, violating the
* uniqueness constraint for user logins.
*/
public class LoginAlreadyExists extends UserRepositoryException {
public class LoginAlreadyExistsException extends UserRepositoryException {

private static final long serialVersionUID = 1L;

private final String login;

private final long owner;

public LoginAlreadyExists(String login, long owner) {
public LoginAlreadyExistsException(String login, long owner) {
super();
this.login = login;
this.owner = owner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.sitepark.ies.userrepository.core.domain.exception;

/**
* The <code>UserNotFound</code> exception is thrown when a user cannot be found or does not exist
* The <code>UserNotFoundException</code> exception is thrown when a user cannot be found or does not exist
* in the system, typically when attempting to access or manipulate user-related information for
* a user that is not present.
*/
public class UserNotFound extends UserRepositoryException {
public class UserNotFoundException extends UserRepositoryException {

private static final long serialVersionUID = 1L;

private final long id;

public UserNotFound(long id) {
public UserNotFoundException(long id) {
super();
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import com.sitepark.ies.userrepository.core.domain.entity.AccessToken;
import com.sitepark.ies.userrepository.core.domain.entity.User;
import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenExpired;
import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenNotActive;
import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenRevoked;
import com.sitepark.ies.userrepository.core.domain.exception.InvalidAccessToken;
import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenExpiredException;
import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenNotActiveException;
import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenRevokedException;
import com.sitepark.ies.userrepository.core.domain.exception.InvalidAccessTokenException;
import com.sitepark.ies.userrepository.core.port.AccessTokenRepository;
import com.sitepark.ies.userrepository.core.port.UserRepository;

Expand All @@ -32,21 +32,21 @@ public User authenticateByToken(String token) {

Optional<AccessToken> accessTokenOptinal = this.accessTokenRepository.getByToken(token);
if (accessTokenOptinal.isEmpty()) {
throw new InvalidAccessToken("Token not found");
throw new InvalidAccessTokenException("Token not found");
}

AccessToken accessToken = accessTokenOptinal.get();
if (!accessToken.isActive()) {
throw new AccessTokenNotActive();
throw new AccessTokenNotActiveException();
}
if (accessToken.isRevoked()) {
throw new AccessTokenRevoked();
throw new AccessTokenRevokedException();
}
this.checkExpirationDate(accessToken.getExpiresAt());

Optional<User> user = this.userRepository.get(accessToken.getUser());
if (user.isEmpty()) {
throw new InvalidAccessToken("User " + accessToken.getUser() + " not found");
throw new InvalidAccessTokenException("User " + accessToken.getUser() + " not found");
}

return user.get();
Expand All @@ -60,7 +60,7 @@ public void checkExpirationDate(Optional<OffsetDateTime> expiredAt) {

OffsetDateTime now = OffsetDateTime.now();
if (expiredAt.get().isBefore(now)) {
throw new AccessTokenExpired(expiredAt.get());
throw new AccessTokenExpiredException(expiredAt.get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.apache.logging.log4j.Logger;

import com.sitepark.ies.userrepository.core.domain.entity.AccessToken;
import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied;
import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException;
import com.sitepark.ies.userrepository.core.port.AccessControl;
import com.sitepark.ies.userrepository.core.port.AccessTokenRepository;

Expand All @@ -33,7 +33,7 @@ public AccessToken createPersonalAccessToken(AccessToken accessToken) {
.build();

if (!this.accessControl.isImpersonationTokensManageable()) {
throw new AccessDenied("Not allowed manage impersonation tokens");
throw new AccessDeniedException("Not allowed manage impersonation tokens");
}

if (LOGGER.isInfoEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.apache.logging.log4j.Logger;

import com.sitepark.ies.userrepository.core.domain.entity.User;
import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied;
import com.sitepark.ies.userrepository.core.domain.exception.AnchorAlreadyExists;
import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExists;
import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException;
import com.sitepark.ies.userrepository.core.domain.exception.AnchorAlreadyExistsException;
import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExistsException;
import com.sitepark.ies.userrepository.core.port.AccessControl;
import com.sitepark.ies.userrepository.core.port.ExtensionsNotifier;
import com.sitepark.ies.userrepository.core.port.IdGenerator;
Expand Down Expand Up @@ -57,7 +57,7 @@ public long createUser(User newUser) {
this.validateLogin(newUser);

if (!this.accessControl.isUserCreateable()) {
throw new AccessDenied("Not allowed to create user " + newUser);
throw new AccessDeniedException("Not allowed to create user " + newUser);
}

long generatedId = this.idGenerator.generate();
Expand All @@ -83,15 +83,15 @@ private void validateAnchor(User newUser) {
if (newUser.getAnchor().isPresent()) {
Optional<Long> anchorOwner = this.repository.resolveAnchor(newUser.getAnchor().get());
if (anchorOwner.isPresent()) {
throw new AnchorAlreadyExists(newUser.getAnchor().get(), anchorOwner.get());
throw new AnchorAlreadyExistsException(newUser.getAnchor().get(), anchorOwner.get());
}
}
}

private void validateLogin(User newUser) {
Optional<Long> resolveLogin = this.repository.resolveLogin(newUser.getLogin());
if (resolveLogin.isPresent()) {
throw new LoginAlreadyExists(newUser.getLogin(), resolveLogin.get());
throw new LoginAlreadyExistsException(newUser.getLogin(), resolveLogin.get());
}
}
}
Loading
Loading