예제 #1
0
 @SuppressWarnings("rawtypes")
 private User getLocker(int projectId) {
   Map app = ContextManager.getApplication();
   Map projectLockList = (Map) app.get(ContextManager.KEY_PROJECT_LOCK_LIST);
   if (projectLockList != null) {
     long userId = (Long) MapUtils.getKeyByValue(projectLockList, projectId);
     User user = getAccountMgr().getUser(userId);
     return user;
   }
   return null;
 }
예제 #2
0
 @SuppressWarnings({"rawtypes"})
 public String unlock() {
   if (isLocked(getId())) {
     Map app = ContextManager.getApplication();
     Map projectLockList = (Map) app.get(ContextManager.KEY_PROJECT_LOCK_LIST);
     if (projectLockList == null) return SUCCESS;
     long userId = super.getCurUserId();
     int projectId = (Integer) projectLockList.get(userId);
     projectLockList.remove(userId);
     logger.info("user[%d] unlock project[%d]", userId, projectId);
   }
   return SUCCESS;
 }
예제 #3
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;
  }
예제 #4
0
 @SuppressWarnings("rawtypes")
 private boolean isLocked(int projectId) {
   Map app = ContextManager.getApplication();
   Map projectLockList = (Map) app.get(ContextManager.KEY_PROJECT_LOCK_LIST);
   return projectLockList != null && projectLockList.containsValue(projectId) ? true : false;
 }