|
|
@@ -46,7 +46,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
|
private final ApplicationProperties properties;
|
|
|
|
|
|
- private final static Logger log = LoggerFactory.getLogger(ProjectServiceImpl.class);
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ProjectServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
public ProjectServiceImpl(UserService userService, ProjectMapper projectMapper, ProjectRelatedMapper projectRelatedMapper, UserMapper userMapper, SeecoderGitlabApi seecoderGitlabApi, ApplicationProperties properties) {
|
|
|
@@ -65,22 +65,27 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
try {
|
|
|
projects = seecoderGitlabApi.getAllProjectsByUserId(userId);
|
|
|
|
|
|
- //同步数据,有可能gitlab那边有的项目我们这边没有
|
|
|
- List<ProjectPO> pos = projects.stream().filter(x -> projectMapper.getProjectById(x.getProjectId()) == null).map(ProjectPO::new).collect(Collectors.toList());
|
|
|
- if (pos.size() != 0) {
|
|
|
- for (ProjectPO po : pos) {
|
|
|
- seecoderGitlabApi.addWebHook(po.getId(), properties.getGitlab().getWebhookProxy(), true, false, false);
|
|
|
- log.info("项目Id是{},名称是{}",po.getId(),po.getName());
|
|
|
- projectMapper.insertProject(po);
|
|
|
- log.info("同步成功");
|
|
|
- }
|
|
|
+ List<ProjectPO> missingProjects = projects.stream()
|
|
|
+ .filter(x -> projectMapper.getProjectById(x.getProjectId()) == null)
|
|
|
+ .map(ProjectPO::new)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (ProjectPO project : missingProjects) {
|
|
|
+ seecoderGitlabApi.addWebHook(project.getId(), properties.getGitlab().getWebhookProxy(), true, false, false);
|
|
|
+ log.info("同步项目, projectId={}, projectName={}", project.getId(), project.getName());
|
|
|
+ projectMapper.insertProject(project);
|
|
|
+ log.info("项目同步成功, projectId={}", project.getId());
|
|
|
}
|
|
|
} catch (SeecoderGitlabException e) {
|
|
|
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "获取项目列表失败", e);
|
|
|
}
|
|
|
- List<Integer> projectIds = projects.stream().map(com.nju.edu.gitlab.vo.ProjectVO::getProjectId).collect(Collectors.toList());
|
|
|
|
|
|
- return projectIds.size() == 0 ? new ArrayList<>() : projectMapper.selectByIds(projectIds).stream().map(ProjectVO::new).collect(Collectors.toList());
|
|
|
+ List<Integer> projectIds = projects.stream()
|
|
|
+ .map(com.nju.edu.gitlab.vo.ProjectVO::getProjectId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return projectIds.isEmpty()
|
|
|
+ ? new ArrayList<>()
|
|
|
+ : projectMapper.selectByIds(projectIds).stream().map(ProjectVO::new).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -94,15 +99,21 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
ProjectPO po = new ProjectPO();
|
|
|
BeanUtils.copyProperties(vo, po);
|
|
|
try {
|
|
|
- if(vo.getVisibility()==null) vo.setVisibility("private");
|
|
|
- com.nju.edu.gitlab.vo.ProjectVO project = seecoderGitlabApi.createPrivateProject(po.getName(), vo.getVisibility().equals("public")?VisibilityForm.PUBLIC:VisibilityForm.PRIVATE, UserService.loginUser().getId());
|
|
|
- log.info("项目可见性为:{}", vo.getVisibility());
|
|
|
+ String visibility = vo.getVisibility() == null ? "private" : vo.getVisibility();
|
|
|
+ vo.setVisibility(visibility);
|
|
|
+ com.nju.edu.gitlab.vo.ProjectVO project = seecoderGitlabApi.createPrivateProject(
|
|
|
+ po.getName(),
|
|
|
+ "public".equals(visibility) ? VisibilityForm.PUBLIC : VisibilityForm.PRIVATE,
|
|
|
+ UserService.loginUser().getId()
|
|
|
+ );
|
|
|
+ log.info("项目可见性为:{}", visibility);
|
|
|
po.setId(project.getProjectId());
|
|
|
po.setGitRemoteUrl(project.getWebUrl());
|
|
|
} catch (SeecoderGitlabException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("创建项目失败, projectName={}", po.getName(), e);
|
|
|
throw new ServiceException("创建项目时发生异常[project id:" + po.getId() + ", " + e.getMessage() + "]", e);
|
|
|
}
|
|
|
+
|
|
|
projectMapper.insertProject(po);
|
|
|
try {
|
|
|
seecoderGitlabApi.addWebHook(po.getId(), properties.getGitlab().getWebhookProxy(), true, false, false);
|
|
|
@@ -110,65 +121,49 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
throw new ServiceException("给项目添加webhook发生异常[project id:" + po.getId() + ", " + e.getMessage() + "]", e);
|
|
|
}
|
|
|
|
|
|
- //ANA 日志需要打出创建项目的基础信息
|
|
|
- try{
|
|
|
+ try {
|
|
|
JSONObject object = new JSONObject();
|
|
|
- object.put("user_id",userService.getLoginUser().getId());
|
|
|
- object.put("project_id",po.getId());
|
|
|
- object.put("project_name",po.getName());
|
|
|
- object.put("description",po.getDescription());
|
|
|
-
|
|
|
- String data = JSONObject.toJSONString(object);
|
|
|
- LogTrackingUtil.log(data,OpType.CREATE_PROJECT);
|
|
|
- }catch (Exception e){}
|
|
|
+ object.put("user_id", userService.getLoginUser().getId());
|
|
|
+ object.put("project_id", po.getId());
|
|
|
+ object.put("project_name", po.getName());
|
|
|
+ object.put("description", po.getDescription());
|
|
|
+ LogTrackingUtil.log(JSONObject.toJSONString(object), OpType.CREATE_PROJECT);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("操作日志记录失败, action=CREATE_PROJECT, projectId={}", po.getId(), e);
|
|
|
+ }
|
|
|
|
|
|
return new ProjectVO(po);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addMember(Integer projectId, String phone) throws ServiceException {
|
|
|
Integer userId = userMapper.selectIdByPhone(phone);
|
|
|
- if(userId == null){
|
|
|
+ if (userId == null) {
|
|
|
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "该手机号不存在对应用户");
|
|
|
}
|
|
|
- try {
|
|
|
- seecoderGitlabApi.addAuthorization(projectId, userId, AccessLevelForm.MASTER);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "添加项目权限失败", e);
|
|
|
- }
|
|
|
- //ANA 日志需要打出加入的成员信息
|
|
|
- try{
|
|
|
- JSONObject object = new JSONObject();
|
|
|
-
|
|
|
- object.put("project_id",projectId);
|
|
|
- object.put("user_id",userId);
|
|
|
-
|
|
|
- String data = JSONObject.toJSONString(object);
|
|
|
- LogTrackingUtil.log(data, OpType.ADD_MEMBER);
|
|
|
- }catch (Exception e){}
|
|
|
+ addMember(projectId, userId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addMember(Integer projectId, Integer userId) throws ServiceException {
|
|
|
-// Integer userId = userMapper.selectIdByPhone(phone);
|
|
|
- if(userId == null){
|
|
|
+ if (userId == null) {
|
|
|
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "该手机号不存在对应用户");
|
|
|
}
|
|
|
+
|
|
|
try {
|
|
|
seecoderGitlabApi.addAuthorization(projectId, userId, AccessLevelForm.MASTER);
|
|
|
} catch (Exception e) {
|
|
|
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "添加项目权限失败", e);
|
|
|
}
|
|
|
- //ANA 日志需要打出加入的成员信息
|
|
|
- try{
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- object.put("project_id",projectId);
|
|
|
- object.put("user_id",userId);
|
|
|
|
|
|
- String data = JSONObject.toJSONString(object);
|
|
|
- LogTrackingUtil.log(data, OpType.ADD_MEMBER);
|
|
|
- }catch (Exception e){}
|
|
|
+ try {
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("project_id", projectId);
|
|
|
+ object.put("user_id", userId);
|
|
|
+ LogTrackingUtil.log(JSONObject.toJSONString(object), OpType.ADD_MEMBER);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("操作日志记录失败, action=ADD_MEMBER, projectId={}, userId={}", projectId, userId, e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -199,23 +194,22 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
return "不可将本项目与自身关联!";
|
|
|
}
|
|
|
List<ProjectRelatedPO> projectRelatedPOS = projectRelatedMapper.isExistRelated(projectId, result[0].intValue());
|
|
|
- if (projectRelatedPOS.size() != 0) {
|
|
|
+ if (!projectRelatedPOS.isEmpty()) {
|
|
|
return "该项目已与目标项目关联过,无须重复关联";
|
|
|
}
|
|
|
projectRelatedMapper.insert(ProjectRelatedPO.builder()
|
|
|
.projectIdA(projectId)
|
|
|
.projectIdB(result[0].intValue()).build(), "id");
|
|
|
|
|
|
- //ANA 日志需要打出关联项目的id
|
|
|
- try{
|
|
|
+ try {
|
|
|
JSONObject object = new JSONObject();
|
|
|
- object.put("user_id",userService.getLoginUser().getId());
|
|
|
- object.put("projectA_id",projectId);
|
|
|
- object.put("projectB_id",result[0].intValue());
|
|
|
-
|
|
|
- String data = JSONObject.toJSONString(object);
|
|
|
- LogTrackingUtil.log(data, OpType.RELATE_PROJECT);
|
|
|
- }catch (Exception e){}
|
|
|
+ object.put("user_id", userService.getLoginUser().getId());
|
|
|
+ object.put("projectA_id", projectId);
|
|
|
+ object.put("projectB_id", result[0].intValue());
|
|
|
+ LogTrackingUtil.log(JSONObject.toJSONString(object), OpType.RELATE_PROJECT);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("操作日志记录失败, action=RELATE_PROJECT, projectAId={}, projectBId={}", projectId, result[0].intValue(), e);
|
|
|
+ }
|
|
|
|
|
|
return "关联项目成功";
|
|
|
}
|
|
|
@@ -229,6 +223,6 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
int projectIdB = projectRelatedPO.getProjectIdB();
|
|
|
projectIds.add(projectIdA == projectId ? projectIdB : projectIdA);
|
|
|
}
|
|
|
- return projectIds.size() == 0 ? new ArrayList<>() : projectMapper.selectByIds(projectIds).stream().map(ProjectVO::new).collect(Collectors.toList());
|
|
|
+ return projectIds.isEmpty() ? new ArrayList<>() : projectMapper.selectByIds(projectIds).stream().map(ProjectVO::new).collect(Collectors.toList());
|
|
|
}
|
|
|
}
|