1 package hero.struts.actions; 2 3 import java.io.IOException ; 4 import javax.servlet.ServletException ; 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpSession ; 7 import javax.servlet.http.HttpServletResponse ; 8 import org.apache.struts.action.ActionError; 9 import org.apache.struts.action.ActionErrors; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionMapping; 12 import org.apache.struts.action.ActionForward; 13 14 import java.util.*; 15 16 import hero.interfaces.*; 17 import hero.util.*; 18 import hero.struts.forms.*; 19 20 26 27 public class ActivityAction extends AbstStrutsActionBase 28 { 29 public boolean authenticate(String username, String password) 30 { 31 return(true); 32 } 33 41 public ActionForward perform(ActionMapping mapping, ActionForm form, 42 HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException 43 { 44 45 ActionForward actionForward = mapping.findForward(EDITACTIVITY); 46 ActionErrors errors = new ActionErrors(); 48 49 String action = request.getParameter("action"); 50 HttpSession session = request.getSession(); 51 String name = (String )session.getAttribute("nodename"); 52 String project = (String )session.getAttribute("projectname"); 53 54 try 55 { 56 hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome)hero.interfaces.ProjectSessionUtil.getLocalHome(); 57 hero.interfaces.ProjectSessionLocal projectsession = projecth.create(); 58 projectsession.initProject(project); 59 60 if (!isCancelled(request)) 61 { 62 if (action.equals("Edit")) 63 { 64 request.getSession(true).setAttribute("edit", "true"); 65 actionForward = mapping.findForward(EDITACTIVITY); 67 } 68 if (action.equals("Add")) 69 { 70 71 ActivityForm activityForm = (ActivityForm) form; 72 String role = request.getParameter("role"); 73 String description = activityForm.getDescription(); 74 String anticipable = activityForm.getAnticipable(); 75 String type = activityForm.getType(); 76 String automatic = activityForm.getAutomatic(); 77 String deadline = activityForm.getDeadline()+" 00:00:00"; 78 79 java.sql.Timestamp dl = java.sql.Timestamp.valueOf(deadline); 80 if (dl.getTime() <= (new java.util.Date ()).getTime()) 81 errors.add("activity_error", new ActionError("error.deadlineIncorrect")); 82 else { 83 if (anticipable.equals("true")) 84 projectsession.setNodeAnticipable(name); 85 else 86 projectsession.setNodeTraditional(name); 87 88 projectsession.setNodeDeadline(name, java.sql.Timestamp.valueOf(deadline).getTime()); 89 projectsession.setNodeRole(name,role); 90 projectsession.setNodeDescription(name,description); 91 92 StrutsNodeValue node = projectsession.getStrutsNode(name); 93 request.getSession(true).setAttribute("node", node); 94 request.getSession(true).setAttribute("edges", projectsession.getStrutsNodeEdges(node.getName())); 95 96 } 97 request.getSession(true).setAttribute("edit", "false"); 98 actionForward = mapping.findForward(EDITACTIVITY); 99 } 100 101 if (action.equals("editactivity")) 102 { 103 104 StrutsNodeValue node = projectsession.getStrutsNode(name); 105 request.getSession(true).setAttribute("node", node); 106 request.getSession(true).setAttribute("edges", projectsession.getStrutsNodeEdges(node.getName())); 107 108 Vector roles = new Vector(); 109 Collection pRoles = projectsession.getRoles(); 110 Iterator iproles = pRoles.iterator(); 111 request.getSession(true).setAttribute("pRoles", pRoles); 112 113 while(iproles.hasNext()) 114 { 115 BnRoleLocal actualpRole = (BnRoleLocal)iproles.next(); 116 roles.add(actualpRole.getName()); 117 118 } 119 request.getSession(true).setAttribute("roles", roles); 120 121 Vector prop = new Vector(projectsession.getNodeProperties(node.getName())); 122 Vector hooks = new Vector(projectsession.getNodeHooks(node.getName())); 123 Vector interhooks = new Vector(projectsession.getNodeInterHooks(node.getName())); 124 request.getSession(true).setAttribute("properties", prop); 125 request.getSession(true).setAttribute("hooks", hooks); 126 request.getSession(true).setAttribute("interhooks", interhooks); 127 actionForward = mapping.findForward(EDITACTIVITY); 128 } 129 130 if (action.equals("viewactivity")) 131 actionForward = mapping.findForward(ACTIVITY); 132 } 133 else 134 request.getSession().setAttribute("edit", "false"); 135 }catch(Exception e){e.printStackTrace();errors.add("activity_error", new ActionError("error.deadline.mismatch"));} 136 137 if (!errors.empty()) { 138 saveErrors(request, errors); 139 } 140 141 return (actionForward); 143 } 144 } 145
| Popular Tags
|