1 package com.instantbank.collections.basicInfo.web; 2 3 import javax.ejb.*; 4 import java.io.IOException; 5 import java.util.*; 6 import javax.servlet.RequestDispatcher; 7 import javax.servlet.ServletConfig; 8 import javax.servlet.ServletContext; 9 import javax.servlet.ServletException; 10 import javax.servlet.http.HttpServlet; 11 import javax.servlet.http.HttpServletRequest; 12 import javax.servlet.http.HttpServletResponse; 13 import javax.servlet.http.HttpSession; 14 import com.instantbank.collections.basicInfo.ejb.BasicInfoServices; 15 import com.instantbank.collections.basicInfo.ejb.BasicInfoServicesHome; 16 import com.instantbank.collections.util.FilterChain; 17 import com.instantbank.collections.util.InstantbankException; 18 import com.instantbank.collections.util.ServiceLocator; 19 20 public class StatesMaintenanceController extends HttpServlet { 21 private String counId; 22 private String debug; 23 private BasicInfoServices services; 24 private HttpSession session; 25 private Long userId; 26 27 28 public void init(ServletConfig config) throws ServletException { 29 super.init(config); 30 try { 31 BasicInfoServicesHome home = (BasicInfoServicesHome) 32 ServiceLocator.instance().createEJB("BasicInfoServicesHome", BasicInfoServicesHome.class, false); 33 services = home.create(); 34 } 35 catch(Exception e) { 36 throw new ServletException(e); 37 } 38 } 39 40 41 public void doGet(HttpServletRequest request, HttpServletResponse response) throws 42 ServletException, IOException { 43 44 doPost(request, response); 45 } 46 47 48 public void doPost(HttpServletRequest request, HttpServletResponse response) throws 49 ServletException, IOException { 50 51 String action; 52 com.instantbank.collections.util.FilterChain chain; 53 54 try { 55 session = request.getSession(false); 56 action = request.getParameter("action"); 57 counId = (String)request.getAttribute("countryId"); 58 try { 59 60 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext()); 61 if(chain.processFilter(request, response)) { 62 return; 63 } 64 if(action.equals("initialize")) { 65 initialize(request, response); 66 } 67 else if(action.equals("save")) { 68 save(request, response); 69 } 70 else { 71 throw new InstantbankException("112001", "Action " + action + " not supported"); 72 } 73 } 74 catch(Exception e) { 75 throw new InstantbankException(e, "112002", "Failed to execute controller action " + action); 76 } 77 } 78 catch(InstantbankException e) { 79 session.setAttribute("Exception", e); 80 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0"); 81 } 82 } 83 84 85 public String getServletInfo() { 86 return "com.instantbank.collections.basicInfo.web.StatesMaintenanceController Information"; 87 } 88 89 90 private void initialize(HttpServletRequest request, HttpServletResponse response) throws 91 ServletException, IOException, InstantbankException { 92 93 String xml; 94 String counName; 95 96 xml = services.getStates(counId); 97 counName = services.getCountryName(counId); 98 ServletContext sc = getServletConfig().getServletContext(); 99 request.setAttribute("title", "States Maintenance"); 100 request.setAttribute("data", xml); 101 request.setAttribute("CounName", counName); 102 RequestDispatcher rd = sc.getRequestDispatcher("/basicInfo_web/StatesView.jsp"); 103 rd.forward(request, response); 104 } 105 106 107 private void save(HttpServletRequest request, HttpServletResponse response) throws 108 ServletException, IOException, InstantbankException { 109 110 String xml; 111 112 userId = (Long)session.getAttribute("userId"); 113 xml = request.getParameter("data"); 114 counId = request.getParameter("countryId"); 115 try { 116 services.saveStates(userId, xml); 117 } 118 catch(InstantbankException e) { 119 String errorMessage = e.toString(); 120 String msg = "One of the states cannot be deleted because it is referenced in an address.\\nPlease verify that the states you are trying to delete are no longer used or referenced."; 121 if(errorMessage.indexOf("ORA-02292") != -1) { 122 request.setAttribute("msg", msg); 123 } 124 else { 125 throw e; 126 } 127 } 128 initialize(request, response); 129 } 130 } 131