diff --git a/src/main/java/io/choerodon/test/manager/app/assembler/TestCaseAssembler.java b/src/main/java/io/choerodon/test/manager/app/assembler/TestCaseAssembler.java index 7323a1aa..f4661cf3 100644 --- a/src/main/java/io/choerodon/test/manager/app/assembler/TestCaseAssembler.java +++ b/src/main/java/io/choerodon/test/manager/app/assembler/TestCaseAssembler.java @@ -14,6 +14,9 @@ import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; +import org.hzero.boot.file.dto.FileDTO; +import org.hzero.core.base.BaseConstants; +import org.hzero.core.util.ResponseUtils; import io.choerodon.core.exception.CommonException; import io.choerodon.core.oauth.CustomUserDetails; import io.choerodon.mybatis.domain.AuditDomain; @@ -29,10 +32,6 @@ import io.choerodon.test.manager.infra.util.AttachmentUtils; import io.choerodon.test.manager.infra.util.IAttachmentPreviewInfoUtil; -import org.hzero.boot.file.dto.FileDTO; -import org.hzero.core.base.BaseConstants; -import org.hzero.core.util.ResponseUtils; - /** * @author zhaotianxin * @since 2019/11/22 @@ -68,8 +67,6 @@ public class TestCaseAssembler { private FileFeignClient fileFeignClient; @Autowired private ModelMapper modelMapper; - @Autowired - private AttachmentUtils attachmentUtils; private static final String TYPE = "CYCLE_CASE"; @@ -162,9 +159,9 @@ public TestCaseInfoVO dtoToInfoVO(TestCaseDTO testCaseDTO) { List fileKeys = new ArrayList<>(); if (CollectionUtils.isNotEmpty(attachment)) { Set urls = attachment.stream().map(TestCaseAttachmentDTO::getUrl).collect(Collectors.toSet()); - Map stringStringMap = attachmentUtils.getFileKeys(urls); + Map urlToFileKeyMap = AttachmentUtils.getFileKeys(urls); for (TestCaseAttachmentDTO testCaseAttachment : attachment) { - String fileKey = stringStringMap.get(testCaseAttachment.getUrl()); + String fileKey = urlToFileKeyMap.get(testCaseAttachment.getUrl()); if (!ObjectUtils.isEmpty(fileKey)) { testCaseAttachment.setFileKey(fileKey); fileKeys.add(fileKey); diff --git a/src/main/java/io/choerodon/test/manager/app/service/impl/TestCaseAttachmentServiceImpl.java b/src/main/java/io/choerodon/test/manager/app/service/impl/TestCaseAttachmentServiceImpl.java index e30a51fa..267dba7d 100644 --- a/src/main/java/io/choerodon/test/manager/app/service/impl/TestCaseAttachmentServiceImpl.java +++ b/src/main/java/io/choerodon/test/manager/app/service/impl/TestCaseAttachmentServiceImpl.java @@ -16,6 +16,9 @@ import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.hzero.boot.file.FileClient; +import org.hzero.boot.file.dto.FileDTO; +import org.hzero.core.util.ResponseUtils; import io.choerodon.core.exception.CommonException; import io.choerodon.core.oauth.CustomUserDetails; import io.choerodon.core.oauth.DetailsHelper; @@ -42,10 +45,6 @@ import io.choerodon.test.manager.infra.util.AttachmentUtils; import io.choerodon.test.manager.infra.util.IAttachmentPreviewInfoUtil; -import org.hzero.boot.file.FileClient; -import org.hzero.boot.file.dto.FileDTO; -import org.hzero.core.util.ResponseUtils; - /** * @author zhaotianxin * @since 2019/11/21 @@ -79,9 +78,6 @@ public class TestCaseAttachmentServiceImpl implements TestCaseAttachmentService private FilePathService filePathService; @Autowired private FileClient fileClient; - @Autowired - private AttachmentUtils attachmentUtils; - @Override public TestCaseAttachmentDTO dealIssue(Long projectId, Long issueId, String fileName, String url) { @@ -286,7 +282,7 @@ public TestCaseAttachmentDTO attachmentCombineUpload(Long projectId, TestCaseAtt String relativePath = filePathService.generateRelativePath(path); TestCaseAttachmentDTO attachment = dealIssue(projectId, caseId, fileName, relativePath); // 填充wps onlyOffice预览所需要的信息 - String fileKey = attachmentUtils.getFileKey(attachment.getUrl()); + String fileKey = AttachmentUtils.getFileKey(attachment.getUrl()); attachment.setFileKey(fileKey); ProjectDTO project = remoteIamOperator.getProjectById(projectId); if (project != null && StringUtils.isNotBlank(fileKey)) { diff --git a/src/main/java/io/choerodon/test/manager/app/service/impl/TestCycleCaseAttachmentRelServiceImpl.java b/src/main/java/io/choerodon/test/manager/app/service/impl/TestCycleCaseAttachmentRelServiceImpl.java index 1bb7221c..a2780c6e 100644 --- a/src/main/java/io/choerodon/test/manager/app/service/impl/TestCycleCaseAttachmentRelServiceImpl.java +++ b/src/main/java/io/choerodon/test/manager/app/service/impl/TestCycleCaseAttachmentRelServiceImpl.java @@ -15,6 +15,8 @@ import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.hzero.boot.file.dto.FileDTO; +import org.hzero.core.util.ResponseUtils; import io.choerodon.core.exception.CommonException; import io.choerodon.core.oauth.CustomUserDetails; import io.choerodon.core.oauth.DetailsHelper; @@ -33,12 +35,8 @@ import io.choerodon.test.manager.infra.feign.operator.RemoteIamOperator; import io.choerodon.test.manager.infra.mapper.TestAttachmentMapper; import io.choerodon.test.manager.infra.mapper.TestCycleCaseAttachmentRelMapper; -import io.choerodon.test.manager.infra.util.AttachmentUtils; import io.choerodon.test.manager.infra.util.IAttachmentPreviewInfoUtil; -import org.hzero.boot.file.dto.FileDTO; -import org.hzero.core.util.ResponseUtils; - /** * Created by 842767365@qq.com on 6/11/18. */ @@ -62,8 +60,6 @@ public class TestCycleCaseAttachmentRelServiceImpl implements TestCycleCaseAttac private TestCycleCaseAttachmentRelUploadService testCycleCaseAttachmentRelUploadService; @Autowired private FilePathService filePathService; - @Autowired - private AttachmentUtils attachmentUtils; @Override public void deleteAttachmentRel(Long projectId,Long attachId) { @@ -201,7 +197,10 @@ private void handAttachment(ProjectDTO project, List fileUrls = testCycleCaseAttachmentRelVOS.stream().map(TestCycleCaseAttachmentRelVO::getUrl).collect(Collectors.toList()); + List fileUrls = testCycleCaseAttachmentRelVOS.stream() + .peek(testCycleCaseAttachmentRel -> testCycleCaseAttachmentRel.setFileKey(testCycleCaseAttachmentRel.getUrl())) + .map(TestCycleCaseAttachmentRelVO::getUrl) + .collect(Collectors.toList()); if(CollectionUtils.isEmpty(fileUrls)) { return; } diff --git a/src/main/java/io/choerodon/test/manager/app/service/impl/TestCycleCaseStepServiceImpl.java b/src/main/java/io/choerodon/test/manager/app/service/impl/TestCycleCaseStepServiceImpl.java index 85dae4a8..f5091507 100644 --- a/src/main/java/io/choerodon/test/manager/app/service/impl/TestCycleCaseStepServiceImpl.java +++ b/src/main/java/io/choerodon/test/manager/app/service/impl/TestCycleCaseStepServiceImpl.java @@ -11,6 +11,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.hzero.boot.file.dto.FileDTO; +import org.hzero.core.util.ResponseUtils; import io.choerodon.core.domain.Page; import io.choerodon.core.exception.CommonException; import io.choerodon.core.oauth.CustomUserDetails; @@ -29,14 +31,10 @@ import io.choerodon.test.manager.infra.feign.FileFeignClient; import io.choerodon.test.manager.infra.feign.operator.RemoteIamOperator; import io.choerodon.test.manager.infra.mapper.*; -import io.choerodon.test.manager.infra.util.AttachmentUtils; import io.choerodon.test.manager.infra.util.ConvertUtils; import io.choerodon.test.manager.infra.util.IAttachmentPreviewInfoUtil; import io.choerodon.test.manager.infra.util.PageUtil; -import org.hzero.boot.file.dto.FileDTO; -import org.hzero.core.util.ResponseUtils; - /** * Created by 842767365@qq.com on 6/11/18. */ @@ -66,14 +64,10 @@ public class TestCycleCaseStepServiceImpl implements TestCycleCaseStepService { @Autowired private TestCycleCaseMapper testCycleCaseMapper; @Autowired - private FilePathService filePathService; - @Autowired private RemoteIamOperator remoteIamOperator; @Autowired private FileFeignClient fileFeignClient; - @Autowired - private AttachmentUtils attachmentUtils; - + @Override public void update(TestCycleCaseStepVO testCycleCaseStepVO) { TestCycleCaseStepDTO testCycleCaseStepDTO = modelMapper.map(testCycleCaseStepVO, TestCycleCaseStepDTO.class); @@ -298,7 +292,10 @@ private void handAttachment(Long projectId, List testCycleC if (CollectionUtils.isEmpty(testCycleCaseAttachmentRelVOS)) { return; } - List fileUrls = testCycleCaseAttachmentRelVOS.stream().map(TestCycleCaseAttachmentRelVO::getUrl).collect(Collectors.toList()); + List fileUrls = testCycleCaseAttachmentRelVOS.stream() + .peek(testCycleCaseAttachmentRel -> testCycleCaseAttachmentRel.setFileKey(testCycleCaseAttachmentRel.getUrl())) + .map(TestCycleCaseAttachmentRelVO::getUrl) + .collect(Collectors.toList()); if(CollectionUtils.isEmpty(fileUrls)) { return; } diff --git a/src/main/java/io/choerodon/test/manager/infra/util/AttachmentUtils.java b/src/main/java/io/choerodon/test/manager/infra/util/AttachmentUtils.java index 2c3f9b6c..b9bf2bfa 100644 --- a/src/main/java/io/choerodon/test/manager/infra/util/AttachmentUtils.java +++ b/src/main/java/io/choerodon/test/manager/infra/util/AttachmentUtils.java @@ -7,7 +7,6 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Component; import org.hzero.core.base.BaseConstants; @@ -16,9 +15,9 @@ * * @author 汪翔 2023-06-05 */ -@Component public class AttachmentUtils { - public String getFileKey(String relativePath) { + + public static String getFileKey(String relativePath) { if (StringUtils.isNotEmpty(relativePath) && relativePath.startsWith(BaseConstants.Symbol.SLASH)) { return relativePath.substring(1); } else { @@ -26,7 +25,7 @@ public String getFileKey(String relativePath) { } } - public Map getFileKeys(Set relativePaths) { + public static Map getFileKeys(Set relativePaths) { // 对于测试的附件 if (CollectionUtils.isEmpty(relativePaths)) { return Collections.emptyMap(); @@ -36,15 +35,15 @@ public Map getFileKeys(Set relativePaths) { return fileKeys; } - public static String getFileType(String fileKey) { - if (StringUtils.isEmpty(fileKey)) { - return ""; + public static String getFileType(String fileKeyOrUrl) { + if (StringUtils.isEmpty(fileKeyOrUrl)) { + return StringUtils.EMPTY; } - int index = fileKey.lastIndexOf("."); + int index = fileKeyOrUrl.lastIndexOf(BaseConstants.Symbol.POINT); if (index > -1) { - return fileKey.substring(index + 1); + return fileKeyOrUrl.substring(index + 1); } else { - return ""; + return StringUtils.EMPTY; } } } diff --git a/src/main/java/io/choerodon/test/manager/infra/util/IAttachmentPreviewInfoUtil.java b/src/main/java/io/choerodon/test/manager/infra/util/IAttachmentPreviewInfoUtil.java index e0e3381d..2317f4be 100644 --- a/src/main/java/io/choerodon/test/manager/infra/util/IAttachmentPreviewInfoUtil.java +++ b/src/main/java/io/choerodon/test/manager/infra/util/IAttachmentPreviewInfoUtil.java @@ -10,10 +10,9 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; -import io.choerodon.test.manager.api.vo.IAttachmentPreviewInfo; - import org.hzero.boot.file.dto.FileDTO; import org.hzero.core.base.BaseConstants; +import io.choerodon.test.manager.api.vo.IAttachmentPreviewInfo; /** * 可预览附件处理工具 @@ -29,7 +28,7 @@ public class IAttachmentPreviewInfoUtil { * @param fileInfos 文件信息 */ public static void fillAttachmentFileAttributeByFileKey(Collection attachmentInfos, Collection fileInfos) { - fillAttachmentFileAttributeByFileKey(attachmentInfos, fileInfos, IAttachmentPreviewInfo::getFileKey, FileDTO::getFileKey); + fillAttachmentFileAttributeByFileIdentity(attachmentInfos, fileInfos, IAttachmentPreviewInfo::getFileKey, FileDTO::getFileKey); } /** @@ -38,7 +37,7 @@ public static void fillAttachmentFileAttributeByFileKey(Collection attachmentInfos, Collection fileInfos) { - fillAttachmentFileAttributeByFileKey(attachmentInfos, fileInfos, IAttachmentPreviewInfo::getUrl, FileDTO::getFileUrl); + fillAttachmentFileAttributeByFileIdentity(attachmentInfos, fileInfos, IAttachmentPreviewInfo::getUrl, FileDTO::getFileUrl); } /** @@ -48,7 +47,7 @@ public static void fillAttachmentFileAttributeByFileUrl(Collection void fillAttachmentFileAttributeByFileKey(Collection attachmentInfos, + private static void fillAttachmentFileAttributeByFileIdentity(Collection attachmentInfos, Collection fileInfos, Function attachmentIdentityExtractor, Function fileIdentityExtractor) {