From 5f0c38acf6f6428f8e796a90dce3a7a113c471ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Mon, 18 Apr 2022 21:30:40 +0800 Subject: [PATCH] fix: correct annotations for Spring Validation 2022-04-17 22:45:12.564 ERROR [auth-center,84c36bf256e4a45e,3f2acdd760061cb6] 1 - [nio-8800-exec-6] c.j.m.s.aspect.CommonExceptionControllerAdvice : Internal server exception occurred! Exception message: HV000151: A method overriding another method must not redefine the parameter constraint configuration, but method JwtServiceImpl#createJwt(boolean, long, String, List, Collection) redefines the configuration of JwtService#createJwt(boolean, long, String, List, Collection). javax.validation.ConstraintDeclarationException: HV000151: A method overriding another method must not redefine the parameter constraint configuration, but method JwtServiceImpl#createJwt(boolean, long, String, List, Collection) redefines the configuration of JwtService#createJwt(boolean, long, String, List, Collection). --- .../impl/AuthCenterWebClientServiceImpl.kt | 10 +- .../configuration/OpenApiConfiguration.kt | 5 +- .../SwaggerConfigurationProperties.kt | 4 +- .../service/impl/PermissionServiceImpl.kt | 4 +- .../impl/PermissionDomainServiceImpl.kt | 5 +- .../remote/impl/OssCenterFeignServiceImpl.kt | 5 +- .../service/impl/RoleDomainServiceImpl.kt | 8 +- .../security/service/impl/JwtServiceImpl.kt | 22 ++-- .../service/impl/UserDomainServiceImpl.kt | 16 +-- .../service/impl/UserDomainServiceImplTest.kt | 4 +- .../authcenter/remote/OssCenterFeignClient.kt | 2 +- .../user/payload/GetUserPageListPayload.kt | 8 +- .../user/payload/GetUserStatusPayload.kt | 10 +- .../maf/authcenter/user/persistence/User.kt | 16 +-- .../PermissionRemoteApiController.kt | 8 +- .../maf/common/bean/PaginationBase.kt | 2 +- .../common/domain/ValidationTestPayload.kt | 6 +- .../domain/authcenter/user/SignupResponse.kt | 6 +- .../enumeration/ValueDescriptionBaseEnum.java | 6 +- .../exception/ResourceNotFoundException.kt | 5 +- .../maf/common/exception/SecurityException.kt | 5 +- .../remote/impl/OssCenterFeignServiceImpl.kt | 3 +- .../maf/mafmis/remote/OssCenterFeignClient.kt | 2 +- .../service/impl/ReadResourceServiceImpl.kt | 17 ++- .../service/impl/WriteResourceServiceImpl.kt | 10 +- .../maf/osscenter/WriteResourceController.kt | 5 +- .../configuration/WebFluxConfiguration.kt | 6 +- .../property/MafConfigurationProperties.kt | 5 +- .../service/impl/CommonServiceImpl.kt | 4 +- .../DatabaseExceptionControllerAdvice.kt | 5 +- .../configuration/WebSecurityConfiguration.kt | 5 +- .../function/ExceptionHandling.kt | 5 +- .../springcloudstarter/minio/MinioHelper.kt | 5 +- .../property/MafConfigurationProperties.kt | 5 +- ...teOrModifyQuartzJobConfigurationPayload.kt | 19 +--- .../impl/QuartzJobConfigurationServiceImpl.kt | 24 ++-- .../service/impl/QuartzJobServiceImpl.kt | 21 ++-- .../RedisDistributedLockDemoController.kt | 3 +- .../service/impl/CommonServiceImpl.kt | 4 +- .../annotation/DateTimeRangeConstraints.kt | 23 ---- .../annotation/DateTimeRangeGroup.kt | 19 ---- .../annotation/DateTimeRangeType.kt | 20 ---- .../validation/annotation/ValidEnumValue.java | 37 ------- .../validator/DateTimeRangeValidator.kt | 103 ------------------ .../validator/EnumValueValidator.java | 76 ------------- 45 files changed, 122 insertions(+), 461 deletions(-) delete mode 100644 spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeConstraints.kt delete mode 100644 spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeGroup.kt delete mode 100644 spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeType.kt delete mode 100644 spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/ValidEnumValue.java delete mode 100644 spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/validator/DateTimeRangeValidator.kt delete mode 100644 spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/validator/EnumValueValidator.java diff --git a/api-gateway/api-gateway-domain/src/main/java/com/jmsoftware/maf/apigateway/remote/impl/AuthCenterWebClientServiceImpl.kt b/api-gateway/api-gateway-domain/src/main/java/com/jmsoftware/maf/apigateway/remote/impl/AuthCenterWebClientServiceImpl.kt index b84e777f..fa880aa6 100644 --- a/api-gateway/api-gateway-domain/src/main/java/com/jmsoftware/maf/apigateway/remote/impl/AuthCenterWebClientServiceImpl.kt +++ b/api-gateway/api-gateway-domain/src/main/java/com/jmsoftware/maf/apigateway/remote/impl/AuthCenterWebClientServiceImpl.kt @@ -9,10 +9,6 @@ import com.jmsoftware.maf.common.domain.authcenter.security.ParseJwtResponse import com.jmsoftware.maf.common.domain.authcenter.user.GetUserByLoginTokenResponse import org.springframework.stereotype.Service import reactor.core.publisher.Mono -import javax.validation.Valid -import javax.validation.constraints.Min -import javax.validation.constraints.NotBlank -import javax.validation.constraints.NotNull /** * # AuthCenterWebClientServiceImpl @@ -25,14 +21,14 @@ import javax.validation.constraints.NotNull class AuthCenterWebClientServiceImpl( private val authCenterWebClient: AuthCenterWebClient ) : AuthCenterWebClientService { - override fun getUserByLoginToken(loginToken: @NotBlank String): Mono = + override fun getUserByLoginToken(loginToken: String): Mono = authCenterWebClient.getUserByLoginToken(loginToken) - override fun getRoleListByUserId(userId: @NotNull @Min(1L) Long): Mono> = + override fun getRoleListByUserId(userId: Long): Mono> = authCenterWebClient.getRoleListByUserId(userId) override fun getPermissionListByRoleIdList( - payload: @Valid @NotNull GetPermissionListByRoleIdListPayload + payload: GetPermissionListByRoleIdListPayload ): Mono> = authCenterWebClient.getPermissionListByRoleIdList(payload) override fun parse(authorization: String): Mono = authCenterWebClient.parse(authorization) diff --git a/api-gateway/api-gateway-web/src/main/java/com/jmsoftware/maf/apigateway/configuration/OpenApiConfiguration.kt b/api-gateway/api-gateway-web/src/main/java/com/jmsoftware/maf/apigateway/configuration/OpenApiConfiguration.kt index 92cedeea..22da7973 100644 --- a/api-gateway/api-gateway-web/src/main/java/com/jmsoftware/maf/apigateway/configuration/OpenApiConfiguration.kt +++ b/api-gateway/api-gateway-web/src/main/java/com/jmsoftware/maf/apigateway/configuration/OpenApiConfiguration.kt @@ -16,12 +16,11 @@ import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration /** - *

OpenApiConfiguration

- * + * # OpenApiConfiguration * * Change description here. * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com, 2/1/22 11:51 PM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:18 PM */ @Configuration class OpenApiConfiguration( diff --git a/api-gateway/api-gateway-web/src/main/java/com/jmsoftware/maf/apigateway/property/SwaggerConfigurationProperties.kt b/api-gateway/api-gateway-web/src/main/java/com/jmsoftware/maf/apigateway/property/SwaggerConfigurationProperties.kt index 73a5f3a9..29a985ca 100644 --- a/api-gateway/api-gateway-web/src/main/java/com/jmsoftware/maf/apigateway/property/SwaggerConfigurationProperties.kt +++ b/api-gateway/api-gateway-web/src/main/java/com/jmsoftware/maf/apigateway/property/SwaggerConfigurationProperties.kt @@ -7,9 +7,9 @@ import org.springframework.validation.annotation.Validated import javax.validation.constraints.NotEmpty /** - *

