Esempio n. 1
0
 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;
 }
Esempio n. 2
0
  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;
  }
Esempio n. 3
0
  /**
   * 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;
  }
Esempio n. 4
0
  @Override
  public boolean canUserAccessProject(long userId, int projectId) {
    User u = accountMgr.getUser(userId);
    Project p = projectMgr.getProject(projectId);

    return u.isAdmin() || p.isUserMember(userId);
  }
Esempio n. 5
0
 @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;
 }
Esempio n. 6
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public String lock() {
    long curUserId = getCurUserId();
    if (curUserId <= 0) {
      setIsOk(false);
      setErrMsg(LOGIN_WARN_MSG);
      return JSON_ERROR;
    }

    boolean isOk = false;
    if (isLocked(getId())) {
      // if the project is locked, find the locker
      User user = getLocker(getId());
      if (!user.getAccount().equals(getCurAccount())) {
        setJson("{\"isOk\":false, \"errMsg\":\"该项目目前正被" + user.getName() + "锁定.\"}");
      } else {
        // user request lock a locked project
        // which is locked by himself, so let him go
        isOk = true;
      }

    } else {
      // else, lock the project, than let him go.
      Map app = ContextManager.getApplication();
      if (app.get(ContextManager.KEY_PROJECT_LOCK_LIST) == null) {
        app.put(ContextManager.KEY_PROJECT_LOCK_LIST, new HashMap());
      }
      Map projectLockList = (Map) app.get(ContextManager.KEY_PROJECT_LOCK_LIST);
      if (projectLockList.get(curUserId) == null) {
        projectLockList.put(curUserId, getId());
        // System.out.println("user[" + curUserId + "] locked project["+
        // getId() + "]");
      }
      isOk = true;
    }
    if (isOk) {
      setJson(
          "{\"isOk\":true, \"projectData\":"
              + projectMgr.getProject(getId()).getProjectData()
              + "}");
    }
    return SUCCESS;
  }
Esempio n. 7
0
  public String onlineDocs() 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);

    return SUCCESS;
  }
Esempio n. 8
0
  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;
  }
Esempio n. 9
0
  private boolean groupCanBeDeleted(int groupId) {
    List<Project> list = projectMgr.getProjectListByGroup(groupId);

    return list == null || list.size() == 0;
  }