Skip to content

Commit

Permalink
Apply Google Java Style Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiser-Yang authored and github-actions[bot] committed Oct 22, 2024
1 parent e04e17e commit 7666758
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 40 deletions.
12 changes: 7 additions & 5 deletions src/main/java/edu/cmipt/gcs/controller/RepositoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ public ResponseEntity<RepositoryVO> 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);
Expand Down Expand Up @@ -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<RepositoryPO> queryWrapper = new QueryWrapper<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -38,7 +39,9 @@ public class GlobalExceptionHandler {
public ResponseEntity<ErrorVO> 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);
}

/**
Expand Down Expand Up @@ -110,6 +113,7 @@ public ResponseEntity<ErrorVO> handleException(Exception e, HttpServletRequest r

private ResponseEntity<ErrorVO> handleValidationException(
String message, HttpServletRequest request) {
return handleGenericException(new GenericException(ErrorCodeEnum.VALIDATION_ERROR, message), request);
return handleGenericException(
new GenericException(ErrorCodeEnum.VALIDATION_ERROR, message), request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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})
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/edu/cmipt/gcs/pojo/ssh/SshKeyDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/edu/cmipt/gcs/pojo/user/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -43,10 +42,8 @@ public record UserDTO(
description = "Email",
requiredMode = Schema.RequiredMode.REQUIRED,
example = "[email protected]")
@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)",
Expand All @@ -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})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/edu/cmipt/gcs/service/SshKeyServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/edu/cmipt/gcs/service/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 7666758

Please sign in to comment.