Skip to content

Commit

Permalink
Merge pull request #10 from liuliaozhong/3.7.x_issue_2414
Browse files Browse the repository at this point in the history
perf: 更新文件源接口只传id不传code时报错 TencentBlueKing#2414
  • Loading branch information
liuliaozhong authored Nov 24, 2023
2 parents 8d71fbe + 0490695 commit 7c50e59
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
1260016=文件源ID与标识至少指定一个
1260017=文件源[id={0}]不在业务/业务集下
1260018=接入点响应异常,详情:{0}
1260019=文件源code不可为空

##业务错误-文件Worker服务(job-file-worker)
1262001=第三方文件源响应异常:ListBucket,详情:{0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
1260016=At least one of id/code required
1260017=FileSource[id={0}] does not belong to specified business
1260018=FileWorker response error, Detail:{0}
1260019=File source code can not be empty

## Business error (job-file-worker)
1262001=Third file source response error:ListBucket, Detail:{0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
1260016=At least one of id/code required
1260017=FileSource[id={0}] does not belong to specified business
1260018=FileWorker response error, Detail:{0}
1260019=File source code can not be empty

## Business error (job-file-worker)
1262001=Third file source response error:ListBucket, Detail:{0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
1260016=文件源ID与标识至少指定一个
1260017=文件源[id={0}]不在业务/业务集下
1260018=接入点响应异常,详情:{0}
1260019=文件源code不可为空

##业务错误-文件Worker服务(job-file-worker)
1262001=第三方文件源响应异常:ListBucket,详情:{0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
1260016=文件源ID与标识至少指定一个
1260017=文件源[id={0}]不在业务/业务集下
1260018=接入点响应异常,详情:{0}
1260019=文件源code不可为空

##业务错误-文件Worker服务(job-file-worker)
1262001=第三方文件源响应异常:ListBucket,详情:{0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.tencent.bk.job.common.exception.FailedPreconditionException;
import com.tencent.bk.job.common.exception.InternalException;
import com.tencent.bk.job.common.exception.InvalidParamException;
import com.tencent.bk.job.common.exception.MissingParameterException;
import com.tencent.bk.job.common.exception.NotFoundException;
import com.tencent.bk.job.common.exception.ResourceExhaustedException;
import com.tencent.bk.job.common.exception.ServiceException;
Expand Down Expand Up @@ -160,6 +161,15 @@ ResponseEntity<?> handleUnauthenticatedException(HttpServletRequest request, Una
return new ResponseEntity<>(EsbResp.buildCommonFailResp(ex), HttpStatus.OK);
}

@ExceptionHandler({MissingParameterException.class})
@ResponseBody
ResponseEntity<?> handleMissingParameterException (HttpServletRequest request,
MissingParameterException ex) {
String errorMsg = "Handle MissingParameterException , uri: " + request.getRequestURI();
log.warn(errorMsg, ex);
return new ResponseEntity<>(EsbResp.buildCommonFailResp(ex), HttpStatus.BAD_REQUEST);
}

@Override
@SuppressWarnings("all")
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ public class ErrorCode {
public static final int FILE_SOURCE_ID_NOT_IN_BIZ = 1260017;
// 接入点响应异常,详情:{0}
public static final int FAIL_TO_REQUEST_FILE_WORKER_WITH_REASON = 1260018;
// 文件源code不可为空
public static final int FILE_SOURCE_CODE_CAN_NOT_BE_EMPTY = 1260019;

// 文件网关 end
// 文件代理 start
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.exception;

import com.tencent.bk.job.common.model.ValidateResult;
import com.tencent.bk.job.common.model.error.ErrorType;
import lombok.Getter;
import lombok.ToString;

/**
* 请求参数为空异常
*/
@Getter
@ToString
public class MissingParameterException extends ServiceException {
public MissingParameterException(Integer errorCode) {
super(ErrorType.INVALID_PARAM, errorCode);
}

public MissingParameterException(Integer errorCode, Object[] errorParams) {
super(ErrorType.INVALID_PARAM, errorCode, errorParams);
}

public MissingParameterException(Integer errorCode, Object errorParam) {
super(ErrorType.INVALID_PARAM, errorCode, new Object[]{errorParam});
}

public MissingParameterException(String message, Integer errorCode) {
super(message, ErrorType.INVALID_PARAM, errorCode);
}

public MissingParameterException(String message, Integer errorCode, Object[] errorParams) {
super(message, ErrorType.INVALID_PARAM, errorCode, errorParams);
}

public MissingParameterException(Throwable cause, Integer errorCode) {
super(cause, ErrorType.INVALID_PARAM, errorCode);
}

public MissingParameterException(Throwable cause, Integer errorCode, Object[] errorParams) {
super(cause, ErrorType.INVALID_PARAM, errorCode, errorParams);
}

public MissingParameterException(String message, Throwable cause, Integer errorCode) {
super(message, cause, ErrorType.INVALID_PARAM, errorCode);
}

public MissingParameterException(String message, Throwable cause, Integer errorCode,
Object[] errorParams) {
super(message, cause, ErrorType.INVALID_PARAM, errorCode, errorParams);
}

public MissingParameterException(ValidateResult validateResult) {
super(ErrorType.INVALID_PARAM, validateResult.getErrorCode(), validateResult.getErrorParams());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.tencent.bk.job.common.esb.model.EsbResp;
import com.tencent.bk.job.common.exception.FailedPreconditionException;
import com.tencent.bk.job.common.exception.InvalidParamException;
import com.tencent.bk.job.common.exception.MissingParameterException;
import com.tencent.bk.job.common.iam.exception.PermissionDeniedException;
import com.tencent.bk.job.common.iam.model.AuthResult;
import com.tencent.bk.job.common.model.dto.AppResourceScope;
Expand Down Expand Up @@ -106,6 +107,9 @@ private void checkCreateParam(EsbCreateOrUpdateFileSourceV3Req req) {
private Integer checkUpdateParamAndGetId(EsbCreateOrUpdateFileSourceV3Req req) {
Long appId = req.getAppId();
String code = req.getCode();
if (StringUtils.isBlank(code)) {
throw new MissingParameterException(ErrorCode.FILE_SOURCE_CODE_CAN_NOT_BE_EMPTY);
}
Integer id = fileSourceService.getFileSourceIdByCode(appId, code);
if (id == null) {
throw new FailedPreconditionException(ErrorCode.FAIL_TO_FIND_FILE_SOURCE_BY_CODE, new String[]{code});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ private void saveFileSourceShareInfo(DSLContext dslContext, Integer fileSourceId
public int updateFileSource(DSLContext dslContext, FileSourceDTO fileSourceDTO) {
val query = dslContext.update(defaultTable);
var updateSetStep = query.set(defaultTable.APP_ID, fileSourceDTO.getAppId());
updateSetStep = updateSetStep.set(defaultTable.CODE, fileSourceDTO.getCode());
if (StringUtils.isNotBlank(fileSourceDTO.getCode())) {
updateSetStep = updateSetStep.set(defaultTable.CODE, fileSourceDTO.getCode());
}
if (StringUtils.isNotBlank(fileSourceDTO.getAlias())) {
updateSetStep = updateSetStep.set(defaultTable.ALIAS, fileSourceDTO.getAlias());
}
Expand Down Expand Up @@ -490,22 +492,15 @@ public boolean existsFileSource(Long appId, Integer id) {
@Override
public Integer getFileSourceIdByCode(Long appId, String code) {
List<Condition> conditions = new ArrayList<>();
if (appId != null) {
conditions.add(defaultTable.APP_ID.eq(appId));
}
if (code != null) {
conditions.add(defaultTable.CODE.eq(code));
}
conditions.add(defaultTable.APP_ID.eq(appId));
conditions.add(defaultTable.CODE.eq(code));
val query = defaultContext.select(
defaultTable.ID
).from(defaultTable)
.where(conditions);
val result = query.fetch();
if (result.size() > 0) {
if (result.size() > 1) {
log.warn("{} records found when get id by code, use first one", result.size());
}
return result.get(0).get(defaultTable.ID);
val result = query.fetchOne();
if (result != null) {
return result.get(defaultTable.ID);
}
return null;
}
Expand Down

0 comments on commit 7c50e59

Please sign in to comment.