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:
014: import java.util.*;
015:
016: import hero.interfaces.*;
017: import hero.util.*;
018: import hero.struts.forms.*;
019:
020: /**
021: * <strong>ActivityAction</strong>
022: * Action that allows the user to edit activity properties
023: *
024: *@author Miguel Valdes Faura
025: */
026:
027: public class ActivityAction extends AbstStrutsActionBase {
028: public boolean authenticate(String username, String password) {
029: return (true);
030: }
031:
032: /**
033: * @param mapping The ActionMapping used to select this instance
034: * @param actionForm The optional AbstActionFormBase bean for this request (if any)
035: * @param request The HTTP request we are processing
036: * @param response The HTTP response we are creating
037: * @exception IOException if an input/output error occurs
038: * @exception ServletException if a servlet exception occurs
039: */
040: public ActionForward perform(ActionMapping mapping,
041: ActionForm form, HttpServletRequest request,
042: HttpServletResponse response) throws IOException,
043: ServletException {
044:
045: ActionForward actionForward = mapping.findForward(EDITACTIVITY);
046: // Create the container for any errors that occur
047: ActionErrors errors = new ActionErrors();
048:
049: String action = request.getParameter("action");
050: HttpSession session = request.getSession();
051: String name = (String) session.getAttribute("nodename");
052: String project = (String) session.getAttribute("projectname");
053:
054: try {
055: hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
056: .getLocalHome();
057: hero.interfaces.ProjectSessionLocal projectsession = projecth
058: .create();
059: projectsession.initProject(project);
060:
061: if (!isCancelled(request)) {
062: if (action.equals("Edit")) {
063: request.getSession(true).setAttribute("edit",
064: "true");
065: // Forward control to the specified 'success' URI specified in the structs-config.xml
066: actionForward = mapping.findForward(EDITACTIVITY);
067: }
068: if (action.equals("Add")) {
069:
070: ActivityForm activityForm = (ActivityForm) form;
071: String role = request.getParameter("role");
072: String description = activityForm.getDescription();
073: String anticipable = activityForm.getAnticipable();
074: String type = activityForm.getType();
075: String automatic = activityForm.getAutomatic();
076: String deadline = activityForm.getDeadline()
077: + " 00:00:00";
078:
079: java.sql.Timestamp dl = java.sql.Timestamp
080: .valueOf(deadline);
081: if (dl.getTime() <= (new java.util.Date())
082: .getTime())
083: errors.add("activity_error", new ActionError(
084: "error.deadlineIncorrect"));
085: else {
086: if (anticipable.equals("true"))
087: projectsession.setNodeAnticipable(name);
088: else
089: projectsession.setNodeTraditional(name);
090:
091: projectsession.setNodeDeadline(name,
092: java.sql.Timestamp.valueOf(deadline)
093: .getTime());
094: projectsession.setNodeRole(name, role);
095: projectsession.setNodeDescription(name,
096: description);
097:
098: StrutsNodeValue node = projectsession
099: .getStrutsNode(name);
100: request.getSession(true).setAttribute("node",
101: node);
102: request.getSession(true).setAttribute(
103: "edges",
104: projectsession.getStrutsNodeEdges(node
105: .getName()));
106:
107: }
108: request.getSession(true).setAttribute("edit",
109: "false");
110: actionForward = mapping.findForward(EDITACTIVITY);
111: }
112:
113: if (action.equals("editactivity")) {
114:
115: StrutsNodeValue node = projectsession
116: .getStrutsNode(name);
117: request.getSession(true).setAttribute("node", node);
118: request.getSession(true).setAttribute(
119: "edges",
120: projectsession.getStrutsNodeEdges(node
121: .getName()));
122:
123: Vector roles = new Vector();
124: Collection pRoles = projectsession.getRoles();
125: Iterator iproles = pRoles.iterator();
126: request.getSession(true).setAttribute("pRoles",
127: pRoles);
128:
129: while (iproles.hasNext()) {
130: BnRoleLocal actualpRole = (BnRoleLocal) iproles
131: .next();
132: roles.add(actualpRole.getName());
133:
134: }
135: request.getSession(true).setAttribute("roles",
136: roles);
137:
138: Vector prop = new Vector(projectsession
139: .getNodeProperties(node.getName()));
140: Vector hooks = new Vector(projectsession
141: .getNodeHooks(node.getName()));
142: Vector interhooks = new Vector(projectsession
143: .getNodeInterHooks(node.getName()));
144: request.getSession(true).setAttribute("properties",
145: prop);
146: request.getSession(true).setAttribute("hooks",
147: hooks);
148: request.getSession(true).setAttribute("interhooks",
149: interhooks);
150: actionForward = mapping.findForward(EDITACTIVITY);
151: }
152:
153: if (action.equals("viewactivity"))
154: actionForward = mapping.findForward(ACTIVITY);
155: } else
156: request.getSession().setAttribute("edit", "false");
157: } catch (Exception e) {
158: e.printStackTrace();
159: errors.add("activity_error", new ActionError(
160: "error.deadline.mismatch"));
161: }
162:
163: if (!errors.empty()) {
164: saveErrors(request, errors);
165: }
166:
167: // Forward control to the appropriate URI as determined by the action.
168: return (actionForward);
169: }
170: }
|