KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > struts > actions > ActivityAction


1 package hero.struts.actions;
2
3 import java.io.IOException JavaDoc;
4 import javax.servlet.ServletException JavaDoc;
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.http.HttpSession JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
21  * <strong>ActivityAction</strong>
22  * Action that allows the user to edit activity properties
23  *
24  *@author Miguel Valdes Faura
25  */

26
27 public class ActivityAction extends AbstStrutsActionBase
28 {
29   public boolean authenticate(String JavaDoc username, String JavaDoc password)
30   {
31     return(true);
32   }
33     /**
34      * @param mapping The ActionMapping used to select this instance
35      * @param actionForm The optional AbstActionFormBase bean for this request (if any)
36      * @param request The HTTP request we are processing
37      * @param response The HTTP response we are creating
38      * @exception IOException if an input/output error occurs
39      * @exception ServletException if a servlet exception occurs
40      */

41     public ActionForward perform(ActionMapping mapping, ActionForm form,
42         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc
43     {
44
45         ActionForward actionForward = mapping.findForward(EDITACTIVITY);
46         // Create the container for any errors that occur
47
ActionErrors errors = new ActionErrors();
48
49     String JavaDoc action = request.getParameter("action");
50     HttpSession JavaDoc session = request.getSession();
51     String JavaDoc name = (String JavaDoc)session.getAttribute("nodename");
52     String JavaDoc project = (String JavaDoc)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             // Forward control to the specified 'success' URI specified in the structs-config.xml
66
actionForward = mapping.findForward(EDITACTIVITY);
67         }
68         if (action.equals("Add"))
69         {
70             
71             ActivityForm activityForm = (ActivityForm) form;
72             String JavaDoc role = request.getParameter("role");
73             String JavaDoc description = activityForm.getDescription();
74             String JavaDoc anticipable = activityForm.getAnticipable();
75             String JavaDoc type = activityForm.getType();
76             String JavaDoc automatic = activityForm.getAutomatic();
77             String JavaDoc deadline = activityForm.getDeadline()+" 00:00:00";
78             
79             java.sql.Timestamp JavaDoc dl = java.sql.Timestamp.valueOf(deadline);
80             if (dl.getTime() <= (new java.util.Date JavaDoc()).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 JavaDoc e){e.printStackTrace();errors.add("activity_error", new ActionError("error.deadline.mismatch"));}
136     
137     if (!errors.empty()) {
138         saveErrors(request, errors);
139         }
140     
141     // Forward control to the appropriate URI as determined by the action.
142
return (actionForward);
143     }
144 }
145
Popular Tags