feat(项目设置): 文件库查询和文件库文件类型查询接口开发
This commit is contained in:
parent
26ebc94b79
commit
45cdc8cc36
|
@ -7,6 +7,8 @@ public class ModuleConstants {
|
|||
public static final String ROOT_NODE_PARENT_ID = "none";
|
||||
//默认节点类型
|
||||
public static final String NODE_TYPE_DEFAULT = "module";
|
||||
//Git节点类型
|
||||
public static final String NODE_TYPE_GIT = "git";
|
||||
//GitHub节点类型
|
||||
public static final String NODE_TYPE_GITHUB = "GitHub";
|
||||
//Gitee节点类型
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package io.metersphere.functional.utils;
|
||||
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.request.filemanagement.FileMetadataTableRequest;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileMetadataTableRequest;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
@ -96,7 +96,7 @@ public class FileBaseUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void checkFilePage(Pager<List<FileInformationDTO>> tableData, Map<String, Integer> moduleCount, FileMetadataTableRequest request, boolean hasData) {
|
||||
public static void checkFilePage(Pager<List<FileInformationResponse>> tableData, Map<String, Integer> moduleCount, FileMetadataTableRequest request, boolean hasData) {
|
||||
//返回值的页码和当前页码相同
|
||||
Assertions.assertEquals(tableData.getCurrent(), request.getCurrent());
|
||||
//返回的数据量不超过规定要返回的数据量相同
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.request.filemanagement.*;
|
||||
import io.metersphere.project.dto.filemanagement.request.*;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
|
||||
import io.metersphere.project.service.FileManagementService;
|
||||
import io.metersphere.project.service.FileMetadataService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
@ -35,20 +34,20 @@ public class FileManagementController {
|
|||
@Operation(summary = "项目管理-文件管理-获取已存在的文件类型")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ)
|
||||
public List<String> getFileType(@PathVariable String projectId) {
|
||||
return fileMetadataService.getFileType(projectId);
|
||||
return fileMetadataService.getFileType(projectId, StorageType.MINIO.name());
|
||||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
@Operation(summary = "项目管理-文件管理-表格分页查询文件")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ)
|
||||
public Pager<List<FileInformationDTO>> page(@Validated @RequestBody FileMetadataTableRequest request) {
|
||||
public Pager<List<FileInformationResponse>> page(@Validated @RequestBody FileMetadataTableRequest request) {
|
||||
return fileMetadataService.page(request);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
@Operation(summary = "项目管理-文件管理-查看文件详情")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ)
|
||||
public FileInformationDTO page(@PathVariable String id) {
|
||||
public FileInformationResponse page(@PathVariable String id) {
|
||||
return fileMetadataService.get(id);
|
||||
}
|
||||
|
||||
|
@ -63,23 +62,15 @@ public class FileManagementController {
|
|||
@PostMapping("/upload")
|
||||
@Operation(summary = "项目管理-文件管理-上传文件")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_ADD)
|
||||
public String upload(@Validated @RequestPart("request") FileUploadRequest request, @RequestPart(value = "file", required = false) MultipartFile uploadFile) {
|
||||
try {
|
||||
public String upload(@Validated @RequestPart("request") FileUploadRequest request, @RequestPart(value = "file", required = false) MultipartFile uploadFile) throws Exception {
|
||||
return fileMetadataService.upload(request, SessionUtils.getUserId(), uploadFile);
|
||||
} catch (Exception e) {
|
||||
throw new MSException(Translator.get("upload.file.error"), e);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/re-upload")
|
||||
@Operation(summary = "项目管理-文件管理-重新上传文件")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_UPDATE)
|
||||
public String reUpload(@Validated @RequestPart("request") FileReUploadRequest request, @RequestPart(value = "file", required = false) MultipartFile uploadFile) {
|
||||
try {
|
||||
public String reUpload(@Validated @RequestPart("request") FileReUploadRequest request, @RequestPart(value = "file", required = false) MultipartFile uploadFile) throws Exception {
|
||||
return fileMetadataService.reUpload(request, SessionUtils.getUserId(), uploadFile);
|
||||
} catch (Exception e) {
|
||||
throw new MSException(Translator.get("upload.file.error"), e);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/download/{id}")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.project.request.filemanagement.FileModuleCreateRequest;
|
||||
import io.metersphere.project.request.filemanagement.FileModuleUpdateRequest;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileModuleCreateRequest;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileModuleUpdateRequest;
|
||||
import io.metersphere.project.service.FileModuleService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
|
||||
import io.metersphere.project.service.FileMetadataService;
|
||||
import io.metersphere.project.service.PermissionCheckService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
|
@ -29,12 +29,12 @@ public class FilePreviewController {
|
|||
@GetMapping(value = "/original/{userId}/{fileId}")
|
||||
@Operation(summary = "预览原图")
|
||||
public ResponseEntity<byte[]> originalImg(@PathVariable String userId,@PathVariable String fileId) {
|
||||
FileInformationDTO fileInformationDTO = fileMetadataService.get(fileId);
|
||||
if (StringUtils.isEmpty(fileInformationDTO.getId())) {
|
||||
FileInformationResponse fileInformationResponse = fileMetadataService.get(fileId);
|
||||
if (StringUtils.isEmpty(fileInformationResponse.getId())) {
|
||||
throw new MSException("file.not.exist");
|
||||
}
|
||||
//检查权限
|
||||
if(permissionCheckService.userHasProjectPermission(userId,fileInformationDTO.getProjectId(),PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_DOWNLOAD)){
|
||||
if (permissionCheckService.userHasProjectPermission(userId, fileInformationResponse.getProjectId(), PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_DOWNLOAD)) {
|
||||
return fileMetadataService.downloadById(fileId);
|
||||
}else {
|
||||
throw new MSException("http_result_forbidden");
|
||||
|
@ -44,12 +44,12 @@ public class FilePreviewController {
|
|||
@GetMapping(value = "/compressed/{userId}/{fileId}")
|
||||
@Operation(summary = "预览缩略图")
|
||||
public ResponseEntity<byte[]> compressedImg(@PathVariable String userId,@PathVariable String fileId) {
|
||||
FileInformationDTO fileInformationDTO = fileMetadataService.get(fileId);
|
||||
if (StringUtils.isEmpty(fileInformationDTO.getId())) {
|
||||
FileInformationResponse fileInformationResponse = fileMetadataService.get(fileId);
|
||||
if (StringUtils.isEmpty(fileInformationResponse.getId())) {
|
||||
throw new MSException("file.not.exist");
|
||||
}
|
||||
//检查权限
|
||||
if(permissionCheckService.userHasProjectPermission(userId,fileInformationDTO.getProjectId(),PermissionConstants.PROJECT_FILE_MANAGEMENT_READ)){
|
||||
if (permissionCheckService.userHasProjectPermission(userId, fileInformationResponse.getProjectId(), PermissionConstants.PROJECT_FILE_MANAGEMENT_READ)) {
|
||||
return fileMetadataService.downloadPreviewImgById(fileId);
|
||||
}else {
|
||||
throw new MSException("http_result_forbidden");
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package io.metersphere.project.controller;
|
||||
|
||||
import io.metersphere.project.service.FileMetadataService;
|
||||
import io.metersphere.project.service.FileRepositoryService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "项目管理-文件管理-存储库")
|
||||
@RestController
|
||||
@RequestMapping("/project/file/repository")
|
||||
public class FileRepositoryController {
|
||||
|
||||
@Resource
|
||||
private FileRepositoryService fileRepositoryService;
|
||||
@Resource
|
||||
private FileMetadataService fileMetadataService;
|
||||
|
||||
@GetMapping("/list/{projectId}")
|
||||
@Operation(summary = "项目管理-文件管理-存储库-存储库列表")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ)
|
||||
public List<BaseTreeNode> getTree(@PathVariable String projectId) {
|
||||
return fileRepositoryService.getTree(projectId);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/file-type/{projectId}")
|
||||
@Operation(summary = "项目管理-文件管理-获取已存在的存储库文件类型")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ)
|
||||
public List<String> getFileType(@PathVariable String projectId) {
|
||||
return fileMetadataService.getFileType(projectId, StorageType.GIT.name());
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package io.metersphere.project.dto.filemanagement;
|
||||
|
||||
import io.metersphere.project.request.filemanagement.FileBatchProcessRequest;
|
||||
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(FileBatchProcessRequest 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package io.metersphere.project.dto.filemanagement;
|
||||
|
||||
import io.metersphere.project.dto.filemanagement.request.FileBatchProcessRequest;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileMetadataTableRequest;
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class FileManagementQuery {
|
||||
public String projectId;
|
||||
public String keyword;
|
||||
public List<String> moduleIds;
|
||||
public String fileType;
|
||||
public String operator;
|
||||
public String storage = StorageType.MINIO.name();
|
||||
|
||||
public FileManagementQuery(FileBatchProcessRequest batchProcessDTO) {
|
||||
this.projectId = batchProcessDTO.getProjectId();
|
||||
this.keyword = batchProcessDTO.getCondition().getKeyword();
|
||||
this.moduleIds = batchProcessDTO.getModuleIds();
|
||||
this.fileType = batchProcessDTO.getFileType();
|
||||
if (MapUtils.isNotEmpty(batchProcessDTO.getCondition().getCombine())) {
|
||||
if (batchProcessDTO.getCondition().getCombine().get("createUser") != null) {
|
||||
this.operator = batchProcessDTO.getCondition().getCombine().get("createUser").toString();
|
||||
}
|
||||
if (batchProcessDTO.getCondition().getCombine().get("storage") != null) {
|
||||
this.storage = batchProcessDTO.getCondition().getCombine().get("storage").toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FileManagementQuery(FileMetadataTableRequest batchProcessDTO) {
|
||||
this.projectId = batchProcessDTO.getProjectId();
|
||||
this.keyword = batchProcessDTO.getKeyword();
|
||||
this.moduleIds = batchProcessDTO.getModuleIds();
|
||||
this.fileType = batchProcessDTO.getFileType();
|
||||
if (MapUtils.isNotEmpty(batchProcessDTO.getCombine())) {
|
||||
if (batchProcessDTO.getCombine().get("createUser") != null) {
|
||||
this.operator = batchProcessDTO.getCombine().get("createUser").toString();
|
||||
}
|
||||
if (batchProcessDTO.getCombine().get("storage") != null) {
|
||||
this.storage = batchProcessDTO.getCombine().get("storage").toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.request.filemanagement;
|
||||
package io.metersphere.project.dto.filemanagement.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.request.filemanagement;
|
||||
package io.metersphere.project.dto.filemanagement.request;
|
||||
|
||||
import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
@ -19,4 +19,5 @@ public class FileBatchProcessRequest extends TableBatchProcessDTO {
|
|||
|
||||
@Schema(description = "模块ID")
|
||||
private List<String> moduleIds;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.request.filemanagement;
|
||||
package io.metersphere.project.dto.filemanagement.request;
|
||||
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.request.filemanagement;
|
||||
package io.metersphere.project.dto.filemanagement.request;
|
||||
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.request.filemanagement;
|
||||
package io.metersphere.project.dto.filemanagement.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.request.filemanagement;
|
||||
package io.metersphere.project.dto.filemanagement.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.request.filemanagement;
|
||||
package io.metersphere.project.dto.filemanagement.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.request.filemanagement;
|
||||
package io.metersphere.project.dto.filemanagement.request;
|
||||
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.project.dto.filemanagement;
|
||||
package io.metersphere.project.dto.filemanagement.response;
|
||||
|
||||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class FileInformationDTO {
|
||||
public class FileInformationResponse {
|
||||
@Schema(description = "ID")
|
||||
private String id;
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class FileInformationDTO {
|
|||
@Schema(description = "启用/禁用(jar文件)")
|
||||
private boolean enable;
|
||||
|
||||
public FileInformationDTO(FileMetadata fileMetadata) {
|
||||
public FileInformationResponse(FileMetadata fileMetadata) {
|
||||
if (fileMetadata != null) {
|
||||
this.id = fileMetadata.getId();
|
||||
this.projectId = fileMetadata.getProjectId();
|
|
@ -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 io.metersphere.project.dto.filemanagement.FileManagementQuery;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtFileMetadataMapper {
|
||||
List<FileMetadata> selectByKeywordAndFileType(FileManagementPageDTO fileManagementPageDTO);
|
||||
List<FileMetadata> selectByKeywordAndFileType(FileManagementQuery fileManagementQuery);
|
||||
|
||||
List<FileMetadata> selectRefIdByKeywordAndFileType(FileManagementPageDTO fileManagementPageDTO);
|
||||
List<FileMetadata> selectRefIdByKeywordAndFileType(FileManagementQuery fileManagementQuery);
|
||||
|
||||
List<ModuleCountDTO> countModuleIdByKeywordAndFileType(FileManagementPageDTO fileManagementPageDTO);
|
||||
List<ModuleCountDTO> countModuleIdByKeywordAndFileType(FileManagementQuery fileManagementQuery);
|
||||
|
||||
long countMyFile(FileManagementPageDTO fileManagementPageDTO);
|
||||
long countMyFile(FileManagementQuery fileManagementQuery);
|
||||
|
||||
FileMetadata getById(String id);
|
||||
|
||||
|
@ -28,5 +28,5 @@ public interface ExtFileMetadataMapper {
|
|||
|
||||
List<FileMetadata> selectRefIdByModuleIds(@Param("moduleIds") List<String> moduleIds);
|
||||
|
||||
List<String> selectFileTypeByProjectId(String projectId);
|
||||
List<String> selectFileTypeByProjectId(@Param("projectId") String projectId, @Param("storage") String storage);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<!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"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementPageDTO"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementQuery"
|
||||
resultType="io.metersphere.project.domain.FileMetadata">
|
||||
SELECT
|
||||
f.id,
|
||||
|
@ -27,7 +27,7 @@
|
|||
</select>
|
||||
|
||||
<select id="selectRefIdByKeywordAndFileType"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementPageDTO"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementQuery"
|
||||
resultType="io.metersphere.project.domain.FileMetadata">
|
||||
SELECT
|
||||
f.id,
|
||||
|
@ -39,7 +39,7 @@
|
|||
</select>
|
||||
|
||||
<select id="countModuleIdByKeywordAndFileType"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementPageDTO"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementQuery"
|
||||
resultType="io.metersphere.project.dto.ModuleCountDTO">
|
||||
SELECT f.module_id AS moduleId, count(f.id) AS dataCount
|
||||
FROM file_metadata f
|
||||
|
@ -50,7 +50,7 @@
|
|||
</select>
|
||||
|
||||
<select id="countMyFile"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementPageDTO"
|
||||
parameterType="io.metersphere.project.dto.filemanagement.FileManagementQuery"
|
||||
resultType="java.lang.Long">
|
||||
SELECT count(f.id)
|
||||
FROM file_metadata f
|
||||
|
@ -65,6 +65,9 @@
|
|||
<if test="keyword != null and keyword != ''">
|
||||
AND f.name like concat('%', #{keyword}, '%')
|
||||
</if>
|
||||
<if test="storage != null and storage != ''">
|
||||
AND f.storage = #{storage}
|
||||
</if>
|
||||
<if test="moduleIds != null and moduleIds.size() != 0">
|
||||
AND f.module_id IN
|
||||
<foreach collection="moduleIds" item="item" open="(" separator="," close=")">
|
||||
|
@ -129,6 +132,7 @@
|
|||
SELECT DISTINCT f.type
|
||||
FROM file_metadata f
|
||||
WHERE f.project_id = #{projectId}
|
||||
AND f.storage = #{storage}
|
||||
</select>
|
||||
<select id="getById" resultType="io.metersphere.project.domain.FileMetadata">
|
||||
SELECT f.id,
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.apache.ibatis.annotations.Param;
|
|||
import java.util.List;
|
||||
|
||||
public interface ExtFileModuleMapper {
|
||||
List<BaseTreeNode> selectBaseByProjectId(String projectId);
|
||||
List<BaseTreeNode> selectBaseByProjectId(@Param("projectId") String projectId, @Param("moduleType") String moduleType);
|
||||
|
||||
List<BaseTreeNode> selectIdAndParentIdByProjectId(String projectId);
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
<select id="selectBaseByProjectId" resultType="io.metersphere.system.dto.sdk.BaseTreeNode">
|
||||
SELECT id, name, parent_id AS parentId, 'module' AS type
|
||||
FROM file_module
|
||||
WHERE project_id = #{0}
|
||||
WHERE project_id = #{projectId}
|
||||
AND module_type = #{moduleType}
|
||||
ORDER BY pos
|
||||
</select>
|
||||
<select id="selectIdAndParentIdByProjectId" resultType="io.metersphere.system.dto.sdk.BaseTreeNode">
|
||||
|
|
|
@ -3,11 +3,11 @@ 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.dto.filemanagement.FileManagementQuery;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileBatchProcessRequest;
|
||||
import io.metersphere.project.mapper.ExtFileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileModuleMapper;
|
||||
import io.metersphere.project.request.filemanagement.FileBatchProcessRequest;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
|
@ -77,7 +77,7 @@ public class FileManagementService {
|
|||
public List<FileMetadata> getDeleteList(FileBatchProcessRequest request) {
|
||||
List<String> processIds = request.getSelectIds();
|
||||
List<FileMetadata> refFileList = new ArrayList<>();
|
||||
FileManagementPageDTO pageDTO = new FileManagementPageDTO(request);
|
||||
FileManagementQuery pageDTO = new FileManagementQuery(request);
|
||||
if (request.isSelectAll()) {
|
||||
refFileList = extFileMetadataMapper.selectRefIdByKeywordAndFileType(pageDTO);
|
||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||
|
@ -100,7 +100,7 @@ public class FileManagementService {
|
|||
List<String> processIds = request.getSelectIds();
|
||||
List<FileMetadata> processFileList = new ArrayList<>();
|
||||
if (request.isSelectAll()) {
|
||||
FileManagementPageDTO pageDTO = new FileManagementPageDTO(request);
|
||||
FileManagementQuery pageDTO = new FileManagementQuery(request);
|
||||
processFileList = extFileMetadataMapper.selectByKeywordAndFileType(pageDTO);
|
||||
//去除未选择的文件
|
||||
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
|
||||
|
|
|
@ -5,11 +5,11 @@ import com.github.pagehelper.PageHelper;
|
|||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.project.domain.FileMetadataExample;
|
||||
import io.metersphere.project.dto.ModuleCountDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileManagementPageDTO;
|
||||
import io.metersphere.project.dto.filemanagement.FileManagementQuery;
|
||||
import io.metersphere.project.dto.filemanagement.request.*;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
|
||||
import io.metersphere.project.mapper.ExtFileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileMetadataMapper;
|
||||
import io.metersphere.project.request.filemanagement.*;
|
||||
import io.metersphere.project.utils.FileDownloadUtils;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
|
@ -61,29 +61,29 @@ public class FileMetadataService {
|
|||
@Value("${metersphere.file.batch-download-max:600MB}")
|
||||
private DataSize maxFileSize;
|
||||
|
||||
public FileInformationDTO get(String id) {
|
||||
public FileInformationResponse get(String id) {
|
||||
FileMetadata fileMetadata = extFileMetadataMapper.getById(id);
|
||||
FileInformationDTO dto = new FileInformationDTO(fileMetadata);
|
||||
FileInformationResponse dto = new FileInformationResponse(fileMetadata);
|
||||
initModuleName(dto);
|
||||
return dto;
|
||||
}
|
||||
|
||||
public List<FileInformationDTO> list(FileMetadataTableRequest request) {
|
||||
List<FileInformationDTO> returnList = new ArrayList<>();
|
||||
FileManagementPageDTO pageDTO = new FileManagementPageDTO(request);
|
||||
public List<FileInformationResponse> list(FileMetadataTableRequest request) {
|
||||
List<FileInformationResponse> returnList = new ArrayList<>();
|
||||
FileManagementQuery pageDTO = new FileManagementQuery(request);
|
||||
List<FileMetadata> fileMetadataList = extFileMetadataMapper.selectByKeywordAndFileType(pageDTO);
|
||||
fileMetadataList.forEach(fileMetadata -> {
|
||||
FileInformationDTO fileInformationDTO = new FileInformationDTO(fileMetadata);
|
||||
returnList.add(fileInformationDTO);
|
||||
FileInformationResponse fileInformationResponse = new FileInformationResponse(fileMetadata);
|
||||
returnList.add(fileInformationResponse);
|
||||
});
|
||||
this.initModuleName(returnList);
|
||||
return returnList;
|
||||
}
|
||||
|
||||
private void initModuleName(List<FileInformationDTO> returnList) {
|
||||
List<String> moduleIds = returnList.stream().map(FileInformationDTO::getModuleId).distinct().toList();
|
||||
private void initModuleName(List<FileInformationResponse> returnList) {
|
||||
List<String> moduleIds = returnList.stream().map(FileInformationResponse::getModuleId).distinct().toList();
|
||||
Map<String, String> moduleNameMap = fileModuleService.getModuleNameMapByIds(moduleIds);
|
||||
for (FileInformationDTO dto : returnList) {
|
||||
for (FileInformationResponse dto : returnList) {
|
||||
if (StringUtils.equals(dto.getModuleId(), ModuleConstants.DEFAULT_NODE_ID)) {
|
||||
dto.setModuleName(Translator.get("default.module"));
|
||||
} else {
|
||||
|
@ -92,7 +92,7 @@ public class FileMetadataService {
|
|||
}
|
||||
}
|
||||
|
||||
private void initModuleName(FileInformationDTO dto) {
|
||||
private void initModuleName(FileInformationResponse dto) {
|
||||
if (StringUtils.equals(dto.getModuleId(), ModuleConstants.DEFAULT_NODE_ID)) {
|
||||
dto.setModuleName(Translator.get("default.module"));
|
||||
} else {
|
||||
|
@ -238,7 +238,7 @@ public class FileMetadataService {
|
|||
}
|
||||
}
|
||||
|
||||
public Pager<List<FileInformationDTO>> page(FileMetadataTableRequest request) {
|
||||
public Pager<List<FileInformationResponse>> page(FileMetadataTableRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
|
||||
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "update_time desc");
|
||||
return PageUtils.setPageInfo(page, this.list(request));
|
||||
|
@ -338,7 +338,7 @@ public class FileMetadataService {
|
|||
//获取模块统计
|
||||
public Map<String, Long> moduleCount(FileMetadataTableRequest request, String operator) {
|
||||
//查出每个模块节点下的资源数量。 不需要按照模块进行筛选
|
||||
FileManagementPageDTO pageDTO = new FileManagementPageDTO(request);
|
||||
FileManagementQuery pageDTO = new FileManagementQuery(request);
|
||||
pageDTO.setModuleIds(null);
|
||||
List<ModuleCountDTO> moduleCountDTOList = extFileMetadataMapper.countModuleIdByKeywordAndFileType(pageDTO);
|
||||
long allCount = fileModuleService.getAllCount(moduleCountDTOList);
|
||||
|
@ -375,8 +375,8 @@ public class FileMetadataService {
|
|||
.body(bytes);
|
||||
}
|
||||
|
||||
public List<String> getFileType(String projectId) {
|
||||
return extFileMetadataMapper.selectFileTypeByProjectId(projectId);
|
||||
public List<String> getFileType(String projectId, String storage) {
|
||||
return extFileMetadataMapper.selectFileTypeByProjectId(projectId, storage);
|
||||
}
|
||||
|
||||
public void changeJarFileStatus(String fileId, boolean enable, String operator) {
|
||||
|
|
|
@ -4,10 +4,10 @@ import io.metersphere.project.domain.FileModule;
|
|||
import io.metersphere.project.domain.FileModuleExample;
|
||||
import io.metersphere.project.dto.ModuleCountDTO;
|
||||
import io.metersphere.project.dto.NodeSortDTO;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileModuleCreateRequest;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileModuleUpdateRequest;
|
||||
import io.metersphere.project.mapper.ExtFileModuleMapper;
|
||||
import io.metersphere.project.mapper.FileModuleMapper;
|
||||
import io.metersphere.project.request.filemanagement.FileModuleCreateRequest;
|
||||
import io.metersphere.project.request.filemanagement.FileModuleUpdateRequest;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
|
@ -25,7 +25,10 @@ import org.mybatis.spring.SqlSessionUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
@ -43,7 +46,7 @@ public class FileModuleService extends ModuleTreeService implements CleanupProje
|
|||
private FileManagementService fileManagementService;
|
||||
|
||||
public List<BaseTreeNode> getTree(String projectId) {
|
||||
List<BaseTreeNode> fileModuleList = extFileModuleMapper.selectBaseByProjectId(projectId);
|
||||
List<BaseTreeNode> fileModuleList = extFileModuleMapper.selectBaseByProjectId(projectId, ModuleConstants.NODE_TYPE_DEFAULT);
|
||||
return super.buildTreeAndCountResource(fileModuleList, true, Translator.get("default.module"));
|
||||
}
|
||||
|
||||
|
@ -173,25 +176,13 @@ public class FileModuleService extends ModuleTreeService implements CleanupProje
|
|||
/**
|
||||
* 查找当前项目下模块每个节点对应的资源统计
|
||||
*
|
||||
* @param projectId
|
||||
* @param moduleCountDTOList
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Long> getModuleCountMap(String projectId, List<ModuleCountDTO> moduleCountDTOList) {
|
||||
Map<String, Long> returnMap = new HashMap<>();
|
||||
|
||||
//构建模块树,并计算每个节点下的所有数量(包含子节点)
|
||||
List<BaseTreeNode> treeNodeList = this.getTreeOnlyIdsAndResourceCount(projectId, moduleCountDTOList);
|
||||
//通过广度遍历的方式构建返回值
|
||||
List<BaseTreeNode> whileList = new ArrayList<>(treeNodeList);
|
||||
while (CollectionUtils.isNotEmpty(whileList)) {
|
||||
List<BaseTreeNode> childList = new ArrayList<>();
|
||||
for (BaseTreeNode treeNode : whileList) {
|
||||
returnMap.put(treeNode.getId(), treeNode.getCount());
|
||||
childList.addAll(treeNode.getChildren());
|
||||
}
|
||||
whileList = childList;
|
||||
}
|
||||
return returnMap;
|
||||
return super.getIdCountMapByBreadth(treeNodeList);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.project.mapper.ExtFileModuleMapper;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class FileRepositoryService extends FileModuleService {
|
||||
|
||||
// @Resource
|
||||
// private FileModuleMapper fileModuleMapper;
|
||||
@Resource
|
||||
private ExtFileModuleMapper extFileModuleMapper;
|
||||
// @Resource
|
||||
// private FileManagementService fileManagementService;
|
||||
// @Resource
|
||||
// private SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
public List<BaseTreeNode> getTree(String projectId) {
|
||||
List<BaseTreeNode> fileModuleList = extFileModuleMapper.selectBaseByProjectId(projectId, ModuleConstants.NODE_TYPE_GIT);
|
||||
return super.buildTreeAndCountResource(fileModuleList, false, Translator.get("default.module"));
|
||||
}
|
||||
}
|
|
@ -225,4 +225,18 @@ public abstract class ModuleTreeService {
|
|||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
protected Map<String, Long> getIdCountMapByBreadth(List<BaseTreeNode> treeNodeList) {
|
||||
Map<String, Long> returnMap = new HashMap<>();
|
||||
List<BaseTreeNode> whileList = new ArrayList<>(treeNodeList);
|
||||
while (CollectionUtils.isNotEmpty(whileList)) {
|
||||
List<BaseTreeNode> childList = new ArrayList<>();
|
||||
for (BaseTreeNode treeNode : whileList) {
|
||||
returnMap.put(treeNode.getId(), treeNode.getCount());
|
||||
childList.addAll(treeNode.getChildren());
|
||||
}
|
||||
whileList = childList;
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package io.metersphere.project.controller.filemanagement;
|
||||
|
||||
import io.metersphere.project.domain.*;
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.dto.filemanagement.request.*;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
|
||||
import io.metersphere.project.mapper.FileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileModuleMapper;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.project.request.filemanagement.*;
|
||||
import io.metersphere.project.service.FileModuleService;
|
||||
import io.metersphere.project.utils.FileManagementBaseUtils;
|
||||
import io.metersphere.project.utils.FileManagementRequestUtils;
|
||||
|
@ -47,7 +47,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@AutoConfigureMockMvc
|
||||
public class FileManagementControllerTests extends BaseTest {
|
||||
|
||||
private static final String FILE_TEST_PROJECT_ID = "1507121382013";
|
||||
private static Project project;
|
||||
|
||||
private static List<BaseTreeNode> preliminaryTreeNodes = new ArrayList<>();
|
||||
|
@ -72,13 +72,17 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
|
||||
@BeforeEach
|
||||
public void initTestData() {
|
||||
//文件管理专用项目
|
||||
if (project == null) {
|
||||
project = projectMapper.selectByPrimaryKey(FILE_TEST_PROJECT_ID);
|
||||
}
|
||||
if (project == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId(IDGenerator.nextStr());
|
||||
initProject.setId(FILE_TEST_PROJECT_ID);
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId("100001");
|
||||
initProject.setName("建国创建的项目");
|
||||
initProject.setDescription("建国创建的项目");
|
||||
initProject.setName("文件管理专用项目");
|
||||
initProject.setDescription("建国创建的文件管理专用项目");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
|
@ -113,7 +117,7 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
MvcResult pageResult = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_PAGE, request);
|
||||
String returnData = pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
Pager<List<FileInformationDTO>> result = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), Pager.class);
|
||||
Pager<List<FileInformationResponse>> result = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), Pager.class);
|
||||
//返回值的页码和当前页码相同
|
||||
Assertions.assertEquals(result.getCurrent(), request.getCurrent());
|
||||
//返回的数据量不超过规定要返回的数据量相同
|
||||
|
@ -819,11 +823,11 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
}};
|
||||
//获取第一页的所有文件(一页50)
|
||||
MvcResult fileMvcResult = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_PAGE, request);
|
||||
Pager<List<FileInformationDTO>> pageResult = JSON.parseObject(JSON.toJSONString(
|
||||
Pager<List<FileInformationResponse>> 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) {
|
||||
List<FileInformationResponse> fileList = JSON.parseArray(JSON.toJSONString(pageResult.getList()), FileInformationResponse.class);
|
||||
for (FileInformationResponse fileDTO : fileList) {
|
||||
MvcResult originalResult = this.downloadFile(String.format(FileManagementRequestUtils.URL_FILE_PREVIEW_ORIGINAL, "admin", fileDTO.getId()));
|
||||
Assertions.assertTrue(originalResult.getResponse().getContentAsByteArray().length > 0);
|
||||
MvcResult compressedResult = this.downloadFile(String.format(FileManagementRequestUtils.URL_FILE_PREVIEW_COMPRESSED, "admin", fileDTO.getId()));
|
||||
|
@ -840,7 +844,7 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
}
|
||||
}
|
||||
//测试重复获取
|
||||
for (FileInformationDTO fileDTO : fileList) {
|
||||
for (FileInformationResponse fileDTO : fileList) {
|
||||
MvcResult originalResult = this.downloadFile(String.format(FileManagementRequestUtils.URL_FILE_PREVIEW_ORIGINAL, "admin", fileDTO.getId()));
|
||||
Assertions.assertTrue(originalResult.getResponse().getContentAsByteArray().length > 0);
|
||||
MvcResult compressedResult = this.downloadFile(String.format(FileManagementRequestUtils.URL_FILE_PREVIEW_COMPRESSED, "admin", fileDTO.getId()));
|
||||
|
@ -1013,7 +1017,7 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
MvcResult fileTypeResult = this.requestGetWithOkAndReturn(String.format(FileManagementRequestUtils.URL_FILE, IDGenerator.nextNum()));
|
||||
String returnData = fileTypeResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
FileInformationDTO dto = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), FileInformationDTO.class);
|
||||
FileInformationResponse dto = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), FileInformationResponse.class);
|
||||
Assertions.assertTrue(StringUtils.isEmpty(dto.getId()));
|
||||
}
|
||||
|
||||
|
@ -1277,7 +1281,6 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
checkLog(a3Node.getId(), OperationLogType.UPDATE, FileManagementRequestUtils.URL_MODULE_MOVE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(81)
|
||||
public void moveFileTest() throws Exception {
|
||||
|
@ -1475,7 +1478,7 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
|
||||
private void filePageRequestAndCheck(FileMetadataTableRequest request) throws Exception {
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_PAGE, request);
|
||||
Pager<List<FileInformationDTO>> pageResult = JSON.parseObject(JSON.toJSONString(
|
||||
Pager<List<FileInformationResponse>> pageResult = JSON.parseObject(JSON.toJSONString(
|
||||
JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
|
||||
Pager.class);
|
||||
MvcResult moduleCountMvcResult = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_MODULE_COUNT, request);
|
||||
|
@ -1487,7 +1490,7 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
|
||||
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(
|
||||
Pager<List<FileInformationResponse>> pageResult = JSON.parseObject(JSON.toJSONString(
|
||||
JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
|
||||
Pager.class);
|
||||
Assertions.assertEquals(pageResult.getTotal(), fileCount);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.metersphere.project.controller.filemanagement;
|
||||
|
||||
import io.metersphere.project.request.filemanagement.*;
|
||||
import io.metersphere.project.dto.filemanagement.request.*;
|
||||
import io.metersphere.project.utils.FileManagementBaseUtils;
|
||||
import io.metersphere.project.utils.FileManagementRequestUtils;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
package io.metersphere.project.controller.filemanagement;
|
||||
|
||||
import io.metersphere.project.domain.Project;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileMetadataTableRequest;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
|
||||
import io.metersphere.project.mapper.FileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileModuleMapper;
|
||||
import io.metersphere.project.mapper.ProjectMapper;
|
||||
import io.metersphere.project.service.FileModuleService;
|
||||
import io.metersphere.project.utils.FileManagementRequestUtils;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@AutoConfigureMockMvc
|
||||
public class FileRepositoryControllerTest extends BaseTest {
|
||||
|
||||
private static final String FILE_TEST_PROJECT_ID = "1507121382013";
|
||||
private static Project project;
|
||||
|
||||
private static List<BaseTreeNode> repositoryTreeNodes = new ArrayList<>();
|
||||
|
||||
private static final Map<String, String> FILE_ID_PATH = new LinkedHashMap<>();
|
||||
|
||||
private static final Map<String, String> FILE_VERSIONS_ID_MAP = new HashMap<>();
|
||||
|
||||
private static String reUploadFileId;
|
||||
|
||||
private static String picFileId;
|
||||
private static String jarFileId;
|
||||
|
||||
@Resource
|
||||
private FileModuleService fileModuleService;
|
||||
@Resource
|
||||
private FileModuleMapper fileModuleMapper;
|
||||
@Resource
|
||||
private FileMetadataMapper fileMetadataMapper;
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
|
||||
@BeforeEach
|
||||
public void initTestData() {
|
||||
//文件管理专用项目
|
||||
if (project == null) {
|
||||
project = projectMapper.selectByPrimaryKey(FILE_TEST_PROJECT_ID);
|
||||
}
|
||||
if (project == null) {
|
||||
Project initProject = new Project();
|
||||
initProject.setId(FILE_TEST_PROJECT_ID);
|
||||
initProject.setNum(null);
|
||||
initProject.setOrganizationId("100001");
|
||||
initProject.setName("文件管理专用项目");
|
||||
initProject.setDescription("建国创建的文件管理专用项目");
|
||||
initProject.setCreateUser("admin");
|
||||
initProject.setUpdateUser("admin");
|
||||
initProject.setCreateTime(System.currentTimeMillis());
|
||||
initProject.setUpdateTime(System.currentTimeMillis());
|
||||
initProject.setEnable(true);
|
||||
initProject.setModuleSetting("[\"apiTest\",\"uiTest\"]");
|
||||
projectMapper.insertSelective(initProject);
|
||||
project = projectMapper.selectByPrimaryKey(initProject.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void emptyDataTest() throws Exception {
|
||||
//空数据下,检查模块树
|
||||
List<BaseTreeNode> treeNodes = this.getFileModuleTreeNode();
|
||||
//不能有默认节点
|
||||
boolean hasNode = false;
|
||||
for (BaseTreeNode baseTreeNode : treeNodes) {
|
||||
if (StringUtils.equals(baseTreeNode.getId(), ModuleConstants.DEFAULT_NODE_ID)) {
|
||||
hasNode = true;
|
||||
}
|
||||
Assertions.assertNotNull(baseTreeNode.getParentId());
|
||||
}
|
||||
Assertions.assertTrue(!hasNode);
|
||||
|
||||
//空数据下,检查文件列表
|
||||
FileMetadataTableRequest request = new FileMetadataTableRequest() {{
|
||||
this.setCurrent(1);
|
||||
this.setPageSize(10);
|
||||
this.setProjectId(project.getId());
|
||||
this.setCombine(new HashMap<>() {{
|
||||
this.put("storage", StorageType.GIT.name());
|
||||
}});
|
||||
}};
|
||||
MvcResult pageResult = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_PAGE, request);
|
||||
String returnData = pageResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
Pager<List<FileInformationResponse>> result = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), Pager.class);
|
||||
//返回值的页码和当前页码相同
|
||||
Assertions.assertEquals(result.getCurrent(), request.getCurrent());
|
||||
//返回的数据量不超过规定要返回的数据量相同
|
||||
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(result.getList())).size() <= request.getPageSize());
|
||||
|
||||
//此时该接口数量应该为空
|
||||
List<String> fileTypes = this.getFileType();
|
||||
Assertions.assertTrue(fileTypes.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
public void repositoryListTest() throws Exception {
|
||||
this.getFileModuleTreeNode();
|
||||
//权限校验
|
||||
this.requestGetPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ, String.format(FileManagementRequestUtils.URL_FILE_REPOSITORY_LIST, DEFAULT_PROJECT_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
public void repositoryFileTypeTest() throws Exception {
|
||||
this.getFileType();
|
||||
//权限校验
|
||||
this.requestGetPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ, String.format(FileManagementRequestUtils.URL_FILE_REPOSITORY_FILE_TYPE, DEFAULT_PROJECT_ID));
|
||||
}
|
||||
|
||||
private List<BaseTreeNode> getFileModuleTreeNode() throws Exception {
|
||||
MvcResult result = this.requestGetWithOkAndReturn(String.format(FileManagementRequestUtils.URL_FILE_REPOSITORY_LIST, project.getId()));
|
||||
String returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
return JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class);
|
||||
}
|
||||
|
||||
private List<String> getFileType() throws Exception {
|
||||
MvcResult fileTypeResult = this.requestGetWithOkAndReturn(String.format(FileManagementRequestUtils.URL_FILE_REPOSITORY_FILE_TYPE, project.getId()));
|
||||
String returnData = fileTypeResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
return JSON.parseArray(JSON.toJSONString(resultHolder.getData()), String.class);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package io.metersphere.project.utils;
|
||||
|
||||
import io.metersphere.project.dto.filemanagement.FileInformationDTO;
|
||||
import io.metersphere.project.request.filemanagement.FileMetadataTableRequest;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.project.dto.filemanagement.request.FileMetadataTableRequest;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
@ -73,13 +73,11 @@ public class FileManagementBaseUtils {
|
|||
BigInteger bigInt = new BigInteger(1, digest.digest());
|
||||
return bigInt.toString(16);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,12 +89,11 @@ public class FileManagementBaseUtils {
|
|||
BigInteger bigInt = new BigInteger(1, digest.digest());
|
||||
return bigInt.toString(16);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkFilePage(Pager<List<FileInformationDTO>> tableData, Map<String, Integer> moduleCount, FileMetadataTableRequest request) {
|
||||
public static void checkFilePage(Pager<List<FileInformationResponse>> tableData, Map<String, Integer> moduleCount, FileMetadataTableRequest request) {
|
||||
//返回值的页码和当前页码相同
|
||||
Assertions.assertEquals(tableData.getCurrent(), request.getCurrent());
|
||||
//返回的数据量不超过规定要返回的数据量相同
|
||||
|
|
|
@ -41,4 +41,12 @@ public class FileManagementRequestUtils {
|
|||
//文件批量移动(权限判断需要提前上传文件,所以放在了主测试类里)
|
||||
public static final String URL_FILE_BATCH_UPDATE = "/project/file/batch-move";
|
||||
|
||||
/**
|
||||
* 存储库相关路径
|
||||
*/
|
||||
//存储库列表
|
||||
public static final String URL_FILE_REPOSITORY_LIST = "/project/file/repository/list/%s";
|
||||
//存储库文件类型
|
||||
public static final String URL_FILE_REPOSITORY_FILE_TYPE = "/project/file/repository/file-type/%s";
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue