1 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.util.*; 33 34 import cowsultants.itracker.ejb.client.exceptions.*; 35 import cowsultants.itracker.ejb.client.interfaces.*; 36 import cowsultants.itracker.ejb.client.models.*; 37 import cowsultants.itracker.ejb.client.resources.*; 38 import cowsultants.itracker.ejb.client.util.*; 39 import cowsultants.itracker.web.scheduler.*; 40 import cowsultants.itracker.web.util.*; 41 42 43 public class RemoveConfigurationItemAction extends ITrackerAction { 44 45 public RemoveConfigurationItemAction() { 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 55 if(! hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) { 56 return mapping.findForward("unauthorized"); 57 } 58 59 try { 60 InitialContext ic = new InitialContext(); 61 62 Object scRef = ic.lookup("java:comp/env/" + SystemConfiguration.JNDI_NAME); 63 SystemConfigurationHome scHome = (SystemConfigurationHome) PortableRemoteObject.narrow(scRef, SystemConfigurationHome.class); 64 SystemConfiguration sc = scHome.create(); 65 66 Integer configId = (Integer ) PropertyUtils.getSimpleProperty(form, "id"); 67 if(configId == null || configId.intValue() <= 0) { 68 throw new SystemConfigurationException("Invalid configuration id."); 69 } 70 71 ConfigurationModel configItem = sc.getConfigurationItem(configId); 72 if(configItem == null) { 73 throw new SystemConfigurationException("Invalid configuration id."); 74 } 75 76 String key = null; 77 if(configItem.getType() == SystemConfigurationUtilities.TYPE_SEVERITY) { 78 key = ITrackerResources.KEY_BASE_SEVERITY + configItem.getValue(); 79 80 try { 83 String currConfigValue = configItem.getValue(); 84 String newConfigValue = null; 85 86 ConfigurationModel[] configItems = sc.getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_SEVERITY); 87 for(int i = 0; i < configItems.length; i++) { 88 if(configItems[i] != null && configId.equals(configItems[i].getId())) { 89 if(i == 0 && (i + 1) < configItems.length) { 90 newConfigValue = configItems[i + 1].getValue(); 91 break; 92 } else if(i > 0) { 93 newConfigValue = configItems[i - 1].getValue(); 94 break; 95 } 96 } 97 } 98 99 int currSeverity = Integer.parseInt(currConfigValue); 100 int newSeverity = Integer.parseInt(newConfigValue); 101 Logger.logDebug("Promoting issues in severity " + IssueUtilities.getSeverityName(currSeverity) + " to " + IssueUtilities.getSeverityName(newSeverity)); 102 103 HttpSession session = request.getSession(true); 104 UserModel currUser = (UserModel) session.getAttribute(Constants.USER_KEY); 105 Integer currUserId = (currUser == null ? new Integer (-1) : currUser.getId()); 106 107 Object ihRef = ic.lookup("java:comp/env/" + IssueHandler.JNDI_NAME); 108 IssueHandlerHome ihHome = (IssueHandlerHome) PortableRemoteObject.narrow(ihRef, IssueHandlerHome.class); 109 IssueHandler ih = ihHome.create(); 110 IssueModel[] issues = ih.getIssuesWithSeverity(currSeverity); 111 for(int i = 0; i < issues.length; i++) { 112 if(issues[i] != null) { 113 issues[i].setSeverity(newSeverity); 114 issues[i] = ih.updateIssue(issues[i], currUserId); 115 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_SYSTEM_UPDATE, 116 ITrackerResources.getString("itracker.activity.system.severity"), issues[i].getId(), currUserId); 117 ih.addIssueActivity(activity); 118 } 119 } 120 } catch(Exception e) { 121 Logger.logDebug("Exception while promoting issues with severity " + configItem.getValue(), e); 122 } 123 } else if(configItem.getType() == SystemConfigurationUtilities.TYPE_STATUS) { 124 key = ITrackerResources.KEY_BASE_STATUS + configItem.getValue(); 125 126 130 try { 131 String currConfigValue = configItem.getValue(); 132 String newConfigValue = null; 133 134 ConfigurationModel[] configItems = sc.getConfigurationItemsByType(SystemConfigurationUtilities.TYPE_STATUS); 135 for(int i = 0; i < configItems.length; i++) { 136 if(configItems[i] != null && configId.equals(configItems[i].getId())) { 137 if(i == 0 && (i + 1) < configItems.length) { 138 newConfigValue = configItems[i + 1].getValue(); 139 break; 140 } else if(i > 0) { 141 newConfigValue = configItems[i - 1].getValue(); 142 break; 143 } 144 } 145 } 146 147 int currStatus = Integer.parseInt(currConfigValue); 148 int newStatus = Integer.parseInt(newConfigValue); 149 Logger.logDebug("Promoting issues in status " + IssueUtilities.getStatusName(currStatus) + " to " + IssueUtilities.getStatusName(newStatus)); 150 151 HttpSession session = request.getSession(true); 152 UserModel currUser = (UserModel) session.getAttribute(Constants.USER_KEY); 153 Integer currUserId = (currUser == null ? new Integer (-1) : currUser.getId()); 154 155 Object ihRef = ic.lookup("java:comp/env/" + IssueHandler.JNDI_NAME); 156 IssueHandlerHome ihHome = (IssueHandlerHome) PortableRemoteObject.narrow(ihRef, IssueHandlerHome.class); 157 IssueHandler ih = ihHome.create(); 158 IssueModel[] issues = ih.getIssuesWithStatus(currStatus); 159 for(int i = 0; i < issues.length; i++) { 160 if(issues[i] != null) { 161 issues[i].setStatus(newStatus); 162 issues[i] = ih.updateIssue(issues[i], currUserId); 163 IssueActivityModel activity = new IssueActivityModel(IssueUtilities.ACTIVITY_SYSTEM_UPDATE, 164 ITrackerResources.getString("itracker.activity.system.status"), issues[i].getId(), currUserId); 165 ih.addIssueActivity(activity); 166 } 167 } 168 } catch(Exception e) { 169 Logger.logDebug("Exception while promoting issues with status " + configItem.getValue(), e); 170 } 171 } else if(configItem.getType() == SystemConfigurationUtilities.TYPE_RESOLUTION) { 172 key = ITrackerResources.KEY_BASE_RESOLUTION + configItem.getValue(); 173 174 } else { 176 throw new SystemConfigurationException("Unsupported configuration item type " + configItem.getType() + " found."); 177 } 178 179 sc.removeConfigurationItem(configItem.getId()); 180 if(key != null) { 181 sc.removeLanguageKey(key); 182 ITrackerResources.clearKeyFromBundles(key, false); 183 } 184 185 return mapping.findForward("listconfiguration"); 186 } catch(SystemConfigurationException sce) { 187 Logger.logDebug(sce.getMessage(), sce); 188 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidconfiguration")); 189 } catch(NumberFormatException nfe) { 190 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.invalidconfiguration")); 191 Logger.logDebug("Invalid configuration item id " + request.getParameter("id") + " specified."); 192 } catch(Exception e) { 193 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("itracker.web.error.system")); 194 Logger.logError("System Error.", e); 195 } 196 if(! errors.isEmpty()) { 197 saveErrors(request, errors); 198 } 199 return mapping.findForward("error"); 200 } 201 202 } 203 | Popular Tags |