SwaggerConfigurationProperties

+ * # SwaggerConfigurationProperties * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 2/7/2021 3:28 PM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:17 PM */ @Validated @RefreshScope diff --git a/auth-center/auth-center-biz/src/main/java/com/jmsoftware/maf/authcenter/permission/service/impl/PermissionServiceImpl.kt b/auth-center/auth-center-biz/src/main/java/com/jmsoftware/maf/authcenter/permission/service/impl/PermissionServiceImpl.kt index f6c2007f..fe17e0b2 100644 --- a/auth-center/auth-center-biz/src/main/java/com/jmsoftware/maf/authcenter/permission/service/impl/PermissionServiceImpl.kt +++ b/auth-center/auth-center-biz/src/main/java/com/jmsoftware/maf/authcenter/permission/service/impl/PermissionServiceImpl.kt @@ -25,8 +25,6 @@ import org.springframework.cloud.client.discovery.DiscoveryClient import org.springframework.stereotype.Service import org.springframework.web.client.RestTemplate import java.util.* -import javax.validation.Valid -import javax.validation.constraints.NotNull /** * # PermissionServiceImpl @@ -49,7 +47,7 @@ class PermissionServiceImpl( } override fun getPermissionListByRoleIdList( - payload: @Valid @NotNull GetPermissionListByRoleIdListPayload + payload: GetPermissionListByRoleIdListPayload ): GetPermissionListByRoleIdListResponse { val adminRole = roleDomainService.checkAdmin(payload.roleIdList) val response = GetPermissionListByRoleIdListResponse() diff --git a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/permission/service/impl/PermissionDomainServiceImpl.kt b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/permission/service/impl/PermissionDomainServiceImpl.kt index af7d8245..5f064926 100644 --- a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/permission/service/impl/PermissionDomainServiceImpl.kt +++ b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/permission/service/impl/PermissionDomainServiceImpl.kt @@ -6,7 +6,6 @@ import com.jmsoftware.maf.authcenter.permission.persistence.Permission import com.jmsoftware.maf.authcenter.permission.service.PermissionDomainService import com.jmsoftware.maf.common.domain.authcenter.permission.PermissionType import org.springframework.stereotype.Service -import javax.validation.constraints.NotEmpty /** * # PermissionDomainServiceImpl @@ -19,8 +18,8 @@ import javax.validation.constraints.NotEmpty class PermissionDomainServiceImpl : ServiceImpl(), PermissionDomainService { override fun getPermissionListByRoleIdList( - roleIdList: @NotEmpty List, - permissionTypeList: @NotEmpty List + roleIdList: List, + permissionTypeList: List ): List { return getBaseMapper().selectPermissionListByRoleIdList(roleIdList, permissionTypeList) } diff --git a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/remote/impl/OssCenterFeignServiceImpl.kt b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/remote/impl/OssCenterFeignServiceImpl.kt index a46d1b65..6a332b6d 100644 --- a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/remote/impl/OssCenterFeignServiceImpl.kt +++ b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/remote/impl/OssCenterFeignServiceImpl.kt @@ -8,7 +8,6 @@ import com.jmsoftware.maf.common.util.logger import org.springframework.stereotype.Service import org.springframework.web.multipart.MultipartFile import java.util.* -import javax.validation.constraints.NotNull /** * # OssCenterFeignServiceImpl @@ -25,8 +24,8 @@ class OssCenterFeignServiceImpl( private val log = logger() } - override fun uploadSingleResource(multipartFile: @NotNull MultipartFile): ObjectResponse { - log.info("Uploading single resource to oss center. multipartFile: {}", multipartFile) + override fun uploadSingleResource(multipartFile: MultipartFile): ObjectResponse { + log.info("Uploading single resource to oss center. multipartFile: $multipartFile") return Optional.ofNullable(ossCenterFeignClient.uploadSingleResource(multipartFile)) .map { response -> response.data!! } .orElseThrow { diff --git a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/role/service/impl/RoleDomainServiceImpl.kt b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/role/service/impl/RoleDomainServiceImpl.kt index 8df5d3c8..227fd449 100644 --- a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/role/service/impl/RoleDomainServiceImpl.kt +++ b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/role/service/impl/RoleDomainServiceImpl.kt @@ -25,8 +25,6 @@ import org.springframework.data.redis.core.RedisTemplate import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.util.concurrent.TimeUnit -import javax.validation.constraints.NotEmpty -import javax.validation.constraints.NotNull /** * # RoleDomainServiceImpl @@ -46,7 +44,7 @@ class RoleDomainServiceImpl( private val logger = logger() } - override fun getRoleList(userId: @NotNull Long): GetRoleListByUserIdResponse { + override fun getRoleList(userId: Long): GetRoleListByUserIdResponse { val key = "${mafProjectProperties.projectParentArtifactId}${GET_ROLE_LIST_BY_USER_ID.keyInfixFormat}$userId" val hadKey = redisTemplate.hasKey(key) if (hadKey) { @@ -63,7 +61,7 @@ class RoleDomainServiceImpl( return getBaseMapper().selectRoleListByUserId(userId) } - override fun checkAdmin(roleIdList: @NotEmpty List): Boolean { + override fun checkAdmin(roleIdList: List): Boolean { // If roleNameSet is not empty (contains "admin") return this.ktQuery() .select(Role::name) @@ -96,7 +94,7 @@ class RoleDomainServiceImpl( } @Transactional(rollbackFor = [Throwable::class]) - override fun save(beanList: @NotEmpty List) { + override fun save(beanList: List) { val roleList = beanList .stream() .map { roleExcelBean: RoleExcelBean -> RoleExcelBean.transformTo(roleExcelBean) } diff --git a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/security/service/impl/JwtServiceImpl.kt b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/security/service/impl/JwtServiceImpl.kt index acbd2ac8..129ee672 100644 --- a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/security/service/impl/JwtServiceImpl.kt +++ b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/security/service/impl/JwtServiceImpl.kt @@ -23,8 +23,6 @@ import java.util.concurrent.TimeUnit import javax.annotation.PostConstruct import javax.crypto.SecretKey import javax.servlet.http.HttpServletRequest -import javax.validation.constraints.NotBlank -import javax.validation.constraints.NotNull /** * # JwtServiceImpl @@ -55,7 +53,7 @@ class JwtServiceImpl( log.warn("Secret key for JWT parser was generated. Algorithm: ${secretKey.algorithm}") } - override fun createJwt(@NotNull authentication: Authentication, @NotNull rememberMe: Boolean): String { + override fun createJwt(authentication: Authentication, rememberMe: Boolean): String { val userPrincipal = authentication.principal as UserPrincipal return this.createJwt( rememberMe, @@ -67,9 +65,9 @@ class JwtServiceImpl( } override fun createJwt( - @NotNull rememberMe: Boolean, - @NotNull id: Long, - @NotNull subject: String, + rememberMe: Boolean, + id: Long, + subject: String, roles: List, authorities: Collection ): String { @@ -95,7 +93,7 @@ class JwtServiceImpl( return jwt } - override fun parseJwt(@NotBlank jwt: String): Claims { + override fun parseJwt(jwt: String): Claims { val claims: Claims = try { Optional.ofNullable(jwtParser.parseClaimsJws(jwt).body) .orElseThrow { @@ -131,7 +129,7 @@ class JwtServiceImpl( return claims } - override fun invalidateJwt(@NotNull request: HttpServletRequest) { + override fun invalidateJwt(request: HttpServletRequest) { val jwt = getJwtFromRequest(request) val username = getUsernameFromJwt(jwt) // Delete JWT from redis @@ -140,17 +138,17 @@ class JwtServiceImpl( log.error("Invalidate JWT. Redis key of JWT = $redisKeyOfJwt, deleted = $deletedKeyNumber") } - override fun getUsernameFromJwt(@NotBlank jwt: String): String { + override fun getUsernameFromJwt(jwt: String): String { val claims = parseJwt(jwt) return claims.subject } - override fun getUsernameFromRequest(@NotNull request: HttpServletRequest): String { + override fun getUsernameFromRequest(request: HttpServletRequest): String { val jwt = getJwtFromRequest(request) return getUsernameFromJwt(jwt) } - override fun getJwtFromRequest(@NotNull request: HttpServletRequest): String { + override fun getJwtFromRequest(request: HttpServletRequest): String { val bearerToken = request.getHeader(HttpHeaders.AUTHORIZATION) return if (CharSequenceUtil.isNotBlank(bearerToken) && bearerToken.startsWith(JwtConfigurationProperties.TOKEN_PREFIX) @@ -159,7 +157,7 @@ class JwtServiceImpl( } else null.toString() } - override fun parse(@NotNull request: HttpServletRequest): ParseJwtResponse { + override fun parse(request: HttpServletRequest): ParseJwtResponse { val jwt = getJwtFromRequest(request) val claims = parseJwt(jwt) val parseJwtResponse = ParseJwtResponse() diff --git a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/user/service/impl/UserDomainServiceImpl.kt b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/user/service/impl/UserDomainServiceImpl.kt index 1b8cc8a4..9ab475d2 100644 --- a/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/user/service/impl/UserDomainServiceImpl.kt +++ b/auth-center/auth-center-domain/src/main/java/com/jmsoftware/maf/authcenter/user/service/impl/UserDomainServiceImpl.kt @@ -21,7 +21,6 @@ import com.jmsoftware.maf.authcenter.user.service.UserDomainService import com.jmsoftware.maf.authcenter.user.service.UserRoleDomainService import com.jmsoftware.maf.common.bean.PageResponseBodyBean import com.jmsoftware.maf.common.domain.authcenter.user.* -import com.jmsoftware.maf.common.enumeration.ValueDescriptionBaseEnum import com.jmsoftware.maf.common.exception.SecurityException import com.jmsoftware.maf.common.util.logger import com.jmsoftware.maf.springcloudstarter.property.MafConfigurationProperties @@ -37,9 +36,6 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.util.concurrent.TimeUnit import javax.servlet.http.HttpServletRequest -import javax.validation.Valid -import javax.validation.constraints.NotBlank -import javax.validation.constraints.NotNull /** * # UserDomainServiceImpl @@ -63,7 +59,7 @@ class UserDomainServiceImpl( private val logger = logger() } - override fun getUserByLoginToken(loginToken: @NotBlank String): GetUserByLoginTokenResponse? { + override fun getUserByLoginToken(loginToken: String): GetUserByLoginTokenResponse? { val key = "${mafProjectProperties.projectParentArtifactId}${UserRedisKey.GET_USER_BY_LOGIN_TOKEN.keyInfixFormat}$loginToken" val hasKey = redisTemplate.hasKey(key) @@ -80,7 +76,7 @@ class UserDomainServiceImpl( } @Transactional(rollbackFor = [Throwable::class]) - override fun saveUserForSignup(payload: @Valid SignupPayload): SignupResponse { + override fun saveUserForSignup(payload: SignupPayload): SignupResponse { val user = User() user.username = payload.username user.email = payload.email @@ -94,7 +90,7 @@ class UserDomainServiceImpl( return response } - override fun login(payload: @Valid LoginPayload): LoginResponse { + override fun login(payload: LoginPayload): LoginResponse { val user = getUserByLoginToken(payload.loginToken) ?: throw SecurityException(HttpStatus.UNAUTHORIZED) logger.info("User login: $user") val matched = bCryptPasswordEncoder.matches(payload.password, user.password) @@ -117,12 +113,12 @@ class UserDomainServiceImpl( return true } - override fun getUserStatus(payload: @Valid @NotNull GetUserStatusPayload): String { + override fun getUserStatus(payload: GetUserStatusPayload): String { logger.info("Current username: {}", currentUsername()) - return ValueDescriptionBaseEnum.getDescriptionByValue(UserStatus::class.java, payload.status) + return payload.status.toString() } - override fun getUserPageList(payload: @Valid @NotNull GetUserPageListPayload): PageResponseBodyBean { + override fun getUserPageList(payload: GetUserPageListPayload): PageResponseBodyBean { logger.info("{}", payload) val page = Page( payload.currentPage.toLong(), payload.pageSize.toLong() diff --git a/auth-center/auth-center-domain/src/test/java/com/jmsoftware/maf/authcenter/user/service/impl/UserDomainServiceImplTest.kt b/auth-center/auth-center-domain/src/test/java/com/jmsoftware/maf/authcenter/user/service/impl/UserDomainServiceImplTest.kt index 0a820fae..16d7f925 100644 --- a/auth-center/auth-center-domain/src/test/java/com/jmsoftware/maf/authcenter/user/service/impl/UserDomainServiceImplTest.kt +++ b/auth-center/auth-center-domain/src/test/java/com/jmsoftware/maf/authcenter/user/service/impl/UserDomainServiceImplTest.kt @@ -11,6 +11,7 @@ import com.jmsoftware.maf.authcenter.user.persistence.User import com.jmsoftware.maf.authcenter.user.service.UserRoleDomainService import com.jmsoftware.maf.common.domain.authcenter.user.LoginPayload import com.jmsoftware.maf.common.domain.authcenter.user.SignupPayload +import com.jmsoftware.maf.common.domain.authcenter.user.UserStatus import com.jmsoftware.maf.common.exception.SecurityException import com.jmsoftware.maf.common.util.logger import com.jmsoftware.maf.springcloudstarter.property.MafConfigurationProperties @@ -149,8 +150,7 @@ internal class UserDomainServiceImplTest { @Test fun getUserStatus() { val payload = GetUserStatusPayload() - payload.status = 1.toByte() - payload.status2 = 0.toByte() + payload.status = UserStatus.ENABLED val thrownException = assertThrows(IllegalStateException::class.java) { userDomainService.getUserStatus(payload) } log.warn("Thrown exception: ${thrownException.message}") diff --git a/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/remote/OssCenterFeignClient.kt b/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/remote/OssCenterFeignClient.kt index 64e694dd..0aed7573 100644 --- a/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/remote/OssCenterFeignClient.kt +++ b/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/remote/OssCenterFeignClient.kt @@ -45,7 +45,7 @@ interface OssCenterFeignClient { private val log = logger() } - override fun uploadSingleResource(multipartFile: @NotNull MultipartFile): ResponseBodyBean { + override fun uploadSingleResource(multipartFile: MultipartFile): ResponseBodyBean { log.error("Fallback -> OssCenterFeignClient#uploadSingleResource()") return ResponseBodyBean.ofFailureMessage("Fell back uploading single resource") } diff --git a/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/payload/GetUserPageListPayload.kt b/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/payload/GetUserPageListPayload.kt index 9b5abe64..f02c30a7 100644 --- a/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/payload/GetUserPageListPayload.kt +++ b/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/payload/GetUserPageListPayload.kt @@ -1,8 +1,6 @@ package com.jmsoftware.maf.authcenter.user.payload import com.jmsoftware.maf.common.bean.PaginationBase -import com.jmsoftware.maf.springcloudstarter.validation.annotation.DateTimeRangeGroup -import com.jmsoftware.maf.springcloudstarter.validation.annotation.DateTimeRangeType import java.time.LocalDateTime /** @@ -15,9 +13,7 @@ import java.time.LocalDateTime class GetUserPageListPayload : PaginationBase() { var username: String? = null - @DateTimeRangeGroup(type = DateTimeRangeType.START_TIME) - val startTime: LocalDateTime? = null + var startTime: LocalDateTime? = null - @DateTimeRangeGroup(type = DateTimeRangeType.END_TIME) - val endTime: LocalDateTime? = null + var endTime: LocalDateTime? = null } diff --git a/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/payload/GetUserStatusPayload.kt b/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/payload/GetUserStatusPayload.kt index eea82f1a..0c3f6acf 100644 --- a/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/payload/GetUserStatusPayload.kt +++ b/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/payload/GetUserStatusPayload.kt @@ -1,8 +1,7 @@ package com.jmsoftware.maf.authcenter.user.payload import com.jmsoftware.maf.common.domain.authcenter.user.UserStatus -import com.jmsoftware.maf.common.domain.authcenter.user.UserStatus2 -import com.jmsoftware.maf.springcloudstarter.validation.annotation.ValidEnumValue +import javax.validation.constraints.NotNull /** * # GetUserStatusPayload @@ -12,9 +11,6 @@ import com.jmsoftware.maf.springcloudstarter.validation.annotation.ValidEnumValu * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/12/22 12:50 PM */ class GetUserStatusPayload { - @ValidEnumValue(targetEnum = UserStatus::class) - var status: Byte? = null - - @ValidEnumValue(targetEnum = UserStatus2::class) - var status2: Byte? = null + @NotNull + lateinit var status: UserStatus } diff --git a/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/persistence/User.kt b/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/persistence/User.kt index 4158028b..7a311b23 100644 --- a/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/persistence/User.kt +++ b/auth-center/auth-center-infra/src/main/java/com/jmsoftware/maf/authcenter/user/persistence/User.kt @@ -31,49 +31,49 @@ class User : BasePersistenceEntity() { * Username */ @TableField(value = COL_USERNAME) - lateinit var username: String + var username: String? = null /** * Email */ @TableField(value = COL_EMAIL) - lateinit var email: String + var email: String? = null /** * Cellphone number */ @TableField(value = COL_CELLPHONE) - lateinit var cellphone: String + var cellphone: String? = null /** * Password */ @TableField(value = COL_PASSWORD) - lateinit var password: String + var password: String? = null /** * Full name */ @TableField(value = COL_FULL_NAME) - lateinit var fullName: String + var fullName: String? = null /** * Birthday */ @TableField(value = COL_BIRTHDAY) - lateinit var birthday: LocalDate + var birthday: LocalDate? = null /** * 26 gender options */ @TableField(value = COL_GENDER) - lateinit var gender: String + var gender: String? = null /** * User avatar full path on SFTP server */ @TableField(value = COL_AVATAR) - lateinit var avatar: String + var avatar: String? = null /** * Status. 1 - enabled, 2 - disabled diff --git a/auth-center/auth-center-web/src/main/java/com/jmsoftware/maf/authcenter/permission/PermissionRemoteApiController.kt b/auth-center/auth-center-web/src/main/java/com/jmsoftware/maf/authcenter/permission/PermissionRemoteApiController.kt index 29ec7289..44faa816 100644 --- a/auth-center/auth-center-web/src/main/java/com/jmsoftware/maf/authcenter/permission/PermissionRemoteApiController.kt +++ b/auth-center/auth-center-web/src/main/java/com/jmsoftware/maf/authcenter/permission/PermissionRemoteApiController.kt @@ -4,20 +4,20 @@ import com.jmsoftware.maf.authcenter.permission.service.PermissionService import com.jmsoftware.maf.common.bean.ResponseBodyBean import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse +import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import javax.validation.Valid /** - *

