@Override public Action getAction(long id, String ver, int projectId) { CheckIn check = workspaceDao.getVersion(projectId, ver); Gson gson = new Gson(); Project p = gson.fromJson(check.getProjectData(), Project.class); return p.findAction(id); }
@Override public boolean canUserAccessProject(long userId, int projectId) { User u = accountMgr.getUser(userId); Project p = projectMgr.getProject(projectId); return u.isAdmin() || p.isUserMember(userId); }
@Override public List<Project> getProjectList(User user, int curPageNum, int pageSize) { List<Project> projectList = projectDao.getProjectList(user, curPageNum, pageSize); for (Project p : projectList) { if (user.isUserInRole("admin") || p.getUser().getId() == user.getId()) p.setIsManagable(true); } return projectList; }
@Override public Project getProject(int id, String ver) { CheckIn check = workspaceDao.getVersion(id, ver); String projectData = check.getProjectData(); Gson gson = new Gson(); Project p = gson.fromJson(projectData, Project.class); p.setVersion(check.getVersion()); return p; }
@Override public void updateCache(int projectId) { Project project = getProject(projectId); for (Module module : project.getModuleList()) { for (Page page : module.getPageList()) { for (Action action : page.getActionList()) { updateActionCache(action); } } } }
public String switchVersion() { CheckIn check = workspaceMgr.getVersion(getVersionId()); workspaceMgr.prepareForVersionSwitch(check); projectMgr.updateProject( check.getProject().getId(), check.getProjectData(), "[]", new HashMap<Long, Long>()); Project project = projectMgr.getProject(check.getProject().getId()); String projectData = project.toString(Project.TO_STRING_TYPE.TO_PARAMETER); setJson("{\"projectData\":" + projectData + ", \"isOk\":true}"); project.setProjectData(projectData); projectMgr.updateProject(project); return SUCCESS; }
@Override public int removeProject(int id) { Project p = getProject(id); Group g = organizationDao.getGroup(p.getGroupId()); int result = projectDao.removeProject(id); if (g != null) { int pId = g.getProductionLineId(); if (pId > 0) { organizationDao.updateCountersInProductionLine(pId); } } return result; }
@Override public boolean canUserAccessPage(long userId, int pageId) { Page page = projectMgr.getPage(pageId); if (page != null) { Module module = page.getModule(); if (module != null) { Project project = module.getProject(); if (project != null) { return canUserAccessProject(userId, project.getId()); } } } return false; }
public String __init__() { // prevent repeated intialization of servcie if (SystemConstant.serviceInitialized) { return SUCCESS; } SystemConstant.serviceInitialized = true; List<Project> list = projectMgr.getProjectList(); for (Project p : list) { projectMgr.updateDoc(p.getId()); } return SUCCESS; }
/** * caution: no authentication so far * * @return * @throws Exception */ public String export() throws Exception { project = projectMgr.getProject(projectId); velocityEngine.init(); VelocityContext context = new VelocityContext(); context.put("project", project); Template template = null; try { template = velocityEngine.getTemplate("resource/export.vm", "UTF8"); } catch (ResourceNotFoundException rnfe) { rnfe.printStackTrace(); } catch (ParseErrorException pee) { pee.printStackTrace(); } catch (MethodInvocationException mie) { mie.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } StringWriter sw = new StringWriter(); template.merge(context, sw); fileInputStream = new ByteArrayInputStream(sw.toString().getBytes("UTF8")); // 记录操作日志 RapLog log = new RapLog(); log.setIp(org.apache.struts2.ServletActionContext.getRequest().getRemoteAddr()); log.setOperation("导出接口文档.项目名称:" + project.getName()); log.setUserName(getAccountMgr().getUser(getCurUserId()).getName()); logMgr.createLog(log); return SUCCESS; }
@Override public int addProject(Project project) { project.setUpdateTime(new Date()); project.setCreateDate(new Date()); List<User> usersInformed = new ArrayList<User>(); for (String account : project.getMemberAccountList()) { User user = accountDao.getUser(account); if (user != null) { boolean addSuccess = project.addMember(user); if (addSuccess) { usersInformed.add(user); } } } int result = projectDao.addProject(project); for (User u : usersInformed) { Notification o = new Notification(); o.setTypeId((short) 2); o.setTargetUser(project.getUser()); o.setUser(u); o.setParam1(new Integer(result).toString()); o.setParam2(project.getName()); accountMgr.addNotification(o); } Group g = organizationDao.getGroup(project.getGroupId()); if (g.getProductionLineId() > 0) { organizationDao.updateCountersInProductionLine(g.getProductionLineId()); } return result; }
@Override public List<Action> getMatchedActionList(int projectId, String pattern) { List<Action> actionList = projectDao.getMatchedActionList(projectId, pattern); if (actionList == null || actionList.size() == 0) { Project project = projectDao.getProject(projectId); if (project != null) { String ids = project.getRelatedIds(); if (ids != null && !ids.isEmpty()) { String[] arr = ids.split(","); for (String id : arr) { actionList = projectDao.getMatchedActionList(Integer.parseInt(id), pattern); if (actionList != null && actionList.size() != 0) { return actionList; } } } } } return actionList; }
public String myWorkspace() { if (!isUserLogined()) { plsLogin(); setRelativeReturnUrl("/workspace/myWorkspace.action?projectId=" + projectId); return LOGIN; } Project p = projectMgr.getProject(getProjectId()); if (p == null || p.getId() <= 0) { setErrMsg("该项目不存在或已被删除,会不会是亲这个链接保存的太久了呢?0 .0"); logger.error("Unexpected project id=%d", getProjectId()); return ERROR; } Workspace workspace = new Workspace(); workspace.setProject(p); setWorkspaceJsonString(workspace.toString()); setWorkspace(workspace); // modified by liweiguang 2016-1-18 setAccessable(getAccountMgr().canUserAccessProject(getCurUserId(), getProjectId())); setManageable(getAccountMgr().canUserManageProject(getCurUserId(), getProjectId())); // modified by liweiguang 2016-1-18 end return SUCCESS; }
public String checkIn() throws Exception { User curUser = getCurUser(); if (curUser == null) { setErrMsg(LOGIN_WARN_MSG); setIsOk(false); logger.error("Unlogined user trying to checkin and failed."); return JSON_ERROR; } if (!getAccountMgr().canUserManageProject(getCurUserId(), getId())) { setErrMsg("access deny"); setIsOk(false); logger.error( "User %s trying to checkedin project(id=$d) and denied.", getCurAccount(), getId()); return JSON_ERROR; } /*//save pb content String requestPBParameters = getRequestPBParameters(); String responsePBParameters = getResponsePBParameters(); System.out.println("requestPBParameters:"+ requestPBParameters); System.out.println("responsePBParameters:"+ responsePBParameters);*/ // update project Map<Long, Long> actionIdMap = new HashMap<Long, Long>(); projectMgr.updateProject(getId(), getProjectData(), getDeletedObjectListData(), actionIdMap); project = projectMgr.getProject(getId()); // generate one check-in of VSS mode submit CheckIn checkIn = new CheckIn(); checkIn.setCreateDate(new Date()); checkIn.setDescription(getDescription()); checkIn.setProject(project); checkIn.setProjectData(project.toString(Project.TO_STRING_TYPE.TO_PARAMETER)); checkIn.setTag(getTag()); checkIn.setUser(curUser); checkIn.setVersion(project.getVersion()); checkIn.versionUpgrade(getVersionPosition()); // after version upgrade, set back to project project.setVersion(checkIn.getVersion()); checkIn.setWorkspaceMode(Workspace.ModeType.VSS); workspaceMgr.addCheckIn(checkIn); // calculate JSON string for client project = projectMgr.getProject(getId()); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("{\"projectData\":" + checkIn.getProjectData()); stringBuilder.append(",\"checkList\":["); Iterator<CheckIn> iterator = project.getCheckInListOrdered().iterator(); while (iterator.hasNext()) { stringBuilder.append(iterator.next()); if (iterator.hasNext()) { stringBuilder.append(","); } } Gson g = new Gson(); stringBuilder .append("],\"actionIdMap\":") .append(g.toJson(actionIdMap)) .append(",\"isOk\":true}"); setJson(stringBuilder.toString()); // update project data project.setProjectData(checkIn.getProjectData()); projectMgr.updateProject(project); // unlock the workspace unlock(); // 记录操作日志 RapLog log = new RapLog(); log.setIp(org.apache.struts2.ServletActionContext.getRequest().getRemoteAddr()); log.setOperation("更新接口文档.项目名称:" + project.getName()); log.setUserName(getAccountMgr().getUser(getCurUserId()).getName()); logMgr.createLog(log); // notification for doc change /* for (User user : project.getUserList()) { Notification notification = new Notification(); notification.setParam1(new Integer(id).toString()); notification.setParam2(project.getName()); notification.setTypeId((short) 1); notification.setTargetUser(getCurUser()); notification.setUser(user); if (notification.getUser().getId() != getCurUserId()) getAccountMgr().addNotification(notification); } Notification notification = new Notification(); notification.setParam1(new Integer(id).toString()); notification.setParam2(project.getName()); notification.setTypeId((short) 1); notification.setTargetUser(getCurUser()); notification.setUser(project.getUser()); if (notification.getUser().getId() != getCurUserId()) getAccountMgr().addNotification(notification); */ // unfinished Callable<String> taskSub = new Callable<String>() { @Override public String call() throws Exception { try { // async update doc // projectMgr.updateDoc(id); // async update disableCache projectMgr.updateCache(id); // async update batch jsonschem added by liweiguang 2016-1-15 // System.out.println("in call....id:"+id); validationMgr.generateJsonSchemaByProject(id); // add by liweiguang 2016-03-01 validationMgr.generateMockdataByProject(id); // request jsonschema validationMgr.generateRequestSchemaByProject(id); } catch (Exception ex) { ex.printStackTrace(); } return null; } }; FutureTask<String> futureTask = new FutureTask<String>(taskSub); Thread asyncThread = new Thread(futureTask); asyncThread.start(); logger.info("Future task CHECK_IN running..."); return SUCCESS; }
public void update(Project project) { setIntroduction(project.getIntroduction()); setName(project.getName()); }
@Override public int updateProject(Project outerProject) { Project project = getProject(outerProject.getId()); project.setName(outerProject.getName()); project.setIntroduction(outerProject.getIntroduction()); project.setUpdateTime(new Date()); if (outerProject.getMemberAccountList() != null) { // adding new ones for (String account : outerProject.getMemberAccountList()) { User user = accountDao.getUser(account); if (user != null) { boolean addSuccess = project.addMember(user); if (addSuccess) { Notification o = new Notification(); o.setTypeId((short) 2); o.setTargetUser(outerProject.getUser()); o.setUser(user); o.setParam1(new Integer(outerProject.getId()).toString()); o.setParam2(outerProject.getName()); accountMgr.addNotification(o); } } } if (project.getUserList() != null) { // remove old ones List<User> userListToBeRemoved = new ArrayList<User>(); for (User user : project.getUserList()) { if (!outerProject.getMemberAccountList().contains(user.getAccount())) { userListToBeRemoved.add(user); } } for (User user : userListToBeRemoved) { project.removeMember(user); } } } return projectDao.updateProject(project); }