|
|
|
@@ -38,6 +38,8 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
import redis.clients.jedis.Jedis; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.*; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.net.URLEncoder; |
|
|
|
@@ -110,8 +112,12 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
private RemoteInfoPublishService remoteInfoPublishService; |
|
|
|
|
|
|
|
// 固定存储桶名 |
|
|
|
@Value("${minio.endpointIp}") |
|
|
|
String endpointIp; |
|
|
|
@Value("${minio.dataReleaseBucketName}") |
|
|
|
private String bucketName; |
|
|
|
@Value("${minio.platformDataBucketName}") |
|
|
|
private String platformDataBucketName; |
|
|
|
@Resource |
|
|
|
private MinioUtil minioUtil; |
|
|
|
|
|
|
|
@@ -289,25 +295,27 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResponseEntity<InputStreamResource> downloadDatasetlocal(String filePath) throws Exception { |
|
|
|
File file = new File(filePath); |
|
|
|
|
|
|
|
if (!file.exists()) { |
|
|
|
throw new FileNotFoundException("File not found: " + filePath); |
|
|
|
} |
|
|
|
|
|
|
|
InputStreamResource resource = new InputStreamResource(new FileInputStream(file)); |
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName()); |
|
|
|
headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length())); |
|
|
|
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE); |
|
|
|
|
|
|
|
return ResponseEntity.ok() |
|
|
|
.headers(headers) |
|
|
|
.contentLength(file.length()) |
|
|
|
.contentType(MediaType.APPLICATION_OCTET_STREAM) |
|
|
|
.body(resource); |
|
|
|
public String downloadDatasetlocal(String filePath) throws Exception { |
|
|
|
// File file = new File(filePath); |
|
|
|
// |
|
|
|
// if (!file.exists()) { |
|
|
|
// throw new FileNotFoundException("File not found: " + filePath); |
|
|
|
// } |
|
|
|
// |
|
|
|
// InputStreamResource resource = new InputStreamResource(new FileInputStream(file)); |
|
|
|
// |
|
|
|
// HttpHeaders headers = new HttpHeaders(); |
|
|
|
// headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName()); |
|
|
|
// headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length())); |
|
|
|
// headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE); |
|
|
|
// |
|
|
|
// return ResponseEntity.ok() |
|
|
|
// .headers(headers) |
|
|
|
// .contentLength(file.length()) |
|
|
|
// .contentType(MediaType.APPLICATION_OCTET_STREAM) |
|
|
|
// .body(resource); |
|
|
|
String[] split = filePath.split("/"); |
|
|
|
return endpointIp + "/" + bucketName + "/" + platformDataBucketName + "/" + String.join("/", Arrays.copyOfRange(split, 3, split.length)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@@ -919,7 +927,7 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResponseEntity<InputStreamResource> downloadAllModelFilesNew(String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws Exception { |
|
|
|
public void downloadAllModelFilesNew(HttpServletRequest req, HttpServletResponse resp, String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws Exception { |
|
|
|
// 命令行操作 git clone 项目地址 |
|
|
|
String localPath1 = localPath + owner + "/model/" + id + "/" + identifier + "/" + version; |
|
|
|
// 打包 data 文件夹 |
|
|
|
@@ -944,13 +952,32 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
|
|
|
|
// 返回压缩文件的输入流 |
|
|
|
File zipFile = new File(zipFilePath); |
|
|
|
InputStreamResource resource = new InputStreamResource(new FileInputStream(zipFile)); |
|
|
|
|
|
|
|
return ResponseEntity.ok() |
|
|
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + name + "_" + version + "_model.zip") |
|
|
|
.contentType(MediaType.APPLICATION_OCTET_STREAM) |
|
|
|
.contentLength(zipFile.length()) |
|
|
|
.body(resource); |
|
|
|
BufferedInputStream bis = null; |
|
|
|
BufferedOutputStream bos = null; |
|
|
|
OutputStream fos = null; |
|
|
|
try { |
|
|
|
bis = new BufferedInputStream(new FileInputStream(zipFile)); |
|
|
|
fos = resp.getOutputStream(); |
|
|
|
bos = new BufferedOutputStream(fos); |
|
|
|
ServletUtils.setFileDownloadHeader(req, resp, name); |
|
|
|
int byteRead = 0; |
|
|
|
byte[] buffer = new byte[8192]; |
|
|
|
while ((byteRead = bis.read(buffer, 0, 8192)) != -1) { |
|
|
|
bos.write(buffer, 0, byteRead); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
bos.flush(); |
|
|
|
bis.close(); |
|
|
|
fos.close(); |
|
|
|
bos.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@@ -979,7 +1006,8 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Page<ModelsVo> newPubilcQueryByPage(ModelsVo modelsVo, PageRequest pageRequest, String accessToken) throws Exception { |
|
|
|
public Page<ModelsVo> newPubilcQueryByPage(ModelsVo modelsVo, PageRequest pageRequest, String accessToken) throws |
|
|
|
Exception { |
|
|
|
String token; |
|
|
|
if (StringUtils.isNotEmpty(accessToken)) { |
|
|
|
token = accessToken; |
|
|
|
@@ -1007,7 +1035,8 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Page<Map<String, Object>> queryVersions(PageRequest pageRequest, String identifier, String owner, String type) throws Exception { |
|
|
|
public Page<Map<String, Object>> queryVersions(PageRequest pageRequest, String identifier, String owner, String |
|
|
|
type) throws Exception { |
|
|
|
String token = gitService.checkoutToken(); |
|
|
|
List<Map<String, Object>> collect = gitService.getBrancheList(token, owner, identifier); |
|
|
|
List<Map<String, Object>> result = collect.stream() |
|
|
|
@@ -1119,7 +1148,8 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ModelsVo getModelDetail(Integer id, String identifier, String owner, String version, Boolean isPublic) throws Exception { |
|
|
|
public ModelsVo getModelDetail(Integer id, String identifier, String owner, String version, Boolean isPublic) throws |
|
|
|
Exception { |
|
|
|
if (StringUtils.isEmpty(version)) { |
|
|
|
version = "origin"; |
|
|
|
} |
|
|
|
@@ -1220,7 +1250,8 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteVersion(Integer repoId, String identifier, String owner, String version, String relativePath) throws Exception { |
|
|
|
public void deleteVersion(Integer repoId, String identifier, String owner, String version, String relativePath) throws |
|
|
|
Exception { |
|
|
|
List<AssetWorkflow> assetWorkflow = assetWorkflowDao.getAssetWorkflow(Long.valueOf(repoId), Constant.Asset_Type_Model, version); |
|
|
|
if (assetWorkflow != null && !assetWorkflow.isEmpty()) { |
|
|
|
String workflows = String.join(",", assetWorkflow.stream().map(AssetWorkflow::getWorkflowName).collect(Collectors.toSet())); |
|
|
|
@@ -1305,7 +1336,8 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<ModelsVo> convert(List<Map<String, Object>> lst, String modelTopic, String modelTagName, String modelTypeName) { |
|
|
|
public List<ModelsVo> convert(List<Map<String, Object>> lst, String modelTopic, String |
|
|
|
modelTagName, String modelTypeName) { |
|
|
|
if (lst != null && lst.size() > 0) { |
|
|
|
List<ModelsVo> result = new ArrayList<>(); |
|
|
|
List<ModelsVo> newModelVos = ConvertUtil.convertListMapToObjectList(lst, ModelsVo.class); |
|
|
|
@@ -1364,7 +1396,7 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void privateToPublic(ModelsVo modelsVo) throws Exception { |
|
|
|
public void privateToPublic(ModelsVo modelsVo) throws Exception { |
|
|
|
//获取版本列表信息,每一个版本的配置文件都要更改 |
|
|
|
String token = gitService.checkoutToken(); |
|
|
|
List<Map<String, Object>> brancheList = gitService.getBrancheList(token, modelsVo.getOwner(), modelsVo.getIdentifier()); |
|
|
|
@@ -1390,7 +1422,7 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("id", projectDetail.get("project_id")); |
|
|
|
param.put("is_public", true); |
|
|
|
gitService.updateProjectDetail(param,modelsVo.getOwner(),modelsVo.getIdentifier(),token); |
|
|
|
gitService.updateProjectDetail(param, modelsVo.getOwner(), modelsVo.getIdentifier(), token); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@@ -1401,7 +1433,7 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
//无需审批,直接通过 |
|
|
|
return "发布成功"; |
|
|
|
} |
|
|
|
ModelsVo modelsVotDesc = getModelDetail(modelsVo.getId(), modelsVo.getIdentifier(),modelsVo.getOwner(),modelsVo.getVersion(), false); |
|
|
|
ModelsVo modelsVotDesc = getModelDetail(modelsVo.getId(), modelsVo.getIdentifier(), modelsVo.getOwner(), modelsVo.getVersion(), false); |
|
|
|
String username = loginUser.getUsername(); |
|
|
|
Long userid = loginUser.getUserid(); |
|
|
|
ApprovalRequest approvalRequest = new ApprovalRequest(); |
|
|
|
|