PermissionRemoteApiController

- * + * # PermissionRemoteApiController * * Change description here. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 5/11/20 8:24 AM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 8:54 PM */ +@Validated @RestController @RequestMapping("/permission-remote-api") class PermissionRemoteApiController( diff --git a/common/src/main/java/com/jmsoftware/maf/common/bean/PaginationBase.kt b/common/src/main/java/com/jmsoftware/maf/common/bean/PaginationBase.kt index 98388bc2..808d3ecb 100644 --- a/common/src/main/java/com/jmsoftware/maf/common/bean/PaginationBase.kt +++ b/common/src/main/java/com/jmsoftware/maf/common/bean/PaginationBase.kt @@ -27,7 +27,7 @@ open class PaginationBase { * The page size. Default: 10 */ @JsonIgnore - @NotNull(message = "The page size is required!") + @NotNull(message = "The page size is required!") @Range(min = 10L, max = 100L, message = "The rage of page size: 10 <= page size <= 100!") var pageSize: Int = 10 diff --git a/common/src/main/java/com/jmsoftware/maf/common/domain/ValidationTestPayload.kt b/common/src/main/java/com/jmsoftware/maf/common/domain/ValidationTestPayload.kt index 5d0b81cd..8a141062 100644 --- a/common/src/main/java/com/jmsoftware/maf/common/domain/ValidationTestPayload.kt +++ b/common/src/main/java/com/jmsoftware/maf/common/domain/ValidationTestPayload.kt @@ -5,13 +5,11 @@ import javax.validation.constraints.NotBlank import javax.validation.constraints.NotNull /** - *

