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 hero.interfaces.*;
014:
015: /**
016: * <strong>NodeAction</strong>
017: * Action that allows the user to add a new node in the current project
018: *
019: *@author Miguel Valdes Faura
020: */
021: public class NodeAction extends AbstStrutsActionBase {
022:
023: public boolean authenticate(String username, String password) {
024: return (true);
025: }
026:
027: /**
028: * @param mapping The ActionMapping used to select this instance
029: * @param actionForm The optional AbstActionFormBase bean for this request (if any)
030: * @param request The HTTP request we are processing
031: * @param response The HTTP response we are creating
032: * @exception IOException if an input/output error occurs
033: * @exception ServletException if a servlet exception occurs
034: */
035: public ActionForward perform(ActionMapping mapping,
036: ActionForm form, HttpServletRequest request,
037: HttpServletResponse response) throws IOException,
038: ServletException {
039:
040: ActionForward actionForward = mapping.findForward(PROJECT);
041: // Create the container for any errors that occur
042: ActionErrors errors = new ActionErrors();
043:
044: String action = request.getParameter("nodeAction");
045: HttpSession session = request.getSession();
046: String project = (String) session.getAttribute("projectname");
047: String userName = (String) session.getAttribute("username");
048:
049: try {
050: hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
051: .getLocalHome();
052: hero.interfaces.ProjectSessionLocal projectsession = projecth
053: .create();
054: projectsession.initProject(project);
055:
056: if (!isCancelled(request)) {
057: if (action.equals("Edit")) {
058: // Forward control to the specified 'success' URI specified in the structs-config.xml
059: actionForward = mapping.findForward(PROJECT);
060: }
061: if (action.equals("Activity")) {
062: String name = request.getParameter("nodename");
063: hero.util.StrutsNodeValue node = projectsession
064: .getStrutsNode(name);
065: request.getSession(true).setAttribute("node", node);
066:
067: /*if (!node.getDeadline().equals("Deadline needed"))
068: {
069: java.sql.Timestamp deadline = java.sql.Timestamp.valueOf(node.getDeadline());
070: if (deadline.getTime() <= (new java.util.Date()).getTime() && !node.getState().equals("TERMINATED"));
071: errors.add("deadline_error", new ActionError("error.deadline"));
072: }*/
073:
074: request.getSession(true).setAttribute("nodename",
075: name);
076:
077: // Forward control to the specified 'success' URI specified in the structs-config.xml
078: actionForward = mapping.findForward(ACTIVITY);
079: }
080:
081: if (action.equals("Add")) {
082: String nodeName = request.getParameter("name");
083: if (nodeName.length() != 0) {
084: projectsession.addNode(nodeName, 1);
085: //request.setAttribute("project", projectsession);
086: request.getSession(true).setAttribute(
087: "project", projectsession);
088: // Forward control to the specified 'success' URI specified in the structs-config.xml
089: actionForward = mapping.findForward(PROJECT);
090: } else
091: errors.add("node_error", new ActionError(
092: "error.node.mismatch"));
093: }
094: if (action.equals("Delete")) {
095: String nodeName = request.getParameter("nodename");
096: projectsession.deleteNode(nodeName);
097: request.getSession(true).setAttribute("project",
098: projectsession);
099:
100: // Forward control to the specified 'success' URI specified in the structs-config.xml
101: actionForward = mapping.findForward(PROJECT);
102: }
103: }
104: // }catch(NodeExecutingException e){errors.add("node_error", new ActionError("error.nodeexecuting.mismatch"));
105: } catch (Exception e1) {
106: errors.add("node_error", new ActionError(
107: "error.nodeexisting.mismatch"));
108: }
109:
110: if (!errors.empty()) {
111: saveErrors(request, errors);
112: }
113:
114: // Forward control to the appropriate URI as determined by the action.
115: return (actionForward);
116: }
117:
118: }
|