diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiFileUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiFileUtil.java index cce14f38aa..13fdf2e6d0 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiFileUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiFileUtil.java @@ -204,6 +204,7 @@ public class ApiFileUtil extends FileUtils { attachmentBodyFile.setFileUpdateTime(fileMetadata.getUpdateTime()); attachmentBodyFile.setProjectId(fileMetadata.getProjectId()); attachmentBodyFile.setFilePath(path); + attachmentBodyFile.setFileType(fileMetadata.getType()); if (StringUtils.isNotBlank(fileMetadata.getAttachInfo())) { attachmentBodyFile.setFileAttachInfoJson(fileMetadata.getAttachInfo()); } @@ -212,10 +213,11 @@ public class ApiFileUtil extends FileUtils { if (!isLocal) { testElement.setProperty(JmxFileMetadataColumns.REF_FILE_STORAGE.name(), fileMetadata.getStorage()); testElement.setProperty(JmxFileMetadataColumns.REF_FILE_NAME.name(), fileMetadata.getName()); + testElement.setProperty(JmxFileMetadataColumns.REF_FILE_TYPE.name(), fileMetadata.getType()); testElement.setProperty(JmxFileMetadataColumns.REF_FILE_UPDATE_TIME.name(), fileMetadata.getUpdateTime()); testElement.setProperty(JmxFileMetadataColumns.REF_FILE_PROJECT_ID.name(), fileMetadata.getProjectId()); } else { - path = temporaryFileUtil.generateFilePath(attachmentBodyFile.getProjectId(), attachmentBodyFile.getFileMetadataId(), attachmentBodyFile.getFileUpdateTime(), attachmentBodyFile.getName()); + path = temporaryFileUtil.generateFilePath(attachmentBodyFile.getProjectId(), attachmentBodyFile.getFileMetadataId(), attachmentBodyFile.getFileUpdateTime(), attachmentBodyFile.getName(), attachmentBodyFile.getFileType()); } testElement.setProperty(ElementConstants.FILENAME, path); diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/AttachmentBodyFile.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/AttachmentBodyFile.java index b6e601875c..1bb36866b1 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/AttachmentBodyFile.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/AttachmentBodyFile.java @@ -8,6 +8,7 @@ import lombok.Setter; public class AttachmentBodyFile { private String id; private String name; + private String fileType; // 调试附件处理 private String refResourceId; diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/enums/JmxFileMetadataColumns.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/enums/JmxFileMetadataColumns.java index c2640c78e4..9c393ec1b6 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/enums/JmxFileMetadataColumns.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/enums/JmxFileMetadataColumns.java @@ -5,5 +5,6 @@ public enum JmxFileMetadataColumns { REF_FILE_UPDATE_TIME, REF_FILE_PROJECT_ID, REF_FILE_NAME, + REF_FILE_TYPE, JAR_PATH_CONFIG, } diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/TemporaryFileUtil.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/TemporaryFileUtil.java index c06a60f069..a4534b860e 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/TemporaryFileUtil.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/TemporaryFileUtil.java @@ -49,8 +49,16 @@ public class TemporaryFileUtil { return fileFolder + generateRelativeDir(folder, fileMetadataId, updateTime); } - public String generateFilePath(String folder, String fileMetadataId, long updateTime, String fileName) { - return generateFileDir(folder, fileMetadataId, updateTime) + fileName; + private String getFileName(String fileName, String fileSuffix) { + if (StringUtils.endsWithIgnoreCase(fileName, "." + fileSuffix)) { + return fileName; + } else { + return StringUtils.join(fileName, ".", fileSuffix); + } + } + + public String generateFilePath(String folder, String fileMetadataId, long updateTime, String fileName, String fileSuffix) { + return generateFileDir(folder, fileMetadataId, updateTime) + getFileName(fileName, fileSuffix); } public String generateLocalFilePath(String filePath) { @@ -63,8 +71,8 @@ public class TemporaryFileUtil { return file.exists() ? file : null; } - public File getFile(String folder, String fileMetadataId, long updateTime, String fileName) { - File file = new File(generateFilePath(folder, fileMetadataId, updateTime, fileName)); + public File getFile(String folder, String fileMetadataId, long updateTime, String fileName, String fileSuffix) { + File file = new File(generateFilePath(folder, fileMetadataId, updateTime, fileName, fileSuffix)); if (file.exists()) { return file; } else { @@ -72,18 +80,18 @@ public class TemporaryFileUtil { } } - public void saveFile(String folder, String fileMetadataId, long updateTime, String fileName, byte[] fileBytes) { + public void saveFile(String folder, String fileMetadataId, long updateTime, String fileName, String fileSuffix, byte[] fileBytes) { //删除过期文件 deleteOldFile(folder, fileMetadataId, updateTime, fileName); - this.createFile(generateFilePath(folder, fileMetadataId, updateTime, fileName), fileBytes); + this.createFile(generateFilePath(folder, fileMetadataId, updateTime, fileName, fileSuffix), fileBytes); } - public void saveFileByParamCheck(String folder, String fileMetadataId, long updateTime, String fileName, byte[] fileBytes) { + public void saveFileByParamCheck(String folder, String fileMetadataId, long updateTime, String fileName, String fileSuffix, byte[] fileBytes) { if (fileBytes != null && StringUtils.isNotBlank(folder) && updateTime > 0 && StringUtils.isNotBlank(fileName) && fileBytes.length > 0) { //删除过期文件 deleteOldFile(folder, fileMetadataId, updateTime, fileName); - this.createFile(generateFilePath(folder, fileMetadataId, updateTime, fileName), fileBytes); + this.createFile(generateFilePath(folder, fileMetadataId, updateTime, fileName, fileSuffix), fileBytes); } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/FileInfoDTO.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/FileInfoDTO.java index a81eaae984..d9890d7c52 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/FileInfoDTO.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/FileInfoDTO.java @@ -8,6 +8,8 @@ import lombok.Data; public class FileInfoDTO { private String id; private String fileName; + + private String type; private String projectId; private long fileLastUpdateTime; private String storage; diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/GitFileRepository.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/GitFileRepository.java index 1483c20cb5..d52f18bfb7 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/GitFileRepository.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/GitFileRepository.java @@ -101,6 +101,7 @@ public class GitFileRepository implements FileRepository { FileInfoDTO repositoryFileDTO = new FileInfoDTO( fileRequest.getResourceId(), MetadataUtils.getFileNameByRemotePath(gitFileInfo.getFilePath()), + fileRequest.getType(), fileRequest.getProjectId(), fileRequest.getUpdateTime(), StorageConstants.GIT.name(), diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/LocalFileRepository.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/LocalFileRepository.java index b3cff109a3..ba1d495092 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/LocalFileRepository.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/LocalFileRepository.java @@ -118,7 +118,7 @@ public class LocalFileRepository implements FileRepository { throw new RuntimeException(e); } return new FileInfoDTO( - fileRequest.getResourceId(), fileRequest.getFileName(), + fileRequest.getResourceId(), fileRequest.getFileName(), fileRequest.getType(), fileRequest.getProjectId(), fileRequest.getUpdateTime(), fileRequest.getStorage(), fileRequest.getPath(), content); }).collect(Collectors.toList()); diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/MinIOFileRepository.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/MinIOFileRepository.java index 43635e3a5f..99c619e427 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/MinIOFileRepository.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/repository/MinIOFileRepository.java @@ -133,7 +133,7 @@ public class MinIOFileRepository implements FileRepository { List list = new ArrayList<>(); if (CollectionUtils.isNotEmpty(requestList)) { for (FileRequest fileRequest : requestList) { - FileInfoDTO fileInfoDTO = new FileInfoDTO(fileRequest.getResourceId(), fileRequest.getFileName(), fileRequest.getProjectId(), fileRequest.getUpdateTime(), fileRequest.getStorage(), fileRequest.getPath(), this.getFile(fileRequest)); + FileInfoDTO fileInfoDTO = new FileInfoDTO(fileRequest.getResourceId(), fileRequest.getFileName(), fileRequest.getType(), fileRequest.getProjectId(), fileRequest.getUpdateTime(), fileRequest.getStorage(), fileRequest.getPath(), this.getFile(fileRequest)); list.add(fileInfoDTO); } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/service/FileMetadataService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/service/FileMetadataService.java index 6d6b0e5bce..c1dc1924bb 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/service/FileMetadataService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/metadata/service/FileMetadataService.java @@ -564,7 +564,7 @@ public class FileMetadataService { //检查是否存在已下载的文件 attachmentBodyFileList.forEach(fileMetadata -> { if (!StringUtils.equals(fileMetadata.getFileStorage(), StorageConstants.LOCAL.name())) { - File file = temporaryFileUtil.getFile(fileMetadata.getProjectId(), fileMetadata.getFileMetadataId(), fileMetadata.getFileUpdateTime(), fileMetadata.getName()); + File file = temporaryFileUtil.getFile(fileMetadata.getProjectId(), fileMetadata.getFileMetadataId(), fileMetadata.getFileUpdateTime(), fileMetadata.getName(), fileMetadata.getFileType()); if (file == null) { downloadFileList.add(fileMetadata); LoggerUtil.info("文件【" + fileMetadata.getFileUpdateTime() + "_" + fileMetadata.getName() + "】在执行目录【" + fileMetadata.getProjectId() + "】未找到,需要下载"); @@ -594,10 +594,10 @@ public class FileMetadataService { List downloadFileRequest = new ArrayList<>(); //检查是否存在已下载的文件 fileMetadataWithBLOBList.forEach(fileMetadata -> { - File file = temporaryFileUtil.getFile(fileMetadata.getProjectId(), fileMetadata.getId(), fileMetadata.getUpdateTime(), fileMetadata.getName()); + File file = temporaryFileUtil.getFile(fileMetadata.getProjectId(), fileMetadata.getId(), fileMetadata.getUpdateTime(), fileMetadata.getName(), fileMetadata.getType()); if (file != null) { LoggerUtil.info("文件【" + fileMetadata.getUpdateTime() + "_" + fileMetadata.getName() + "】在执行目录【" + fileMetadata.getProjectId() + "】已找到,无需下载"); - FileInfoDTO fileInfoDTO = new FileInfoDTO(fileMetadata.getId(), fileMetadata.getName(), fileMetadata.getProjectId(), fileMetadata.getUpdateTime(), fileMetadata.getStorage(), fileMetadata.getPath(), FileUtils.fileToByte(file)); + FileInfoDTO fileInfoDTO = new FileInfoDTO(fileMetadata.getId(), fileMetadata.getName(), fileMetadata.getType(), fileMetadata.getProjectId(), fileMetadata.getUpdateTime(), fileMetadata.getStorage(), fileMetadata.getPath(), FileUtils.fileToByte(file)); fileInfoDTOList.add(fileInfoDTO); } else { LoggerUtil.info("文件【" + fileMetadata.getUpdateTime() + "_" + fileMetadata.getName() + "】在执行目录【" + fileMetadata.getProjectId() + "】未找到,需要下载"); @@ -607,7 +607,7 @@ public class FileMetadataService { List repositoryFileDTOList = fileManagerService.downloadFileBatch(downloadFileRequest); //将文件存储到执行文件目录中,避免多次执行时触发多次下载 if (CollectionUtils.isNotEmpty(repositoryFileDTOList)) { - repositoryFileDTOList.forEach(repositoryFile -> temporaryFileUtil.saveFileByParamCheck(repositoryFile.getProjectId(), repositoryFile.getId(), repositoryFile.getFileLastUpdateTime(), repositoryFile.getFileName(), repositoryFile.getFileByte())); + repositoryFileDTOList.forEach(repositoryFile -> temporaryFileUtil.saveFileByParamCheck(repositoryFile.getProjectId(), repositoryFile.getId(), repositoryFile.getFileLastUpdateTime(), repositoryFile.getFileName(), repositoryFile.getType(), repositoryFile.getFileByte())); fileInfoDTOList.addAll(repositoryFileDTOList); } return fileInfoDTOList; @@ -624,7 +624,7 @@ public class FileMetadataService { List repositoryFileDTOList = fileManagerService.downloadFileBatch(downloadFileRequest); //将文件存储到执行文件目录中,避免多次执行时触发多次下载 if (CollectionUtils.isNotEmpty(repositoryFileDTOList)) { - repositoryFileDTOList.forEach(repositoryFile -> temporaryFileUtil.saveFileByParamCheck(repositoryFile.getProjectId(), repositoryFile.getId(), repositoryFile.getFileLastUpdateTime(), repositoryFile.getFileName(), repositoryFile.getFileByte())); + repositoryFileDTOList.forEach(repositoryFile -> temporaryFileUtil.saveFileByParamCheck(repositoryFile.getProjectId(), repositoryFile.getId(), repositoryFile.getFileLastUpdateTime(), repositoryFile.getFileName(), repositoryFile.getType(), repositoryFile.getFileByte())); } LogUtil.info(JSON.toJSONString(downloadFileList) + " 获取执行文件结束"); } @@ -654,6 +654,7 @@ public class FileMetadataService { request.setResourceId(attachmentBodyFile.getFileMetadataId()); request.setPath(attachmentBodyFile.getFilePath()); request.setStorage(attachmentBodyFile.getFileStorage()); + request.setType(attachmentBodyFile.getFileType()); request.setUpdateTime(attachmentBodyFile.getFileUpdateTime()); if (StringUtils.equals(attachmentBodyFile.getFileStorage(), StorageConstants.GIT.name())) { try {