revert(接口定义): 回退服务器同步删除文件 (#17751)
Co-authored-by: wxg0103 <727495428@qq.com>
This commit is contained in:
parent
f6e5d0a8ed
commit
c95204c94b
|
@ -427,13 +427,6 @@ public class ApiAutomationService {
|
||||||
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务
|
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务
|
||||||
uploadFiles(request, bodyFiles, scenarioFiles);
|
uploadFiles(request, bodyFiles, scenarioFiles);
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(request.getScenarioDefinition().getHashTree())) {
|
|
||||||
request.getScenarioDefinition().getHashTree().stream().forEach(hashTree -> {
|
|
||||||
//删除不需要的文件
|
|
||||||
FileUtils.deleteBodyFiles(hashTree);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 存储依赖关系
|
// 存储依赖关系
|
||||||
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
|
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
|
||||||
if (relationshipEdgeService != null) {
|
if (relationshipEdgeService != null) {
|
||||||
|
|
|
@ -421,9 +421,6 @@ public class ApiDefinitionService {
|
||||||
mockConfigService.updateMockReturnMsgByApi(returnModel);
|
mockConfigService.updateMockReturnMsgByApi(returnModel);
|
||||||
FileUtils.createBodyFiles(request.getRequest().getId(), bodyFiles);
|
FileUtils.createBodyFiles(request.getRequest().getId(), bodyFiles);
|
||||||
|
|
||||||
//删除不需要的文件
|
|
||||||
FileUtils.deleteBodyFiles(request.getRequest());
|
|
||||||
|
|
||||||
String context = SessionUtils.getUserId().concat(Translator.get("update_api")).concat(":").concat(returnModel.getName());
|
String context = SessionUtils.getUserId().concat(Translator.get("update_api")).concat(":").concat(returnModel.getName());
|
||||||
Map<String, Object> paramMap = new HashMap<>();
|
Map<String, Object> paramMap = new HashMap<>();
|
||||||
getParamMap(paramMap, returnModel.getProjectId(), SessionUtils.getUserId(), returnModel.getId(), returnModel.getName(), returnModel.getCreateUser());
|
getParamMap(paramMap, returnModel.getProjectId(), SessionUtils.getUserId(), returnModel.getId(), returnModel.getName(), returnModel.getCreateUser());
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
package io.metersphere.commons.utils;
|
package io.metersphere.commons.utils;
|
||||||
|
|
||||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
|
||||||
import io.metersphere.api.dto.scenario.Body;
|
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
|
||||||
import io.metersphere.api.dto.scenario.request.BodyFile;
|
import io.metersphere.api.dto.scenario.request.BodyFile;
|
||||||
import io.metersphere.base.domain.FileMetadata;
|
import io.metersphere.base.domain.FileMetadata;
|
||||||
import io.metersphere.base.domain.JarConfig;
|
import io.metersphere.base.domain.JarConfig;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.i18n.Translator;
|
import io.metersphere.i18n.Translator;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
|
||||||
import io.metersphere.service.JarConfigService;
|
import io.metersphere.service.JarConfigService;
|
||||||
import io.metersphere.utils.LoggerUtil;
|
import io.metersphere.utils.LoggerUtil;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
@ -24,7 +20,6 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
@ -128,44 +123,7 @@ public class FileUtils {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteBodyFiles(MsTestElement request) {
|
|
||||||
if (request != null && StringUtils.isNotBlank(request.getId())) {
|
|
||||||
String path = BODY_FILE_DIR + File.separator + request.getId();
|
|
||||||
File testDir = new File(path);
|
|
||||||
if (!testDir.exists()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<String> files = new ArrayList<>();
|
|
||||||
if (request != null && StringUtils.equalsIgnoreCase(request.getType(), HTTPSamplerProxy.class.getSimpleName())) {
|
|
||||||
MsHTTPSamplerProxy samplerProxy = (MsHTTPSamplerProxy) request;
|
|
||||||
Body body = samplerProxy.getBody();
|
|
||||||
if (body != null && !CollectionUtils.isEmpty(body.getKvs())) {
|
|
||||||
body.getKvs().stream().filter(KeyValue::isFile).forEach(keyValue -> {
|
|
||||||
files.addAll(keyValue.getFiles().stream().map(BodyFile::getName).collect(Collectors.toList()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (body != null && !CollectionUtils.isEmpty(body.getBinary())) {
|
|
||||||
body.getBinary().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> {
|
|
||||||
files.addAll(keyValue.getFiles().stream().map(BodyFile::getName).collect(Collectors.toList()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File[] optFilesName = testDir.listFiles();
|
|
||||||
if (CollectionUtils.isNotEmpty(files)) {
|
|
||||||
for (File f : optFilesName) {
|
|
||||||
if (!files.contains(f.getName())) {
|
|
||||||
f.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
FileUtil.deleteContents(testDir);
|
|
||||||
testDir.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void copyBodyFiles(String sourceId, String targetId) {
|
public static void copyBodyFiles(String sourceId, String targetId) {
|
||||||
try {
|
try {
|
||||||
String sourcePath = BODY_FILE_DIR + File.separator + sourceId;
|
String sourcePath = BODY_FILE_DIR + File.separator + sourceId;
|
||||||
|
|
Loading…
Reference in New Issue