Commit 75ce9158 authored by liaozan's avatar liaozan 🏀

Generate toString method with callSuper=true

parent 9f4bf6fc
......@@ -38,4 +38,4 @@ public class BaseException extends RuntimeException {
this.action = action;
}
}
\ No newline at end of file
}
package com.schbrain.common.web.exception;
import com.schbrain.common.web.annotation.ResponseWrapOption;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.method.HandlerMethod;
......@@ -30,7 +29,6 @@ import static com.schbrain.common.web.utils.HandlerMethodAnnotationUtils.getAnno
* @since 2022/8/30
*/
@Slf4j
@EqualsAndHashCode(callSuper = true)
public class DefaultGlobalExceptionResolver extends AbstractHandlerMethodExceptionResolver {
private final GlobalExceptionHandler exceptionHandler;
......@@ -49,6 +47,9 @@ public class DefaultGlobalExceptionResolver extends AbstractHandlerMethodExcepti
@Override
protected boolean shouldApplyTo(HttpServletRequest request, @Nullable Object handler) {
if (handler == null) {
return super.shouldApplyTo(request, null);
}
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
ResponseWrapOption responseWrapOption = getAnnotation(handlerMethod, ResponseWrapOption.class);
......
......@@ -39,12 +39,13 @@ public class ExceptionHandingWebMvcConfigurer implements WebMvcConfigurer {
}
}
int index;
if (adviceExceptionResolver == null) {
log.warn("ExceptionHandlerExceptionResolver is not exist, ignore global exception handing");
return;
index = 0;
} else {
index = resolvers.indexOf(adviceExceptionResolver) + 1;
}
int index = resolvers.indexOf(adviceExceptionResolver) + 1;
resolvers.add(index, createExceptionResolver(adviceExceptionResolver));
}
......
......@@ -2,17 +2,17 @@ package com.schbrain.framework.autoconfigure.oss.bean;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* @author lik
* @since 2022/9/6
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class CopyResult extends OssOperationResult {
private static final long serialVersionUID = 7322484488471640978L;
private String destinationKey;
private String destinationBucket;
......
......@@ -2,6 +2,7 @@ package com.schbrain.framework.autoconfigure.oss.bean;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.List;
......@@ -10,11 +11,10 @@ import java.util.List;
* @since 2022/9/6
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class DeleteResult extends OssOperationResult {
private static final long serialVersionUID = -1964404722922995469L;
private List<String> deleteObjectKeys;
public static DeleteResult success(String bucket, List<String> objectKeys) {
......
......@@ -3,17 +3,17 @@ package com.schbrain.framework.autoconfigure.oss.bean;
import com.aliyun.oss.model.OSSObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* @author liaozan
* @since 2021/12/3
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class DownloadResult extends OssOperationResult {
private static final long serialVersionUID = -9010079317621184645L;
private OSSObject ossObject;
public static DownloadResult success(String bucket, String objectKey, OSSObject ossObject) {
......@@ -34,4 +34,4 @@ public class DownloadResult extends OssOperationResult {
return result;
}
}
\ No newline at end of file
}
......@@ -3,6 +3,8 @@ package com.schbrain.framework.autoconfigure.oss.bean;
import com.aliyuncs.auth.sts.AssumeRoleResponse.Credentials;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.time.LocalDateTime;
import java.time.ZoneId;
......@@ -14,11 +16,11 @@ import java.time.format.DateTimeFormatter;
* @since 2021/12/4
*/
@Data
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class UploadCredentials extends OssOperationResult {
private static final long serialVersionUID = 5546792221041679671L;
private String accessKeyId;
private String accessKeySecret;
......@@ -27,11 +29,6 @@ public class UploadCredentials extends OssOperationResult {
private LocalDateTime expiration;
// for json deserialize
public UploadCredentials() {
}
public UploadCredentials(Credentials credentials) {
this.success = true;
this.accessKeyId = credentials.getAccessKeyId();
......@@ -49,4 +46,4 @@ public class UploadCredentials extends OssOperationResult {
this.errorMsg = errorMsg;
}
}
\ No newline at end of file
}
......@@ -2,17 +2,17 @@ package com.schbrain.framework.autoconfigure.oss.bean;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* @author liaozan
* @since 2021/12/3
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class UploadResult extends OssOperationResult {
private static final long serialVersionUID = 7408490108665799098L;
private String url;
public static UploadResult success(String bucket, String objectKey, String url) {
......@@ -33,4 +33,4 @@ public class UploadResult extends OssOperationResult {
return result;
}
}
\ No newline at end of file
}
......@@ -16,6 +16,7 @@ import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.schbrain.common.util.ApplicationName;
import com.schbrain.common.util.StreamUtils;
import com.schbrain.common.util.ValidateUtils;
import com.schbrain.framework.autoconfigure.oss.bean.*;
import com.schbrain.framework.autoconfigure.oss.exception.OssException;
......@@ -23,6 +24,7 @@ import com.schbrain.framework.autoconfigure.oss.properties.OssProperties;
import com.schbrain.framework.autoconfigure.oss.properties.OssProperties.StsProperties;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
......@@ -33,7 +35,6 @@ import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author liaozan
......@@ -265,8 +266,8 @@ public class OssUtils {
public static DeleteResult deleteObject(String bucket, List<String> objectKeys) {
ValidateUtils.notEmpty(bucket, "bucket can not be empty");
ValidateUtils.notEmpty(objectKeys, "objectKeys can not be empty");
String notExistKeys = objectKeys.stream().filter(key -> !exist(bucket, key)).collect(Collectors.joining(","));
if (StringUtils.isNotBlank(notExistKeys)) {
List<String> notExistKeys = StreamUtils.filterToList(objectKeys, key -> !exist(bucket, key));
if (CollectionUtils.isNotEmpty(notExistKeys)) {
String errorMsg = StrFormatter.format("objectKeys:[{}] not exist", notExistKeys);
return DeleteResult.fail(bucket, objectKeys, errorMsg);
}
......@@ -286,8 +287,12 @@ public class OssUtils {
private static DownloadResult download0(String bucket, String objectKey) {
GetObjectRequest request = new GetObjectRequest(bucket, objectKey);
OSSObject ossObject = getOssClient().getObject(request);
return DownloadResult.success(bucket, objectKey, ossObject);
try {
OSSObject ossObject = getOssClient().getObject(request);
return DownloadResult.success(bucket, objectKey, ossObject);
} catch (Exception e) {
return DownloadResult.fail(bucket, objectKey, e.getMessage());
}
}
private static UploadResult upload0(Object object, String bucket, String objectKey, boolean allowOverwrite, boolean appendPrefix, ObjectMetadata metadata) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment