001: package hero.struts.actions;
002:
003: import java.io.IOException;
004: import javax.servlet.ServletException;
005: import javax.servlet.http.HttpServletRequest;
006: import javax.servlet.http.HttpSession;
007: import javax.servlet.http.HttpServletResponse;
008: import org.apache.struts.action.ActionError;
009: import org.apache.struts.action.ActionErrors;
010: import org.apache.struts.action.ActionForm;
011: import org.apache.struts.action.ActionMapping;
012: import org.apache.struts.action.ActionForward;
013: import java.util.*;
014:
015: import hero.interfaces.*;
016:
017: /**
018: * <strong>ProjectAction</strong>
019: * Action that allows the admin to add and clone projects
020: *
021: *@author Miguel Valdes Faura
022: */
023:
024: public class ProjectAction extends AbstStrutsActionBase {
025: public boolean authenticate(String username, String password) {
026: return (true);
027: }
028:
029: /**
030: * @param mapping The ActionMapping used to select this instance
031: * @param actionForm The optional AbstActionFormBase bean for this request (if any)
032: * @param request The HTTP request we are processing
033: * @param response The HTTP response we are creating
034: * @exception IOException if an input/output error occurs
035: * @exception ServletException if a servlet exception occurs
036: */
037: public ActionForward perform(ActionMapping mapping,
038: ActionForm form, HttpServletRequest request,
039: HttpServletResponse response) throws IOException,
040: ServletException {
041: ActionForward actionForward = mapping.findForward(ADMIN);
042: // Create the container for any errors that occur
043: ActionErrors errors = new ActionErrors();
044:
045: String action = request.getParameter("action");
046: HttpSession session = request.getSession();
047: String project = (String) session.getAttribute("projectname");
048:
049: if (!isCancelled(request)) {
050: if (action.equals("ProjectDetails")) {
051: try {
052:
053: hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
054: .getLocalHome();
055: hero.interfaces.ProjectSessionLocal projectsession = projecth
056: .create();
057: projectsession.initProject(project);
058:
059: request.getSession(true).setAttribute("project",
060: projectsession);
061: request.getSession(true).setAttribute("proAct",
062: "true");
063: request.getSession(true).setAttribute("edit",
064: "false");
065: actionForward = mapping.findForward(PROJECT);
066: } catch (Exception e2) {
067: errors.add("project_error", new ActionError(
068: "error.projectdetails.mismatch"));
069: actionForward = mapping.findForward(PROJECTDETAILS);
070: }
071: }
072: if (action.equals("configproject")) {
073: try {
074:
075: hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
076: .getLocalHome();
077: hero.interfaces.ProjectSessionLocal projectsession = projecth
078: .create();
079: projectsession.initProject(project);
080: session.setAttribute("hooks", new Vector(
081: projectsession.getHooks()));
082: session.setAttribute("properties", new Vector(
083: projectsession.getProperties()));
084: session.setAttribute("interHooks", new Vector(
085: projectsession.getInterHooks()));
086: Collection users = projectsession.getUsers();
087: Iterator iusers = users.iterator();
088:
089: Vector usersP = new Vector();
090: Vector rolesP = new Vector();
091: int i, j;
092:
093: while (iusers.hasNext()) {
094: String actualUser = (String) iusers.next();
095: Collection uRoles = projectsession
096: .getUserRoles(actualUser);
097: Collection pRoles = projectsession.getRoles();
098:
099: Iterator iuroles = uRoles.iterator();
100: while (iuroles.hasNext()) {
101: BnRoleLocal actualuRole = (BnRoleLocal) iuroles
102: .next();
103: Iterator iproles = pRoles.iterator();
104: while (iproles.hasNext()) {
105: BnRoleLocal actualpRole = (BnRoleLocal) iproles
106: .next();
107: if (actualuRole.getId() == actualpRole
108: .getId()) {
109: usersP.add(actualUser);
110: rolesP.add(actualuRole.getName());
111: }
112: }
113: }
114:
115: }
116: session.setAttribute("usersP", usersP);
117: session.setAttribute("rolesP", rolesP);
118:
119: actionForward = mapping.findForward(CONFIGPROJECT);
120: } catch (Exception e2) {
121: errors.add("project_error", new ActionError(
122: "error.projectdetails.mismatch"));
123: actionForward = mapping.findForward(PROJECTDETAILS);
124: }
125: }
126: if (action.equals("viewproject"))
127: actionForward = mapping.findForward(PROJECT);
128: }
129:
130: if (!errors.empty()) {
131: saveErrors(request, errors);
132: }
133:
134: // Forward control to the appropriate URI as determined by the action.
135: return (actionForward);
136: }
137: }
|