| @@ -81,17 +81,17 @@ public class NewModelFromGitController { | |||
| } | |||
| } | |||
| @GetMapping("/getModelVersions/{model_name}") | |||
| @ApiOperation(value = "获取模型所有版本号") | |||
| public AjaxResult getModelVersions(@PathVariable("model_name") String modelName) throws Exception { | |||
| return AjaxResult.success(this.modelsService.getNewModelVersion(modelName)); | |||
| @GetMapping("/getVersionList") | |||
| @ApiOperation(value = "获取模型分支列表") | |||
| public AjaxResult getVersionList(@RequestParam("identifier") String identifier, @RequestParam("owner")String owner) throws Exception { | |||
| return AjaxResult.success(this.modelsService.getVersionList(identifier, owner)); | |||
| } | |||
| @GetMapping("/getModelDetail") | |||
| @ApiOperation(value = "获取模型详细信息") | |||
| public AjaxResult getModelDetail(@RequestParam("model_name") String modelName, @RequestParam("version") String version) throws Exception { | |||
| return AjaxResult.success(this.modelsService.getModelDetail(modelName, version)); | |||
| public AjaxResult getModelDetail(@RequestParam("model_name") String modelName, @RequestParam("identifier") String identifier,@RequestParam("owner") String owner, @RequestParam("version") String version) throws Exception { | |||
| return AjaxResult.success(this.modelsService.getModelDetail(modelName, identifier, owner, version)); | |||
| } | |||
| @GetMapping("/getModelDependencyTree") | |||
| @@ -4,7 +4,6 @@ package com.ruoyi.platform.service; | |||
| import com.ruoyi.platform.domain.Models; | |||
| import com.ruoyi.platform.domain.ModelsVersion; | |||
| import com.ruoyi.platform.vo.ModelDependency1TreeVo; | |||
| import com.ruoyi.platform.vo.ModelMetaVo; | |||
| import com.ruoyi.platform.vo.ModelsVo; | |||
| import org.springframework.core.io.InputStreamResource; | |||
| import org.springframework.data.domain.Page; | |||
| @@ -98,11 +97,11 @@ public interface ModelsService { | |||
| Page<ModelsVo> newPersonalQueryByPage(ModelsVo modelsVo, PageRequest pageRequest) throws Exception; | |||
| List<String> getNewModelVersion(String modelName); | |||
| List<Map<String, Object>> getVersionList(String identifier, String owner) throws Exception; | |||
| ModelsVo getModelDetail(String modelName, String version) throws Exception; | |||
| ModelsVo getModelDetail(String modelName, String identifier, String owner, String version) throws Exception; | |||
| ModelDependency1TreeVo getModelDependencyTree(Integer repoId, String modelName, String version)throws Exception; | |||
| ModelDependency1TreeVo getModelDependencyTree(Integer repoId, String modelName, String version) throws Exception; | |||
| void deleteModel(Integer repoId, String identifier, String owner) throws Exception; | |||
| @@ -464,7 +464,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| public CompletableFuture<String> newCreateDataset(NewDatasetVo datasetVo) { | |||
| return CompletableFuture.supplyAsync(() -> { | |||
| try { | |||
| checkoutToken(); | |||
| gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -541,7 +541,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| public CompletableFuture<String> newCreateVersion(NewDatasetVo datasetVo) { | |||
| return CompletableFuture.supplyAsync(() -> { | |||
| try { | |||
| checkoutToken(); | |||
| gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -611,7 +611,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| @Override | |||
| public Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { | |||
| checkoutToken(); | |||
| gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -634,7 +634,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| @Override | |||
| public Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { | |||
| checkoutToken(); | |||
| gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -696,12 +696,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| @Override | |||
| public List<Map<String, Object>> getVersionList(String repo, String owner) throws Exception { | |||
| checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String token = jedis.get(ci4sUsername+"_gitToken"); | |||
| List<Map<String, Object>> brancheList = gitService.getBrancheList(token, owner, repo); | |||
| List<Map<String, Object>> brancheList = gitService.getBrancheList(owner, repo); | |||
| return brancheList.stream() | |||
| .filter(branch -> "master".equals(branch.get("name"))) | |||
| .collect(Collectors.toList()); | |||
| @@ -709,7 +704,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| @Override | |||
| public void deleteDatasetNew(String repo, String owner) throws Exception { | |||
| checkoutToken(); | |||
| gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -719,7 +714,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| @Override | |||
| public void deleteDatasetVersionNew(String repo, String owner, String version) throws Exception { | |||
| checkoutToken(); | |||
| gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -779,7 +774,7 @@ public class DatasetServiceImpl implements DatasetService { | |||
| @Override | |||
| public ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String repositoryName, String version) throws Exception { | |||
| // 命令行操作 git clone 项目地址 | |||
| checkoutToken(); | |||
| gitService.checkoutToken(); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||
| @@ -872,33 +867,4 @@ public class DatasetServiceImpl implements DatasetService { | |||
| return new ArrayList<>(); | |||
| } | |||
| private String checkoutToken(){ | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String token = jedis.get(ci4sUsername+"_gitToken"); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||
| if(StringUtils.isEmpty(token)){ | |||
| gitService.login(gitLinkUsername, gitLinkPassword); | |||
| token = jedis.get(ci4sUsername+"_gitToken"); | |||
| }else { | |||
| try { | |||
| Map userInfo = gitService.getUserInfo(token); | |||
| if (userInfo == null ||(userInfo.get("status")!=null&&401==(Integer) userInfo.get("status"))){ | |||
| gitService.login(gitLinkUsername, gitLinkPassword); | |||
| token = jedis.get(ci4sUsername+"_gitToken"); | |||
| } | |||
| } catch (Exception e) { | |||
| throw new RuntimeException(e); | |||
| } | |||
| } | |||
| return token; | |||
| } | |||
| } | |||
| @@ -39,7 +39,7 @@ public class GitServiceImpl implements GitService { | |||
| params.put("client_secret", "L3wBKTNnRo-wPen7bxR3F1myCvtVDgpWa6MnpfyWeJE"); | |||
| try { | |||
| // 发送POST请求 | |||
| String req = HttpUtils.sendPostRequest("https://www.gitlink.org.cn/oauth/token",null, JsonUtils.mapToJson(params)); | |||
| String req = HttpUtils.sendPostRequest("https://www.gitlink.org.cn/oauth/token", null, JsonUtils.mapToJson(params)); | |||
| // 解析响应JSON | |||
| if (StringUtils.isEmpty(req)) { | |||
| throw new RuntimeException("终止响应内容为空。"); | |||
| @@ -51,7 +51,7 @@ public class GitServiceImpl implements GitService { | |||
| String accessToken = (String) runResMap.get("access_token"); | |||
| //通过access_token获取用户信息 | |||
| String userReq = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/users/get_user_info.json",null, accessToken); | |||
| String userReq = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/users/get_user_info.json", null, accessToken); | |||
| if (StringUtils.isEmpty(userReq)) { | |||
| throw new RuntimeException("终止响应内容为空。"); | |||
| } | |||
| @@ -59,8 +59,8 @@ public class GitServiceImpl implements GitService { | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| // 将access_token存入Redis | |||
| Jedis jedis = new Jedis(redisHost); | |||
| jedis.set(ci4sUsername+"_gitToken", accessToken); | |||
| jedis.set(ci4sUsername+"_gitUserInfo", userReq); | |||
| jedis.set(ci4sUsername + "_gitToken", accessToken); | |||
| jedis.set(ci4sUsername + "_gitUserInfo", userReq); | |||
| return accessToken; | |||
| } catch (Exception e) { | |||
| log.error("登录GitLink失败。", e); | |||
| @@ -68,24 +68,51 @@ public class GitServiceImpl implements GitService { | |||
| } | |||
| } | |||
| @Override | |||
| public String checkoutToken() { | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String token = jedis.get(ci4sUsername + "_gitToken"); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||
| if (StringUtils.isEmpty(token)) { | |||
| login(gitLinkUsername, gitLinkPassword); | |||
| token = jedis.get(ci4sUsername + "_gitToken"); | |||
| } else { | |||
| try { | |||
| Map userInfo = getUserInfo(token); | |||
| if (userInfo == null || (userInfo.get("status") != null && 401 == (Integer) userInfo.get("status"))) { | |||
| login(gitLinkUsername, gitLinkPassword); | |||
| token = jedis.get(ci4sUsername + "_gitToken"); | |||
| } | |||
| } catch (Exception e) { | |||
| throw new RuntimeException(e); | |||
| } | |||
| } | |||
| return token; | |||
| } | |||
| @Override | |||
| public Map createProject(String token, GitProjectVo gitProjectVo) throws Exception { | |||
| String userReq = HttpUtils.sendPostWithToken("https://www.gitlink.org.cn/api/projects.json",JsonUtils.objectToJson(gitProjectVo),token); | |||
| String userReq = HttpUtils.sendPostWithToken("https://www.gitlink.org.cn/api/projects.json", JsonUtils.objectToJson(gitProjectVo), token); | |||
| return JsonUtils.jsonToMap(userReq); | |||
| } | |||
| @Override | |||
| public void createBranch(String token,String owner, String projectName, String branchName, String oldBranchName) throws Exception { | |||
| public void createBranch(String token, String owner, String projectName, String branchName, String oldBranchName) throws Exception { | |||
| //https://www.gitlink.org.cn/api/v1/fanshuai/testdssa8755/branches.json | |||
| // { | |||
| // "new_branch_name": "SsS", | |||
| // "old_branch_name": "master" | |||
| // } | |||
| String createBranchUrl = "https://www.gitlink.org.cn/api/v1/"+ owner + "/" + projectName + "/branches.json"; | |||
| String createBranchUrl = "https://www.gitlink.org.cn/api/v1/" + owner + "/" + projectName + "/branches.json"; | |||
| Map<String, Object> resMap = new HashMap<>(); | |||
| resMap.put("new_branch_name", branchName); | |||
| resMap.put("old_branch_name", oldBranchName); | |||
| String req = HttpUtils.sendPostWithToken(createBranchUrl,JsonUtils.objectToJson(resMap),token); | |||
| String req = HttpUtils.sendPostWithToken(createBranchUrl, JsonUtils.objectToJson(resMap), token); | |||
| } | |||
| @Override | |||
| @@ -94,12 +121,13 @@ public class GitServiceImpl implements GitService { | |||
| Map<String, Object> resMap = new HashMap<>(); | |||
| resMap.put("project_id", id); | |||
| resMap.put("name", topicName); | |||
| String req = HttpUtils.sendPostWithToken("https://www.gitlink.org.cn/api/v1/project_topics.json",JsonUtils.objectToJson(resMap),token); | |||
| String req = HttpUtils.sendPostWithToken("https://www.gitlink.org.cn/api/v1/project_topics.json", JsonUtils.objectToJson(resMap), token); | |||
| } | |||
| @Override | |||
| public List<Map<String, Object>> getBrancheList(String token, String owner, String projectName) throws Exception { | |||
| String req = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/v1/"+owner+"/"+projectName+"/branches/all.json",null, token); | |||
| public List<Map<String, Object>> getBrancheList(String owner, String projectName) throws Exception { | |||
| String token = checkoutToken(); | |||
| String req = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/v1/" + owner + "/" + projectName + "/branches/all.json", null, token); | |||
| // 解析响应JSON | |||
| if (StringUtils.isEmpty(req)) { | |||
| throw new RuntimeException("终止响应内容为空。"); | |||
| @@ -111,18 +139,18 @@ public class GitServiceImpl implements GitService { | |||
| @Override | |||
| public void deleteProject(String token, String owner, String projectName) throws Exception { | |||
| HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/"+owner+"/"+projectName+".json", token); | |||
| HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/" + owner + "/" + projectName + ".json", token); | |||
| } | |||
| @Override | |||
| public void deleteBranch(String token, String owner, String projectName, String branchName) throws Exception { | |||
| HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/v1/"+owner+"/"+projectName+"/branches/"+branchName+".json", token); | |||
| HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/v1/" + owner + "/" + projectName + "/branches/" + branchName + ".json", token); | |||
| } | |||
| @Override | |||
| public Map getUserInfo(String token) throws Exception { | |||
| String userReq = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/users/get_user_info.json",null, token); | |||
| String userReq = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/users/get_user_info.json", null, token); | |||
| Map<String, Object> runResMap = JsonUtils.jsonToMap(userReq); | |||
| return runResMap; | |||
| return runResMap; | |||
| } | |||
| } | |||
| @@ -519,14 +519,17 @@ public class ModelsServiceImpl implements ModelsService { | |||
| public CompletableFuture<String> newCreateModel(ModelsVo modelsVo) { | |||
| return CompletableFuture.supplyAsync(() -> { | |||
| try { | |||
| gitService.checkoutToken(); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||
| Map<String, Object> userInfo = getUserInfo(ci4sUsername); | |||
| Integer userId = (Integer) userInfo.get("user_id"); | |||
| String token = (String) userInfo.get("token"); | |||
| String token = gitService.login(gitLinkUsername, gitLinkPassword); | |||
| String repositoryName = modelsVo.getRepositoryName() == null ? ci4sUsername + "_model_" + DateUtils.dateTimeNow() : modelsVo.getRepositoryName(); | |||
| ModelDependency1 modelDependency = new ModelDependency1(); | |||
| List<ModelDependency1> oldModelDependencys = modelDependency1Dao.queryByModelName(modelsVo.getName()); | |||
| @@ -659,10 +662,8 @@ public class ModelsServiceImpl implements ModelsService { | |||
| public Page<ModelsVo> newPubilcQueryByPage(ModelsVo modelsVo, PageRequest pageRequest) throws Exception { | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||
| String token = gitService.login(gitLinkUsername, gitLinkPassword); | |||
| Map<String, Object> userInfo = getUserInfo(ci4sUsername); | |||
| String token = (String) userInfo.get("token"); | |||
| //拼接查询url | |||
| String modelTagName = modelsVo.getModelTag(); | |||
| @@ -684,11 +685,9 @@ public class ModelsServiceImpl implements ModelsService { | |||
| public Page<ModelsVo> newPersonalQueryByPage(ModelsVo modelsVo, PageRequest pageRequest) throws Exception { | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||
| String token = gitService.login(gitLinkUsername, gitLinkPassword); | |||
| Map<String, Object> userInfo = getUserInfo(ci4sUsername); | |||
| Integer userId = (Integer) userInfo.get("user_id"); | |||
| String token = (String) userInfo.get("token"); | |||
| //拼接查询url | |||
| String modelTagName = modelsVo.getModelTag(); | |||
| @@ -707,18 +706,28 @@ public class ModelsServiceImpl implements ModelsService { | |||
| } | |||
| @Override | |||
| public List<String> getNewModelVersion(String modelName) { | |||
| List<ModelDependency1> modelDependency1List = modelDependency1Dao.queryByModelName(modelName); | |||
| return modelDependency1List.stream().map(ModelDependency1::getVersion).collect(Collectors.toList()); | |||
| public List<Map<String, Object>> getVersionList(String identifier, String owner) throws Exception { | |||
| List<Map<String, Object>> brancheList = gitService.getBrancheList(owner, identifier); | |||
| return brancheList.stream() | |||
| .filter(branch -> "master".equals(branch.get("name"))) | |||
| .collect(Collectors.toList()); | |||
| } | |||
| @Override | |||
| public ModelsVo getModelDetail(String modelName, String version) { | |||
| public ModelsVo getModelDetail(String modelName, String identifier, String owner, String version) throws Exception { | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||
| if (StringUtils.isEmpty(version)){ | |||
| List<Map<String, Object>> versionList = this.getVersionList(owner, identifier); | |||
| if (versionList.size() == 0){ | |||
| throw new Exception("数据集文件不存在"); | |||
| } | |||
| version = (String) versionList.get(0).get("name"); | |||
| } | |||
| // git pull操作,然后读取里面的文件列表,列出每个文件的大小和名称,封装成MAP | |||
| List<Map<String, Object>> fileDetailsAfterGitPull = DVCUtils.getFileDetailsAfterGitPull(localPath + ci4sUsername + "/model/", modelName, version, "model", gitLinkUsername, gitLinkPassword); | |||
| @@ -729,7 +738,7 @@ public class ModelsServiceImpl implements ModelsService { | |||
| ModelsVo modelsVo = new ModelsVo(); | |||
| BeanUtils.copyProperties(modelMetaVo, modelsVo); | |||
| List<VersionVo> versionVos = new ArrayList<VersionVo>(); | |||
| List<VersionVo> versionVos = new ArrayList<>(); | |||
| if (!fileDetailsAfterGitPull.isEmpty()) { | |||
| for (Map<String, Object> fileDetail : fileDetailsAfterGitPull) { | |||
| VersionVo versionVo = new VersionVo(); | |||
| @@ -765,11 +774,12 @@ public class ModelsServiceImpl implements ModelsService { | |||
| @Override | |||
| public void deleteModel(Integer repoId, String identifier, String owner) throws Exception { | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||
| String token = gitService.login(gitLinkUsername, gitLinkPassword); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| Map<String, Object> userInfo = getUserInfo(ci4sUsername); | |||
| String token = (String) userInfo.get("token"); | |||
| gitService.deleteProject(token, owner, identifier); | |||
| //删除模型依赖 | |||
| modelDependency1Dao.deleteModel(repoId, identifier, owner, null); | |||
| modelDependency1Dao.deleteModelDependency(repoId, identifier, owner, null); | |||
| @@ -778,11 +788,11 @@ public class ModelsServiceImpl implements ModelsService { | |||
| @Override | |||
| public void deleteVersion(Integer repoId, String identifier, String owner, String version) throws Exception { | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword(); | |||
| String token = gitService.login(gitLinkUsername, gitLinkPassword); | |||
| gitService.deleteBranch(token, owner, identifier, version); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| Map<String, Object> userInfo = getUserInfo(ci4sUsername); | |||
| String token = (String) userInfo.get("token"); | |||
| gitService.deleteBranch(token, owner, identifier, version); | |||
| //删除模型依赖 | |||
| modelDependency1Dao.deleteModel(repoId, identifier, owner, version); | |||
| modelDependency1Dao.deleteModelDependency(repoId, identifier, owner, version); | |||
| @@ -902,6 +912,10 @@ public class ModelsServiceImpl implements ModelsService { | |||
| Map<String, Object> getUserInfo(String ci4sUsername) throws IOException { | |||
| Jedis jedis = new Jedis(redisHost); | |||
| String userReq = jedis.get(ci4sUsername + "_gitUserInfo"); | |||
| return JsonUtils.jsonToMap(userReq); | |||
| Map<String, Object> userInfo = JsonUtils.jsonToMap(userReq); | |||
| String token = gitService.checkoutToken(); | |||
| userInfo.put("token", token); | |||
| return userInfo; | |||
| } | |||
| } | |||