ValidationTestPayload

- * + * # ValidationTestPayload * * Change description here. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 2/14/20 11:34 AM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:18 PM */ class ValidationTestPayload { @NotNull diff --git a/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/user/SignupResponse.kt b/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/user/SignupResponse.kt index 340561d9..e391051c 100644 --- a/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/user/SignupResponse.kt +++ b/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/user/SignupResponse.kt @@ -1,13 +1,11 @@ package com.jmsoftware.maf.common.domain.authcenter.user /** - *

SignupResponse

- * + * # SignupResponse * * Change description here. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 5/11/20 5:37 AM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:18 PM */ class SignupResponse { /** diff --git a/common/src/main/java/com/jmsoftware/maf/common/enumeration/ValueDescriptionBaseEnum.java b/common/src/main/java/com/jmsoftware/maf/common/enumeration/ValueDescriptionBaseEnum.java index 16cee950..95a06315 100644 --- a/common/src/main/java/com/jmsoftware/maf/common/enumeration/ValueDescriptionBaseEnum.java +++ b/common/src/main/java/com/jmsoftware/maf/common/enumeration/ValueDescriptionBaseEnum.java @@ -8,12 +8,12 @@ import lombok.val; /** - *

ValueDescriptionBaseEnum

- *

+ * # ValueDescriptionBaseEnum + * * Change description here. * * @param the type of value - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com, 2/27/22 11:32 AM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:18 PM */ @SuppressWarnings("unused") public interface ValueDescriptionBaseEnum { diff --git a/common/src/main/java/com/jmsoftware/maf/common/exception/ResourceNotFoundException.kt b/common/src/main/java/com/jmsoftware/maf/common/exception/ResourceNotFoundException.kt index 58a72d9e..eb6f266e 100644 --- a/common/src/main/java/com/jmsoftware/maf/common/exception/ResourceNotFoundException.kt +++ b/common/src/main/java/com/jmsoftware/maf/common/exception/ResourceNotFoundException.kt @@ -4,12 +4,11 @@ import org.springframework.http.HttpStatus import java.io.Serial /** - *

ResourceNotFoundException

- * + * # ResourceNotFoundException * * Resource not found exception * - * @author Johnny Miller (鍾俊), e-mail: johnnysviva@outlook.com, date: 2/19/2022 5:05 PM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:18 PM */ class ResourceNotFoundException : BaseException { constructor(message: String) : super(HttpStatus.NOT_FOUND, message) diff --git a/common/src/main/java/com/jmsoftware/maf/common/exception/SecurityException.kt b/common/src/main/java/com/jmsoftware/maf/common/exception/SecurityException.kt index cb6cfbce..3c8bacad 100644 --- a/common/src/main/java/com/jmsoftware/maf/common/exception/SecurityException.kt +++ b/common/src/main/java/com/jmsoftware/maf/common/exception/SecurityException.kt @@ -4,12 +4,11 @@ import org.springframework.http.HttpStatus import java.io.Serial /** - *

SecurityException

