From e0ee4cd184a96907e250d43e94ce014e598aac30 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 11 Oct 2023 14:32:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=96=87=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/sdk/file/LocalFileRepository.java | 11 +++++------ .../sdk/util/{SubListUtil.java => SubListUtils.java} | 2 +- .../service/OrganizationCustomFieldService.java | 4 ++-- .../system/service/OrganizationTemplateService.java | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) rename backend/framework/sdk/src/main/java/io/metersphere/sdk/util/{SubListUtil.java => SubListUtils.java} (96%) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java index 4cebee74b9..b221350851 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/LocalFileRepository.java @@ -29,8 +29,8 @@ public class LocalFileRepository implements FileRepository { private void createFileDir(FileRequest request) { String dir = getFileDir(request); File fileDir = new File(dir); - if (!fileDir.exists()) { - fileDir.mkdirs(); + if (!fileDir.exists() && !fileDir.mkdirs()) { + throw new RuntimeException("Failed to create directory: " + dir); } } @@ -40,8 +40,6 @@ public class LocalFileRepository implements FileRepository { try (OutputStream ops = new FileOutputStream(file)) { ops.write(bytes); return file.getPath(); - } catch (Exception e) { - throw e; } } @@ -50,8 +48,8 @@ public class LocalFileRepository implements FileRepository { String path = StringUtils.join(getFilePath(request)); File file = new File(path); FileUtil.deleteContents(file); - if (file.exists()) { - file.delete(); + if (file.exists() && !file.delete()) { + throw new RuntimeException("Failed to delete file: " + path); } } @@ -74,6 +72,7 @@ public class LocalFileRepository implements FileRepository { @Override public void downloadFile(FileRequest request, String localPath) { + throw new UnsupportedOperationException(); } @Override diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/SubListUtil.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/SubListUtils.java similarity index 96% rename from backend/framework/sdk/src/main/java/io/metersphere/sdk/util/SubListUtil.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/util/SubListUtils.java index e4fa35e439..210442d476 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/SubListUtil.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/SubListUtils.java @@ -3,7 +3,7 @@ package io.metersphere.sdk.util; import java.util.List; import java.util.function.Consumer; -public class SubListUtil { +public class SubListUtils { /** * 将较长的数组截断成较短的数组进行批处理 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationCustomFieldService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationCustomFieldService.java index f8c43bc46e..1582e02595 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationCustomFieldService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationCustomFieldService.java @@ -5,7 +5,7 @@ import io.metersphere.sdk.dto.CustomFieldDTO; import io.metersphere.sdk.dto.request.CustomFieldOptionRequest; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.BeanUtils; -import io.metersphere.sdk.util.SubListUtil; +import io.metersphere.sdk.util.SubListUtils; import io.metersphere.system.domain.CustomField; import io.metersphere.system.domain.CustomFieldExample; import io.metersphere.system.domain.CustomFieldOption; @@ -143,7 +143,7 @@ public class OrganizationCustomFieldService extends BaseCustomFieldService { // 删除字段选项 List projectCustomFieldIds = extOrganizationCustomFieldMapper.getCustomFieldByRefId(orgCustomFieldId); // 分批删除 - SubListUtil.dealForSubList(projectCustomFieldIds, 100, baseCustomFieldOptionService::deleteByFieldIds); + SubListUtils.dealForSubList(projectCustomFieldIds, 100, baseCustomFieldOptionService::deleteByFieldIds); } private void checkOrganizationTemplateEnable(String orgId, String scene) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationTemplateService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationTemplateService.java index 10238c4fbf..632cbda61a 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationTemplateService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationTemplateService.java @@ -5,7 +5,7 @@ import io.metersphere.sdk.dto.TemplateDTO; import io.metersphere.sdk.dto.request.TemplateCustomFieldRequest; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.BeanUtils; -import io.metersphere.sdk.util.SubListUtil; +import io.metersphere.sdk.util.SubListUtils; import io.metersphere.system.domain.OrganizationParameter; import io.metersphere.system.domain.Template; import io.metersphere.system.domain.TemplateExample; @@ -179,7 +179,7 @@ public class OrganizationTemplateService extends BaseTemplateService { // 删除项目模板和字段的关联关系 List projectTemplateIds = extOrganizationTemplateMapper.getTemplateIdByRefId(orgTemplateId); // 分批删除 - SubListUtil.dealForSubList(projectTemplateIds, 100, baseTemplateCustomFieldService::deleteByTemplateIds); + SubListUtils.dealForSubList(projectTemplateIds, 100, baseTemplateCustomFieldService::deleteByTemplateIds); } private void checkOrganizationTemplateEnable(String orgId, String scene) {