fix(测试跟踪): 复制用例及缺陷操作附件的问题
--bug=1023874 --user=宋昌昌 【测试跟踪】复制用例,无法上法上传附件 https://www.tapd.cn/55049933/s/1347956
This commit is contained in:
parent
fa5c23e512
commit
9158ffef76
|
@ -26,12 +26,23 @@ public class EditTestCaseRequest extends TestCaseWithBLOBs {
|
|||
* 复制测试用例时原始用例ID
|
||||
*/
|
||||
private String copyCaseId;
|
||||
// 是否处理附件文件
|
||||
/**
|
||||
* 是否处理附件文件
|
||||
*/
|
||||
private boolean handleAttachment = true;
|
||||
// 关联文件管理引用ID
|
||||
/**
|
||||
* 关联文件管理引用ID(新增操作)
|
||||
*/
|
||||
private List<String> relateFileMetaIds = new ArrayList<>();
|
||||
// 取消关联文件应用ID
|
||||
/**
|
||||
* 取消关联文件应用ID(新增操作)
|
||||
*/
|
||||
private List<String> unRelateFileMetaIds = new ArrayList<>();
|
||||
/**
|
||||
* since v2.8.0
|
||||
* 复制用例过滤掉的原始附件ID
|
||||
*/
|
||||
private List<String> filterCopyFileMetaIds = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 创建新版本时 是否连带复制其他信息的配置类
|
||||
|
|
|
@ -57,6 +57,11 @@ public class IssuesUpdateRequest extends IssuesWithBLOBs {
|
|||
* 取消关联文件应用ID
|
||||
*/
|
||||
private List<String> unRelateFileMetaIds = new ArrayList<>();
|
||||
/**
|
||||
* since v2.8.0
|
||||
* 复制用例过滤掉的原始附件ID
|
||||
*/
|
||||
private List<String> filterCopyFileMetaIds = new ArrayList<>();
|
||||
|
||||
private List<String> batchDeleteIds;
|
||||
|
||||
|
|
|
@ -200,8 +200,6 @@ public class TestCaseController {
|
|||
if (StringUtils.isBlank(request.getId())) {
|
||||
//新增 后端生成 id
|
||||
request.setId(UUID.randomUUID().toString());
|
||||
} else {
|
||||
//复制,前端生成 id
|
||||
}
|
||||
return testCaseService.add(request, files);
|
||||
}
|
||||
|
|
|
@ -162,13 +162,20 @@ public class AttachmentService {
|
|||
attachmentModuleRelationMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void copyAttachment(AttachmentRequest request) {
|
||||
public void copyAttachment(AttachmentRequest request, List<String> filterIds) {
|
||||
List<AttachmentModuleRelation> needDealFiles = new ArrayList<>();
|
||||
AttachmentModuleRelationExample example = new AttachmentModuleRelationExample();
|
||||
example.createCriteria().andRelationIdEqualTo(request.getCopyBelongId()).andRelationTypeEqualTo(request.getBelongType());
|
||||
List<AttachmentModuleRelation> attachmentModuleRelations = attachmentModuleRelationMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(attachmentModuleRelations)) {
|
||||
if (CollectionUtils.isNotEmpty(filterIds)) {
|
||||
// 复制用例或缺陷时, 需过滤掉的附件
|
||||
needDealFiles = attachmentModuleRelations.stream().filter(relation -> !filterIds.contains(relation.getAttachmentId())).collect(Collectors.toList());
|
||||
} else {
|
||||
needDealFiles = attachmentModuleRelations;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(needDealFiles)) {
|
||||
// 本地附件
|
||||
List<String> localAttachments = attachmentModuleRelations.stream()
|
||||
List<String> localAttachments = needDealFiles.stream()
|
||||
.filter(relation -> StringUtils.isEmpty(relation.getFileMetadataRefId()))
|
||||
.map(AttachmentModuleRelation::getAttachmentId)
|
||||
.filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
||||
|
@ -181,7 +188,7 @@ public class AttachmentService {
|
|||
attachmentModuleRelationMapper.insert(record);
|
||||
});
|
||||
// 文件管理关联附件
|
||||
List<AttachmentModuleRelation> refAttachments = attachmentModuleRelations.stream()
|
||||
List<AttachmentModuleRelation> refAttachments = needDealFiles.stream()
|
||||
.filter(relation -> StringUtils.isNotEmpty(relation.getFileMetadataRefId())).collect(Collectors.toList());
|
||||
refAttachments.forEach(refAttachment -> {
|
||||
refAttachment.setRelationId(request.getBelongId());
|
||||
|
|
|
@ -176,14 +176,20 @@ public class IssuesService {
|
|||
// 用例与第三方缺陷平台中的缺陷关联
|
||||
handleTestCaseIssues(issuesRequest);
|
||||
|
||||
// 如果是复制新增, 同步MS附件到Jira
|
||||
// 如果是复制新增, 同步MS附件到Jira, 需过滤移除的附件
|
||||
if (StringUtils.isNotEmpty(issuesRequest.getCopyIssueId())) {
|
||||
AttachmentRequest attachmentRequest = new AttachmentRequest();
|
||||
attachmentRequest.setBelongId(issuesRequest.getCopyIssueId());
|
||||
attachmentRequest.setBelongType(AttachmentType.ISSUE.type());
|
||||
List<String> attachmentIds = attachmentService.getAttachmentIdsByParam(attachmentRequest);
|
||||
if (CollectionUtils.isNotEmpty(attachmentIds)) {
|
||||
for (String attachmentId : attachmentIds) {
|
||||
List<String> needDealAttachmentIds = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(issuesRequest.getFilterCopyFileMetaIds())) {
|
||||
needDealAttachmentIds = attachmentIds.stream().filter(attachmentId -> !issuesRequest.getFilterCopyFileMetaIds().contains(attachmentId)).collect(Collectors.toList());
|
||||
} else {
|
||||
needDealAttachmentIds = attachmentIds;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(needDealAttachmentIds)) {
|
||||
for (String attachmentId : needDealAttachmentIds) {
|
||||
FileAttachmentMetadata fileAttachmentMetadata = attachmentService.getFileAttachmentMetadataByFileId(attachmentId);
|
||||
File file = new File(fileAttachmentMetadata.getFilePath() + "/" + fileAttachmentMetadata.getName());
|
||||
attachmentService.syncIssuesAttachment(issues, file, AttachmentSyncType.UPLOAD);
|
||||
|
@ -213,74 +219,75 @@ public class IssuesService {
|
|||
attachmentRequest.setCopyBelongId(issuesRequest.getCopyIssueId());
|
||||
attachmentRequest.setBelongId(issues.getId());
|
||||
attachmentRequest.setBelongType(AttachmentType.ISSUE.type());
|
||||
attachmentService.copyAttachment(attachmentRequest);
|
||||
attachmentService.copyAttachment(attachmentRequest, issuesRequest.getFilterCopyFileMetaIds());
|
||||
|
||||
// MS附件同步到其他平台, Jira, Zentao已经在创建缺陷时处理, AzureDevops单独处理
|
||||
// MS附件同步到其他平台, Jira, Zentao已经在创建缺陷时处理, AzureDevops单独处理, 需过滤移除的附件
|
||||
if (StringUtils.equals(issuesRequest.getPlatform(), IssuesManagePlatform.AzureDevops.toString())) {
|
||||
AttachmentRequest request = new AttachmentRequest();
|
||||
request.setBelongId(issuesRequest.getCopyIssueId());
|
||||
request.setBelongType(AttachmentType.ISSUE.type());
|
||||
uploadAzureCopyAttachment(request, issuesRequest.getPlatform(), platformId);
|
||||
uploadAzureCopyAttachment(request, issuesRequest.getPlatform(), platformId, issuesRequest.getFilterCopyFileMetaIds());
|
||||
}
|
||||
} else {
|
||||
final String issueId = issues.getId();
|
||||
final String platform = issues.getPlatform();
|
||||
// 新增, 需保存并同步所有待上传的附件
|
||||
if (CollectionUtils.isNotEmpty(files)) {
|
||||
files.forEach(file -> {
|
||||
AttachmentRequest attachmentRequest = new AttachmentRequest();
|
||||
attachmentRequest.setBelongId(issueId);
|
||||
attachmentRequest.setBelongType(AttachmentType.ISSUE.type());
|
||||
attachmentService.uploadAttachment(attachmentRequest, file);
|
||||
});
|
||||
}
|
||||
// 处理待关联的文件附件, 生成关联记录, 并同步至第三方平台
|
||||
if (CollectionUtils.isNotEmpty(issuesRequest.getRelateFileMetaIds())) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
FileAssociationMapper associationBatchMapper = sqlSession.getMapper(FileAssociationMapper.class);
|
||||
AttachmentModuleRelationMapper attachmentModuleRelationBatchMapper = sqlSession.getMapper(AttachmentModuleRelationMapper.class);
|
||||
FileAttachmentMetadataMapper fileAttachmentMetadataBatchMapper = sqlSession.getMapper(FileAttachmentMetadataMapper.class);
|
||||
issuesRequest.getRelateFileMetaIds().forEach(filemetaId -> {
|
||||
FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(filemetaId);
|
||||
FileAssociation fileAssociation = new FileAssociation();
|
||||
fileAssociation.setId(UUID.randomUUID().toString());
|
||||
fileAssociation.setFileMetadataId(filemetaId);
|
||||
fileAssociation.setFileType(fileMetadata.getType());
|
||||
fileAssociation.setType(FileAssociationType.ISSUE.name());
|
||||
fileAssociation.setProjectId(fileMetadata.getProjectId());
|
||||
fileAssociation.setSourceItemId(filemetaId);
|
||||
fileAssociation.setSourceId(issueId);
|
||||
associationBatchMapper.insert(fileAssociation);
|
||||
AttachmentModuleRelation relation = new AttachmentModuleRelation();
|
||||
relation.setRelationId(issueId);
|
||||
relation.setRelationType(AttachmentType.ISSUE.type());
|
||||
relation.setFileMetadataRefId(fileAssociation.getId());
|
||||
relation.setAttachmentId(UUID.randomUUID().toString());
|
||||
attachmentModuleRelationBatchMapper.insert(relation);
|
||||
FileAttachmentMetadata fileAttachmentMetadata = new FileAttachmentMetadata();
|
||||
BeanUtils.copyBean(fileAttachmentMetadata, fileMetadata);
|
||||
fileAttachmentMetadata.setId(relation.getAttachmentId());
|
||||
fileAttachmentMetadata.setCreator(fileMetadata.getCreateUser() == null ? StringUtils.EMPTY : fileMetadata.getCreateUser());
|
||||
fileAttachmentMetadata.setFilePath(fileMetadata.getPath() == null ? StringUtils.EMPTY : fileMetadata.getPath());
|
||||
fileAttachmentMetadataBatchMapper.insert(fileAttachmentMetadata);
|
||||
// 下载文件管理文件, 同步到第三方平台
|
||||
File refFile = attachmentService.downloadMetadataFile(filemetaId, fileMetadata.getName());
|
||||
if (PlatformPluginService.isPluginPlatform(platform)) {
|
||||
issuesRequest.setPlatform(platform);
|
||||
attachmentService.syncIssuesAttachment(issuesRequest, refFile, AttachmentSyncType.UPLOAD);
|
||||
} else {
|
||||
IssuesRequest addIssueRequest = new IssuesRequest();
|
||||
addIssueRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
||||
addIssueRequest.setProjectId(SessionUtils.getCurrentProjectId());
|
||||
Objects.requireNonNull(IssueFactory.createPlatform(platform, addIssueRequest))
|
||||
.syncIssuesAttachment(issuesRequest, refFile, AttachmentSyncType.UPLOAD);
|
||||
}
|
||||
FileUtils.deleteFile(FileUtils.ATTACHMENT_TMP_DIR + File.separator + fileMetadata.getName());
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
|
||||
// 新增,复制; 需保存并同步所有待上传, 待关联的附件
|
||||
final String issueId = issues.getId();
|
||||
final String platform = issues.getPlatform();
|
||||
// upload file
|
||||
if (CollectionUtils.isNotEmpty(files)) {
|
||||
files.forEach(file -> {
|
||||
AttachmentRequest attachmentRequest = new AttachmentRequest();
|
||||
attachmentRequest.setBelongId(issueId);
|
||||
attachmentRequest.setBelongType(AttachmentType.ISSUE.type());
|
||||
attachmentService.uploadAttachment(attachmentRequest, file);
|
||||
});
|
||||
}
|
||||
// relate file
|
||||
if (CollectionUtils.isNotEmpty(issuesRequest.getRelateFileMetaIds())) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
FileAssociationMapper associationBatchMapper = sqlSession.getMapper(FileAssociationMapper.class);
|
||||
AttachmentModuleRelationMapper attachmentModuleRelationBatchMapper = sqlSession.getMapper(AttachmentModuleRelationMapper.class);
|
||||
FileAttachmentMetadataMapper fileAttachmentMetadataBatchMapper = sqlSession.getMapper(FileAttachmentMetadataMapper.class);
|
||||
issuesRequest.getRelateFileMetaIds().forEach(filemetaId -> {
|
||||
FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(filemetaId);
|
||||
FileAssociation fileAssociation = new FileAssociation();
|
||||
fileAssociation.setId(UUID.randomUUID().toString());
|
||||
fileAssociation.setFileMetadataId(filemetaId);
|
||||
fileAssociation.setFileType(fileMetadata.getType());
|
||||
fileAssociation.setType(FileAssociationType.ISSUE.name());
|
||||
fileAssociation.setProjectId(fileMetadata.getProjectId());
|
||||
fileAssociation.setSourceItemId(filemetaId);
|
||||
fileAssociation.setSourceId(issueId);
|
||||
associationBatchMapper.insert(fileAssociation);
|
||||
AttachmentModuleRelation relation = new AttachmentModuleRelation();
|
||||
relation.setRelationId(issueId);
|
||||
relation.setRelationType(AttachmentType.ISSUE.type());
|
||||
relation.setFileMetadataRefId(fileAssociation.getId());
|
||||
relation.setAttachmentId(UUID.randomUUID().toString());
|
||||
attachmentModuleRelationBatchMapper.insert(relation);
|
||||
FileAttachmentMetadata fileAttachmentMetadata = new FileAttachmentMetadata();
|
||||
BeanUtils.copyBean(fileAttachmentMetadata, fileMetadata);
|
||||
fileAttachmentMetadata.setId(relation.getAttachmentId());
|
||||
fileAttachmentMetadata.setCreator(fileMetadata.getCreateUser() == null ? StringUtils.EMPTY : fileMetadata.getCreateUser());
|
||||
fileAttachmentMetadata.setFilePath(fileMetadata.getPath() == null ? StringUtils.EMPTY : fileMetadata.getPath());
|
||||
fileAttachmentMetadataBatchMapper.insert(fileAttachmentMetadata);
|
||||
// 下载文件管理文件, 同步到第三方平台
|
||||
File refFile = attachmentService.downloadMetadataFile(filemetaId, fileMetadata.getName());
|
||||
if (PlatformPluginService.isPluginPlatform(platform)) {
|
||||
issuesRequest.setPlatform(platform);
|
||||
attachmentService.syncIssuesAttachment(issuesRequest, refFile, AttachmentSyncType.UPLOAD);
|
||||
} else {
|
||||
IssuesRequest addIssueRequest = new IssuesRequest();
|
||||
addIssueRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
||||
addIssueRequest.setProjectId(SessionUtils.getCurrentProjectId());
|
||||
Objects.requireNonNull(IssueFactory.createPlatform(platform, addIssueRequest))
|
||||
.syncIssuesAttachment(issuesRequest, refFile, AttachmentSyncType.UPLOAD);
|
||||
}
|
||||
FileUtils.deleteFile(FileUtils.ATTACHMENT_TMP_DIR + File.separator + fileMetadata.getName());
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
return getIssue(issues.getId());
|
||||
|
@ -1768,10 +1775,16 @@ public class IssuesService {
|
|||
return filterIssues;
|
||||
}
|
||||
|
||||
private void uploadAzureCopyAttachment(AttachmentRequest attachmentRequest, String platform, String platformId) {
|
||||
private void uploadAzureCopyAttachment(AttachmentRequest attachmentRequest, String platform, String platformId, List filterIds) {
|
||||
List<String> attachmentIds = attachmentService.getAttachmentIdsByParam(attachmentRequest);
|
||||
if (CollectionUtils.isNotEmpty(attachmentIds)) {
|
||||
attachmentIds.forEach(attachmentId -> {
|
||||
List<String> needDealAttachmentIds = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(filterIds)) {
|
||||
needDealAttachmentIds = attachmentIds.stream().filter(attachmentId -> !filterIds.contains(attachmentId)).collect(Collectors.toList());
|
||||
} else {
|
||||
needDealAttachmentIds = attachmentIds;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(needDealAttachmentIds)) {
|
||||
needDealAttachmentIds.forEach(attachmentId -> {
|
||||
FileAttachmentMetadata fileAttachmentMetadata = attachmentService.getFileAttachmentMetadataByFileId(attachmentId);
|
||||
File file = new File(fileAttachmentMetadata.getFilePath() + "/" + fileAttachmentMetadata.getName());
|
||||
IssuesRequest createRequest = new IssuesRequest();
|
||||
|
|
|
@ -570,7 +570,7 @@ public class TestCaseService {
|
|||
attachmentRequest.setBelongId(testCase.getId());
|
||||
attachmentRequest.setCopyBelongId(oldTestCaseId);
|
||||
attachmentRequest.setBelongType(AttachmentType.TEST_CASE.type());
|
||||
attachmentService.copyAttachment(attachmentRequest);
|
||||
attachmentService.copyAttachment(attachmentRequest, null);
|
||||
}
|
||||
if (otherInfoConfig.isDependency()) {
|
||||
List<RelationshipEdge> preRelations = relationshipEdgeService.getRelationshipEdgeByType(oldTestCaseId, "PRE");
|
||||
|
@ -2202,51 +2202,51 @@ public class TestCaseService {
|
|||
attachmentRequest.setCopyBelongId(request.getCopyCaseId());
|
||||
attachmentRequest.setBelongId(testCaseWithBLOBs.getId());
|
||||
attachmentRequest.setBelongType(AttachmentType.TEST_CASE.type());
|
||||
attachmentService.copyAttachment(attachmentRequest);
|
||||
} else {
|
||||
// 新增需上传用例所有待上传的附件
|
||||
if (CollectionUtils.isNotEmpty(files)) {
|
||||
files.forEach(file -> {
|
||||
AttachmentRequest attachmentRequest = new AttachmentRequest();
|
||||
attachmentRequest.setBelongId(testCaseWithBLOBs.getId());
|
||||
attachmentRequest.setBelongType(AttachmentType.TEST_CASE.type());
|
||||
attachmentService.uploadAttachment(attachmentRequest, file);
|
||||
});
|
||||
}
|
||||
// 同步待关联的文件附件, 生成关联记录
|
||||
if (CollectionUtils.isNotEmpty(request.getRelateFileMetaIds())) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
FileAssociationMapper associationBatchMapper = sqlSession.getMapper(FileAssociationMapper.class);
|
||||
AttachmentModuleRelationMapper attachmentModuleRelationBatchMapper = sqlSession.getMapper(AttachmentModuleRelationMapper.class);
|
||||
FileAttachmentMetadataMapper fileAttachmentMetadataBatchMapper = sqlSession.getMapper(FileAttachmentMetadataMapper.class);
|
||||
request.getRelateFileMetaIds().forEach(filemetaId -> {
|
||||
FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(filemetaId);
|
||||
FileAssociation fileAssociation = new FileAssociation();
|
||||
fileAssociation.setId(UUID.randomUUID().toString());
|
||||
fileAssociation.setFileMetadataId(filemetaId);
|
||||
fileAssociation.setFileType(fileMetadata.getType());
|
||||
fileAssociation.setType(FileAssociationType.TEST_CASE.name());
|
||||
fileAssociation.setProjectId(fileMetadata.getProjectId());
|
||||
fileAssociation.setSourceItemId(filemetaId);
|
||||
fileAssociation.setSourceId(testCaseWithBLOBs.getId());
|
||||
associationBatchMapper.insert(fileAssociation);
|
||||
AttachmentModuleRelation record = new AttachmentModuleRelation();
|
||||
record.setRelationId(testCaseWithBLOBs.getId());
|
||||
record.setRelationType(AttachmentType.TEST_CASE.type());
|
||||
record.setFileMetadataRefId(fileAssociation.getId());
|
||||
record.setAttachmentId(UUID.randomUUID().toString());
|
||||
attachmentModuleRelationBatchMapper.insert(record);
|
||||
FileAttachmentMetadata fileAttachmentMetadata = new FileAttachmentMetadata();
|
||||
BeanUtils.copyBean(fileAttachmentMetadata, fileMetadata);
|
||||
fileAttachmentMetadata.setId(record.getAttachmentId());
|
||||
fileAttachmentMetadata.setCreator(SessionUtils.getUserId());
|
||||
fileAttachmentMetadata.setFilePath(fileMetadata.getPath() == null ? StringUtils.EMPTY : fileMetadata.getPath());
|
||||
fileAttachmentMetadataBatchMapper.insert(fileAttachmentMetadata);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
attachmentService.copyAttachment(attachmentRequest, request.getFilterCopyFileMetaIds());
|
||||
}
|
||||
// 新增及复制都需处理用例所有待上传和待关联的附件
|
||||
// upload file
|
||||
if (CollectionUtils.isNotEmpty(files)) {
|
||||
files.forEach(file -> {
|
||||
AttachmentRequest attachmentRequest = new AttachmentRequest();
|
||||
attachmentRequest.setBelongId(testCaseWithBLOBs.getId());
|
||||
attachmentRequest.setBelongType(AttachmentType.TEST_CASE.type());
|
||||
attachmentService.uploadAttachment(attachmentRequest, file);
|
||||
});
|
||||
}
|
||||
// relate file
|
||||
if (CollectionUtils.isNotEmpty(request.getRelateFileMetaIds())) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
FileAssociationMapper associationBatchMapper = sqlSession.getMapper(FileAssociationMapper.class);
|
||||
AttachmentModuleRelationMapper attachmentModuleRelationBatchMapper = sqlSession.getMapper(AttachmentModuleRelationMapper.class);
|
||||
FileAttachmentMetadataMapper fileAttachmentMetadataBatchMapper = sqlSession.getMapper(FileAttachmentMetadataMapper.class);
|
||||
request.getRelateFileMetaIds().forEach(filemetaId -> {
|
||||
FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(filemetaId);
|
||||
FileAssociation fileAssociation = new FileAssociation();
|
||||
fileAssociation.setId(UUID.randomUUID().toString());
|
||||
fileAssociation.setFileMetadataId(filemetaId);
|
||||
fileAssociation.setFileType(fileMetadata.getType());
|
||||
fileAssociation.setType(FileAssociationType.TEST_CASE.name());
|
||||
fileAssociation.setProjectId(fileMetadata.getProjectId());
|
||||
fileAssociation.setSourceItemId(filemetaId);
|
||||
fileAssociation.setSourceId(testCaseWithBLOBs.getId());
|
||||
associationBatchMapper.insert(fileAssociation);
|
||||
AttachmentModuleRelation record = new AttachmentModuleRelation();
|
||||
record.setRelationId(testCaseWithBLOBs.getId());
|
||||
record.setRelationType(AttachmentType.TEST_CASE.type());
|
||||
record.setFileMetadataRefId(fileAssociation.getId());
|
||||
record.setAttachmentId(UUID.randomUUID().toString());
|
||||
attachmentModuleRelationBatchMapper.insert(record);
|
||||
FileAttachmentMetadata fileAttachmentMetadata = new FileAttachmentMetadata();
|
||||
BeanUtils.copyBean(fileAttachmentMetadata, fileMetadata);
|
||||
fileAttachmentMetadata.setId(record.getAttachmentId());
|
||||
fileAttachmentMetadata.setCreator(SessionUtils.getUserId());
|
||||
fileAttachmentMetadata.setFilePath(fileMetadata.getPath() == null ? StringUtils.EMPTY : fileMetadata.getPath());
|
||||
fileAttachmentMetadataBatchMapper.insert(fileAttachmentMetadata);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
return testCaseWithBLOBs;
|
||||
|
|
|
@ -64,15 +64,15 @@
|
|||
<el-button @click="handleDownload(scope.row)" type="primary" :disabled="!scope.row.id || scope.row.status === 'toRelate' || scope.row.isRelatedDeleted"
|
||||
v-if="scope.row.progress === 100"
|
||||
icon="el-icon-download" size="mini" circle/>
|
||||
<el-button :disabled="isCopy || !scope.row.id"
|
||||
<el-button :disabled="!scope.row.id"
|
||||
@click="handleUpload(scope.row)" type="primary"
|
||||
v-if="scope.row.progress === 100 && scope.row.isLocal"
|
||||
v-if="scope.row.progress === 100 && scope.row.isLocal && !isCopy"
|
||||
icon="el-icon-upload" size="mini" circle/>
|
||||
<el-button :disabled="readOnly || !isDelete || isCopy || (!scope.row.id && scope.row.status !== 'toUpload')"
|
||||
<el-button :disabled="readOnly || !isDelete || (!scope.row.id && scope.row.status !== 'toUpload')"
|
||||
@click="handleDelete(scope.row, scope.$index)" type="danger"
|
||||
v-if="scope.row.progress === 100 && scope.row.isLocal"
|
||||
icon="el-icon-delete" size="mini" circle/>
|
||||
<el-button :disabled="readOnly || !isDelete || isCopy || (!scope.row.id && scope.row.status !== 'toRelate')"
|
||||
<el-button :disabled="readOnly || !isDelete || (!scope.row.id && scope.row.status !== 'toRelate')"
|
||||
@click="handleUnRelate(scope.row, scope.$index)" type="danger"
|
||||
v-if="scope.row.progress === 100 && !scope.row.isLocal"
|
||||
icon="el-icon-unlock" size="mini"
|
||||
|
|
|
@ -221,7 +221,7 @@
|
|||
:copy-case-id="caseId"
|
||||
:label-width="formLabelWidth"
|
||||
:case-id="caseId"
|
||||
:type="type"
|
||||
:type="!caseId ? 'add' : 'edit'"
|
||||
:comments.sync="comments"
|
||||
@openComment="openComment"
|
||||
@getComments="getComments"
|
||||
|
@ -1299,6 +1299,9 @@ export default {
|
|||
if (this.$refs.otherInfo.getUnRelateFiles() && this.$refs.otherInfo.getUnRelateFiles().length > 0) {
|
||||
param.unRelateFileMetaIds = this.$refs.otherInfo.getUnRelateFiles();
|
||||
}
|
||||
if (this.$refs.otherInfo.getFilterCopyFiles() && this.$refs.otherInfo.getFilterCopyFiles().length > 0) {
|
||||
param.filterCopyFileMetaIds = this.$refs.otherInfo.getFilterCopyFiles();
|
||||
}
|
||||
}
|
||||
if (this.createVersionId) {
|
||||
param.versionId = this.createVersionId;
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
:on-exceed="handleExceed"
|
||||
:on-success="handleSuccess"
|
||||
:on-error="handleError"
|
||||
:disabled="readOnly || isCopy"
|
||||
:disabled="readOnly"
|
||||
>
|
||||
<div class="icon" style="display: inline-flex; line-height: 34px" @click="uploadLocalFile">
|
||||
<div style="margin-right: 10px">
|
||||
|
@ -47,7 +47,7 @@
|
|||
</div>
|
||||
<el-button
|
||||
size="small"
|
||||
:disabled="readOnly || isCopy"
|
||||
:disabled="readOnly"
|
||||
type="text"
|
||||
>{{ $t("permission.project_file.local_upload") }}</el-button
|
||||
>
|
||||
|
@ -78,7 +78,7 @@
|
|||
>
|
||||
<el-button
|
||||
type="text"
|
||||
:disabled="readOnly || isCopy"
|
||||
:disabled="readOnly"
|
||||
size="small"
|
||||
@click="associationFile"
|
||||
>{{ $t("permission.project_file.associated_files") }}</el-button
|
||||
|
@ -163,6 +163,7 @@ export default {
|
|||
uploadFiles: [],
|
||||
relateFiles: [],
|
||||
unRelateFiles: [],
|
||||
filterCopyFiles: [],
|
||||
dumpFile: {},
|
||||
result: {},
|
||||
};
|
||||
|
@ -188,7 +189,7 @@ export default {
|
|||
},
|
||||
associationFile() {
|
||||
this.$refs['popover'].doClose();
|
||||
if (this.readOnly || this.isCopy) {
|
||||
if (this.readOnly) {
|
||||
return;
|
||||
}
|
||||
//唤起关联文件
|
||||
|
@ -329,15 +330,31 @@ export default {
|
|||
}
|
||||
this.fileList.splice(index, 1);
|
||||
this.tableData.splice(index, 1);
|
||||
if (this.type === "add") {
|
||||
this.uploadFiles.splice(index, 1);
|
||||
if (file.status === 'toUpload') {
|
||||
// 带上传的附件直接移除
|
||||
let uploadIndex = this.findUploadFileIndex(file);
|
||||
this.uploadFiles.splice(uploadIndex, 1);
|
||||
} else {
|
||||
deleteTestCaseAttachment(file.id).then(() => {
|
||||
this.$success(this.$t("commons.delete_success"), false);
|
||||
this.getFileMetaData();
|
||||
});
|
||||
if (this.isCopy) {
|
||||
//复制过来的附件需在后台过滤
|
||||
this.filterCopyFiles.push(file.id);
|
||||
} else {
|
||||
// 编辑, 直接删除
|
||||
deleteTestCaseAttachment(file.id).then(() => {
|
||||
this.$success(this.$t("commons.delete_success"), false);
|
||||
this.getFileMetaData();
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
findUploadFileIndex(targetFile) {
|
||||
for (let i = 0; i < this.uploadFiles.length; i++) {
|
||||
if (this.uploadFiles[i].name === targetFile.name) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
handleUnRelate(file, index) {
|
||||
// 取消关联
|
||||
this.$alert(
|
||||
|
@ -349,30 +366,31 @@ export default {
|
|||
callback: (action) => {
|
||||
if (action === "confirm") {
|
||||
this.result.loading = true;
|
||||
let unRelateFileIndex = this.tableData.findIndex(
|
||||
(f) => f.name === file.name
|
||||
);
|
||||
let unRelateFileIndex = this.tableData.findIndex((f) => f.name === file.name);
|
||||
this.tableData.splice(unRelateFileIndex, 1);
|
||||
if (file.status === "toRelate") {
|
||||
// 待关联的记录, 直接移除
|
||||
let unRelateId = this.relateFiles.findIndex(
|
||||
(f) => f === file.id
|
||||
);
|
||||
let unRelateId = this.relateFiles.findIndex((f) => f === file.id);
|
||||
this.relateFiles.splice(unRelateId, 1);
|
||||
this.result.loading = false;
|
||||
} else {
|
||||
// 已经关联的记录
|
||||
this.unRelateFiles.push(file.id);
|
||||
let data = {
|
||||
belongType: this.belongType,
|
||||
belongId: this.targetId,
|
||||
metadataRefIds: this.unRelateFiles,
|
||||
};
|
||||
unrelatedAttachment(data).then(() => {
|
||||
this.$success(this.$t("commons.unrelated_success"), false);
|
||||
this.result.loading = false;
|
||||
this.getFileMetaData(this.issueId);
|
||||
});
|
||||
if (this.isCopy) {
|
||||
// 复制过来的记录, 后台过滤
|
||||
this.filterCopyFiles.push(file.id)
|
||||
} else {
|
||||
// 已经关联的记录
|
||||
this.unRelateFiles.push(file.id);
|
||||
let data = {
|
||||
belongType: this.belongType,
|
||||
belongId: this.targetId,
|
||||
metadataRefIds: this.unRelateFiles,
|
||||
};
|
||||
unrelatedAttachment(data).then(() => {
|
||||
this.$success(this.$t("commons.unrelated_success"), false);
|
||||
this.result.loading = false;
|
||||
this.getFileMetaData(this.issueId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -175,7 +175,7 @@ export default {
|
|||
!(
|
||||
this.readOnly ||
|
||||
!this.isDelete ||
|
||||
this.isCopy ||
|
||||
// this.isCopy ||
|
||||
(!this.fileItem.id && !this.isToRelate)
|
||||
) &&
|
||||
this.isComplete &&
|
||||
|
@ -190,7 +190,7 @@ export default {
|
|||
!(
|
||||
this.readOnly ||
|
||||
// !this.isDelete ||
|
||||
this.isCopy ||
|
||||
// this.isCopy ||
|
||||
(!this.fileItem.id && !this.isToUpload)
|
||||
) &&
|
||||
this.isComplete &&
|
||||
|
|
|
@ -292,6 +292,13 @@ export default {
|
|||
return [];
|
||||
}
|
||||
},
|
||||
getFilterCopyFiles() {
|
||||
if (this.$refs.attachmentComp) {
|
||||
return this.$refs.attachmentComp.filterCopyFiles;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
textBlur(options, refName) {
|
||||
if (!this.editable && options.autoSave) {
|
||||
options.editFactor = false;
|
||||
|
|
|
@ -283,6 +283,11 @@ export default {
|
|||
return this.$refs.testCaseBaseInfo.getUnRelateFiles();
|
||||
}
|
||||
},
|
||||
getFilterCopyFiles() {
|
||||
if (this.$refs.testCaseBaseInfo) {
|
||||
return this.$refs.testCaseBaseInfo.getFilterCopyFiles();
|
||||
}
|
||||
},
|
||||
getFileMetaData(id) {
|
||||
if (!this.$refs.testCaseBaseInfo) {
|
||||
return;
|
||||
|
|
|
@ -108,13 +108,13 @@
|
|||
:on-exceed="handleExceed"
|
||||
:on-success="handleSuccess"
|
||||
:on-error="handleError"
|
||||
:disabled="readOnly || type === 'copy'">
|
||||
<el-button :disabled="readOnly || type === 'copy'" type="text">
|
||||
:disabled="readOnly">
|
||||
<el-button :disabled="readOnly" type="text">
|
||||
{{ $t('permission.project_file.local_upload') }}
|
||||
</el-button>
|
||||
</el-upload>
|
||||
</div>
|
||||
<el-button type="text" :disabled="readOnly || type === 'copy'" @click="associationFile">
|
||||
<el-button type="text" :disabled="readOnly" @click="associationFile">
|
||||
{{ $t('permission.project_file.associated_files') }}
|
||||
</el-button>
|
||||
<i class="el-icon-plus" slot="reference"/>
|
||||
|
@ -325,6 +325,7 @@ export default {
|
|||
uploadFiles: [],
|
||||
relateFiles: [],
|
||||
unRelateFiles: [],
|
||||
filterCopyFiles: [],
|
||||
dumpFile: {},
|
||||
enableThirdPartTemplate: false
|
||||
};
|
||||
|
@ -567,6 +568,9 @@ export default {
|
|||
if (this.relateFiles.length > 0) {
|
||||
param.relateFileMetaIds = this.relateFiles;
|
||||
}
|
||||
if (this.filterCopyFiles.length > 0) {
|
||||
param.filterCopyFileMetaIds = this.filterCopyFiles;
|
||||
}
|
||||
return param;
|
||||
},
|
||||
_save() {
|
||||
|
@ -671,14 +675,14 @@ export default {
|
|||
name: file.name,
|
||||
size: byteToSize(file.size),
|
||||
updateTime: new Date().getTime(),
|
||||
progress: this.type === 'add' || this.isCaseEdit ? 100 : 0,
|
||||
status: this.type === 'add' || this.isCaseEdit ? 'toUpload' : 0,
|
||||
progress: this.type === 'add' || this.isCaseEdit || this.type === 'copy' ? 100 : 0,
|
||||
status: this.type === 'add' || this.isCaseEdit || this.type === 'copy'? 'toUpload' : 0,
|
||||
creator: user.name,
|
||||
type: getTypeByFileName(file.name),
|
||||
isLocal: true
|
||||
});
|
||||
|
||||
if (this.type === 'add' || this.isCaseEdit) {
|
||||
if (this.type === 'add' || this.isCaseEdit || this.type === 'copy') {
|
||||
// 新增上传
|
||||
this.uploadFiles.push(file);
|
||||
return false;
|
||||
|
@ -770,15 +774,19 @@ export default {
|
|||
}
|
||||
this.fileList.splice(index, 1);
|
||||
this.tableData.splice(index, 1);
|
||||
if (this.type === 'add' || this.isCaseEdit) {
|
||||
if (file.status === 'toUpload') {
|
||||
let delIndex = this.uploadFiles.findIndex(uploadFile => uploadFile.name === file.name)
|
||||
this.uploadFiles.splice(delIndex, 1);
|
||||
} else {
|
||||
deleteIssueAttachment(file.id)
|
||||
.then(() => {
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
this.getFileMetaData(this.issueId);
|
||||
});
|
||||
if (this.type === 'copy') {
|
||||
this.filterCopyFiles.push(file.id);
|
||||
} else {
|
||||
deleteIssueAttachment(file.id)
|
||||
.then(() => {
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
this.getFileMetaData(this.issueId);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
handleUnRelate(file, index) {
|
||||
|
@ -795,16 +803,20 @@ export default {
|
|||
let unRelateId = this.relateFiles.findIndex(f => f === file.id);
|
||||
this.relateFiles.splice(unRelateId, 1);
|
||||
} else {
|
||||
// 已经关联的记录
|
||||
this.unRelateFiles.push(file.id);
|
||||
let data = {'belongType': 'issue', 'belongId': this.issueId, 'metadataRefIds': this.unRelateFiles};
|
||||
this.result.loading = true;
|
||||
unrelatedAttachment(data)
|
||||
.then(() => {
|
||||
this.$success(this.$t('commons.unrelated_success'));
|
||||
this.result.loading = false;
|
||||
this.getFileMetaData(this.issueId);
|
||||
})
|
||||
if (this.type === 'copy') {
|
||||
this.filterCopyFiles.push(file.id);
|
||||
} else {
|
||||
// 已经关联的记录
|
||||
this.unRelateFiles.push(file.id);
|
||||
let data = {'belongType': 'issue', 'belongId': this.issueId, 'metadataRefIds': this.unRelateFiles};
|
||||
this.result.loading = true;
|
||||
unrelatedAttachment(data)
|
||||
.then(() => {
|
||||
this.$success(this.$t('commons.unrelated_success'));
|
||||
this.result.loading = false;
|
||||
this.getFileMetaData(this.issueId);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -836,7 +848,7 @@ export default {
|
|||
}
|
||||
}
|
||||
if (!repeatRecord) {
|
||||
if (this.type === 'add' || this.isCaseEdit) {
|
||||
if (this.type === 'add' || this.isCaseEdit || this.type === 'copy') {
|
||||
// 新增
|
||||
rows.forEach(row => {
|
||||
this.relateFiles.push(row.id);
|
||||
|
|
Loading…
Reference in New Issue