- * + * # SecurityException * * Change description here. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date 3/12/20 3:15 PM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:18 PM */ class SecurityException : BaseException { constructor(httpStatus: HttpStatus) : super(httpStatus) diff --git a/maf-mis/maf-mis-domain/src/main/java/com/jmsoftware/maf/mafmis/remote/impl/OssCenterFeignServiceImpl.kt b/maf-mis/maf-mis-domain/src/main/java/com/jmsoftware/maf/mafmis/remote/impl/OssCenterFeignServiceImpl.kt index 288b458c..5d4c73eb 100644 --- a/maf-mis/maf-mis-domain/src/main/java/com/jmsoftware/maf/mafmis/remote/impl/OssCenterFeignServiceImpl.kt +++ b/maf-mis/maf-mis-domain/src/main/java/com/jmsoftware/maf/mafmis/remote/impl/OssCenterFeignServiceImpl.kt @@ -8,7 +8,6 @@ import com.jmsoftware.maf.mafmis.remote.OssCenterFeignService import org.springframework.stereotype.Service import org.springframework.web.multipart.MultipartFile import java.util.* -import javax.validation.constraints.NotNull /** * # OssCenterFeignServiceImpl @@ -25,7 +24,7 @@ class OssCenterFeignServiceImpl( private val log = logger() } - override fun uploadSingleResource(multipartFile: @NotNull MultipartFile): ObjectResponse { + override fun uploadSingleResource(multipartFile: MultipartFile): ObjectResponse { log.info("Uploading single resource to oss center. multipartFile: {}", multipartFile) return Optional.ofNullable(ossCenterFeignClient.uploadSingleResource(multipartFile)) .map { response -> response.data!! } diff --git a/maf-mis/maf-mis-infra/src/main/java/com/jmsoftware/maf/mafmis/remote/OssCenterFeignClient.kt b/maf-mis/maf-mis-infra/src/main/java/com/jmsoftware/maf/mafmis/remote/OssCenterFeignClient.kt index bb16b1fe..baf5146d 100644 --- a/maf-mis/maf-mis-infra/src/main/java/com/jmsoftware/maf/mafmis/remote/OssCenterFeignClient.kt +++ b/maf-mis/maf-mis-infra/src/main/java/com/jmsoftware/maf/mafmis/remote/OssCenterFeignClient.kt @@ -45,7 +45,7 @@ interface OssCenterFeignClient { private val log = logger() } - override fun uploadSingleResource(multipartFile: @NotNull MultipartFile): ResponseBodyBean { + override fun uploadSingleResource(multipartFile: MultipartFile): ResponseBodyBean { log.error("Fallback -> OssCenterFeignClient#uploadSingleResource()") return ResponseBodyBean.ofFailureMessage("Fell back uploading single resource") } diff --git a/oss-center/oss-center-biz/src/main/java/com/jmsoftware/maf/osscenter/service/impl/ReadResourceServiceImpl.kt b/oss-center/oss-center-biz/src/main/java/com/jmsoftware/maf/osscenter/service/impl/ReadResourceServiceImpl.kt index 2ca32eee..3866d98c 100644 --- a/oss-center/oss-center-biz/src/main/java/com/jmsoftware/maf/osscenter/service/impl/ReadResourceServiceImpl.kt +++ b/oss-center/oss-center-biz/src/main/java/com/jmsoftware/maf/osscenter/service/impl/ReadResourceServiceImpl.kt @@ -15,7 +15,6 @@ import org.springframework.http.* import org.springframework.stereotype.Service import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody import java.io.OutputStream -import javax.validation.constraints.NotBlank /** * # ReadResourceServiceImpl @@ -34,8 +33,8 @@ class ReadResourceServiceImpl( } override fun asyncGetSingleResource( - bucket: @NotBlank String, - `object`: @NotBlank String + bucket: String, + `object`: String ): ResponseEntity { val statObjectResponse: StatObjectResponse? = try { minioHelper.statObject(bucket, `object`) @@ -59,8 +58,8 @@ class ReadResourceServiceImpl( } override fun asyncStreamSingleResource( - bucket: @NotBlank String, - `object`: @NotBlank String, + bucket: String, + `object`: String, range: String? ): ResponseEntity { val statObjectResponse: StatObjectResponse? = try { @@ -96,8 +95,8 @@ class ReadResourceServiceImpl( } override fun asyncDownloadSingleResource( - bucket: @NotBlank String, - `object`: @NotBlank String + bucket: String, + `object`: String ): ResponseEntity { val statObjectResponse: StatObjectResponse? = try { minioHelper.statObject(bucket, `object`) @@ -128,8 +127,8 @@ class ReadResourceServiceImpl( } override fun stateObject( - bucket: @NotBlank String, - `object`: @NotBlank String + bucket: String, + `object`: String ): SerializableStatObjectResponse { val statObjectResponse = minioHelper.statObject(bucket, `object`) if (statObjectResponse == null) { diff --git a/oss-center/oss-center-biz/src/main/java/com/jmsoftware/maf/osscenter/service/impl/WriteResourceServiceImpl.kt b/oss-center/oss-center-biz/src/main/java/com/jmsoftware/maf/osscenter/service/impl/WriteResourceServiceImpl.kt index edd94750..9eb75c6e 100644 --- a/oss-center/oss-center-biz/src/main/java/com/jmsoftware/maf/osscenter/service/impl/WriteResourceServiceImpl.kt +++ b/oss-center/oss-center-biz/src/main/java/com/jmsoftware/maf/osscenter/service/impl/WriteResourceServiceImpl.kt @@ -18,8 +18,6 @@ import org.springframework.stereotype.Service import org.springframework.web.multipart.MultipartFile import java.io.InputStream import java.util.stream.Collectors -import javax.validation.Valid -import javax.validation.constraints.NotNull /** * # WriteResourceServiceImpl @@ -36,7 +34,7 @@ class WriteResourceServiceImpl( private val log = logger() } - override fun uploadSingleResource(multipartFile: @NotNull MultipartFile): ObjectResponse { + override fun uploadSingleResource(multipartFile: MultipartFile): ObjectResponse { val mediaType = this.parseMediaType(multipartFile) minioHelper.makeBucket(mediaType.type) val objectWriteResponse = minioHelper.put( @@ -88,8 +86,8 @@ class WriteResourceServiceImpl( * @see All about AWS S3 ETags */ override fun uploadResourceChunk( - multipartFile: @NotNull MultipartFile, - payload: @Valid @NotNull UploadResourceChunkPayload + multipartFile: MultipartFile, + payload: UploadResourceChunkPayload ): ObjectResponse { require(!CharSequenceUtil.isBlank(multipartFile.originalFilename)) { "File name required" } var mediaType: MediaType? = null @@ -114,7 +112,7 @@ class WriteResourceServiceImpl( } @SneakyThrows - override fun mergeResourceChunk(payload: @Valid @NotNull MergeResourceChunkPayload): ObjectResponse { + override fun mergeResourceChunk(payload: MergeResourceChunkPayload): ObjectResponse { val objectName = validateObject(payload.objectList) val sources = payload.objectList .stream() diff --git a/oss-center/oss-center-web/src/main/java/com/jmsoftware/maf/osscenter/WriteResourceController.kt b/oss-center/oss-center-web/src/main/java/com/jmsoftware/maf/osscenter/WriteResourceController.kt index 3a96af19..1f38cde4 100644 --- a/oss-center/oss-center-web/src/main/java/com/jmsoftware/maf/osscenter/WriteResourceController.kt +++ b/oss-center/oss-center-web/src/main/java/com/jmsoftware/maf/osscenter/WriteResourceController.kt @@ -13,12 +13,11 @@ import org.springframework.web.multipart.MultipartFile import javax.validation.Valid /** - *

WriteResourceController

- * + * # WriteResourceController * * Change description here. * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com, 6/20/21 1:57 PM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:19 PM */ @Validated @RestController diff --git a/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/configuration/WebFluxConfiguration.kt b/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/configuration/WebFluxConfiguration.kt index d24ae66a..24f4bef5 100644 --- a/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/configuration/WebFluxConfiguration.kt +++ b/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/configuration/WebFluxConfiguration.kt @@ -3,12 +3,10 @@ package com.jmsoftware.maf.reactivespringcloudstarter.configuration import org.springframework.web.reactive.config.WebFluxConfigurer /** - *

WebFluxConfiguration

