diff --git a/src/main/java/edu/cmipt/gcs/controller/RepositoryController.java b/src/main/java/edu/cmipt/gcs/controller/RepositoryController.java index 0a314ea..4a53126 100644 --- a/src/main/java/edu/cmipt/gcs/controller/RepositoryController.java +++ b/src/main/java/edu/cmipt/gcs/controller/RepositoryController.java @@ -177,8 +177,7 @@ public ResponseEntity updateRepository( && !repository .repositoryName() .equals(repositoryService.getById(id).getRepositoryName())) { - throw new GenericException( - ErrorCodeEnum.OPERATION_NOT_IMPLEMENTED); + throw new GenericException(ErrorCodeEnum.OPERATION_NOT_IMPLEMENTED); } if (!repositoryService.updateById(new RepositoryPO(repository))) { throw new GenericException(ErrorCodeEnum.REPOSITORY_UPDATE_FAILED, repository); @@ -214,12 +213,15 @@ public void checkRepositoryNameValidity( @Size( min = ValidationConstant.MIN_REPOSITORY_NAME_LENGTH, max = ValidationConstant.MAX_REPOSITORY_NAME_LENGTH, - message ="{Size.repositoryController#checkRepositoryNameValidity.repositoryName}") + message = + "{Size.repositoryController#checkRepositoryNameValidity.repositoryName}") @NotBlank( - message ="{NotBlank.repositoryController#checkRepositoryNameValidity.repositoryName}") + message = + "{NotBlank.repositoryController#checkRepositoryNameValidity.repositoryName}") @Pattern( regexp = ValidationConstant.REPOSITORY_NAME_PATTERN, - message = "{Pattern.repositoryController#checkRepositoryNameValidity.repositoryName}") + message = + "{Pattern.repositoryController#checkRepositoryNameValidity.repositoryName}") String repositoryName, @RequestParam("userId") Long userId) { QueryWrapper queryWrapper = new QueryWrapper<>(); diff --git a/src/main/java/edu/cmipt/gcs/exception/GlobalExceptionHandler.java b/src/main/java/edu/cmipt/gcs/exception/GlobalExceptionHandler.java index 5ec4bf1..8db5a9f 100644 --- a/src/main/java/edu/cmipt/gcs/exception/GlobalExceptionHandler.java +++ b/src/main/java/edu/cmipt/gcs/exception/GlobalExceptionHandler.java @@ -3,6 +3,7 @@ import edu.cmipt.gcs.enumeration.ErrorCodeEnum; import edu.cmipt.gcs.pojo.error.ErrorVO; import edu.cmipt.gcs.util.MessageSourceUtil; + import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.ConstraintViolationException; @@ -38,7 +39,9 @@ public class GlobalExceptionHandler { public ResponseEntity handleMethodArgumentNotValidException( MethodArgumentNotValidException e, HttpServletRequest request) { var fieldError = e.getBindingResult().getFieldError(); - return handleValidationException(MessageSourceUtil.getMessage(fieldError.getCodes()[0], fieldError.getArguments()), request); + return handleValidationException( + MessageSourceUtil.getMessage(fieldError.getCodes()[0], fieldError.getArguments()), + request); } /** @@ -110,6 +113,7 @@ public ResponseEntity handleException(Exception e, HttpServletRequest r private ResponseEntity handleValidationException( String message, HttpServletRequest request) { - return handleGenericException(new GenericException(ErrorCodeEnum.VALIDATION_ERROR, message), request); + return handleGenericException( + new GenericException(ErrorCodeEnum.VALIDATION_ERROR, message), request); } } diff --git a/src/main/java/edu/cmipt/gcs/pojo/repository/RepositoryDTO.java b/src/main/java/edu/cmipt/gcs/pojo/repository/RepositoryDTO.java index 74606f3..cbcf94f 100644 --- a/src/main/java/edu/cmipt/gcs/pojo/repository/RepositoryDTO.java +++ b/src/main/java/edu/cmipt/gcs/pojo/repository/RepositoryDTO.java @@ -15,10 +15,8 @@ @Schema(description = "Repository Data Transfer Object") public record RepositoryDTO( @Schema(description = "Repository ID") - @Null( - groups = CreateGroup.class) - @NotNull( - groups = UpdateGroup.class) + @Null(groups = CreateGroup.class) + @NotNull(groups = UpdateGroup.class) String id, @Schema( description = "Repository Name", @@ -28,8 +26,7 @@ public record RepositoryDTO( groups = {CreateGroup.class, UpdateGroup.class}, min = ValidationConstant.MIN_REPOSITORY_NAME_LENGTH, max = ValidationConstant.MAX_REPOSITORY_NAME_LENGTH) - @NotBlank( - groups = CreateGroup.class) + @NotBlank(groups = CreateGroup.class) @Pattern( regexp = ValidationConstant.REPOSITORY_NAME_PATTERN, groups = {CreateGroup.class, UpdateGroup.class}) diff --git a/src/main/java/edu/cmipt/gcs/pojo/ssh/SshKeyDTO.java b/src/main/java/edu/cmipt/gcs/pojo/ssh/SshKeyDTO.java index b3ce970..0209ead 100644 --- a/src/main/java/edu/cmipt/gcs/pojo/ssh/SshKeyDTO.java +++ b/src/main/java/edu/cmipt/gcs/pojo/ssh/SshKeyDTO.java @@ -15,20 +15,17 @@ public record SshKeyDTO( @Schema(description = "SSH Key ID") @Null(groups = CreateGroup.class) - @NotNull( - groups = UpdateGroup.class) + @NotNull(groups = UpdateGroup.class) String id, @Schema(description = "Name", example = "My SSH Key") - @NotBlank( - groups = {CreateGroup.class, UpdateGroup.class}) + @NotBlank(groups = {CreateGroup.class, UpdateGroup.class}) @Size( groups = {CreateGroup.class, UpdateGroup.class}, min = ValidationConstant.MIN_SSH_KEY_NAME_LENGTH, max = ValidationConstant.MAX_SSH_KEY_NAME_LENGTH) String name, @Schema(description = "Public Key") - @NotBlank( - groups = CreateGroup.class) + @NotBlank(groups = CreateGroup.class) @Size( groups = {CreateGroup.class, UpdateGroup.class}, min = ValidationConstant.MIN_SSH_KEY_PUBLICKEY_LENGTH, diff --git a/src/main/java/edu/cmipt/gcs/pojo/user/UserDTO.java b/src/main/java/edu/cmipt/gcs/pojo/user/UserDTO.java index b47ea2b..4f83fa3 100644 --- a/src/main/java/edu/cmipt/gcs/pojo/user/UserDTO.java +++ b/src/main/java/edu/cmipt/gcs/pojo/user/UserDTO.java @@ -33,8 +33,7 @@ public record UserDTO( groups = {CreateGroup.class, UpdateGroup.class}, min = ValidationConstant.MIN_USERNAME_LENGTH, max = ValidationConstant.MAX_USERNAME_LENGTH) - @NotBlank( - groups = {CreateGroup.class}) + @NotBlank(groups = {CreateGroup.class}) @Pattern( regexp = ValidationConstant.USERNAME_PATTERN, groups = {CreateGroup.class, UpdateGroup.class}) @@ -43,10 +42,8 @@ public record UserDTO( description = "Email", requiredMode = Schema.RequiredMode.REQUIRED, example = "admin@cmipt.edu") - @Email( - groups = {CreateGroup.class, UpdateGroup.class}) - @NotBlank( - groups = {CreateGroup.class}) + @Email(groups = {CreateGroup.class, UpdateGroup.class}) + @NotBlank(groups = {CreateGroup.class}) String email, @Schema( description = "User Password (Unencrypted)", @@ -56,8 +53,7 @@ public record UserDTO( groups = {CreateGroup.class, UpdateGroup.class}, min = ValidationConstant.MIN_PASSWORD_LENGTH, max = ValidationConstant.MAX_PASSWORD_LENGTH) - @NotBlank( - groups = {CreateGroup.class}) + @NotBlank(groups = {CreateGroup.class}) @Pattern( regexp = ValidationConstant.PASSWORD_PATTERN, groups = {CreateGroup.class, UpdateGroup.class}) diff --git a/src/main/java/edu/cmipt/gcs/service/RepositoryServiceImpl.java b/src/main/java/edu/cmipt/gcs/service/RepositoryServiceImpl.java index 48dc0d0..e96e607 100644 --- a/src/main/java/edu/cmipt/gcs/service/RepositoryServiceImpl.java +++ b/src/main/java/edu/cmipt/gcs/service/RepositoryServiceImpl.java @@ -39,8 +39,7 @@ public boolean save(RepositoryPO repositoryPO) { repositoryPO.getUserId(), repositoryPO.getIsPrivate())) { logger.error("Failed to create repository in gitolite"); - throw new GenericException( - ErrorCodeEnum.REPOSITORY_CREATE_FAILED, repositoryPO); + throw new GenericException(ErrorCodeEnum.REPOSITORY_CREATE_FAILED, repositoryPO); } return true; } @@ -59,8 +58,7 @@ public boolean removeById(Serializable id) { repositoryPO.getUserId(), repositoryPO.getIsPrivate())) { logger.error("Failed to remove repository from gitolite"); - throw new GenericException( - ErrorCodeEnum.REPOSITORY_DELETE_FAILED, repositoryPO); + throw new GenericException(ErrorCodeEnum.REPOSITORY_DELETE_FAILED, repositoryPO); } return true; } diff --git a/src/main/java/edu/cmipt/gcs/service/SshKeyServiceImpl.java b/src/main/java/edu/cmipt/gcs/service/SshKeyServiceImpl.java index 2096fbc..7779edf 100644 --- a/src/main/java/edu/cmipt/gcs/service/SshKeyServiceImpl.java +++ b/src/main/java/edu/cmipt/gcs/service/SshKeyServiceImpl.java @@ -30,8 +30,7 @@ public boolean save(SshKeyPO sshKeyPO) { if (!GitoliteUtil.addSshKey( sshKeyPO.getId(), sshKeyPO.getPublicKey(), sshKeyPO.getUserId())) { logger.error("Failed to add SSH key to gitolite"); - throw new GenericException( - ErrorCodeEnum.SSH_KEY_UPLOAD_FAILED, sshKeyPO); + throw new GenericException(ErrorCodeEnum.SSH_KEY_UPLOAD_FAILED, sshKeyPO); } return true; } @@ -47,8 +46,7 @@ public boolean removeById(Serializable id) { } if (!GitoliteUtil.removeSshKey(sshKeyPO.getId(), sshKeyPO.getUserId())) { logger.error("Failed to remove SSH key from gitolite"); - throw new GenericException( - ErrorCodeEnum.SSH_KEY_DELETE_FAILED, sshKeyPO); + throw new GenericException(ErrorCodeEnum.SSH_KEY_DELETE_FAILED, sshKeyPO); } return true; } diff --git a/src/main/java/edu/cmipt/gcs/service/UserServiceImpl.java b/src/main/java/edu/cmipt/gcs/service/UserServiceImpl.java index 5f96b0f..fa41fd1 100644 --- a/src/main/java/edu/cmipt/gcs/service/UserServiceImpl.java +++ b/src/main/java/edu/cmipt/gcs/service/UserServiceImpl.java @@ -36,9 +36,7 @@ public boolean removeById(Serializable id) { var sshKeyList = sshKeyService.list(wrapper); for (var sshKey : sshKeyList) { if (!sshKeyService.removeById(sshKey.getId())) { - throw new GenericException( - ErrorCodeEnum.USER_DELETE_FAILED, - sshKey); + throw new GenericException(ErrorCodeEnum.USER_DELETE_FAILED, sshKey); } } return true; @@ -53,8 +51,7 @@ public boolean save(UserPO user) { } if (!GitoliteUtil.initUserConfig(user.getId())) { logger.error("Failed to add user to gitolite"); - throw new GenericException( - ErrorCodeEnum.USER_CREATE_FAILED, user); + throw new GenericException(ErrorCodeEnum.USER_CREATE_FAILED, user); } return true; }