feat(项目管理): 文件详情增加存储库相关字段
This commit is contained in:
parent
2a7d4a38e5
commit
4aea30d3ed
|
@ -139,6 +139,12 @@ public class TempFileUtils {
|
|||
return file.exists();
|
||||
}
|
||||
|
||||
//图片原图是否存在
|
||||
public static boolean isImgTmpFileExists(String fileId) {
|
||||
File file = new File(getTmpFilePath(fileId));
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
public static byte[] getFile(String filePath) {
|
||||
File file = new File(filePath);
|
||||
byte[] previewByte = new byte[0];
|
||||
|
|
|
@ -449,7 +449,7 @@ file.log.next=之后
|
|||
file.log.previous=之前
|
||||
file.log.upload=上传
|
||||
file.log.repository.add=添加了存储库文件
|
||||
file.log.re-upload=重新上传
|
||||
file.log.re-upload=重新上传了文件
|
||||
file.log.pull=拉取了文件
|
||||
file.log.association=关联了文件
|
||||
file.log.association.update=更新了关联了文件
|
||||
|
|
|
@ -485,7 +485,7 @@ file.log.next=next
|
|||
file.log.previous=behind
|
||||
file.log.upload=upload
|
||||
file.log.repository.add=Add repository file
|
||||
file.log.re-upload=re-upload
|
||||
file.log.re-upload=re-upload file
|
||||
file.log.pull=Pull file
|
||||
file.log.association=has association file
|
||||
file.log.association.update=updated file
|
||||
|
|
|
@ -484,7 +484,7 @@ file.log.next=之后
|
|||
file.log.previous=之前
|
||||
file.log.upload=上传
|
||||
file.log.repository.add=添加了存储库文件
|
||||
file.log.re-upload=重新上传
|
||||
file.log.re-upload=重新上传了文件
|
||||
file.log.pull=拉取了文件
|
||||
file.log.association=关联了文件
|
||||
file.log.association.update=更新了关联了文件
|
||||
|
|
|
@ -485,7 +485,7 @@ file.log.next=之後
|
|||
file.log.previous=之前
|
||||
file.log.upload=上傳
|
||||
file.log.repository.add=添加了存儲庫文件
|
||||
file.log.re-upload=重新上傳
|
||||
file.log.re-upload=重新上傳了文件
|
||||
file.log.pull=拉取了文件
|
||||
file.log.association=關聯了文件
|
||||
file.log.association.update=更新了關聯了文件
|
||||
|
|
|
@ -26,14 +26,14 @@ public class FileAssociationController {
|
|||
private FileAssociationService fileAssociationService;
|
||||
|
||||
@GetMapping("/list/{id}")
|
||||
@Operation(summary = "项目管理-文件管理-表格分页查询文件")
|
||||
@Operation(summary = "项目管理-文件管理-文件关联-文件资源关联列表")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ)
|
||||
public List<FileAssociationResponse> getAssociationList(@PathVariable String id) {
|
||||
return fileAssociationService.selectFileAllVersionAssociation(id);
|
||||
}
|
||||
|
||||
@GetMapping("/upgrade/{projectId}/{id}")
|
||||
@Operation(summary = "项目管理-文件管理-表格分页查询文件")
|
||||
@Operation(summary = "项目管理-文件管理-文件关联-更新资源关联的文件到最新版本")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_UPDATE)
|
||||
public String upgrade(@PathVariable String projectId,@PathVariable String id) {
|
||||
FileLogRecord fileLogRecord = FileLogRecord.builder()
|
||||
|
@ -48,7 +48,7 @@ public class FileAssociationController {
|
|||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@Operation(summary = "项目管理-文件管理-表格分页查询文件")
|
||||
@Operation(summary = "项目管理-文件管理-文件关联-取消文件和资源的关联")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_UPDATE)
|
||||
public int delete(@RequestBody @Validated FileAssociationDeleteRequest request) {
|
||||
FileLogRecord fileLogRecord = FileLogRecord.builder()
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.project.controller;
|
|||
|
||||
import io.metersphere.project.dto.filemanagement.request.*;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileVersionResponse;
|
||||
import io.metersphere.project.service.FileManagementService;
|
||||
import io.metersphere.project.service.FileMetadataService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
|
@ -114,4 +115,12 @@ public class FileManagementController {
|
|||
public void batchMoveFiles(@Validated @RequestBody FileBatchMoveRequest request) {
|
||||
fileMetadataService.batchMove(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/file-version/{fileId}")
|
||||
@Operation(summary = "项目管理-文件管理-文件历史版本")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ)
|
||||
public List<FileVersionResponse> getFileVersion(@PathVariable String fileId) {
|
||||
return fileMetadataService.getFileVersion(fileId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@ package io.metersphere.project.dto.filemanagement.request;
|
|||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class FileBatchMoveRequest extends FileBatchProcessRequest {
|
||||
@Schema(description = "目标模块ID")
|
||||
@NotEmpty(message = "{file_module_blob.file_module_id.not_blank}")
|
||||
|
|
|
@ -4,10 +4,12 @@ import io.metersphere.system.dto.table.TableBatchProcessDTO;
|
|||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class FileBatchProcessRequest extends TableBatchProcessDTO {
|
||||
|
||||
@Schema(description = "项目ID")
|
||||
|
|
|
@ -4,10 +4,12 @@ import io.metersphere.system.dto.sdk.BasePageRequest;
|
|||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class FileMetadataTableRequest extends BasePageRequest {
|
||||
@Schema(description = "模块ID(根据模块树查询时要把当前节点以及子节点都放在这里。)")
|
||||
private List<String> moduleIds;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.project.dto.filemanagement.response;
|
||||
|
||||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.project.domain.FileMetadataRepository;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
@ -61,7 +62,22 @@ public class FileInformationResponse {
|
|||
@Schema(description = "关联ID")
|
||||
private String refId;
|
||||
|
||||
public FileInformationResponse(FileMetadata fileMetadata) {
|
||||
@Schema(description = "文件版本")
|
||||
private String fileVersion;
|
||||
|
||||
@Schema(description = "文件路径")
|
||||
private String filePath;
|
||||
|
||||
@Schema(description = "文件分支")
|
||||
private String branch;
|
||||
|
||||
@Schema(description = "文件分支")
|
||||
private String commitId;
|
||||
|
||||
@Schema(description = "文件分支")
|
||||
private String commitMessage;
|
||||
|
||||
public FileInformationResponse(FileMetadata fileMetadata, FileMetadataRepository repositoryFile) {
|
||||
if (fileMetadata != null) {
|
||||
this.id = fileMetadata.getId();
|
||||
this.projectId = fileMetadata.getProjectId();
|
||||
|
@ -80,6 +96,13 @@ public class FileInformationResponse {
|
|||
this.updateTime = fileMetadata.getUpdateTime();
|
||||
this.storage = fileMetadata.getStorage();
|
||||
this.refId = fileMetadata.getRefId();
|
||||
this.fileVersion = fileMetadata.getFileVersion();
|
||||
this.filePath = fileMetadata.getPath();
|
||||
}
|
||||
if (repositoryFile != null) {
|
||||
this.branch = repositoryFile.getBranch();
|
||||
this.commitId = repositoryFile.getCommitId();
|
||||
this.commitMessage = repositoryFile.getCommitMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package io.metersphere.project.dto.filemanagement.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FileVersionResponse {
|
||||
@Schema(description = "ID")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "文件版本")
|
||||
private String fileVersion;
|
||||
|
||||
@Schema(description = "更新历史")
|
||||
private String updateHistory;
|
||||
|
||||
@Schema(description = "操作人")
|
||||
private String operator;
|
||||
|
||||
@Schema(description = "操作时间")
|
||||
private long operateTime;
|
||||
|
||||
}
|
|
@ -151,6 +151,7 @@
|
|||
f.project_id,
|
||||
f.size,
|
||||
f.ref_id,
|
||||
f.file_version,
|
||||
f.storage
|
||||
FROM file_metadata f
|
||||
INNER JOIN user updateUser ON f.update_user = updateUser.id
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
package io.metersphere.project.service;
|
||||
|
||||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.project.domain.FileMetadataExample;
|
||||
import io.metersphere.project.domain.FileMetadataRepositoryExample;
|
||||
import io.metersphere.project.domain.FileModuleExample;
|
||||
import io.metersphere.project.domain.*;
|
||||
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.FileMetadataRepositoryMapper;
|
||||
import io.metersphere.project.mapper.FileModuleMapper;
|
||||
import io.metersphere.project.mapper.*;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
|
@ -32,6 +26,8 @@ public class FileManagementService {
|
|||
@Resource
|
||||
private FileMetadataRepositoryMapper fileMetadataRepositoryMapper;
|
||||
@Resource
|
||||
private FileAssociationMapper fileAssociationMapper;
|
||||
@Resource
|
||||
private FileModuleMapper fileModuleMapper;
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
@ -62,6 +58,10 @@ public class FileManagementService {
|
|||
repositoryExample.createCriteria().andFileMetadataIdIn(deleteIds);
|
||||
fileMetadataRepositoryMapper.deleteByExample(repositoryExample);
|
||||
|
||||
FileAssociationExample associationExample = new FileAssociationExample();
|
||||
associationExample.createCriteria().andFileIdIn(deleteIds);
|
||||
fileAssociationMapper.deleteByExample(associationExample);
|
||||
|
||||
//记录日志
|
||||
fileMetadataLogService.saveDeleteLog(deleteList, request.getProjectId(), operator);
|
||||
|
||||
|
|
|
@ -2,14 +2,12 @@ package io.metersphere.project.service;
|
|||
|
||||
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.domain.FileMetadataRepository;
|
||||
import io.metersphere.project.domain.FileModuleRepository;
|
||||
import io.metersphere.project.domain.*;
|
||||
import io.metersphere.project.dto.ModuleCountDTO;
|
||||
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.dto.filemanagement.response.FileVersionResponse;
|
||||
import io.metersphere.project.mapper.ExtFileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileMetadataRepositoryMapper;
|
||||
|
@ -26,6 +24,7 @@ import io.metersphere.system.dto.sdk.RemoteFileAttachInfo;
|
|||
import io.metersphere.system.file.FileRepository;
|
||||
import io.metersphere.system.file.FileRequest;
|
||||
import io.metersphere.system.file.MinioRepository;
|
||||
import io.metersphere.system.mapper.BaseUserMapper;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import io.metersphere.system.utils.GitRepositoryUtil;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
|
@ -42,11 +41,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.util.unit.DataSize;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
@ -61,6 +59,9 @@ public class FileMetadataService {
|
|||
private FileMetadataRepositoryMapper fileMetadataRepositoryMapper;
|
||||
@Resource
|
||||
private FileModuleRepositoryMapper fileModuleRepositoryMapper;
|
||||
@Resource
|
||||
private BaseUserMapper baseUserMapper;
|
||||
|
||||
@Resource
|
||||
private FileMetadataLogService fileMetadataLogService;
|
||||
@Resource
|
||||
|
@ -70,6 +71,7 @@ public class FileMetadataService {
|
|||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
|
||||
@Value("${metersphere.file.batch-download-max:600MB}")
|
||||
private DataSize batchDownloadMaxSize;
|
||||
@Value("50MB")
|
||||
|
@ -81,7 +83,8 @@ public class FileMetadataService {
|
|||
|
||||
public FileInformationResponse getFileInformation(String id) {
|
||||
FileMetadata fileMetadata = extFileMetadataMapper.getById(id);
|
||||
FileInformationResponse dto = new FileInformationResponse(fileMetadata);
|
||||
FileMetadataRepository repositoryMap = fileMetadataRepositoryMapper.selectByPrimaryKey(id);
|
||||
FileInformationResponse dto = new FileInformationResponse(fileMetadata, repositoryMap);
|
||||
initModuleName(dto);
|
||||
return dto;
|
||||
}
|
||||
|
@ -91,7 +94,7 @@ public class FileMetadataService {
|
|||
FileManagementQuery pageDTO = new FileManagementQuery(request);
|
||||
List<FileMetadata> fileMetadataList = extFileMetadataMapper.selectByKeywordAndFileType(pageDTO);
|
||||
fileMetadataList.forEach(fileMetadata -> {
|
||||
FileInformationResponse fileInformationResponse = new FileInformationResponse(fileMetadata);
|
||||
FileInformationResponse fileInformationResponse = new FileInformationResponse(fileMetadata, null);
|
||||
returnList.add(fileInformationResponse);
|
||||
});
|
||||
this.initModuleName(returnList);
|
||||
|
@ -284,7 +287,7 @@ public class FileMetadataService {
|
|||
|
||||
public byte[] getFileByte(FileMetadata fileMetadata) {
|
||||
String filePath = null;
|
||||
if (TempFileUtils.isImgPreviewFileExists(fileMetadata.getId())) {
|
||||
if (TempFileUtils.isImgTmpFileExists(fileMetadata.getId())) {
|
||||
filePath = TempFileUtils.getTmpFilePath(fileMetadata.getId());
|
||||
} else {
|
||||
try {
|
||||
|
@ -292,8 +295,7 @@ public class FileMetadataService {
|
|||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
byte[] bytes = TempFileUtils.getFile(filePath);
|
||||
return bytes;
|
||||
return TempFileUtils.getFile(filePath);
|
||||
}
|
||||
|
||||
public ResponseEntity<byte[]> downloadById(String id) {
|
||||
|
@ -350,7 +352,7 @@ public class FileMetadataService {
|
|||
this.checkMinIOFileName(request.getId(), request.getName(), fileMetadata.getProjectId());
|
||||
updateExample.setName(request.getName());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(request.getTags())) {
|
||||
if (request.getTags() != null) {
|
||||
updateExample.setTags(JSON.toJSONString(request.getTags()));
|
||||
} else {
|
||||
updateExample.setTags(null);
|
||||
|
@ -613,4 +615,49 @@ public class FileMetadataService {
|
|||
throw new MSException(Translator.get("latest.file.not.exist"));
|
||||
}
|
||||
}
|
||||
|
||||
public List<FileVersionResponse> getFileVersion(String fileId) {
|
||||
FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(fileId);
|
||||
if (fileMetadata == null) {
|
||||
throw new MSException(Translator.get("file.not.exist"));
|
||||
}
|
||||
|
||||
//获取fileMetadata以及可能存在的fileMetadataRepository
|
||||
FileMetadataExample example = new FileMetadataExample();
|
||||
example.createCriteria().andRefIdEqualTo(fileMetadata.getRefId());
|
||||
List<FileMetadata> fileMetadataList = fileMetadataMapper.selectByExample(example);
|
||||
List<String> fileIdList = fileMetadataList.stream().map(FileMetadata::getId).toList();
|
||||
FileMetadataRepositoryExample repositoryExample = new FileMetadataRepositoryExample();
|
||||
repositoryExample.createCriteria().andFileMetadataIdIn(fileIdList);
|
||||
List<FileMetadataRepository> fileMetadataRepositoryList = fileMetadataRepositoryMapper.selectByExample(repositoryExample);
|
||||
Map<String, FileMetadataRepository> fileIdMap = fileMetadataRepositoryList.stream().collect(Collectors.toMap(FileMetadataRepository::getFileMetadataId, Function.identity()));
|
||||
|
||||
//用户ID-用户名的映射
|
||||
Map<String, String> userNameMap = new HashMap<>();
|
||||
|
||||
List<FileVersionResponse> fileVersionResponseList = new ArrayList<>();
|
||||
fileMetadataList.forEach(item -> {
|
||||
|
||||
FileVersionResponse fileVersionResponse = new FileVersionResponse();
|
||||
String userName = userNameMap.get(item.getCreateUser());
|
||||
if (userName == null) {
|
||||
userName = baseUserMapper.selectNameById(item.getCreateUser());
|
||||
userNameMap.put(item.getCreateUser(), userName);
|
||||
}
|
||||
|
||||
fileVersionResponse.setId(item.getId());
|
||||
fileVersionResponse.setFileVersion(item.getFileVersion());
|
||||
fileVersionResponse.setOperator(userName);
|
||||
fileVersionResponse.setOperateTime(item.getCreateTime());
|
||||
|
||||
FileMetadataRepository fileRepository = fileIdMap.get(item.getId());
|
||||
if (fileRepository == null) {
|
||||
fileVersionResponse.setUpdateHistory(Translator.get("file.log.re-upload"));
|
||||
} else {
|
||||
fileVersionResponse.setUpdateHistory(fileRepository.getCommitMessage());
|
||||
}
|
||||
fileVersionResponseList.add(fileVersionResponse);
|
||||
});
|
||||
return fileVersionResponseList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.project.dto.filemanagement.FileLogRecord;
|
|||
import io.metersphere.project.dto.filemanagement.request.*;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileAssociationResponse;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileInformationResponse;
|
||||
import io.metersphere.project.dto.filemanagement.response.FileVersionResponse;
|
||||
import io.metersphere.project.mapper.FileAssociationMapper;
|
||||
import io.metersphere.project.mapper.FileMetadataMapper;
|
||||
import io.metersphere.project.mapper.FileModuleMapper;
|
||||
|
@ -992,6 +993,14 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
this.requestPostWithOk(FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest);
|
||||
this.checkFileInformation(updateFileId, oldFileMetadata, updateRequest);
|
||||
|
||||
//取消标签
|
||||
oldFileMetadata = fileMetadataMapper.selectByPrimaryKey(updateFileId);
|
||||
updateRequest = new FileUpdateRequest();
|
||||
updateRequest.setId(updateFileId);
|
||||
updateRequest.setTags(new ArrayList<>());
|
||||
this.requestPostWithOk(FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest);
|
||||
this.checkFileInformation(updateFileId, oldFileMetadata, updateRequest);
|
||||
|
||||
//判断更改jar文件的启用禁用
|
||||
oldFileMetadata = fileMetadataMapper.selectByPrimaryKey(jarFileId);
|
||||
updateRequest = new FileUpdateRequest();
|
||||
|
@ -1057,6 +1066,30 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
FileInformationResponse dto = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), FileInformationResponse.class);
|
||||
Assertions.assertTrue(StringUtils.isEmpty(dto.getId()));
|
||||
|
||||
if (StringUtils.isAnyEmpty(fileAssociationOldFileId, fileAssociationNewFileId, fileAssociationNewFilesOne, fileAssociationNewFilesTwo, fileAssociationNewFilesThree)) {
|
||||
this.fileReUploadTestSuccess();
|
||||
}
|
||||
fileTypeResult = this.requestGetWithOkAndReturn(String.format(FileManagementRequestUtils.URL_FILE, fileAssociationNewFilesTwo));
|
||||
returnData = fileTypeResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
dto = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), FileInformationResponse.class);
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getId()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getName()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getProjectId()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getModuleName()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getModuleId()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getCreateUser()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getUpdateUser()));
|
||||
Assertions.assertTrue(dto.getUpdateTime() > 0);
|
||||
Assertions.assertTrue(dto.getCreateTime() > 0);
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getStorage()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getRefId()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getFileVersion()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getFilePath()));
|
||||
Assertions.assertTrue(StringUtils.isEmpty(dto.getBranch()));
|
||||
Assertions.assertTrue(StringUtils.isEmpty(dto.getCommitId()));
|
||||
Assertions.assertTrue(StringUtils.isEmpty(dto.getCommitMessage()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1078,6 +1111,32 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
this.requestGet(String.format(FileManagementRequestUtils.URL_CHANGE_JAR_ENABLE, picFileId, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(29)
|
||||
public void fileVersionTest() throws Exception {
|
||||
if (StringUtils.isAnyEmpty(fileAssociationOldFileId, fileAssociationNewFileId, fileAssociationNewFilesOne, fileAssociationNewFilesTwo, fileAssociationNewFilesThree)) {
|
||||
this.fileReUploadTestSuccess();
|
||||
}
|
||||
MvcResult result = this.requestGetWithOkAndReturn(String.format(FileManagementRequestUtils.URL_FILE_VERSION, fileAssociationNewFileId));
|
||||
ResultHolder resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class);
|
||||
List<FileVersionResponse> fileVersionResponseList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FileVersionResponse.class);
|
||||
|
||||
Assertions.assertTrue(fileVersionResponseList.size() > 1);
|
||||
boolean hasOldVersion = false;
|
||||
boolean hasNewVersion = false;
|
||||
|
||||
for (FileVersionResponse fileVersionResponse : fileVersionResponseList) {
|
||||
if (StringUtils.equals(fileVersionResponse.getId(), fileAssociationOldFileId)) {
|
||||
hasOldVersion = true;
|
||||
} else if (StringUtils.equals(fileVersionResponse.getId(), fileAssociationNewFileId)) {
|
||||
hasNewVersion = true;
|
||||
}
|
||||
}
|
||||
Assertions.assertTrue(hasOldVersion && hasNewVersion);
|
||||
//权限测试
|
||||
this.requestGetPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ, String.format(FileManagementRequestUtils.URL_FILE_VERSION, fileAssociationNewFileId));
|
||||
}
|
||||
|
||||
/*
|
||||
30-80之间是测试文件关联的
|
||||
*/
|
||||
|
@ -1193,6 +1252,7 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
FileMetadataExample example = new FileMetadataExample();
|
||||
example.createCriteria().andProjectIdEqualTo(project.getId());
|
||||
Assertions.assertEquals(fileMetadataMapper.countByExample(example), 0);
|
||||
|
||||
//重新上传,用于后续的测试
|
||||
this.fileUploadTestSuccess();
|
||||
}
|
||||
|
@ -2119,7 +2179,7 @@ public class FileManagementControllerTests extends BaseTest {
|
|||
Assertions.assertEquals(oldFileMetadata.getEnable(), fileMetadata.getEnable());
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(updateRequest.getTags())) {
|
||||
if (updateRequest.getTags() != null) {
|
||||
Assertions.assertTrue(CollectionUtils.isEqualCollection(JSON.parseArray(fileMetadata.getTags(), String.class), updateRequest.getTags()));
|
||||
} else {
|
||||
List<String> fileTags = fileMetadata.getTags() == null ? new ArrayList<>() : JSON.parseArray(fileMetadata.getTags(), String.class);
|
||||
|
|
|
@ -381,7 +381,9 @@ public class FileRepositoryControllerTest extends BaseTest {
|
|||
String fileId = JSON.parseObject(result.getResponse().getContentAsString(), ResultHolder.class).getData().toString();
|
||||
this.checkRepositoryFile(fileId, request);
|
||||
this.checkLog(fileId, OperationLogType.ADD, FileManagementRequestUtils.URL_FILE_REPOSITORY_FILE_ADD);
|
||||
getFileMessage(fileId);
|
||||
fileList.add(fileId);
|
||||
|
||||
//测试其他分支的多层目录的文件
|
||||
String otherBranch = "develop";
|
||||
String folderFilePath1 = "test-folder/gitee/test.txt";
|
||||
|
@ -392,6 +394,7 @@ public class FileRepositoryControllerTest extends BaseTest {
|
|||
result = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_REPOSITORY_FILE_ADD, request);
|
||||
fileId = JSON.parseObject(result.getResponse().getContentAsString(), ResultHolder.class).getData().toString();
|
||||
this.checkRepositoryFile(fileId, request);
|
||||
getFileMessage(fileId);
|
||||
fileList.add(fileId);
|
||||
//测试隐藏文件
|
||||
String folderFilePath2 = "test-folder/.keep";
|
||||
|
@ -402,6 +405,7 @@ public class FileRepositoryControllerTest extends BaseTest {
|
|||
result = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_REPOSITORY_FILE_ADD, request);
|
||||
fileId = JSON.parseObject(result.getResponse().getContentAsString(), ResultHolder.class).getData().toString();
|
||||
this.checkRepositoryFile(fileId, request);
|
||||
getFileMessage(fileId);
|
||||
fileList.add(fileId);
|
||||
//测试添加jar包并且启用
|
||||
request = new RepositoryFileAddRequest();
|
||||
|
@ -412,6 +416,7 @@ public class FileRepositoryControllerTest extends BaseTest {
|
|||
result = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_REPOSITORY_FILE_ADD, request);
|
||||
fileId = JSON.parseObject(result.getResponse().getContentAsString(), ResultHolder.class).getData().toString();
|
||||
this.checkRepositoryFile(fileId, request);
|
||||
getFileMessage(fileId);
|
||||
fileList.add(fileId);
|
||||
//获取图片信息
|
||||
request = new RepositoryFileAddRequest();
|
||||
|
@ -421,6 +426,7 @@ public class FileRepositoryControllerTest extends BaseTest {
|
|||
result = this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_FILE_REPOSITORY_FILE_ADD, request);
|
||||
fileId = JSON.parseObject(result.getResponse().getContentAsString(), ResultHolder.class).getData().toString();
|
||||
this.checkRepositoryFile(fileId, request);
|
||||
getFileMessage(fileId);
|
||||
this.picFileId = fileId;
|
||||
fileList.add(fileId);
|
||||
{
|
||||
|
@ -497,6 +503,29 @@ public class FileRepositoryControllerTest extends BaseTest {
|
|||
|
||||
}
|
||||
|
||||
private void getFileMessage(String fileId) throws Exception {
|
||||
MvcResult fileTypeResult = this.requestGetWithOkAndReturn(String.format(FileManagementRequestUtils.URL_FILE, fileId));
|
||||
String returnData = fileTypeResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
FileInformationResponse dto = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), FileInformationResponse.class);
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getId()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getName()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getProjectId()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getModuleName()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getModuleId()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getCreateUser()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getUpdateUser()));
|
||||
Assertions.assertTrue(dto.getUpdateTime() > 0);
|
||||
Assertions.assertTrue(dto.getCreateTime() > 0);
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getStorage()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getRefId()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getFileVersion()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getFilePath()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getBranch()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getCommitId()));
|
||||
Assertions.assertTrue(StringUtils.isNotEmpty(dto.getCommitMessage()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
public void repositoryGetFileTest() throws Exception {
|
||||
|
|
|
@ -40,6 +40,8 @@ public class FileManagementRequestUtils {
|
|||
public static final String URL_FILE_UPDATE = "/project/file/update";
|
||||
//文件批量移动(权限判断需要提前上传文件,所以放在了主测试类里)
|
||||
public static final String URL_FILE_BATCH_UPDATE = "/project/file/batch-move";
|
||||
//文件批量移动(权限判断需要提前上传文件,所以放在了主测试类里)
|
||||
public static final String URL_FILE_VERSION = "/project/file/file-version/%s";
|
||||
|
||||
/*
|
||||
存储库相关路径
|
||||
|
|
|
@ -14,6 +14,8 @@ public interface BaseUserMapper {
|
|||
|
||||
UserDTO selectById(String id);
|
||||
|
||||
String selectNameById(String id);
|
||||
|
||||
List<User> findAll();
|
||||
|
||||
void batchSave(@Param("users") List<User> users);
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
`email` = id
|
||||
WHERE `id` = #{id}
|
||||
</update>
|
||||
|
||||
<select id="selectNameById" resultType="java.lang.String">
|
||||
SELECT user.name
|
||||
FROM user
|
||||
WHERE user.id = #{id}
|
||||
</select>
|
||||
<select id="selectById" resultType="io.metersphere.system.dto.user.UserDTO">
|
||||
SELECT *
|
||||
FROM user
|
||||
|
|
|
@ -12,7 +12,11 @@ import io.metersphere.system.dto.excel.UserExcel;
|
|||
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
||||
import io.metersphere.system.dto.request.UserInviteRequest;
|
||||
import io.metersphere.system.dto.request.UserRegisterRequest;
|
||||
import io.metersphere.system.dto.request.user.UserChangeEnableRequest;
|
||||
import io.metersphere.system.dto.request.user.UserEditRequest;
|
||||
import io.metersphere.system.dto.response.UserImportResponse;
|
||||
import io.metersphere.system.dto.response.UserInviteResponse;
|
||||
import io.metersphere.system.dto.response.UserTableResponse;
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import io.metersphere.system.dto.sdk.ExcelParseDTO;
|
||||
import io.metersphere.system.dto.sdk.SessionUser;
|
||||
|
@ -26,10 +30,6 @@ import io.metersphere.system.mapper.ExtUserMapper;
|
|||
import io.metersphere.system.mapper.SystemParameterMapper;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.notice.sender.impl.MailNoticeSender;
|
||||
import io.metersphere.system.dto.request.user.UserChangeEnableRequest;
|
||||
import io.metersphere.system.dto.request.user.UserEditRequest;
|
||||
import io.metersphere.system.dto.response.UserImportResponse;
|
||||
import io.metersphere.system.dto.response.UserTableResponse;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import io.metersphere.system.utils.UserImportEventListener;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -438,7 +438,6 @@ public class UserService {
|
|||
}
|
||||
|
||||
public void sendInviteEmailTemporary(HashMap<String, String> hashMap) throws Exception {
|
||||
//todo 发送邮件 等小美女的消息通知提交完毕之后删除。
|
||||
JavaMailSenderImpl javaMailSender = null;
|
||||
try {
|
||||
javaMailSender = mailNoticeSender.getMailSender(hashMap);
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
|||
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||
import org.eclipse.jgit.treewalk.filter.PathFilter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -104,7 +105,8 @@ public class GitRepositoryUtil {
|
|||
if (StringUtils.isEmpty(fileLastCommitId)) {
|
||||
fileLastCommitId = lastCommitId.getName();
|
||||
}
|
||||
return new RemoteFileAttachInfo(repositoryUrl, userName, token, branch, fileLastCommitId, filePath, commit.getFullMessage(), loader.getSize());
|
||||
|
||||
return new RemoteFileAttachInfo(repositoryUrl, userName, token, branch, fileLastCommitId, filePath, this.genCommitMessageWithCommitTime(commit.getFullMessage(), commit.getCommitTime()), loader.getSize());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -118,6 +120,11 @@ public class GitRepositoryUtil {
|
|||
return new RemoteFileAttachInfo();
|
||||
}
|
||||
|
||||
private String genCommitMessageWithCommitTime(String commitMessage, int commitTime) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return commitMessage + StringUtils.LF + simpleDateFormat.format(new Date(commitTime * 1000L));
|
||||
}
|
||||
|
||||
private String getFileLastCommitId(ObjectId objectId, String filePath) throws Exception {
|
||||
Iterable<RevCommit> logs = git.log().add(objectId).addPath(filePath).call();
|
||||
String returnStr = StringUtils.EMPTY;
|
||||
|
|
Loading…
Reference in New Issue