| @@ -12,17 +12,17 @@ public interface GitService { | |||
| String checkoutToken(); | |||
| //输入token,项目名,tag,创建新项目,返回项目地址 | |||
| Map createProject(GitProjectVo gitProjectVo) throws Exception; | |||
| Map createProject(String token,GitProjectVo gitProjectVo) throws Exception; | |||
| void createBranch(String owner, String projectName, String branchName, String oldBranchName) throws Exception; | |||
| void createBranch(String token,String owner, String projectName, String branchName, String oldBranchName) throws Exception; | |||
| void createTopic(Integer id, String topicName) throws Exception; | |||
| void createTopic(String token,Integer id, String topicName) throws Exception; | |||
| List<Map<String, Object>> getBrancheList(String owner, String projectName) throws Exception; | |||
| List<Map<String, Object>> getBrancheList(String token,String owner, String projectName) throws Exception; | |||
| void deleteProject(String owner, String projectName) throws Exception; | |||
| void deleteProject(String token,String owner, String projectName) throws Exception; | |||
| void deleteBranch(String owner, String projectName, String branchName, String localPath) throws Exception; | |||
| void deleteBranch(String token,String owner, String projectName, String branchName, String localPath) throws Exception; | |||
| Map getUserInfo(String token) throws Exception; | |||
| } | |||
| @@ -98,20 +98,18 @@ public class GitServiceImpl implements GitService { | |||
| } | |||
| @Override | |||
| public Map createProject(GitProjectVo gitProjectVo) throws Exception { | |||
| String token = this.checkoutToken(); | |||
| 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); | |||
| return JsonUtils.jsonToMap(userReq); | |||
| } | |||
| @Override | |||
| public void createBranch(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 token = this.checkoutToken(); | |||
| 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); | |||
| @@ -121,9 +119,8 @@ public class GitServiceImpl implements GitService { | |||
| } | |||
| @Override | |||
| public void createTopic(Integer id, String topicName) throws Exception { | |||
| public void createTopic(String token,Integer id, String topicName) throws Exception { | |||
| // https://www.gitlink.org.cn/api/v1/project_topics.json | |||
| String token = this.checkoutToken(); | |||
| Map<String, Object> resMap = new HashMap<>(); | |||
| resMap.put("project_id", id); | |||
| resMap.put("name", topicName); | |||
| @@ -131,8 +128,7 @@ public class GitServiceImpl implements GitService { | |||
| } | |||
| @Override | |||
| public List<Map<String, Object>> getBrancheList(String owner, String projectName) throws Exception { | |||
| String token = checkoutToken(); | |||
| 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); | |||
| // 解析响应JSON | |||
| if (StringUtils.isEmpty(req)) { | |||
| @@ -144,20 +140,18 @@ public class GitServiceImpl implements GitService { | |||
| } | |||
| @Override | |||
| public void deleteProject(String owner, String projectName) throws Exception { | |||
| String token = this.checkoutToken(); | |||
| public void deleteProject(String token,String owner, String projectName) throws Exception { | |||
| HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/" + owner + "/" + projectName + ".json", token); | |||
| } | |||
| @Override | |||
| public void deleteBranch(String owner, String projectName, String branchName, String localPath) throws Exception { | |||
| public void deleteBranch(String token,String owner, String projectName, String branchName, String localPath) throws Exception { | |||
| try (Git git = Git.open(new File(localPath))) { | |||
| git.checkout().setName("master").call(); | |||
| git.branchDelete().setBranchNames(branchName).setForce(true).call(); | |||
| } catch (IOException | GitAPIException e) { | |||
| log.error("Exception occurred while creating local branch based on master",e); | |||
| } | |||
| String token = this.checkoutToken(); | |||
| HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/v1/" + owner + "/" + projectName + "/branches/" + branchName + ".json", token); | |||
| } | |||
| @@ -540,6 +540,7 @@ public class ModelsServiceImpl implements ModelsService { | |||
| @Override | |||
| public String newCreateModel(ModelsVo modelsVo) { | |||
| try { | |||
| String token = gitService.checkoutToken(); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername(); | |||
| @@ -571,17 +572,17 @@ public class ModelsServiceImpl implements ModelsService { | |||
| gitProjectVo.setUserId(userId); | |||
| // 创建项目 | |||
| Map project = gitService.createProject(gitProjectVo); | |||
| Map project = gitService.createProject(token,gitProjectVo); | |||
| Integer gitlinIid = (Integer) project.get("id"); | |||
| if (gitlinIid == null) { | |||
| throw new Exception("创建模型失败:" + project.get("message")); | |||
| } | |||
| // 创建分支 | |||
| gitService.createBranch((String) userInfo.get("login"), repositoryName, modelsVo.getVersion(), "master"); | |||
| gitService.createBranch(token,(String) userInfo.get("login"), repositoryName, modelsVo.getVersion(), "master"); | |||
| // 定义标签 标签1:ci4s_model 标签2:ModelTag 标签3:ModelType | |||
| gitService.createTopic(gitlinIid, "ci4s_model"); | |||
| gitService.createTopic(gitlinIid, "modeltag_" + modelsVo.getModelTag()); | |||
| gitService.createTopic(gitlinIid, "modeltype_" + modelsVo.getModelType()); | |||
| gitService.createTopic(token,gitlinIid, "ci4s_model"); | |||
| gitService.createTopic(token,gitlinIid, "modeltag_" + modelsVo.getModelTag()); | |||
| gitService.createTopic(token,gitlinIid, "modeltype_" + modelsVo.getModelType()); | |||
| String branchName = modelsVo.getVersion(); | |||
| String owner = (String) userInfo.get("login"); | |||
| @@ -874,7 +875,8 @@ public class ModelsServiceImpl implements ModelsService { | |||
| @Override | |||
| public List<Map<String, Object>> getVersionList(String identifier, String owner) throws Exception { | |||
| List<Map<String, Object>> brancheList = gitService.getBrancheList(owner, identifier); | |||
| String token = gitService.checkoutToken(); | |||
| List<Map<String, Object>> brancheList = gitService.getBrancheList(token,owner, identifier); | |||
| return brancheList.stream() | |||
| .filter(branch -> !"master".equals(branch.get("name"))) | |||
| .collect(Collectors.toList()); | |||
| @@ -940,7 +942,8 @@ public class ModelsServiceImpl implements ModelsService { | |||
| @Override | |||
| public void deleteModel(Integer repoId, String identifier, String owner) throws Exception { | |||
| gitService.deleteProject(owner, identifier); | |||
| String token = gitService.checkoutToken(); | |||
| gitService.deleteProject(token,owner, identifier); | |||
| //删除模型依赖 | |||
| modelDependency1Dao.deleteModel(repoId, identifier, owner, null); | |||
| @@ -953,7 +956,8 @@ public class ModelsServiceImpl implements ModelsService { | |||
| @Override | |||
| public void deleteVersion(Integer repoId, String identifier, String owner, String version, String relativePath) throws Exception { | |||
| gitService.deleteBranch(owner, identifier, version, localPath + relativePath); | |||
| String token = gitService.checkoutToken(); | |||
| gitService.deleteBranch(token,owner, identifier, version, localPath + relativePath); | |||
| //删除模型依赖 | |||
| modelDependency1Dao.deleteModel(repoId, identifier, owner, version); | |||
| HashMap<String, Object> map = new HashMap<>(); | |||
| @@ -64,6 +64,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| private DatasetTempStorageService datasetTempStorageService; | |||
| @Override | |||
| public String newCreateDataset(NewDatasetVo datasetVo) throws Exception { | |||
| String token = gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -82,18 +83,18 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| gitProjectVo.setPrivate(!datasetVo.getIsPublic()); | |||
| gitProjectVo.setUserId(userId); | |||
| // 创建项目 | |||
| Map project = gitService.createProject(gitProjectVo); | |||
| Map project = gitService.createProject(token,gitProjectVo); | |||
| Integer gitlinIid = (Integer) project.get("id"); | |||
| if (gitlinIid == null){ | |||
| throw new Exception("创建数据集失败:"+project.get("message")); | |||
| } | |||
| // 创建分支 | |||
| String branchName = datasetVo.getVersion(); | |||
| gitService.createBranch((String) userInfo.get("login"), repositoryName, branchName, "master"); | |||
| gitService.createBranch(token,(String) userInfo.get("login"), repositoryName, branchName, "master"); | |||
| // 定义标签 标签1:ci4s_dataset 标签2:DataTag 标签3:DataType | |||
| gitService.createTopic(gitlinIid, "ci4s_dataset"); | |||
| gitService.createTopic(gitlinIid, "DataTag_" + datasetVo.getDataTag()); | |||
| gitService.createTopic( gitlinIid, "DataType_" + datasetVo.getDataType()); | |||
| gitService.createTopic(token,gitlinIid, "ci4s_dataset"); | |||
| gitService.createTopic(token,gitlinIid, "DataTag_" + datasetVo.getDataTag()); | |||
| gitService.createTopic(token, gitlinIid, "DataType_" + datasetVo.getDataType()); | |||
| // 得到项目地址 | |||
| String projectUrl = gitendpoint + "/" + (String) userInfo.get("login") + "/"+ repositoryName + ".git"; | |||
| @@ -145,6 +146,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| } | |||
| public String newCreateVersion(NewDatasetVo datasetVo) throws Exception { | |||
| gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -215,6 +217,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| @Override | |||
| public Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { | |||
| gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -242,6 +245,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| @Override | |||
| public Page<NewDatasetVo> newPubilcQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception { | |||
| gitService.checkoutToken(); | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| @@ -305,7 +309,8 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| @Override | |||
| public List<Map<String, Object>> getVersionList(String repo, String owner) throws Exception { | |||
| List<Map<String, Object>> brancheList = gitService.getBrancheList(owner, repo); | |||
| String token = gitService.checkoutToken(); | |||
| List<Map<String, Object>> brancheList = gitService.getBrancheList(token,owner, repo); | |||
| return brancheList.stream() | |||
| .filter(branch -> !"master".equals(branch.get("name"))) | |||
| .collect(Collectors.toList()); | |||
| @@ -313,20 +318,14 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| @Override | |||
| public void deleteDatasetNew(String repo, String owner) throws Exception { | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String token = jedis.get(ci4sUsername+"_gitToken"); | |||
| gitService.deleteProject(owner, repo); | |||
| String token = gitService.checkoutToken(); | |||
| gitService.deleteProject(token,owner, repo); | |||
| } | |||
| @Override | |||
| public void deleteDatasetVersionNew(String repo, String owner, String version, String relativePath) throws Exception { | |||
| Jedis jedis = new Jedis(redisHost); | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| String ci4sUsername = loginUser.getUsername(); | |||
| String token = jedis.get(ci4sUsername+"_gitToken"); | |||
| gitService.deleteBranch(owner, repo, version, localPathlocal + relativePath); | |||
| String token = gitService.checkoutToken(); | |||
| gitService.deleteBranch(token,owner, repo, version, localPathlocal + relativePath); | |||
| } | |||
| @Override | |||
| @@ -341,6 +340,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| long sizeInBytes = file.getSize(); | |||
| String formattedSize = FileUtil.formatFileSize(sizeInBytes); | |||
| File targetFile = new File(path, file.getOriginalFilename()); | |||
| // 确保目录存在 | |||
| targetFile.getParentFile().mkdirs(); | |||
| // 保存文件到目标路径 | |||