parent
c74b5806a2
commit
4f08b44e33
|
@ -204,6 +204,7 @@ public class ApiFileUtil extends FileUtils {
|
||||||
attachmentBodyFile.setFileUpdateTime(fileMetadata.getUpdateTime());
|
attachmentBodyFile.setFileUpdateTime(fileMetadata.getUpdateTime());
|
||||||
attachmentBodyFile.setProjectId(fileMetadata.getProjectId());
|
attachmentBodyFile.setProjectId(fileMetadata.getProjectId());
|
||||||
attachmentBodyFile.setFilePath(path);
|
attachmentBodyFile.setFilePath(path);
|
||||||
|
attachmentBodyFile.setFileType(fileMetadata.getType());
|
||||||
if (StringUtils.isNotBlank(fileMetadata.getAttachInfo())) {
|
if (StringUtils.isNotBlank(fileMetadata.getAttachInfo())) {
|
||||||
attachmentBodyFile.setFileAttachInfoJson(fileMetadata.getAttachInfo());
|
attachmentBodyFile.setFileAttachInfoJson(fileMetadata.getAttachInfo());
|
||||||
}
|
}
|
||||||
|
@ -212,10 +213,11 @@ public class ApiFileUtil extends FileUtils {
|
||||||
if (!isLocal) {
|
if (!isLocal) {
|
||||||
testElement.setProperty(JmxFileMetadataColumns.REF_FILE_STORAGE.name(), fileMetadata.getStorage());
|
testElement.setProperty(JmxFileMetadataColumns.REF_FILE_STORAGE.name(), fileMetadata.getStorage());
|
||||||
testElement.setProperty(JmxFileMetadataColumns.REF_FILE_NAME.name(), fileMetadata.getName());
|
testElement.setProperty(JmxFileMetadataColumns.REF_FILE_NAME.name(), fileMetadata.getName());
|
||||||
|
testElement.setProperty(JmxFileMetadataColumns.REF_FILE_TYPE.name(), fileMetadata.getType());
|
||||||
testElement.setProperty(JmxFileMetadataColumns.REF_FILE_UPDATE_TIME.name(), fileMetadata.getUpdateTime());
|
testElement.setProperty(JmxFileMetadataColumns.REF_FILE_UPDATE_TIME.name(), fileMetadata.getUpdateTime());
|
||||||
testElement.setProperty(JmxFileMetadataColumns.REF_FILE_PROJECT_ID.name(), fileMetadata.getProjectId());
|
testElement.setProperty(JmxFileMetadataColumns.REF_FILE_PROJECT_ID.name(), fileMetadata.getProjectId());
|
||||||
} else {
|
} else {
|
||||||
path = temporaryFileUtil.generateFilePath(attachmentBodyFile.getProjectId(), attachmentBodyFile.getFileMetadataId(), attachmentBodyFile.getFileUpdateTime(), attachmentBodyFile.getName());
|
path = temporaryFileUtil.generateFilePath(attachmentBodyFile.getProjectId(), attachmentBodyFile.getFileMetadataId(), attachmentBodyFile.getFileUpdateTime(), attachmentBodyFile.getName(), attachmentBodyFile.getFileType());
|
||||||
}
|
}
|
||||||
|
|
||||||
testElement.setProperty(ElementConstants.FILENAME, path);
|
testElement.setProperty(ElementConstants.FILENAME, path);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import lombok.Setter;
|
||||||
public class AttachmentBodyFile {
|
public class AttachmentBodyFile {
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
|
private String fileType;
|
||||||
// 调试附件处理
|
// 调试附件处理
|
||||||
private String refResourceId;
|
private String refResourceId;
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,6 @@ public enum JmxFileMetadataColumns {
|
||||||
REF_FILE_UPDATE_TIME,
|
REF_FILE_UPDATE_TIME,
|
||||||
REF_FILE_PROJECT_ID,
|
REF_FILE_PROJECT_ID,
|
||||||
REF_FILE_NAME,
|
REF_FILE_NAME,
|
||||||
|
REF_FILE_TYPE,
|
||||||
JAR_PATH_CONFIG,
|
JAR_PATH_CONFIG,
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,16 @@ public class TemporaryFileUtil {
|
||||||
return fileFolder + generateRelativeDir(folder, fileMetadataId, updateTime);
|
return fileFolder + generateRelativeDir(folder, fileMetadataId, updateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateFilePath(String folder, String fileMetadataId, long updateTime, String fileName) {
|
private String getFileName(String fileName, String fileSuffix) {
|
||||||
return generateFileDir(folder, fileMetadataId, updateTime) + fileName;
|
if (StringUtils.endsWithIgnoreCase(fileName, "." + fileSuffix)) {
|
||||||
|
return fileName;
|
||||||
|
} else {
|
||||||
|
return StringUtils.join(fileName, ".", fileSuffix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String generateFilePath(String folder, String fileMetadataId, long updateTime, String fileName, String fileSuffix) {
|
||||||
|
return generateFileDir(folder, fileMetadataId, updateTime) + getFileName(fileName, fileSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateLocalFilePath(String filePath) {
|
public String generateLocalFilePath(String filePath) {
|
||||||
|
@ -63,8 +71,8 @@ public class TemporaryFileUtil {
|
||||||
return file.exists() ? file : null;
|
return file.exists() ? file : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile(String folder, String fileMetadataId, long updateTime, String fileName) {
|
public File getFile(String folder, String fileMetadataId, long updateTime, String fileName, String fileSuffix) {
|
||||||
File file = new File(generateFilePath(folder, fileMetadataId, updateTime, fileName));
|
File file = new File(generateFilePath(folder, fileMetadataId, updateTime, fileName, fileSuffix));
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return file;
|
return file;
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,18 +80,18 @@ public class TemporaryFileUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveFile(String folder, String fileMetadataId, long updateTime, String fileName, byte[] fileBytes) {
|
public void saveFile(String folder, String fileMetadataId, long updateTime, String fileName, String fileSuffix, byte[] fileBytes) {
|
||||||
//删除过期文件
|
//删除过期文件
|
||||||
deleteOldFile(folder, fileMetadataId, updateTime, fileName);
|
deleteOldFile(folder, fileMetadataId, updateTime, fileName);
|
||||||
this.createFile(generateFilePath(folder, fileMetadataId, updateTime, fileName), fileBytes);
|
this.createFile(generateFilePath(folder, fileMetadataId, updateTime, fileName, fileSuffix), fileBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveFileByParamCheck(String folder, String fileMetadataId, long updateTime, String fileName, byte[] fileBytes) {
|
public void saveFileByParamCheck(String folder, String fileMetadataId, long updateTime, String fileName, String fileSuffix, byte[] fileBytes) {
|
||||||
if (fileBytes != null && StringUtils.isNotBlank(folder) && updateTime > 0
|
if (fileBytes != null && StringUtils.isNotBlank(folder) && updateTime > 0
|
||||||
&& StringUtils.isNotBlank(fileName) && fileBytes.length > 0) {
|
&& StringUtils.isNotBlank(fileName) && fileBytes.length > 0) {
|
||||||
//删除过期文件
|
//删除过期文件
|
||||||
deleteOldFile(folder, fileMetadataId, updateTime, fileName);
|
deleteOldFile(folder, fileMetadataId, updateTime, fileName);
|
||||||
this.createFile(generateFilePath(folder, fileMetadataId, updateTime, fileName), fileBytes);
|
this.createFile(generateFilePath(folder, fileMetadataId, updateTime, fileName, fileSuffix), fileBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ import lombok.Data;
|
||||||
public class FileInfoDTO {
|
public class FileInfoDTO {
|
||||||
private String id;
|
private String id;
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
|
private String type;
|
||||||
private String projectId;
|
private String projectId;
|
||||||
private long fileLastUpdateTime;
|
private long fileLastUpdateTime;
|
||||||
private String storage;
|
private String storage;
|
||||||
|
|
|
@ -101,6 +101,7 @@ public class GitFileRepository implements FileRepository {
|
||||||
FileInfoDTO repositoryFileDTO = new FileInfoDTO(
|
FileInfoDTO repositoryFileDTO = new FileInfoDTO(
|
||||||
fileRequest.getResourceId(),
|
fileRequest.getResourceId(),
|
||||||
MetadataUtils.getFileNameByRemotePath(gitFileInfo.getFilePath()),
|
MetadataUtils.getFileNameByRemotePath(gitFileInfo.getFilePath()),
|
||||||
|
fileRequest.getType(),
|
||||||
fileRequest.getProjectId(),
|
fileRequest.getProjectId(),
|
||||||
fileRequest.getUpdateTime(),
|
fileRequest.getUpdateTime(),
|
||||||
StorageConstants.GIT.name(),
|
StorageConstants.GIT.name(),
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class LocalFileRepository implements FileRepository {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return new FileInfoDTO(
|
return new FileInfoDTO(
|
||||||
fileRequest.getResourceId(), fileRequest.getFileName(),
|
fileRequest.getResourceId(), fileRequest.getFileName(), fileRequest.getType(),
|
||||||
fileRequest.getProjectId(), fileRequest.getUpdateTime(),
|
fileRequest.getProjectId(), fileRequest.getUpdateTime(),
|
||||||
fileRequest.getStorage(), fileRequest.getPath(), content);
|
fileRequest.getStorage(), fileRequest.getPath(), content);
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class MinIOFileRepository implements FileRepository {
|
||||||
List<FileInfoDTO> list = new ArrayList<>();
|
List<FileInfoDTO> list = new ArrayList<>();
|
||||||
if (CollectionUtils.isNotEmpty(requestList)) {
|
if (CollectionUtils.isNotEmpty(requestList)) {
|
||||||
for (FileRequest fileRequest : requestList) {
|
for (FileRequest fileRequest : requestList) {
|
||||||
FileInfoDTO fileInfoDTO = new FileInfoDTO(fileRequest.getResourceId(), fileRequest.getFileName(), fileRequest.getProjectId(), fileRequest.getUpdateTime(), fileRequest.getStorage(), fileRequest.getPath(), this.getFile(fileRequest));
|
FileInfoDTO fileInfoDTO = new FileInfoDTO(fileRequest.getResourceId(), fileRequest.getFileName(), fileRequest.getType(), fileRequest.getProjectId(), fileRequest.getUpdateTime(), fileRequest.getStorage(), fileRequest.getPath(), this.getFile(fileRequest));
|
||||||
list.add(fileInfoDTO);
|
list.add(fileInfoDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -564,7 +564,7 @@ public class FileMetadataService {
|
||||||
//检查是否存在已下载的文件
|
//检查是否存在已下载的文件
|
||||||
attachmentBodyFileList.forEach(fileMetadata -> {
|
attachmentBodyFileList.forEach(fileMetadata -> {
|
||||||
if (!StringUtils.equals(fileMetadata.getFileStorage(), StorageConstants.LOCAL.name())) {
|
if (!StringUtils.equals(fileMetadata.getFileStorage(), StorageConstants.LOCAL.name())) {
|
||||||
File file = temporaryFileUtil.getFile(fileMetadata.getProjectId(), fileMetadata.getFileMetadataId(), fileMetadata.getFileUpdateTime(), fileMetadata.getName());
|
File file = temporaryFileUtil.getFile(fileMetadata.getProjectId(), fileMetadata.getFileMetadataId(), fileMetadata.getFileUpdateTime(), fileMetadata.getName(), fileMetadata.getFileType());
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
downloadFileList.add(fileMetadata);
|
downloadFileList.add(fileMetadata);
|
||||||
LoggerUtil.info("文件【" + fileMetadata.getFileUpdateTime() + "_" + fileMetadata.getName() + "】在执行目录【" + fileMetadata.getProjectId() + "】未找到,需要下载");
|
LoggerUtil.info("文件【" + fileMetadata.getFileUpdateTime() + "_" + fileMetadata.getName() + "】在执行目录【" + fileMetadata.getProjectId() + "】未找到,需要下载");
|
||||||
|
@ -594,10 +594,10 @@ public class FileMetadataService {
|
||||||
List<FileRequest> downloadFileRequest = new ArrayList<>();
|
List<FileRequest> downloadFileRequest = new ArrayList<>();
|
||||||
//检查是否存在已下载的文件
|
//检查是否存在已下载的文件
|
||||||
fileMetadataWithBLOBList.forEach(fileMetadata -> {
|
fileMetadataWithBLOBList.forEach(fileMetadata -> {
|
||||||
File file = temporaryFileUtil.getFile(fileMetadata.getProjectId(), fileMetadata.getId(), fileMetadata.getUpdateTime(), fileMetadata.getName());
|
File file = temporaryFileUtil.getFile(fileMetadata.getProjectId(), fileMetadata.getId(), fileMetadata.getUpdateTime(), fileMetadata.getName(), fileMetadata.getType());
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
LoggerUtil.info("文件【" + fileMetadata.getUpdateTime() + "_" + fileMetadata.getName() + "】在执行目录【" + fileMetadata.getProjectId() + "】已找到,无需下载");
|
LoggerUtil.info("文件【" + fileMetadata.getUpdateTime() + "_" + fileMetadata.getName() + "】在执行目录【" + fileMetadata.getProjectId() + "】已找到,无需下载");
|
||||||
FileInfoDTO fileInfoDTO = new FileInfoDTO(fileMetadata.getId(), fileMetadata.getName(), fileMetadata.getProjectId(), fileMetadata.getUpdateTime(), fileMetadata.getStorage(), fileMetadata.getPath(), FileUtils.fileToByte(file));
|
FileInfoDTO fileInfoDTO = new FileInfoDTO(fileMetadata.getId(), fileMetadata.getName(), fileMetadata.getType(), fileMetadata.getProjectId(), fileMetadata.getUpdateTime(), fileMetadata.getStorage(), fileMetadata.getPath(), FileUtils.fileToByte(file));
|
||||||
fileInfoDTOList.add(fileInfoDTO);
|
fileInfoDTOList.add(fileInfoDTO);
|
||||||
} else {
|
} else {
|
||||||
LoggerUtil.info("文件【" + fileMetadata.getUpdateTime() + "_" + fileMetadata.getName() + "】在执行目录【" + fileMetadata.getProjectId() + "】未找到,需要下载");
|
LoggerUtil.info("文件【" + fileMetadata.getUpdateTime() + "_" + fileMetadata.getName() + "】在执行目录【" + fileMetadata.getProjectId() + "】未找到,需要下载");
|
||||||
|
@ -607,7 +607,7 @@ public class FileMetadataService {
|
||||||
List<FileInfoDTO> repositoryFileDTOList = fileManagerService.downloadFileBatch(downloadFileRequest);
|
List<FileInfoDTO> repositoryFileDTOList = fileManagerService.downloadFileBatch(downloadFileRequest);
|
||||||
//将文件存储到执行文件目录中,避免多次执行时触发多次下载
|
//将文件存储到执行文件目录中,避免多次执行时触发多次下载
|
||||||
if (CollectionUtils.isNotEmpty(repositoryFileDTOList)) {
|
if (CollectionUtils.isNotEmpty(repositoryFileDTOList)) {
|
||||||
repositoryFileDTOList.forEach(repositoryFile -> temporaryFileUtil.saveFileByParamCheck(repositoryFile.getProjectId(), repositoryFile.getId(), repositoryFile.getFileLastUpdateTime(), repositoryFile.getFileName(), repositoryFile.getFileByte()));
|
repositoryFileDTOList.forEach(repositoryFile -> temporaryFileUtil.saveFileByParamCheck(repositoryFile.getProjectId(), repositoryFile.getId(), repositoryFile.getFileLastUpdateTime(), repositoryFile.getFileName(), repositoryFile.getType(), repositoryFile.getFileByte()));
|
||||||
fileInfoDTOList.addAll(repositoryFileDTOList);
|
fileInfoDTOList.addAll(repositoryFileDTOList);
|
||||||
}
|
}
|
||||||
return fileInfoDTOList;
|
return fileInfoDTOList;
|
||||||
|
@ -624,7 +624,7 @@ public class FileMetadataService {
|
||||||
List<FileInfoDTO> repositoryFileDTOList = fileManagerService.downloadFileBatch(downloadFileRequest);
|
List<FileInfoDTO> repositoryFileDTOList = fileManagerService.downloadFileBatch(downloadFileRequest);
|
||||||
//将文件存储到执行文件目录中,避免多次执行时触发多次下载
|
//将文件存储到执行文件目录中,避免多次执行时触发多次下载
|
||||||
if (CollectionUtils.isNotEmpty(repositoryFileDTOList)) {
|
if (CollectionUtils.isNotEmpty(repositoryFileDTOList)) {
|
||||||
repositoryFileDTOList.forEach(repositoryFile -> temporaryFileUtil.saveFileByParamCheck(repositoryFile.getProjectId(), repositoryFile.getId(), repositoryFile.getFileLastUpdateTime(), repositoryFile.getFileName(), repositoryFile.getFileByte()));
|
repositoryFileDTOList.forEach(repositoryFile -> temporaryFileUtil.saveFileByParamCheck(repositoryFile.getProjectId(), repositoryFile.getId(), repositoryFile.getFileLastUpdateTime(), repositoryFile.getFileName(), repositoryFile.getType(), repositoryFile.getFileByte()));
|
||||||
}
|
}
|
||||||
LogUtil.info(JSON.toJSONString(downloadFileList) + " 获取执行文件结束");
|
LogUtil.info(JSON.toJSONString(downloadFileList) + " 获取执行文件结束");
|
||||||
}
|
}
|
||||||
|
@ -654,6 +654,7 @@ public class FileMetadataService {
|
||||||
request.setResourceId(attachmentBodyFile.getFileMetadataId());
|
request.setResourceId(attachmentBodyFile.getFileMetadataId());
|
||||||
request.setPath(attachmentBodyFile.getFilePath());
|
request.setPath(attachmentBodyFile.getFilePath());
|
||||||
request.setStorage(attachmentBodyFile.getFileStorage());
|
request.setStorage(attachmentBodyFile.getFileStorage());
|
||||||
|
request.setType(attachmentBodyFile.getFileType());
|
||||||
request.setUpdateTime(attachmentBodyFile.getFileUpdateTime());
|
request.setUpdateTime(attachmentBodyFile.getFileUpdateTime());
|
||||||
if (StringUtils.equals(attachmentBodyFile.getFileStorage(), StorageConstants.GIT.name())) {
|
if (StringUtils.equals(attachmentBodyFile.getFileStorage(), StorageConstants.GIT.name())) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue