/**
  * Adds a feature to the Account attribute of the ProjectUtils class
  *
  * @param db The feature to be added to the Account attribute
  * @param projectId The feature to be added to the Account attribute
  * @param orgId The feature to be added to the Account attribute
  * @throws SQLException Description of the Exception
  */
 public static synchronized void addAccount(Connection db, int projectId, int orgId)
     throws SQLException {
   OrganizationList organizationList = new OrganizationList();
   organizationList.setProjectId(projectId);
   organizationList.setOrgId(orgId);
   organizationList.buildList(db);
   if (organizationList.size() == 0) {
     int i = 0;
     int seqId = DatabaseUtils.getNextSeq(db, "project_accounts_id_seq");
     PreparedStatement pst =
         db.prepareStatement(
             "INSERT INTO project_accounts "
                 + "("
                 + (seqId > -1 ? "id, " : "")
                 + "project_id, org_id) "
                 + "VALUES ("
                 + (seqId > -1 ? "?, " : "")
                 + "?, ?) ");
     if (seqId > -1) {
       pst.setInt(++i, seqId);
     }
     pst.setInt(++i, projectId);
     pst.setInt(++i, orgId);
     pst.execute();
     pst.close();
   }
 }
  /**
   * Description of the Method
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandProjects(ActionContext context) {
    // Parameters
    String value = context.getRequest().getParameter("source");
    String search = context.getRequest().getParameter("search");
    StringTokenizer st = new StringTokenizer(value, "|");
    String source = st.nextToken();
    String status = st.nextToken();
    // Build the list
    Connection db = null;
    ProjectList projects = new ProjectList();
    try {
      db = getConnection(context);
      if ("my".equals(source) || "all".equals(source)) {
        projects.setProjectsForUser(getUserId(context));
        projects.setIncludeGuestProjects(false);
        if ("open".equals(status)) {
          // Check if open or closed
          projects.setOpenProjectsOnly(true);
        } else {
          projects.setClosedProjectsOnly(true);
        }
        projects.buildList(db);
        context.getRequest().setAttribute("projectList", projects);
        return "ProjectsOK";
      } else if ("dept".equals(source) && "all".equals(status)) {
        LookupList departmentList = new LookupList(db, "lookup_department");
        departmentList.addItem(0, "Without a department");
        context.getRequest().setAttribute("departments", departmentList);
        return "MakeDepartmentListOK";
      } else if ("acct".equals(source) && "all".equals(status)) {
        OrganizationList organizationList = new OrganizationList();
        organizationList.setName('%' + search + '%');
        organizationList.buildShortList(db);
        context.getRequest().setAttribute("orgList", organizationList);
        return "MakeOrgListOK";
      }
    } catch (Exception e) {

    } finally {
      freeConnection(context, db);
    }
    return null;
  }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandItems(ActionContext context) {
   // Parameters
   String value = context.getRequest().getParameter("source");
   StringTokenizer st = new StringTokenizer(value, "|");
   String source = st.nextToken();
   String status = st.nextToken();
   String id = st.nextToken();
   String orgId = null;
   if (st.hasMoreTokens()) {
     orgId = st.nextToken();
   }
   Connection db = null;
   try {
     db = getConnection(context);
     if ("my".equals(source) || "all".equals(source)) {
       // Load the project and check permissions
       Project thisProject = new Project(db, Integer.parseInt(id), this.getUserRange(context));
       thisProject.buildPermissionList(db);
       // Prepare list of team members
       TeamMemberList team = new TeamMemberList();
       team.setProjectId(Integer.parseInt(id));
       // Check permission first
       if (hasProjectAccess(context, db, thisProject, "project-team-view")) {
         team.buildList(db);
       }
       context.getRequest().setAttribute("team", team);
       return ("MakeTeamMemberListOK");
     }
     if ("dept".equals(source) && "all".equals(status)) {
       // Load departments and get the contacts
       UserList users = new UserList();
       users.setDepartment(Integer.parseInt(id));
       users.setRoleType(Constants.ROLETYPE_REGULAR); // fetch only regular users
       users.setSiteId(this.getUserSiteId(context));
       users.buildList(db);
       users = UserList.sortEnabledUsers(users, new UserList());
       context.getRequest().setAttribute("UserList", users);
       return ("MakeUserListOK");
     }
     if ("acct".equals(source) && "all".equals(status)) {
       // if account is associated with the project build reguluar and portal users,
       // otherwise build only regular users.
       boolean nonPortalUsersOnly = false;
       OrganizationList organizationList = new OrganizationList();
       organizationList.setProjectId(id);
       organizationList.setOrgId(orgId);
       organizationList.buildList(db);
       if (organizationList.isEmpty()) {
         nonPortalUsersOnly = true;
       }
       ContactList contactList = new ContactList();
       contactList.setOrgId(orgId);
       contactList.setIncludeUsersOnly(true);
       contactList.setWithAccountsOnly(true);
       contactList.setPortalUsersOnly(nonPortalUsersOnly ? Constants.FALSE : Constants.UNDEFINED);
       contactList.buildList(db);
       context.getRequest().setAttribute("contactList", contactList);
       return ("MakeContactListOK");
     }
   } catch (Exception e) {
     e.printStackTrace(System.out);
   } finally {
     freeConnection(context, db);
   }
   return null;
 }