feat(项目设置): 增加查看图片文件缩略图的接口
This commit is contained in:
parent
e90a9bac8a
commit
d918d86edf
|
@ -18,20 +18,20 @@ public class TempFileUtils {
|
|||
}
|
||||
|
||||
|
||||
public static String getFileTmpPath(String fileId) {
|
||||
return TEMP_FILE_FOLDER + fileId;
|
||||
public static String getImgFileTmpPath(String fileId) {
|
||||
return TEMP_FILE_FOLDER + fileId + ".jpg";
|
||||
}
|
||||
|
||||
public static void deleteTmpFile(String fileId) {
|
||||
File file = new File(getFileTmpPath(fileId));
|
||||
File file = new File(getImgFileTmpPath(fileId));
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static String catchCompressFileIfNotExists(String fileId, byte[] fileBytes) {
|
||||
public static String catchCompressImgIfNotExists(String fileId, byte[] fileBytes) {
|
||||
try {
|
||||
String previewPath = getFileTmpPath(fileId);
|
||||
String previewPath = getImgFileTmpPath(fileId);
|
||||
compressPic(fileBytes, previewPath);
|
||||
return previewPath;
|
||||
} catch (Exception ignore) {
|
||||
|
@ -95,8 +95,27 @@ public class TempFileUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isFileExists(String fileId) {
|
||||
File file = new File(getFileTmpPath(fileId));
|
||||
public static boolean isImgFileExists(String fileId) {
|
||||
File file = new File(getImgFileTmpPath(fileId));
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
public static byte[] getPreviewFile(String filePreviewPath) {
|
||||
File file = new File(filePreviewPath);
|
||||
byte[] previewByte = new byte[0];
|
||||
if (file.exists()) {
|
||||
try (FileInputStream fis = new FileInputStream(file);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
|
||||
byte[] b = new byte[1024];
|
||||
int n;
|
||||
while ((n = fis.read(b)) != -1) {
|
||||
bos.write(b, 0, n);
|
||||
}
|
||||
previewByte = bos.toByteArray();
|
||||
} catch (Exception ignore) {
|
||||
|
||||
}
|
||||
}
|
||||
return previewByte;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package io.metersphere.functional.utils;
|
||||
|
||||
import io.metersphere.project.dto.FileInformationDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.request.filemanagement.FileMetadataTableRequest;
|
||||
import io.metersphere.sdk.dto.BaseTreeNode;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.Pager;
|
||||
import io.metersphere.sdk.util.TempFileUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
|
||||
|
@ -102,15 +101,6 @@ public class FileBaseUtils {
|
|||
Assertions.assertEquals(tableData.getCurrent(), request.getCurrent());
|
||||
//返回的数据量不超过规定要返回的数据量相同
|
||||
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= request.getPageSize());
|
||||
List<FileInformationDTO> fileInformationDTOList = JSON.parseArray(JSON.toJSONString(tableData.getList()), FileInformationDTO.class);
|
||||
for (FileInformationDTO fileInformationDTO : fileInformationDTOList) {
|
||||
if (TempFileUtils.isImage(fileInformationDTO.getFileType())) {
|
||||
//检查是否有预览文件
|
||||
String previewPath = fileInformationDTO.getPreviewSrc();
|
||||
File file = new File(previewPath);
|
||||
Assertions.assertTrue(file.exists());
|
||||
}
|
||||
}
|
||||
|
||||
//判断返回的节点统计总量是否和表格总量匹配
|
||||
long allResult = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.project.dto.FileInformationDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.request.filemanagement.*;
|
||||
import io.metersphere.project.service.FileManagementService;
|
||||
import io.metersphere.project.service.FileMetadataService;
|
||||
|
@ -71,10 +71,17 @@ public class FileManagementController {
|
|||
@GetMapping(value = "/download/{id}")
|
||||
@Operation(summary = "项目管理-文件管理-下载文件")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_DOWNLOAD)
|
||||
public ResponseEntity<byte[]> download(@PathVariable String id) throws Exception {
|
||||
public ResponseEntity<byte[]> download(@PathVariable String id) {
|
||||
return fileMetadataService.downloadById(id);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/download/preview-img/{id}")
|
||||
@Operation(summary = "项目管理-文件管理-下载图片预览文件")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_DOWNLOAD)
|
||||
public ResponseEntity<byte[]> downloadPreview(@PathVariable String id) {
|
||||
return fileMetadataService.downloadPreviewImgById(id);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/delete")
|
||||
@Operation(summary = "项目管理-文件管理-删除文件")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_DELETE)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.dto;
|
||||
package io.metersphere.project.dto.filemanagement;
|
||||
|
||||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
|
@ -33,9 +33,6 @@ public class FileInformationDTO {
|
|||
@Schema(description = "更新时间")
|
||||
private long updateTime;
|
||||
|
||||
@Schema(description = "预览路径")
|
||||
private String previewSrc;
|
||||
|
||||
@Schema(description = "文件大小")
|
||||
private long size;
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package io.metersphere.project.dto.filemanagement;
|
||||
|
||||
import io.metersphere.project.request.filemanagement.FileBatchProcessDTO;
|
||||
import io.metersphere.project.request.filemanagement.FileMetadataTableRequest;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class FileManagementPageDTO {
|
||||
public String projectId;
|
||||
public String keyword;
|
||||
public List<String> moduleIds;
|
||||
public String fileType;
|
||||
public String operator;
|
||||
|
||||
public FileManagementPageDTO(FileBatchProcessDTO batchProcessDTO) {
|
||||
this.projectId = batchProcessDTO.getProjectId();
|
||||
this.keyword = batchProcessDTO.getCondition().getKeyword();
|
||||
this.moduleIds = batchProcessDTO.getModuleIds();
|
||||
this.fileType = batchProcessDTO.getFileType();
|
||||
if (MapUtils.isNotEmpty(batchProcessDTO.getCondition().getCombine())) {
|
||||
this.operator = batchProcessDTO.getCondition().getCombine().get("createUser").toString();
|
||||
}
|
||||
}
|
||||
|
||||
public FileManagementPageDTO(FileMetadataTableRequest batchProcessDTO) {
|
||||
this.projectId = batchProcessDTO.getProjectId();
|
||||
this.keyword = batchProcessDTO.getKeyword();
|
||||
this.moduleIds = batchProcessDTO.getModuleIds();
|
||||
this.fileType = batchProcessDTO.getFileType();
|
||||
if (MapUtils.isNotEmpty(batchProcessDTO.getCombine()) && batchProcessDTO.getCombine().get("createUser") != null) {
|
||||
this.operator = batchProcessDTO.getCombine().get("createUser").toString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,19 +2,19 @@ package io.metersphere.project.mapper;
|
|||
|
||||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.project.dto.ModuleCountDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileManagementPageDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtFileMetadataMapper {
|
||||
List<FileMetadata> selectByKeywordAndFileType(@Param("projectId") String projectId, @Param("keyword") String keyword,
|
||||
@Param("moduleIds") List<String> moduleIds, @Param("fileType") String fileType, @Param("isRefId") boolean isRefId);
|
||||
List<FileMetadata> selectByKeywordAndFileType(FileManagementPageDTO fileManagementPageDTO);
|
||||
|
||||
List<ModuleCountDTO> countModuleIdByKeywordAndFileType(@Param("projectId") String projectId, @Param("keyword") String keyword,
|
||||
@Param("moduleIds") List<String> moduleIds, @Param("fileType") String fileType);
|
||||
List<FileMetadata> selectRefIdByKeywordAndFileType(FileManagementPageDTO fileManagementPageDTO);
|
||||
|
||||
long countMyFile(@Param("projectId") String projectId, @Param("keyword") String keyword,
|
||||
@Param("moduleIds") List<String> moduleIds, @Param("fileType") String fileType, @Param("operator") String operator);
|
||||
List<ModuleCountDTO> countModuleIdByKeywordAndFileType(FileManagementPageDTO fileManagementPageDTO);
|
||||
|
||||
long countMyFile(FileManagementPageDTO fileManagementPageDTO);
|
||||
|
||||
List<String> selectIdByRefIdList(@Param("refIdList") List<String> refIdList);
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.project.mapper.ExtFileMetadataMapper">
|
||||
<select id="selectByKeywordAndFileType" resultType="io.metersphere.project.domain.FileMetadata">
|
||||
<select id="selectByKeywordAndFileType"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementPageDTO"
|
||||
resultType="io.metersphere.project.domain.FileMetadata">
|
||||
SELECT
|
||||
f.id,
|
||||
<if test="isRefId">
|
||||
f.ref_id
|
||||
</if>
|
||||
<if test="!isRefId">
|
||||
f.name,
|
||||
f.type,
|
||||
f.tags,
|
||||
|
@ -18,13 +16,25 @@
|
|||
f.project_id,
|
||||
f.size,
|
||||
f.storage
|
||||
</if>
|
||||
FROM file_metadata f
|
||||
INNER JOIN user u ON f.update_user = u.id
|
||||
<include refid="file_page_request"/>
|
||||
</select>
|
||||
|
||||
<select id="countModuleIdByKeywordAndFileType" resultType="io.metersphere.project.dto.ModuleCountDTO">
|
||||
<select id="selectRefIdByKeywordAndFileType"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementPageDTO"
|
||||
resultType="io.metersphere.project.domain.FileMetadata">
|
||||
SELECT
|
||||
f.id,
|
||||
f.ref_id
|
||||
FROM file_metadata f
|
||||
INNER JOIN user u ON f.update_user = u.id
|
||||
<include refid="file_page_request"/>
|
||||
</select>
|
||||
|
||||
<select id="countModuleIdByKeywordAndFileType"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementPageDTO"
|
||||
resultType="io.metersphere.project.dto.ModuleCountDTO">
|
||||
SELECT f.module_id AS moduleId, count(f.id) AS dataCount
|
||||
FROM file_metadata f
|
||||
INNER JOIN user u ON f.update_user = u.id
|
||||
|
@ -32,12 +42,13 @@
|
|||
GROUP BY f.module_id
|
||||
</select>
|
||||
|
||||
<select id="countMyFile" resultType="java.lang.Long">
|
||||
<select id="countMyFile"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementPageDTO"
|
||||
resultType="java.lang.Long">
|
||||
SELECT count(f.id)
|
||||
FROM file_metadata f
|
||||
INNER JOIN user u ON f.update_user = u.id
|
||||
<include refid="file_page_request"/>
|
||||
AND f.create_user = #{operator}
|
||||
</select>
|
||||
<sql id="file_page_request">
|
||||
<where>
|
||||
|
@ -55,6 +66,9 @@
|
|||
<if test="fileType != null and fileType != ''">
|
||||
AND f.type = #{fileType}
|
||||
</if>
|
||||
<if test="operator != null and operator != ''">
|
||||
AND f.create_user = #{operator}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.project.service;
|
|||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.project.domain.FileMetadataExample;
|
||||
import io.metersphere.project.domain.FileModuleExample;
|
||||
import io.metersphere.project.dto.filemanagement.FileManagementPageDTO;
|
||||
import io.metersphere.project.mapper.ExtFileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileModuleMapper;
|
||||
|
@ -79,8 +80,9 @@ public class FileManagementService {
|
|||
public List<FileMetadata> getDeleteList(FileBatchProcessDTO request) {
|
||||
List<String> processIds = request.getSelectIds();
|
||||
List<FileMetadata> refFileList = new ArrayList<>();
|
||||
FileManagementPageDTO pageDTO = new FileManagementPageDTO(request);
|
||||
if (request.isSelectAll()) {
|
||||
refFileList = extFileMetadataMapper.selectByKeywordAndFileType(request.getProjectId(), request.getCondition().getKeyword(), request.getModuleIds(), request.getFileType(), true);
|
||||
refFileList = extFileMetadataMapper.selectRefIdByKeywordAndFileType(pageDTO);
|
||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||
refFileList = refFileList.stream().filter(fileMetadata -> !request.getExcludeIds().contains(fileMetadata.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
@ -101,7 +103,8 @@ public class FileManagementService {
|
|||
List<String> processIds = request.getSelectIds();
|
||||
List<FileMetadata> refFileList = new ArrayList<>();
|
||||
if (request.isSelectAll()) {
|
||||
refFileList = extFileMetadataMapper.selectByKeywordAndFileType(request.getProjectId(), request.getCondition().getKeyword(), request.getModuleIds(), request.getFileType(), false);
|
||||
FileManagementPageDTO pageDTO = new FileManagementPageDTO(request);
|
||||
refFileList = extFileMetadataMapper.selectByKeywordAndFileType(pageDTO);
|
||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||
refFileList = refFileList.stream().filter(fileMetadata -> !request.getExcludeIds().contains(fileMetadata.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ import com.github.pagehelper.Page;
|
|||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.project.domain.FileMetadataExample;
|
||||
import io.metersphere.project.dto.FileInformationDTO;
|
||||
import io.metersphere.project.dto.ModuleCountDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileManagementPageDTO;
|
||||
import io.metersphere.project.mapper.ExtFileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileMetadataMapper;
|
||||
import io.metersphere.project.request.filemanagement.*;
|
||||
|
@ -55,17 +56,10 @@ public class FileMetadataService {
|
|||
|
||||
public List<FileInformationDTO> list(FileMetadataTableRequest request) {
|
||||
List<FileInformationDTO> returnList = new ArrayList<>();
|
||||
List<FileMetadata> fileMetadataList = extFileMetadataMapper.selectByKeywordAndFileType(request.getProjectId(), request.getKeyword(), request.getModuleIds(), request.getFileType(), false);
|
||||
FileManagementPageDTO pageDTO = new FileManagementPageDTO(request);
|
||||
List<FileMetadata> fileMetadataList = extFileMetadataMapper.selectByKeywordAndFileType(pageDTO);
|
||||
fileMetadataList.forEach(fileMetadata -> {
|
||||
FileInformationDTO fileInformationDTO = new FileInformationDTO(fileMetadata);
|
||||
if (TempFileUtils.isImage(fileMetadata.getType())) {
|
||||
if (TempFileUtils.isFileExists(fileMetadata.getId())) {
|
||||
fileInformationDTO.setPreviewSrc(TempFileUtils.getFileTmpPath(fileMetadata.getId()));
|
||||
} else {
|
||||
fileInformationDTO.setPreviewSrc(TempFileUtils.catchCompressFileIfNotExists(fileMetadata.getId(), this.getFile(fileMetadata)));
|
||||
}
|
||||
|
||||
}
|
||||
returnList.add(fileInformationDTO);
|
||||
});
|
||||
return returnList;
|
||||
|
@ -301,12 +295,40 @@ public class FileMetadataService {
|
|||
//获取模块统计
|
||||
public Map<String, Long> moduleCount(FileMetadataTableRequest request, String operator) {
|
||||
//查出每个模块节点下的资源数量
|
||||
List<ModuleCountDTO> moduleCountDTOList = extFileMetadataMapper.countModuleIdByKeywordAndFileType(request.getProjectId(), request.getKeyword(), null, request.getFileType());
|
||||
FileManagementPageDTO pageDTO = new FileManagementPageDTO(request);
|
||||
List<ModuleCountDTO> moduleCountDTOList = extFileMetadataMapper.countModuleIdByKeywordAndFileType(pageDTO);
|
||||
long allCount = fileModuleService.getAllCount(moduleCountDTOList);
|
||||
long myFileCount = extFileMetadataMapper.countMyFile(request.getProjectId(), request.getKeyword(), null, request.getFileType(), operator);
|
||||
|
||||
pageDTO.setOperator(operator);
|
||||
long myFileCount = extFileMetadataMapper.countMyFile(pageDTO);
|
||||
|
||||
Map<String, Long> moduleCountMap = fileModuleService.getModuleCountMap(request.getProjectId(), moduleCountDTOList);
|
||||
moduleCountMap.put(FILE_MODULE_COUNT_MY, myFileCount);
|
||||
moduleCountMap.put(FILE_MODULE_COUNT_ALL, allCount);
|
||||
return moduleCountMap;
|
||||
}
|
||||
|
||||
public ResponseEntity<byte[]> downloadPreviewImgById(String id) {
|
||||
FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(id);
|
||||
String previewImgPath = null;
|
||||
if (TempFileUtils.isImage(fileMetadata.getType())) {
|
||||
if (TempFileUtils.isImgFileExists(fileMetadata.getId())) {
|
||||
previewImgPath = TempFileUtils.getImgFileTmpPath(fileMetadata.getId());
|
||||
} else {
|
||||
previewImgPath = TempFileUtils.catchCompressImgIfNotExists(fileMetadata.getId(), this.getFile(fileMetadata));
|
||||
}
|
||||
}
|
||||
|
||||
byte[] bytes;
|
||||
if (StringUtils.isNotBlank(previewImgPath)) {
|
||||
bytes = TempFileUtils.getPreviewFile(previewImgPath);
|
||||
} else {
|
||||
bytes = new byte[]{};
|
||||
}
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + this.getFileName(fileMetadata.getName(), fileMetadata.getType()) + "\"")
|
||||
.body(bytes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.metersphere.project.controller.filemanagement;
|
||||
|
||||
import io.metersphere.project.domain.*;
|
||||
import io.metersphere.project.dto.FileInformationDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.mapper.FileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileModuleMapper;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
|
@ -16,6 +16,7 @@ import io.metersphere.sdk.dto.BaseTreeNode;
|
|||
import io.metersphere.sdk.dto.request.NodeMoveRequest;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.Pager;
|
||||
import io.metersphere.sdk.util.TempFileUtils;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
|
@ -54,6 +55,8 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
|
||||
private static final Map<String, String> FILE_VERSIONS_ID_MAP = new HashMap<>();
|
||||
|
||||
private static String reUploadFileId;
|
||||
|
||||
@Resource
|
||||
private FileModuleService fileModuleService;
|
||||
@Resource
|
||||
|
@ -453,12 +456,11 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(12)
|
||||
public void fileReUploadTestSuccess() throws Exception {
|
||||
String existFileId = null;
|
||||
if (MapUtils.isEmpty(FILE_ID_PATH)) {
|
||||
this.fileUploadTestSuccess();
|
||||
}
|
||||
for (String key : FILE_ID_PATH.keySet()) {
|
||||
existFileId = key;
|
||||
reUploadFileId = key;
|
||||
}
|
||||
|
||||
FileUploadRequest fileUploadRequest = new FileUploadRequest();
|
||||
|
@ -466,7 +468,7 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
|
||||
//重新上传并修改文件版本
|
||||
FileReUploadRequest fileReUploadRequest = new FileReUploadRequest();
|
||||
fileReUploadRequest.setFileId(existFileId);
|
||||
fileReUploadRequest.setFileId(reUploadFileId);
|
||||
String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/file_re-upload.JPG")).getPath();
|
||||
MockMultipartFile file = new MockMultipartFile("file", "file_re-upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, FileManagementBaseUtils.getFileBytes(filePath));
|
||||
LinkedMultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
|
@ -477,7 +479,7 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
String reUploadId = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData().toString();
|
||||
checkLog(reUploadId, OperationLogType.UPDATE, FileManagementRequestUtils.URL_FILE_RE_UPLOAD);
|
||||
FILE_ID_PATH.put(reUploadId, filePath);
|
||||
FILE_VERSIONS_ID_MAP.put(reUploadId, existFileId);
|
||||
FILE_VERSIONS_ID_MAP.put(reUploadId, reUploadFileId);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -615,6 +617,36 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
this.setFileType("fire");
|
||||
}};
|
||||
this.filePageRequestAndCheck(request);
|
||||
|
||||
//combine掺杂了奇奇怪怪的参数
|
||||
request = new FileMetadataTableRequest() {{
|
||||
this.setCurrent(1);
|
||||
this.setPageSize(10);
|
||||
this.setProjectId(project.getId());
|
||||
this.setFileType("JpG");
|
||||
}};
|
||||
request.setCombine(new HashMap<>() {{
|
||||
this.put(IDGenerator.nextStr(), IDGenerator.nextStr());
|
||||
}});
|
||||
this.filePageRequestAndCheck(request);
|
||||
|
||||
//查找我的文件
|
||||
request = new FileMetadataTableRequest() {{
|
||||
this.setCurrent(1);
|
||||
this.setPageSize(10);
|
||||
this.setProjectId(project.getId());
|
||||
this.setFileType("JpG");
|
||||
}};
|
||||
request.setCombine(new HashMap<>() {{
|
||||
this.put("createUser", "admin");
|
||||
}});
|
||||
this.filePageRequestAndCheck(request);
|
||||
|
||||
//查找任何一个人创建的文件
|
||||
request.setCombine(new HashMap<>() {{
|
||||
this.put("createUser", IDGenerator.nextNum());
|
||||
}});
|
||||
this.filePageRequestAndCheck(request, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -674,6 +706,43 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
.andExpect(status().is5xxServerError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
public void filePreviewImgDownload() throws Exception {
|
||||
this.preliminaryData();
|
||||
if (MapUtils.isEmpty(FILE_ID_PATH)) {
|
||||
//做一个重复上传过的文件的测试
|
||||
this.fileReUploadTestSuccess();
|
||||
}
|
||||
FileMetadataTableRequest request = new FileMetadataTableRequest() {{
|
||||
this.setCurrent(1);
|
||||
this.setPageSize(50);
|
||||
this.setProjectId(project.getId());
|
||||
}};
|
||||
//获取第一页的所有文件(一页50)
|
||||
MvcResult fileMvcResult = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_PAGE, request);
|
||||
Pager<List<FileInformationDTO>> pageResult = JSON.parseObject(JSON.toJSONString(
|
||||
JSON.parseObject(fileMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
|
||||
Pager.class);
|
||||
List<FileInformationDTO> fileList = JSON.parseArray(JSON.toJSONString(pageResult.getList()), FileInformationDTO.class);
|
||||
for (FileInformationDTO fileDTO : fileList) {
|
||||
MvcResult mvcResult = this.downloadFile(String.format(FileManagementRequestUtils.URL_PREVIEW_IMG_FILE_DOWNLOAD, fileDTO.getId()));
|
||||
byte[] fileBytes = mvcResult.getResponse().getContentAsByteArray();
|
||||
if (TempFileUtils.isImage(fileDTO.getFileType())) {
|
||||
if (StringUtils.equals(reUploadFileId, fileDTO.getId())) {
|
||||
//重新上传的文件并不是图片
|
||||
Assertions.assertEquals(fileBytes.length, 0);
|
||||
} else {
|
||||
Assertions.assertTrue(fileBytes.length > 0);
|
||||
}
|
||||
|
||||
} else {
|
||||
Assertions.assertEquals(fileBytes.length, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
public void fileDeleteSuccess() throws Exception {
|
||||
|
@ -1125,6 +1194,14 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
FileManagementBaseUtils.checkFilePage(pageResult, moduleCountResult, request);
|
||||
}
|
||||
|
||||
private void filePageRequestAndCheck(FileMetadataTableRequest request, int fileCount) throws Exception {
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_PAGE, request);
|
||||
Pager<List<FileInformationDTO>> pageResult = JSON.parseObject(JSON.toJSONString(
|
||||
JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
|
||||
Pager.class);
|
||||
Assertions.assertEquals(pageResult.getTotal(), fileCount);
|
||||
}
|
||||
|
||||
private void preliminaryData() throws Exception {
|
||||
if (CollectionUtils.isEmpty(preliminaryTreeNodes)) {
|
||||
/*
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package io.metersphere.project.utils;
|
||||
|
||||
import io.metersphere.project.dto.FileInformationDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.request.filemanagement.FileMetadataTableRequest;
|
||||
import io.metersphere.sdk.dto.BaseTreeNode;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.Pager;
|
||||
import io.metersphere.sdk.util.TempFileUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
|
||||
|
@ -102,15 +101,6 @@ public class FileManagementBaseUtils {
|
|||
Assertions.assertEquals(tableData.getCurrent(), request.getCurrent());
|
||||
//返回的数据量不超过规定要返回的数据量相同
|
||||
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= request.getPageSize());
|
||||
List<FileInformationDTO> fileInformationDTOList = JSON.parseArray(JSON.toJSONString(tableData.getList()), FileInformationDTO.class);
|
||||
for (FileInformationDTO fileInformationDTO : fileInformationDTOList) {
|
||||
if (TempFileUtils.isImage(fileInformationDTO.getFileType())) {
|
||||
//检查是否有预览文件
|
||||
String previewPath = fileInformationDTO.getPreviewSrc();
|
||||
File file = new File(previewPath);
|
||||
Assertions.assertTrue(file.exists());
|
||||
}
|
||||
}
|
||||
|
||||
//如果没有数据,则返回的模块节点也不应该有数据
|
||||
boolean moduleHaveResource = false;
|
||||
|
|
|
@ -22,6 +22,8 @@ public class FileManagementRequestUtils {
|
|||
public static final String URL_FILE_RE_UPLOAD = "/project/file/re-upload";
|
||||
//文件下载
|
||||
public static final String URL_FILE_DOWNLOAD = "/project/file/download/%s";
|
||||
//文件预览下载
|
||||
public static final String URL_PREVIEW_IMG_FILE_DOWNLOAD = "/project/file/download/preview-img/%s";
|
||||
//文件批量下载
|
||||
public static final String URL_FILE_BATCH_DOWNLOAD = "/project/file/batch-download";
|
||||
//文件批量删除
|
||||
|
|
Loading…
Reference in New Issue