001: /*
002: * Created on September 2004, the 16th
003: * By the Message Center Team
004: */
005: package mc.formgenerator.servlets.bonita;
006:
007: import hero.interfaces.ProjectSessionLocalHome;
008: import hero.interfaces.UserSessionLocalHome;
009: import hero.util.HeroException;
010: import hero.util.StrutsNodeValue;
011:
012: import java.util.Collection;
013: import java.util.Hashtable;
014: import java.util.Iterator;
015: import java.util.Vector;
016:
017: import javax.ejb.CreateException;
018: import javax.naming.NamingException;
019:
020: import mc.formgenerator.bonita.Worklist;
021:
022: /**
023: * Model for servlet ServletWorkList to give worklist to display.
024: *
025: */
026: public class ModelWorkList {
027:
028: //The worklists list
029: private Vector workList;
030:
031: /**
032: * Default constructor for our class
033: *
034: */
035: public ModelWorkList() {
036: this .setWorkList(new Vector());
037: }
038:
039: /**
040: * For each project of the user, store its worklist
041: * @throws CreateException
042: * @throws NamingException
043: * @throws HeroException
044: */
045: public void process() throws CreateException, NamingException,
046: HeroException {
047:
048: //Get project session bean
049: hero.interfaces.UserSessionLocalHome userh = (UserSessionLocalHome) hero.interfaces.UserSessionUtil
050: .getLocalHome();
051: hero.interfaces.UserSessionLocal usersession = userh.create();
052: hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
053: .getLocalHome();
054:
055: //Get project list
056: Collection projects = usersession.getProjectList();
057: Iterator i = projects.iterator();
058:
059: while (i.hasNext()) {
060:
061: Worklist currentWorkList = new Worklist();
062:
063: //Get current project name
064: String currentProject = ((hero.interfaces.BnProjectLightValue) i
065: .next()).getName();
066:
067: //Current project todo list name
068: Vector todoListNames = new Vector(usersession
069: .getToDoList(currentProject));
070:
071: //Current activity list for the current project
072: Vector activityListNames = new Vector(usersession
073: .getActivityList(currentProject));
074:
075: Hashtable readyList = new Hashtable();
076: Hashtable executingList = new Hashtable();
077: Hashtable anticipableList = new Hashtable();
078: Hashtable anticipatingList = new Hashtable();
079:
080: //Setting worklist values
081: if (todoListNames.size() != 0
082: || activityListNames.size() != 0) {
083:
084: //Setting project name
085: currentWorkList.setProjectName(currentProject);
086:
087: //Get project session bean
088: hero.interfaces.ProjectSessionLocal projectsession = projecth
089: .create();
090: projectsession.initProject(currentProject);
091:
092: int j = 0;
093: while (j < todoListNames.size()) {
094: StrutsNodeValue stnt = new StrutsNodeValue();
095: stnt.setProjectName(currentProject);
096: stnt
097: .setName(((hero.interfaces.BnNodeValue) projectsession
098: .getNodeValue((String) todoListNames
099: .elementAt(j))).getName());
100:
101: if (((hero.interfaces.BnNodeValue) projectsession
102: .getNodeValue((String) todoListNames
103: .elementAt(j))).getState() == hero.interfaces.Constants.Nd.READY)
104: readyList.put((String) todoListNames
105: .elementAt(j), stnt);
106: else
107: anticipableList.put((String) todoListNames
108: .elementAt(j), stnt);
109: j++;
110: }
111:
112: j = 0;
113: while (j < activityListNames.size()) {
114: StrutsNodeValue stna = new StrutsNodeValue();
115: stna.setProjectName(currentProject);
116: stna
117: .setName(((hero.interfaces.BnNodeValue) projectsession
118: .getNodeValue((String) activityListNames
119: .elementAt(j))).getName());
120:
121: if (((hero.interfaces.BnNodeValue) projectsession
122: .getNodeValue((String) activityListNames
123: .elementAt(j))).getState() == hero.interfaces.Constants.Nd.ANTICIPATING)
124: anticipatingList.put((String) activityListNames
125: .elementAt(j), stna);
126:
127: else {
128: executingList.put((String) activityListNames
129: .elementAt(j), stna);
130: }
131: j++;
132: }
133:
134: //Initializing class attribute
135: currentWorkList.setTodoListReady(readyList);
136: currentWorkList.setTodoListAnti(anticipableList);
137: currentWorkList.setActivityListAnti(anticipatingList);
138: currentWorkList.setActivityListExec(executingList);
139: this .getWorkList().add(currentWorkList);
140: }
141: }
142: }
143:
144: /**
145: * Get the workLists list
146: * @return the workLists list as Vector
147: */
148: public Vector getWorkList() {
149: return workList;
150: }
151:
152: /**
153: * Set the workLists list
154: * @param workList the workLists list to set
155: */
156: public void setWorkList(Vector workList) {
157: this.workList = workList;
158: }
159: }
|