KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > web > actions > MoveIssueAction


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.web.actions;
20
21 import java.io.*;
22 import java.rmi.*;
23 import java.util.*;
24 import javax.ejb.*;
25 import javax.rmi.*;
26 import javax.naming.*;
27 import javax.servlet.*;
28 import javax.servlet.http.*;
29
30 import org.apache.commons.beanutils.*;
31 import org.apache.struts.action.*;
32 import org.apache.struts.upload.*;
33 import org.apache.struts.util.*;
34
35 import cowsultants.itracker.ejb.client.exceptions.*;
36 import cowsultants.itracker.ejb.client.interfaces.*;
37 import cowsultants.itracker.ejb.client.models.*;
38 import cowsultants.itracker.ejb.client.resources.*;
39 import cowsultants.itracker.ejb.client.util.*;
40 import cowsultants.itracker.web.util.*;
41
42
43 public class MoveIssueAction extends ITrackerAction {
44
45     public MoveIssueAction() {
46     }
47
48     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
49         ActionErrors errors = new ActionErrors();
50
51         if(! isLoggedIn(request, response)) {
52             return mapping.findForward("login");
53         }
54         if(! isTokenValid(request)) {
55             Logger.logDebug("Invalid request token while creating issue.");
56             return mapping.findForward("index");
57         }
58         resetToken(request);
59
60         try {
61             InitialContext ic = new InitialContext();
62             Object JavaDoc ihRef = ic.lookup("java:comp/env/" + IssueHandler.JNDI_NAME);
63             IssueHandlerHome ihHome = (IssueHandlerHome) PortableRemoteObject.narrow(ihRef, IssueHandlerHome.class);
64             IssueHandler ih = ihHome.create();
65
66             Integer JavaDoc issueId = (Integer JavaDoc) PropertyUtils.getSimpleProperty(form, "issueId");
67             Integer JavaDoc projectId = (Integer JavaDoc) PropertyUtils.getSimpleProperty(form, "projectId");
68             String JavaDoc caller = (String JavaDoc) PropertyUtils.getSimpleProperty(form, "caller");
69             if(caller == null) {
70                 caller = "index";
71             }
72
73             IssueModel issue = ih.getIssue(issueId);
74             if(issue == null) {
75                 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidissue"));
76             }
77
78             if(errors.isEmpty()) {
79                 HttpSession session = request.getSession(true);
80                 UserModel user = (UserModel) session.getAttribute(Constants.USER_KEY);
81                 HashMap userPermissions = (HashMap) session.getAttribute(Constants.PERMISSIONS_KEY);
82
83                 if(! UserUtilities.hasPermission(userPermissions, issue.getProjectId(), UserUtilities.PERMISSION_EDIT)) {
84                     Logger.logDebug("User not authorized to move issue " + issueId);
85                     return mapping.findForward("unauthorized");
86                 }
87                 if(! UserUtilities.hasPermission(userPermissions, projectId, new int[] {UserUtilities.PERMISSION_EDIT, UserUtilities.PERMISSION_CREATE})) {
88                     Logger.logDebug("User attempted to move issue " + issueId + " to unauthorized project.");
89                     return mapping.findForward("unauthorized");
90                 }
91
92                 ih.moveIssue(issue, projectId, user.getId());
93
94                 session.removeAttribute(Constants.PROJECTS_KEY);
95                 session.removeAttribute(Constants.ISSUE_KEY);
96
97                 if("editissue".equals((String JavaDoc) PropertyUtils.getSimpleProperty(form, "caller"))) {
98                     return new ActionForward(mapping.findForward("editissue").getPath() + "?id=" + issue.getId());
99                 } else if("viewissue".equals((String JavaDoc) PropertyUtils.getSimpleProperty(form, "caller"))) {
100                     return new ActionForward(mapping.findForward("viewissue").getPath() + "?id=" + issue.getId());
101                 } else {
102                     return mapping.findForward("index");
103                 }
104             }
105         } catch(Exception JavaDoc e) {
106             Logger.logError("Exception processing form data", e);
107             errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.system"));
108         }
109
110         if(! errors.isEmpty()) {
111             saveErrors(request, errors);
112         }
113         return mapping.findForward("error");
114     }
115
116 }
117   
Popular Tags