- * + * # WebFluxConfiguration * * Change description here. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com - * @date 2/17/20 5:16 PM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:19 PM */ class WebFluxConfiguration : WebFluxConfigurer diff --git a/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/property/MafConfigurationProperties.kt b/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/property/MafConfigurationProperties.kt index c8c5169e..5be1c27d 100644 --- a/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/property/MafConfigurationProperties.kt +++ b/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/property/MafConfigurationProperties.kt @@ -96,12 +96,11 @@ class MafConfigurationProperties { } /** - *

IgnoredUrl

- * + * # IgnoredUrl * * Ignored URL configuration. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 2/9/2021 9:39 AM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:19 PM **/ class IgnoredUrl { private interface Constant { diff --git a/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/service/impl/CommonServiceImpl.kt b/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/service/impl/CommonServiceImpl.kt index 1ed76794..d036a60e 100644 --- a/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/service/impl/CommonServiceImpl.kt +++ b/reactive-spring-cloud-starter/src/main/java/com/jmsoftware/maf/reactivespringcloudstarter/service/impl/CommonServiceImpl.kt @@ -8,8 +8,6 @@ import com.jmsoftware.maf.reactivespringcloudstarter.property.MafProjectProperti import com.jmsoftware.maf.reactivespringcloudstarter.service.CommonService import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service -import javax.validation.Valid -import javax.validation.constraints.NotNull /** * # CommonServiceImpl @@ -33,7 +31,7 @@ class CommonServiceImpl( return JSONUtil.parseObj(mafProjectProperties).set("greeting", greeting) } - override fun validateObject(payload: @Valid @NotNull ValidationTestPayload) { + override fun validateObject(payload: ValidationTestPayload) { log.info("Validation passed! {}", payload) } } diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/aspect/DatabaseExceptionControllerAdvice.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/aspect/DatabaseExceptionControllerAdvice.kt index f265a788..1a020208 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/aspect/DatabaseExceptionControllerAdvice.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/aspect/DatabaseExceptionControllerAdvice.kt @@ -17,12 +17,11 @@ import org.springframework.web.bind.annotation.RestControllerAdvice import javax.servlet.http.HttpServletRequest /** - *

DatabaseExceptionControllerAdvice

- * + * # DatabaseExceptionControllerAdvice * * Exception advice for database exception. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 6/27/2021 10:41 AM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:20 PM */ @RestControllerAdvice @ConditionalOnClass( diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/configuration/WebSecurityConfiguration.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/configuration/WebSecurityConfiguration.kt index dfe3c166..7aa7cb2c 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/configuration/WebSecurityConfiguration.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/configuration/WebSecurityConfiguration.kt @@ -10,12 +10,11 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder import javax.annotation.PostConstruct /** - *

WebSecurityConfiguration

- * + * # WebSecurityConfiguration * * Security handler configuration. * - * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/16/22 10:52 PM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:20 PM */ @EnableWebSecurity class WebSecurityConfiguration : WebSecurityConfigurerAdapter() { diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/function/ExceptionHandling.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/function/ExceptionHandling.kt index 3b1a79cc..8f2b8228 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/function/ExceptionHandling.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/function/ExceptionHandling.kt @@ -5,12 +5,11 @@ package com.jmsoftware.maf.springcloudstarter.function import java.util.function.Function /** - *

ExceptionHandling

- * + * # ExceptionHandling * * Change description here. * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com, 9/28/21 8:54 AM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:20 PM * @see Java 函数式编程最佳实践 - 赋予函数处理异常的能力 */ private object ExceptionHandling diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/minio/MinioHelper.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/minio/MinioHelper.kt index 7befdc82..9f59c6a6 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/minio/MinioHelper.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/minio/MinioHelper.kt @@ -14,12 +14,11 @@ import java.io.InputStream import javax.validation.constraints.* /** - *

MinioHelper

- * + * # MinioHelper * * Change description here. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 6/7/21 9:52 PM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:20 PM */ @Suppress("unused") @Validated diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/property/MafConfigurationProperties.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/property/MafConfigurationProperties.kt index 74f16882..344beede 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/property/MafConfigurationProperties.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/property/MafConfigurationProperties.kt @@ -96,12 +96,11 @@ class MafConfigurationProperties { } /** - *

IgnoredUrl

