/** * This method is for delete Presenter * * @param presenter code * @param requestParameters Servlet Request Parameter * @return void */ public void deletePresenter(String presenter_code, HttpServletRequest request) { log.log(Level.INFO, "PresenterMaintenance --> delete presenter "); AuditTrailMaintenance auditTrailMaint = new AuditTrailMaintenance(); User user = (User) request.getSession().getAttribute(SessionAttributes.CURR_USER_OBJ); Session session = HibernateFactory.openSession(); Transaction tx = session.beginTransaction(); String msg = ""; Presenter presenter = new Presenter(); try { presenter = (Presenter) session.get(Presenter.class, Integer.parseInt(presenter_code)); presenter.setStatus(false); session.update(presenter); tx.commit(); /*ResourceBundle msgProps = ResourceBundle.getBundle("configurations"); String ModulePath = msgProps.getString("PresenterPath"); String filePath = ModulePath+"/"+presenterName; File file = new File(filePath); FileUtils.deleteFileNFolder(file);*/ msg = "The Presenter has been successfully deleted."; auditTrailMaint.insertAuditTrail( new AuditTrail( user.getStaffLoginId() + "", AuditTrail.MODULE_PRESENTER, AuditTrail.FUNCTION_DELETE, "SUCCESS,Presenter_code:" + presenter_code)); } catch (Exception e) { msg = "The Presenter has not been successfully deleted."; auditTrailMaint.insertAuditTrail( new AuditTrail( user.getStaffLoginId() + "", AuditTrail.MODULE_PRESENTER, AuditTrail.FUNCTION_DELETE, "FAILED,Presenter_code:" + presenter_code)); log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(); } try { HibernateFactory.close(session); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(); } MsgObject msgObj = new MsgObject(msg); request.setAttribute("CacheName", "Presenter"); request.setAttribute(RequestAttributes.MESSAGE_OBJ, msgObj); Pager pager = retrieveActivityListing(getAllPresenter(request)); request.getSession().setAttribute("pager", pager); request.setAttribute("pager", pager); request .getSession() .setAttribute("pageObj", new PathDetail().getPageObj("PresenterMaintenance")); }
/** * This method is for listing all Presenter * * @param presenter list * @return Pager Object */ public Pager retrieveActivityListing(List arrPresenter) { log.log(Level.INFO, "PresenterMaintenance --> presnter listing"); LinkedList item = new LinkedList(); Presenter presenterObj = new Presenter(); try { for (int i = 0; i < arrPresenter.size(); i++) { presenterObj = (Presenter) arrPresenter.get(i); item.add(presenterObj.getPresenterListingTableRow(i)); } } catch (Exception e) { e.printStackTrace(); } Pager pager = new Pager(); pager.setActualSize(item.size()); pager.setCurrentPageNumber(0); pager.setMaxIndexPages(10); pager.setMaxPageItems(10); // pager.setTableHeader(presenterObj.getPresenterListingTableHdr()); for (; item.size() % 10 != 0; item.add("<tr></tr>")) ; pager.setItems(item); return pager; }
/** * This method is for creating new Presenter * * @param presenter Presenter object * @param requestParameters Servlet Request Parameter * @return Presenter Object */ public Presenter insertPresenter(Presenter presenter, HttpServletRequest request) { log.log(Level.INFO, "PresenterMaintenance --> crrating presenter"); User user = (User) request.getSession().getAttribute(SessionAttributes.CURR_USER_OBJ); AuditTrailMaintenance auditTrailMaintenance = new AuditTrailMaintenance(); String msg = "The new Presenter has not been successfully created."; String tempDir = System.getProperty("java.io.tmpdir"); FileOutputStream stream = null; String thumbnail_file_name = ""; String material_file_name = ""; // ResourceBundle msgProps = ResourceBundle.getBundle("configurations"); // String PresenterPath = msgProps.getString("PresenterPath"); Map<String, String> configurationMap = (Map<String, String>) request.getSession().getAttribute(ApplicationAttribute.CONFIGURATION_PROPERTIES_MAP); String PresenterPath = configurationMap.get("PresenterPath"); Session session = HibernateFactory.openSession(); Transaction tx = session.beginTransaction(); presenter.setCreated_by(user.getStaffLoginId()); presenter.setCreated_date(new Date()); presenter.setModified_by(user.getStaffLoginId()); presenter.setModified_date(new Date()); try { if (request.getSession().getAttribute("thumbnail_file_name") != null) { thumbnail_file_name = (String) request.getSession().getAttribute("thumbnail_file_name"); } if (request.getSession().getAttribute("material_file_name") != null) { material_file_name = (String) request.getSession().getAttribute("material_file_name"); } Query query = session.createQuery( "from Presenter where presenterName=:presenterName and status=:status"); query.setParameter("presenterName", presenter.getPresenterName().trim()); query.setParameter("status", true); ArrayList<Presenter> arrActivity = (ArrayList<Presenter>) query.list(); if (arrActivity.size() > 0) { msg = "The Presenter already exist."; } else { String serverFilename = ""; serverFilename = PresenterPath + "/" + presenter.getPresenterName(); File uploadedFolder = new File(serverFilename); if (!uploadedFolder.exists()) { uploadedFolder.mkdirs(); } // upload thumbnail file if (thumbnail_file_name != null && !thumbnail_file_name.equals("")) { byte[] bytearray = (byte[]) request.getSession().getAttribute("thumbnail_byte_session"); BufferedImage imag; try { imag = ImageIO.read(new ByteArrayInputStream(bytearray)); if (thumbnail_file_name.contains(".png") || thumbnail_file_name.contains(".PNG")) ImageIO.write(imag, "png", new File(serverFilename, thumbnail_file_name)); else if (thumbnail_file_name.contains(".jpg") || thumbnail_file_name.contains(".JPG")) ImageIO.write(imag, "jpg", new File(serverFilename, thumbnail_file_name)); else if (thumbnail_file_name.contains(".gif") || thumbnail_file_name.contains(".GIF")) ImageIO.write(imag, "gif", new File(serverFilename, thumbnail_file_name)); } catch (IOException e) { e.printStackTrace(); } // delete temp directory File temp_file = new File(tempDir + "/" + thumbnail_file_name); FileUtils.deleteFileNFolder(temp_file); presenter.setImage_fileName(thumbnail_file_name); presenter.setImage_fileLocation( (serverFilename + "/" + thumbnail_file_name).substring(8)); serverFilename = ""; } // upload material if (material_file_name != null && !material_file_name.equals("")) { serverFilename = PresenterPath + "/" + presenter.getPresenterName(); byte[] bytearray = (byte[]) request.getSession().getAttribute("material_byte_session"); if (material_file_name.contains(".pdf") || material_file_name.contains(".PDF")) { try { stream = new FileOutputStream(serverFilename + "/" + material_file_name); stream.write(bytearray); stream.close(); } catch (Exception e) { e.printStackTrace(); } } // delete temp directory File temp_file = new File(tempDir + "/" + material_file_name); FileUtils.deleteFileNFolder(temp_file); presenter.setFileName(material_file_name); presenter.setFileLocation((serverFilename + "/" + material_file_name).substring(8)); } presenter.setCreated_by(user.getStaffLoginId()); presenter.setCreated_date(new Date()); session.save(presenter); if (request.getSession().getAttribute("thumbnail_file_name") != null) { if (thumbnail_file_name.contains(".jpg") || thumbnail_file_name.contains(".JPG") || thumbnail_file_name.contains(".png") || thumbnail_file_name.contains(".PNG") || thumbnail_file_name.contains(".gif") || thumbnail_file_name.contains("GIF")) { String field_name = (String) request.getSession().getAttribute("thumbnail_field_name"); storeMaterialToDB( session, presenter.getPresenterCode(), "INSERT", request, "thumbnail_byte_session", thumbnail_file_name, field_name); } request .getSession() .removeAttribute( "thumbnail_file_name"); // removing uploaded file details from session after file // is uploaded request.getSession().removeAttribute("thumbnail_byte_session"); // request.getSession().removeAttribute("thumbnail_field_name"); // } if (request.getSession().getAttribute("material_file_name") != null) { if (material_file_name.contains(".pdf") || material_file_name.contains(".PDF")) { String field_name = (String) request.getSession().getAttribute("material_field_name"); storeMaterialToDB( session, presenter.getPresenterCode(), "INSERT", request, "material_byte_session", material_file_name, field_name); } request .getSession() .removeAttribute( "material_file_name"); // removing uploaded file details from session after file // is uploaded request.getSession().removeAttribute("material_byte_session"); // request.getSession().removeAttribute("material_field_name"); // } tx.commit(); msg = "The new Presenter has been successfully created."; // auditTrailMaintenance.insertAuditTrail(new AuditTrail(String.valueOf(user.getUserCode()), // AuditTrail.MODULE_CATEGORY, AuditTrail.FUNCTION_CREATE, "Action // on:T_CATEGORY,CATEGORY_ID:"+activity_id)); auditTrailMaintenance.insertAuditTrail( new AuditTrail( user.getStaffLoginId() + "", AuditTrail.MODULE_PRESENTER, AuditTrail.FUNCTION_CREATE, "SUCCESS,Presenter_code:" + presenter.getPresenterCode())); Pager pager = retrieveActivityListing(getAllPresenter(request)); request.getSession().setAttribute("pager", pager); request.setAttribute("pager", pager); request .getSession() .setAttribute("pageObj", new PathDetail().getPageObj("PresenterMaintenance")); } } catch (Exception e) { auditTrailMaintenance.insertAuditTrail( new AuditTrail( user.getStaffLoginId() + "", AuditTrail.MODULE_PRESENTER, AuditTrail.FUNCTION_CREATE, "FAILED,presenter_code:" + presenter.getPresenterCode())); log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(); } try { HibernateFactory.close(session); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(); } MsgObject msgObj = new MsgObject(msg); request.setAttribute(RequestAttributes.MESSAGE_OBJ, msgObj); request.setAttribute("CacheName", "Presenter"); // ArrayList arr=getAllPresenter(request); // Pager pager=retrieveActivityListing(arr); // request.setAttribute("pager", pager); return presenter; }
/** * This method is for update Presenter * * @param presenter Presenter object * @param requestParameters Servlet Request Parameter * @return Presenter Object */ public Presenter updatePresenter(Presenter presenter, HttpServletRequest request) { log.log(Level.INFO, "PresenterMaintenance --> update presenter"); User user = (User) request.getSession().getAttribute(SessionAttributes.CURR_USER_OBJ); AuditTrailMaintenance auditTrailMaintenance = new AuditTrailMaintenance(); int i = 0; String msg = "The Presenter has not been successfully updated."; String tempDir = System.getProperty("java.io.tmpdir"); FileOutputStream stream = null; String thumbnail_file_name = ""; String material_file_name = ""; // ResourceBundle msgProps = ResourceBundle.getBundle("configurations"); // String PresenterPath = msgProps.getString("PresenterPath"); Map<String, String> configurationMap = (Map<String, String>) request.getSession().getAttribute(ApplicationAttribute.CONFIGURATION_PROPERTIES_MAP); String PresenterPath = configurationMap.get("PresenterPath"); String serverFilename = ""; String filePath = ""; Session session = HibernateFactory.openSession(); Transaction tx = session.beginTransaction(); presenter.setModified_by(user.getStaffLoginId()); presenter.setModified_date(new Date()); try { if (request.getSession().getAttribute("thumbnail_file_name") != null) { thumbnail_file_name = (String) request.getSession().getAttribute("thumbnail_file_name"); } if (request.getSession().getAttribute("material_file_name") != null) { material_file_name = (String) request.getSession().getAttribute("material_file_name"); } String paramater = ""; paramater = " presenterCode!=:presenterCode and presenterName=:presenterName and status=:status"; Query queryDup = session.createQuery("from Presenter where " + paramater + ""); queryDup.setParameter("presenterCode", presenter.getPresenterCode()); queryDup.setParameter("presenterName", presenter.getPresenterName()); queryDup.setParameter("status", true); ArrayList<Presenter> arrActivity = (ArrayList<Presenter>) queryDup.list(); // if(arrActivity.size()>0) // { // msg="The Presenter already exist."; // } // else // { ArrayList<Presenter> list = new ArrayList<Presenter>(); Query query = session.createQuery("from Presenter where presenterCode=:presenterCode"); query.setParameter("presenterCode", presenter.getPresenterCode()); list = (ArrayList<Presenter>) query.list(); Presenter presenterObj = new Presenter(); presenterObj = list.get(0); String oldPresenter = presenterObj.getPresenterName(); String new_presenter = presenter.getPresenterName(); // upload thumbnail file if (thumbnail_file_name != null && !thumbnail_file_name.equals("")) { // chk for new name or old name if (!oldPresenter.equals( new_presenter)) { // if new one then create new presenter and delete old one serverFilename = PresenterPath + "/" + new_presenter; File uploadedFolder = new File(serverFilename); if (!uploadedFolder.exists()) { uploadedFolder.mkdirs(); } FileUtils.deleteFileNFolder(new File(PresenterPath + "/" + oldPresenter)); } else { // if its same then only delete file and store new file serverFilename = PresenterPath + "/" + oldPresenter + "/" + presenterObj.getImage_fileName(); File uploadedFolder = new File(serverFilename); if (uploadedFolder.exists()) { FileUtils.deleteFileNFolder(uploadedFolder); } } // end serverFilename = PresenterPath + "/" + new_presenter; File uploadedFolder = new File(serverFilename); if (!uploadedFolder.exists()) { uploadedFolder.mkdirs(); } byte[] bytearray = (byte[]) request.getSession().getAttribute("thumbnail_byte_session"); BufferedImage imag; try { imag = ImageIO.read(new ByteArrayInputStream(bytearray)); if (thumbnail_file_name.contains(".png") || thumbnail_file_name.contains(".PNG")) ImageIO.write(imag, "png", new File(serverFilename, thumbnail_file_name)); else if (thumbnail_file_name.contains(".jpg") || thumbnail_file_name.contains(".JPG")) ImageIO.write(imag, "jpg", new File(serverFilename, thumbnail_file_name)); else if (thumbnail_file_name.contains(".gif") || thumbnail_file_name.contains(".GIF")) ImageIO.write(imag, "gif", new File(serverFilename, thumbnail_file_name)); } catch (IOException e) { e.printStackTrace(); } // delete temp directory File temp_file = new File(tempDir + "/" + thumbnail_file_name); FileUtils.deleteFileNFolder(temp_file); presenter.setImage_fileName(thumbnail_file_name); presenter.setImage_fileLocation((serverFilename + "/" + thumbnail_file_name).substring(8)); serverFilename = ""; } else { FileUtils.renameFolder(PresenterPath + "/" + oldPresenter, new_presenter); presenter.setImage_fileName(presenterObj.getImage_fileName()); presenter.setImage_fileLocation(presenter.getImage_fileLocation()); } // upload material if (material_file_name != null && !material_file_name.equals("")) { // chk for new name or old name if (!oldPresenter.equals( new_presenter)) { // if new one then create new presenter and delete old one serverFilename = PresenterPath + "/" + new_presenter; File uploadedFolder = new File(serverFilename); if (!uploadedFolder.exists()) { uploadedFolder.mkdirs(); } FileUtils.deleteFileNFolder(new File(PresenterPath + "/" + oldPresenter)); } else { // if its same then only delete file and store new file serverFilename = PresenterPath + "/" + oldPresenter + "/" + presenterObj.getFileName(); File uploadedFolder = new File(serverFilename); if (uploadedFolder.exists()) { FileUtils.deleteFileNFolder(uploadedFolder); } } // end serverFilename = PresenterPath + "/" + new_presenter; File uploadedFolder = new File(serverFilename); if (!uploadedFolder.exists()) { uploadedFolder.mkdirs(); } byte[] bytearray = (byte[]) request.getSession().getAttribute("material_byte_session"); if (material_file_name.contains(".pdf") || material_file_name.contains(".PDF")) { try { stream = new FileOutputStream(serverFilename + "/" + material_file_name); stream.write(bytearray); stream.close(); } catch (Exception e) { e.printStackTrace(); } } // delete temp directory File temp_file = new File(tempDir + "/" + material_file_name); FileUtils.deleteFileNFolder(temp_file); presenter.setFileName(material_file_name); presenter.setFileLocation((serverFilename + "/" + material_file_name).substring(8)); } else { FileUtils.renameFolder(PresenterPath + "/" + oldPresenter, presenter.getPresenterName()); presenter.setFileName(presenterObj.getFileName()); presenter.setFileLocation(presenter.getFileLocation()); } presenter.setModified_by(user.getStaffLoginId()); presenter.setModified_date(new Date()); // presenterObj.setFileName(file_name); // presenterObj.setFileLocation(file_path.replace(oldPresenter, presenter_name)); // category.setHash_code((int)(Math.random() * 1000000000)); HibernateFactory.close(session); session = HibernateFactory.openSession(); tx = session.beginTransaction(); session.update(presenter); if (request.getSession().getAttribute("thumbnail_file_name") != null) { if (thumbnail_file_name.contains(".jpg") || thumbnail_file_name.contains(".JPG") || thumbnail_file_name.contains(".png") || thumbnail_file_name.contains(".PNG") || thumbnail_file_name.contains(".gif") || thumbnail_file_name.contains("GIF")) { String field_name = (String) request.getSession().getAttribute("thumbnail_field_name"); storeMaterialToDB( session, presenter.getPresenterCode(), "UPDATE", request, "thumbnail_byte_session", thumbnail_file_name, field_name); } request .getSession() .removeAttribute( "thumbnail_file_name"); // removing uploaded file details from session after file is // uploaded request.getSession().removeAttribute("thumbnail_byte_session"); // request.getSession().removeAttribute("thumbnail_field_name"); // } if (request.getSession().getAttribute("material_file_name") != null) { if (material_file_name.contains(".pdf") || material_file_name.contains(".PDF")) { String field_name = (String) request.getSession().getAttribute("material_field_name"); storeMaterialToDB( session, presenter.getPresenterCode(), "UPDATE", request, "material_byte_session", material_file_name, field_name); } request .getSession() .removeAttribute( "material_file_name"); // removing uploaded file details from session after file is // uploaded request.getSession().removeAttribute("material_byte_session"); // request.getSession().removeAttribute("material_field_name"); // } tx.commit(); auditTrailMaintenance.insertAuditTrail( new AuditTrail( user.getStaffLoginId() + "", AuditTrail.MODULE_PRESENTER, AuditTrail.FUNCTION_UPDATE, "SUCCESS,Presenter_code:" + presenter.getPresenterCode())); msg = "The Presnter has been successfully updated."; // } } catch (Exception e) { log.log(Level.SEVERE, e.getMessage()); auditTrailMaintenance.insertAuditTrail( new AuditTrail( user.getStaffLoginId() + "", AuditTrail.MODULE_PRESENTER, AuditTrail.FUNCTION_UPDATE, "FAILED,Presenter_code:" + presenter.getPresenterCode())); e.printStackTrace(); } try { HibernateFactory.close(session); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(); } MsgObject msgObj = new MsgObject(msg); request.setAttribute(RequestAttributes.MESSAGE_OBJ, msgObj); request.setAttribute("CacheName", "Presenter"); Pager pager = retrieveActivityListing(getAllPresenter(request)); request.getSession().setAttribute("pager", pager); request.setAttribute("pager", pager); request .getSession() .setAttribute("pageObj", new PathDetail().getPageObj("PresenterMaintenance")); return presenter; }
/** * This method checks all validations & sets values to bean * * @param presenter Presenter object * @param requestParameters Servlet Request Parameter * @return Presenter Object */ public Object mapForm1(Presenter presenter, HttpServletRequest requestParameters) { log.log(Level.INFO, "PresenterMaintenance --> mapping all presnter field "); if (presenter == null) { presenter = new Presenter(); return presenter; } LocaleObject localeObj = (LocaleObject) requestParameters.getSession().getAttribute(SessionAttributes.LOCALE_OBJ); User userObj = (User) requestParameters.getSession().getAttribute("currUserObj"); String presenter_cat_code = requestParameters.getParameter("presenter_category_code"); String presenter_name = requestParameters.getParameter("name"); String startdate = requestParameters.getParameter("startdate"); String enddate = requestParameters.getParameter("enddate"); String desc = requestParameters.getParameter("desc"); String bu = requestParameters.getParameter("bu"); String visibility = requestParameters.getParameter("presenter_visibility"); if (presenter_cat_code.equals("%")) return new ErrorObject("Presenter Category", " field is required", localeObj); if (presenter_name == null || presenter_name.length() == 0) return new ErrorObject("Presenter Name", " field is required", localeObj); if (startdate == null || startdate.length() == 0) return new ErrorObject("Start Date", " field is required", localeObj); if (enddate == null || enddate.length() == 0) return new ErrorObject("Expiry Date", " field is required", localeObj); if (desc == null || desc.length() == 0) return new ErrorObject("Presenter Description", " field is required", localeObj); if (visibility == null || visibility.equals("%")) return new ErrorObject("Presenter Visibility", " field is required", localeObj); if (bu == null || bu.equals("0")) return new ErrorObject("BU", " field is required", localeObj); presenter.setCategory(Integer.parseInt(presenter_cat_code)); presenter.setPresenterName(presenter_name); presenter.setStart_date(LMSUtil.convertToDate1(startdate)); presenter.setExpiry_date(LMSUtil.convertToDate1(enddate)); presenter.setPresenterDescription(desc); presenter.setVisibility(visibility); presenter.setBuCode(Integer.parseInt(requestParameters.getParameter("bu"))); presenter.setDistCode(Integer.parseInt(requestParameters.getParameter("district"))); presenter.setBranchCode(Integer.parseInt(requestParameters.getParameter("branch"))); presenter.setCityCode(Integer.parseInt(requestParameters.getParameter("city"))); presenter.setSscCode(Integer.parseInt(requestParameters.getParameter("ssc"))); presenter.setOfficeCode(Integer.parseInt(requestParameters.getParameter("office"))); if (presenter.getExpiry_date().before(presenter.getStart_date()) || presenter.getExpiry_date().equals(presenter.getStart_date())) { return new ErrorObject(" ", "Expired Date should be after Start Date", localeObj); } presenter.setStatus(true); presenter.setToken(LMSUtil.getRendomToken()); return presenter; }