/** Method deleteCompany. */ private void deleteCompany() { try { openConnection(); // check if company exist CompanyDetails companyDetails = new CompanyDetails(); companyDetails.setCompanyId(new BigDecimal(request.getParameter("dfCompanyId"))); CompanyView companyView = new CompanyView(); companyView.fillWithElements(connection, CompanyDetails.FILL_TYPE_ALL, companyDetails); try { if (companyView.getElements().size() == 0) { throw new ModelException( "The company you are trying to delete can no longer be found in the database.", ModelException.RECORD_NOT_FOUND); } // delete company companyView.doAction(connection, "DELETE", null, companyDetails); } catch (ModelException modelException) { request.setAttribute("modelException", modelException); } commit(); // forward request request .getRequestDispatcher("/jsp/admin/company/companyActionResult.jsp") .forward(request, response); } catch (Exception e) { doCatch(e); } finally { finallyMethod(); } }
/** Method insertCompany. */ private void insertCompany() { try { openConnection(); // check if the company already exist CompanyDetails companyDetails = new CompanyDetails(); companyDetails.setCompany(request.getParameter("dfCompany")); CompanyView companyView = new CompanyView(); companyView.fillWithElements(connection, CompanyDetails.FILL_TYPE_ALL, companyDetails); try { if (companyView.getElements().size() > 0) { throw new ModelException( "A company with this name has already been created.", ModelException.DUPLICATE_RECORD); } // insert company companyView.doAction(connection, "INSERT", CompanyDetails.FILL_TYPE_ALL, companyDetails); } catch (ModelException modelException) { request.setAttribute("modelException", modelException); } commit(); // forward request request .getRequestDispatcher("/jsp/admin/company/companyActionResult.jsp") .forward(request, response); } catch (Exception e) { doCatch(e); } finally { finallyMethod(); } }
/** Method displayUpdateCompany. */ private void displayUpdateCompany() { try { request.setAttribute("displayInsert", new Boolean(false)); openConnection(); // check if the company already exist CompanyDetails companyDetails = new CompanyDetails(); companyDetails.setCompanyId(new BigDecimal(request.getParameter("dfCompanyId"))); CompanyView companyView = new CompanyView(); companyView.fillWithElements(connection, CompanyDetails.FILL_TYPE_ALL, companyDetails); DateFormatView dateFormatView = new DateFormatView(); dateFormatView.fillWithElements( connection, CompanyDetails.FILL_TYPE_ALL, new DateFormatDetails()); request.setAttribute("dateFormatView", dateFormatView); TimeOffsetView timeOffsetView = new TimeOffsetView(); timeOffsetView.fillWithElements( connection, CompanyDetails.FILL_TYPE_ALL, new TimeOffsetDetails()); request.setAttribute("timeOffsetView", timeOffsetView); try { if (companyView.getElements().size() == 1) { companyDetails = (CompanyDetails) companyView.getElements().elementAt(0); request.setAttribute("companyDetails", companyDetails); } else { throw new ModelException("Company cannot be found", ModelException.RECORD_NOT_FOUND); } } catch (ModelException modelException) { request.setAttribute("modelException", modelException); } commit(); // forward request request .getRequestDispatcher("/jsp/admin/company/displayInsertUpdateCompany.jsp") .forward(request, response); } catch (Exception e) { doCatch(e); } finally { finallyMethod(); } }