- * + * # IgnoredUrl * * Ignored URL configuration. * - * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 2/9/2021 9:39 AM + * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/18/22 9:20 PM **/ class IgnoredUrl { private interface Constant { diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/entity/CreateOrModifyQuartzJobConfigurationPayload.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/entity/CreateOrModifyQuartzJobConfigurationPayload.kt index 80f5f5cd..afb2e34a 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/entity/CreateOrModifyQuartzJobConfigurationPayload.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/entity/CreateOrModifyQuartzJobConfigurationPayload.kt @@ -7,7 +7,6 @@ import com.jmsoftware.maf.springcloudstarter.quartz.constant.MisfirePolicy.MISFI import com.jmsoftware.maf.springcloudstarter.quartz.constant.QuartzJobStatus import com.jmsoftware.maf.springcloudstarter.quartz.constant.QuartzJobStatus.NORMAL import com.jmsoftware.maf.springcloudstarter.quartz.entity.persistence.QuartzJobConfiguration -import com.jmsoftware.maf.springcloudstarter.validation.annotation.ValidEnumValue import org.hibernate.validator.constraints.Length import javax.validation.constraints.NotBlank import javax.validation.constraints.NotNull @@ -24,16 +23,10 @@ class CreateOrModifyQuartzJobConfigurationPayload { lateinit var group: @NotBlank @Length(max = 200) String lateinit var invokeTarget: @NotBlank @Length(max = 500) String lateinit var cronExpression: @NotBlank @Length(max = 50) String - - @ValidEnumValue(targetEnum = MisfirePolicy::class) - var misfirePolicy: @NotNull Byte = MISFIRE_INSTRUCTION_SMART_POLICY.value - - @ValidEnumValue(targetEnum = Concurrent::class) - var concurrent: @NotNull Byte = DISALLOW_CONCURRENT.value + var misfirePolicy: @NotNull MisfirePolicy = MISFIRE_INSTRUCTION_SMART_POLICY + var concurrent: @NotNull Concurrent = DISALLOW_CONCURRENT lateinit var description: @NotBlank @Length(max = 1000) String - - @ValidEnumValue(targetEnum = QuartzJobStatus::class) - var status: @NotNull Byte = NORMAL.value + var status: @NotNull QuartzJobStatus = NORMAL fun asQuartzJobConfiguration(): QuartzJobConfiguration { val result = QuartzJobConfiguration() @@ -41,10 +34,10 @@ class CreateOrModifyQuartzJobConfigurationPayload { result.group = group result.invokeTarget = invokeTarget result.cronExpression = cronExpression - result.misfirePolicy = misfirePolicy - result.concurrent = concurrent + result.misfirePolicy = misfirePolicy.value + result.concurrent = concurrent.value result.description = description - result.status = status + result.status = status.value return result } } diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/service/impl/QuartzJobConfigurationServiceImpl.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/service/impl/QuartzJobConfigurationServiceImpl.kt index 484de96d..6f1967b6 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/service/impl/QuartzJobConfigurationServiceImpl.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/service/impl/QuartzJobConfigurationServiceImpl.kt @@ -28,10 +28,6 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.util.* import javax.annotation.PostConstruct -import javax.validation.Valid -import javax.validation.constraints.NotBlank -import javax.validation.constraints.NotEmpty -import javax.validation.constraints.NotNull /** * # QuartzJobConfigurationServiceImpl @@ -73,7 +69,7 @@ class QuartzJobConfigurationServiceImpl( } override fun getPageList( - payload: @Valid @NotNull GetQuartzJobConfigurationPageListPayload + payload: GetQuartzJobConfigurationPageListPayload ): PageResponseBodyBean { val page: Page = Page(payload.currentPage.toLong(), payload.pageSize.toLong()) @@ -93,7 +89,7 @@ class QuartzJobConfigurationServiceImpl( } @Transactional(rollbackFor = [Throwable::class]) - override fun save(beanList: @NotEmpty List) { + override fun save(beanList: List) { requireTrue( this.saveBatch( beanList.stream() @@ -109,7 +105,7 @@ class QuartzJobConfigurationServiceImpl( this.getBaseMapper().selectListForExporting(mafProjectProperties.projectArtifactId) override fun create( - payload: @Valid @NotNull CreateOrModifyQuartzJobConfigurationPayload + payload: CreateOrModifyQuartzJobConfigurationPayload ): Long { validateCronExpression(payload.cronExpression) val quartzJobConfiguration: QuartzJobConfiguration = payload.asQuartzJobConfiguration() @@ -127,8 +123,8 @@ class QuartzJobConfigurationServiceImpl( } override fun modify( - id: @NotNull Long, - payload: @Valid @NotNull CreateOrModifyQuartzJobConfigurationPayload + id: Long, + payload: CreateOrModifyQuartzJobConfigurationPayload ): Long { validateCronExpression(payload.cronExpression) val quartzJobConfiguration: QuartzJobConfiguration = payload.asQuartzJobConfiguration() @@ -140,9 +136,9 @@ class QuartzJobConfigurationServiceImpl( } override fun patch( - id: @NotNull Long, - property: @NotBlank String, - payload: @NotNull CreateOrModifyQuartzJobConfigurationPayload + id: Long, + property: String, + payload: CreateOrModifyQuartzJobConfigurationPayload ): Long { val value = ReflectUtil.getFieldValue(payload, property) Objects.requireNonNull(value, CharSequenceUtil.format("Property's value({}) must not be null", property)) @@ -162,7 +158,7 @@ class QuartzJobConfigurationServiceImpl( return id } - override fun runImmediately(id: @NotNull Long): Long { + override fun runImmediately(id: Long): Long { val quartzJobConfiguration: QuartzJobConfiguration = this.getById(id) ?: throw IllegalArgumentException("Quartz job(id:$id) not found!") val scheduler: Scheduler = schedulerFactoryBean.scheduler @@ -181,7 +177,7 @@ class QuartzJobConfigurationServiceImpl( } @Transactional(rollbackFor = [Throwable::class]) - override fun delete(id: @NotNull Long, group: @NotBlank String): Long { + override fun delete(id: Long, group: String): Long { requireTrue(this.removeById(id)) { deleted: Boolean -> logger.warn("Quartz job configuration deleted: $deleted") }.orElseThrow { IllegalStateException(CharSequenceUtil.format("Failed to delete Quartz job configuration")) } diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/service/impl/QuartzJobServiceImpl.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/service/impl/QuartzJobServiceImpl.kt index 60be3b06..da25362d 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/service/impl/QuartzJobServiceImpl.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/service/impl/QuartzJobServiceImpl.kt @@ -8,7 +8,6 @@ import org.springframework.lang.Nullable import org.springframework.scheduling.quartz.SchedulerFactoryBean import org.springframework.stereotype.Service import java.util.function.UnaryOperator -import javax.validation.constraints.NotBlank /** * # QuartzJobServiceImpl @@ -31,11 +30,11 @@ class QuartzJobServiceImpl( } override fun addJob( - clazzName: @NotBlank String, - jobName: @NotBlank String, - groupName: @NotBlank String, - cronExp: @NotBlank String, - @Nullable param: Map? + clazzName: String, + jobName: String, + groupName: String, + cronExp: String, + param: Map? ) { val jobDetailName = JOB_DETAIL_NAME_OPERATOR.apply(jobName) // Build job @@ -57,19 +56,19 @@ class QuartzJobServiceImpl( log.info("Added job to scheduler. jobDetailName: $jobDetailName, triggerName: $triggerName") } - override fun pauseJob(jobName: @NotBlank String, groupName: @NotBlank String) { + override fun pauseJob(jobName: String, groupName: String) { val jobDetailName = JOB_DETAIL_NAME_OPERATOR.apply(jobName) schedulerFactoryBean.scheduler.pauseJob(JobKey.jobKey(jobDetailName, groupName)) log.info("Paused job. jobDetailName: {}", jobDetailName) } - override fun resumeJob(jobName: @NotBlank String, groupName: @NotBlank String) { + override fun resumeJob(jobName: String, groupName: String) { val jobDetailName = JOB_DETAIL_NAME_OPERATOR.apply(jobName) schedulerFactoryBean.scheduler.resumeJob(JobKey.jobKey(jobDetailName, groupName)) log.info("Resumed job. jobDetailName: {}", jobDetailName) } - override fun runImmediately(jobName: @NotBlank String, groupName: @NotBlank String) { + override fun runImmediately(jobName: String, groupName: String) { val jobDetailName = JOB_DETAIL_NAME_OPERATOR.apply(jobName) schedulerFactoryBean.scheduler.triggerJob(JobKey.jobKey(jobDetailName, groupName)) log.info( @@ -79,7 +78,7 @@ class QuartzJobServiceImpl( } override fun updateJob( - jobName: @NotBlank String, groupName: @NotBlank String, cronExp: @NotBlank String, + jobName: String, groupName: String, cronExp: String, @Nullable param: Map? ) { val triggerName = TRIGGER_NAME_OPERATOR.apply(jobName) @@ -94,7 +93,7 @@ class QuartzJobServiceImpl( log.info("Updated job. triggerName: {}", triggerName) } - override fun deleteJob(jobName: @NotBlank String, groupName: @NotBlank String) { + override fun deleteJob(jobName: String, groupName: String) { val triggerName = TRIGGER_NAME_OPERATOR.apply(jobName) // Pause, Remove the trigger and the job, and then delete the job. schedulerFactoryBean.scheduler.pauseTrigger(TriggerKey.triggerKey(jobName, groupName)) diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/redis/RedisDistributedLockDemoController.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/redis/RedisDistributedLockDemoController.kt index b1e14ff3..5dbdbb39 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/redis/RedisDistributedLockDemoController.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/redis/RedisDistributedLockDemoController.kt @@ -12,8 +12,7 @@ import java.util.concurrent.TimeUnit import java.util.concurrent.locks.Lock /** - *

RedisDistributedLockDemoController

- * + * # RedisDistributedLockDemoController * * Change description here. * diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/service/impl/CommonServiceImpl.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/service/impl/CommonServiceImpl.kt index bd5de0b2..0634b9d8 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/service/impl/CommonServiceImpl.kt +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/service/impl/CommonServiceImpl.kt @@ -8,8 +8,6 @@ import com.jmsoftware.maf.springcloudstarter.property.MafProjectProperties import com.jmsoftware.maf.springcloudstarter.service.CommonService import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service -import javax.validation.Valid -import javax.validation.constraints.NotNull /** * # CommonServiceImpl @@ -33,7 +31,7 @@ class CommonServiceImpl( return JSONUtil.parseObj(mafProjectProperties).set("greeting", greeting) } - override fun validateObject(payload: @Valid @NotNull ValidationTestPayload) { + override fun validateObject(payload: ValidationTestPayload) { log.info("Validation passed! {}", payload) } } diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeConstraints.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeConstraints.kt deleted file mode 100644 index 9a7d5e73..00000000 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeConstraints.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.jmsoftware.maf.springcloudstarter.validation.annotation - -import com.jmsoftware.maf.springcloudstarter.validation.validator.DateTimeRangeValidator -import javax.validation.Constraint -import javax.validation.Payload -import kotlin.reflect.KClass - -/** - * # DateTimeRangeConstraints - * - * Description: DateTimeRangeConstraints, change description here. - * - * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/16/22 9:52 AM - */ -@MustBeDocumented -@Retention(AnnotationRetention.RUNTIME) -@Constraint(validatedBy = [DateTimeRangeValidator::class]) -@Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS) -annotation class DateTimeRangeConstraints( - val message: String = "Invalid date time range", - val groups: Array> = [], - val payload: Array> = [] -) diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeGroup.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeGroup.kt deleted file mode 100644 index eeb53864..00000000 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeGroup.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.jmsoftware.maf.springcloudstarter.validation.annotation - - -/** - * # DateTimeRangeGroup - * - * Description: DateTimeRangeGroup, change description here. - * - * TODO: to support nullable value - * - * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/16/22 9:53 AM - */ -@MustBeDocumented -@Target(AnnotationTarget.FIELD) -@Retention(AnnotationRetention.RUNTIME) -annotation class DateTimeRangeGroup( - val groupName: String = "defaultDateTimeRangeGroup", - val type: DateTimeRangeType = DateTimeRangeType.START_TIME -) diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeType.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeType.kt deleted file mode 100644 index 57d90662..00000000 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/DateTimeRangeType.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.jmsoftware.maf.springcloudstarter.validation.annotation - -/** - * # DateTimeRangeType - * - * Description: DateTimeRangeType, change description here. - * - * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/16/22 9:59 AM - */ -enum class DateTimeRangeType { - /** - * Start time - */ - START_TIME, - - /** - * End time - */ - END_TIME -} diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/ValidEnumValue.java b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/ValidEnumValue.java deleted file mode 100644 index 3a240447..00000000 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/annotation/ValidEnumValue.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.jmsoftware.maf.springcloudstarter.validation.annotation; - -import com.jmsoftware.maf.springcloudstarter.validation.validator.EnumValueValidator; - -import javax.validation.Constraint; -import javax.validation.Payload; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - *

