예제 #1
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;
  }
예제 #2
0
  @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;
  }
예제 #3
0
  @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);
  }
예제 #4
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;
  }
예제 #5
0
 public void update(Project project) {
   setIntroduction(project.getIntroduction());
   setName(project.getName());
 }