Example #1
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;
  }
Example #2
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);
  }