ValidEnumValue

- *

- * Change description here. - * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 5/29/21 12:31 PM - **/ -@Documented -@Retention(RUNTIME) -@Target({FIELD, PARAMETER}) -@Constraint(validatedBy = EnumValueValidator.class) -public @interface ValidEnumValue { - String message() default "Invalid enumeration value"; - - Class[] groups() default {}; - - Class[] payload() default {}; - - Class targetEnum() default Enum.class; - - boolean ignoreNull() default false; -} diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/validator/DateTimeRangeValidator.kt b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/validator/DateTimeRangeValidator.kt deleted file mode 100644 index ff24bdd6..00000000 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/validator/DateTimeRangeValidator.kt +++ /dev/null @@ -1,103 +0,0 @@ -package com.jmsoftware.maf.springcloudstarter.validation.validator - -import cn.hutool.core.collection.CollUtil -import cn.hutool.core.util.ObjectUtil -import cn.hutool.core.util.ReflectUtil -import com.jmsoftware.maf.common.util.logger -import com.jmsoftware.maf.springcloudstarter.validation.annotation.DateTimeRangeConstraints -import com.jmsoftware.maf.springcloudstarter.validation.annotation.DateTimeRangeGroup -import com.jmsoftware.maf.springcloudstarter.validation.annotation.DateTimeRangeType -import java.lang.reflect.Field -import java.time.LocalDateTime -import java.util.* -import javax.validation.ConstraintValidator -import javax.validation.ConstraintValidatorContext - -/** - * # DateTimeRangeValidator - * - * Description: DateTimeRangeValidator, change description here. - * - * @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/16/22 9:39 AM - */ -class DateTimeRangeValidator : ConstraintValidator { - companion object { - const val MAX_GROUP_SIZE = 2 - private const val DEFAULT_HASH_MAP_CAPACITY = 8 - val log = logger() - } - - override fun isValid(value: Any, context: ConstraintValidatorContext): Boolean { - val annotatedFieldSet = getAnnotatedFieldSet(value) - if (CollUtil.isEmpty(annotatedFieldSet)) { - log.warn( - "There is not fields annotated by {} in the class({})", value.javaClass.name, - DateTimeRangeGroup::class.java.simpleName - ) - return true - } - val dateTimeRangeGroupMap = HashMap>(DEFAULT_HASH_MAP_CAPACITY) - for (field in annotatedFieldSet) { - val annotation = field.getAnnotation(DateTimeRangeGroup::class.java) - if (!dateTimeRangeGroupMap.containsKey(annotation.groupName)) { - dateTimeRangeGroupMap[annotation.groupName] = CollUtil.newLinkedList(field) - } else { - dateTimeRangeGroupMap[annotation.groupName]!!.add(field) - if (dateTimeRangeGroupMap[annotation.groupName]!!.size > MAX_GROUP_SIZE) { - log.error( - "The length of DateTimeRangeGroup({}) cannot exceed {}!", annotation.groupName, - MAX_GROUP_SIZE - ) - return false - } - } - } - return validate(value, dateTimeRangeGroupMap) - } - - private fun getAnnotatedFieldSet(value: Any): HashSet { - val fields = value.javaClass.declaredFields - val annotatedFieldSet = CollUtil.newHashSet() - for (field in fields) { - val annotation = field.getAnnotation(DateTimeRangeGroup::class.java) - if (ObjectUtil.isNotNull(annotation)) { - annotatedFieldSet.add(field) - } - } - return annotatedFieldSet - } - - private fun validate(value: Any, dateTimeRangeGroupMap: HashMap>): Boolean { - for ((groupName, fieldList) in dateTimeRangeGroupMap) { - if (fieldList.size != MAX_GROUP_SIZE) { - log.error("The length of DateTimeRangeGroup({}) is not correct!", groupName) - return false - } - val dateTimeRangeGroup = fieldList[0].getAnnotation( - DateTimeRangeGroup::class.java - ) - var startTime: Any? = null - var endTime: Any? = null - when (dateTimeRangeGroup.type) { - DateTimeRangeType.START_TIME -> { - startTime = ReflectUtil.getFieldValue(value, fieldList[0]) - endTime = ReflectUtil.getFieldValue(value, fieldList[1]) - } - DateTimeRangeType.END_TIME -> { - startTime = ReflectUtil.getFieldValue(value, fieldList[1]) - endTime = ReflectUtil.getFieldValue(value, fieldList[0]) - } - } - if (ObjectUtil.hasNull(startTime, endTime)) { - return true - } - if (startTime is Date && endTime is Date && startTime.after(endTime)) { - return false - } - if (startTime is LocalDateTime && endTime is LocalDateTime && startTime.isAfter(endTime)) { - return false - } - } - return true - } -} diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/validator/EnumValueValidator.java b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/validator/EnumValueValidator.java deleted file mode 100644 index ff62a0cb..00000000 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/validation/validator/EnumValueValidator.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.jmsoftware.maf.springcloudstarter.validation.validator; - -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.ReflectUtil; -import com.jmsoftware.maf.common.enumeration.ValueDescriptionBaseEnum; -import com.jmsoftware.maf.springcloudstarter.validation.annotation.ValidEnumValue; -import lombok.extern.slf4j.Slf4j; -import lombok.val; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Objects; - -/** - *

EnumValueValidator

- *

- * Change description here. - * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 5/29/21 12:34 PM - **/ -@Slf4j -public class EnumValueValidator implements ConstraintValidator { - private String methodName; - private ValidEnumValue validEnumValue; - - /** - * {@inheritDoc} - */ - @Override - public void initialize(ValidEnumValue constraintAnnotation) { - ConstraintValidator.super.initialize(constraintAnnotation); - this.validEnumValue = constraintAnnotation; - this.methodName = ReflectUtil.getMethodByName(ValueDescriptionBaseEnum.class, "getValue").getName(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isValid(Number value, ConstraintValidatorContext context) { - val enumClass = this.validEnumValue.targetEnum(); - val ignoreNull = this.validEnumValue.ignoreNull(); - if (!enumClass.isEnum()) { - log.warn("The given target enum class is not enum! {}", enumClass.getName()); - return false; - } - if (ignoreNull && ObjectUtil.isNull(value)) { - return true; - } - val enumConstantArray = enumClass.getEnumConstants(); - Method method; - try { - method = enumClass.getMethod(this.methodName); - } catch (NoSuchMethodException | SecurityException e) { - log.warn("Did not find the method {} in the class {}", this.methodName, enumClass.getName()); - return false; - } - var validResult = false; - try { - for (val obj : enumConstantArray) { - Object valueDeclaredInEnum = method.invoke(obj); - if (Objects.deepEquals(value, valueDeclaredInEnum)) { - validResult = true; - break; - } - } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - log.error("Exception occurred when invoking method! Exception message: {}", e.getMessage()); - return false; - } - return validResult; - } -}