@RequestMapping(value = "create.htm", method = RequestMethod.GET) public ModelAndView initCreate() { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-Start-init"); } ModelAndView mav = new ModelAndView(); mav.addObject(BuckWaConstants.PAGE_SELECT, BuckWaConstants.LEAVE_INIT); mav.setViewName("holidayCreate"); HolidayCriteria holidayCriteria = new HolidayCriteria(); BuckWaResponse response = yearService.getAll(); List<Year> years = null; if (response.getStatus() == BuckWaConstants.SUCCESS) { years = (List) response.getResObj("yearList"); mav.addObject("holidayCriteria", holidayCriteria); if (years != null) { mav.addObject("yearList", years); } } else { mav.addObject("errorCode", response.getErrorCode()); } return mav; }
@RequestMapping(value = "search.htm", method = RequestMethod.POST) public ModelAndView search( HttpServletRequest httpRequest, @ModelAttribute Tumbon tumbon, @ModelAttribute PagingBean bean) { logger.info(" Start "); ModelAndView mav = new ModelAndView(); mav.setViewName("tumbonList"); try { int offset = ServletRequestUtils.getIntParameter(httpRequest, "pager.offset", 0); bean.setOffset(offset); BuckWaRequest request = new BuckWaRequest(); request.put("pagingBean", bean); bean.put("tumbon", tumbon); BuckWaResponse response = tumbonService.getByOffset(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { PagingBean beanReturn = (PagingBean) response.getResObj("pagingBean"); bean.setCurrentPageItem(beanReturn.getCurrentPageItem()); bean.setTotalItems(beanReturn.getTotalItems()); mav.addObject("pagingBean", bean); mav.addObject("doSearch", "true"); } else { mav.addObject("errorCode", response.getErrorCode()); } } catch (Exception ex) { ex.printStackTrace(); mav.addObject("errorCode", "E001"); } return mav; }
@RequestMapping(value = "create.htm", method = RequestMethod.POST) public ModelAndView createTumbon(@ModelAttribute Tumbon tumbon, BindingResult result) { logger.info(" Start "); ModelAndView mav = new ModelAndView(); try { new TumbonValidator().validate(tumbon, result); if (result.hasErrors()) { mav.setViewName("tumbonCreate"); } else { BuckWaRequest request = new BuckWaRequest(); request.put("tumbon", tumbon); BuckWaResponse response = tumbonService.create(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { mav.addObject("tumbon", new Tumbon()); mav.addObject("successCode", response.getSuccessCode()); mav.setViewName("tumbonCreateSuccess"); } else { mav.addObject("errorCode", response.getErrorCode()); mav.setViewName("tumbonCreate"); } } } catch (Exception ex) { ex.printStackTrace(); mav.addObject("errorCode", "E001"); } return mav; }
@RequestMapping(value = "create.htm", method = RequestMethod.POST) public ModelAndView createHoliday( HttpServletRequest httpRequest, @ModelAttribute HolidayCriteria holidayCriteria, BindingResult result) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-- create --"); } ModelAndView mav = new ModelAndView(); try { // new HolidayValidator().validate(holiday, result); if (result.hasErrors()) { mav.setViewName("holidayCreate"); } else { BuckWaRequest request = new BuckWaRequest(); request.put("holidayCriteria", holidayCriteria); BuckWaResponse response = yearService.getAll(); List<Year> years = null; years = (List) response.getResObj("yearList"); mav.addObject("holidayCriteria", holidayCriteria); if (years != null) { Calendar calendar = Calendar.getInstance(); for (Year year : years) { calendar.set(Calendar.YEAR, Integer.parseInt(year.getName())); year.setName( BuckWaDateUtils.getCustomFormat_thai_from_date(calendar.getTime(), "yyyy")); } mav.addObject("yearList", years); } response = holidayService.create(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { logger.info(" Success"); mav.addObject("holidayCriteria", new HolidayCriteria()); mav.addObject("successCode", response.getSuccessCode()); gotoList(mav); } else { mav.addObject("errorCode", response.getErrorCode()); mav.setViewName("holidayCreate"); } } } catch (Exception ex) { ex.printStackTrace(); mav.addObject("errorCode", "E001"); } return mav; }
public BuckWaResponse getHolidayByYear(BuckWaRequest request) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-getHolidayByYear-"); } BuckWaResponse response = new BuckWaResponse(); try { String holidayId = request.get("holidayId").toString(); List<Holiday> holidayList = holidayDao.getHolidayByYear(holidayId); response.addResponse("holidayList", holidayList); } catch (Exception ex) { ex.printStackTrace(); response.setStatus(BuckWaConstants.FAIL); response.setErrorCode("E001"); } return response; }
@Override public BuckWaResponse getAll() { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-getAll-"); } BuckWaResponse response = new BuckWaResponse(); try { List<Holiday> holidayList = holidayDao.getAllHoliday(); response.addResponse("holidayList", holidayList); } catch (Exception ex) { ex.printStackTrace(); response.setStatus(BuckWaConstants.FAIL); response.setErrorCode("E001"); } // response.setSuccessCode("S001"); return response; }
@Override public BuckWaResponse getByOffsetYear(BuckWaRequest request) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-getByOffset-"); } BuckWaResponse response = new BuckWaResponse(); try { PagingBean pagingBean = (PagingBean) request.get("pagingBean"); PagingBean returnBean = holidayDao.getAllHolidayByOffsetYear(pagingBean); response.addResponse("pagingBean", returnBean); } catch (Exception ex) { ex.printStackTrace(); response.setStatus(BuckWaConstants.FAIL); response.setErrorCode("E001"); } // Success return S001 // response.setSuccessCode("S001"); return response; }
@Override public BuckWaResponse getById(BuckWaRequest request) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-getById-"); } BuckWaResponse response = new BuckWaResponse(); try { String holidayId = (String) request.get("holidayId"); Holiday holiday = holidayDao.getHolidayById(holidayId); response.addResponse("holiday", holiday); } catch (Exception ex) { ex.printStackTrace(); response.setStatus(BuckWaConstants.FAIL); response.setErrorCode("E001"); } // Success return S001 // response.setSuccessCode("S001"); return response; }
@RequestMapping(value = "edit.htm", method = RequestMethod.GET) public ModelAndView initEdit(@RequestParam("holidayId") String holidayId) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-EDIT-init"); } ModelAndView mav = new ModelAndView(); mav.addObject(BuckWaConstants.PAGE_SELECT, BuckWaConstants.LEAVE_INIT); BuckWaRequest request = new BuckWaRequest(); request.put("holidayId", holidayId); BuckWaResponse response = yearService.getAll(); List<Year> years = null; if (response.getStatus() == BuckWaConstants.SUCCESS) { years = (List) response.getResObj("yearList"); response = holidayService.getById(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { Holiday holiday = (Holiday) response.getResObj("holiday"); mav.addObject("holiday", holiday); if (years != null) { mav.addObject("yearList", years); } } } else { mav.addObject("errorCode", response.getErrorCode()); } mav.setViewName("holidayEdit"); return mav; }
@RequestMapping(value = "init.htm", method = RequestMethod.GET) public ModelAndView initList(HttpServletRequest httpRequest) { logger.info(" Start "); ModelAndView mav = new ModelAndView(); PagingBean bean = new PagingBean(); mav.addObject("tumbon", new Tumbon()); mav.addObject("pagingBean", bean); mav.setViewName("tumbonList"); // Search with initial int offset = 0; bean.setOffset(offset); BuckWaRequest request = new BuckWaRequest(); mav.addObject("tumbon", new Tumbon()); request.put("pagingBean", bean); bean.put("tumbon", new Tumbon()); BuckWaResponse response = tumbonService.getByOffset(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { logger.info(" Success "); PagingBean beanReturn = (PagingBean) response.getResObj("pagingBean"); bean.setCurrentPageItem(beanReturn.getCurrentPageItem()); bean.setTotalItems(beanReturn.getTotalItems()); mav.addObject("pagingBean", bean); } else { mav.addObject("errorCode", response.getErrorCode()); } response = aumphurService.getAll(); if (response.getStatus() == BuckWaConstants.SUCCESS) { List<Aumphur> aumphurList = (List<Aumphur>) response.getResObj("aumphurList"); mav.addObject("aumphurList", aumphurList); httpRequest.getSession().setAttribute("aumphurList", aumphurList); } return mav; }
@Override public BuckWaResponse deleteById(BuckWaRequest request) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-deleteById-"); } BuckWaResponse response = new BuckWaResponse(); try { String id = request.get("holidayId").toString(); // Check Is using Holiday targetHoliday = holidayDao.getHolidayById(id); if (targetHoliday == null) { response.setStatus(BuckWaConstants.FAIL); response.setErrorCode("E010"); } else { holidayDao.deleteHolidayById(id); } } catch (Exception ex) { ex.printStackTrace(); response.setStatus(BuckWaConstants.FAIL); response.setErrorCode("E001"); } response.setSuccessCode("D001"); return response; }
@RequestMapping(value = "search.htm") public ModelAndView search( HttpServletRequest httpRequest, @ModelAttribute HolidayCriteria holiday) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-Search-"); } ModelAndView mav = new ModelAndView(); mav.addObject(BuckWaConstants.PAGE_SELECT, BuckWaConstants.LEAVE_INIT); mav.setViewName("holidayList"); try { PagingBean bean = new PagingBean(); int offset = ServletRequestUtils.getIntParameter(httpRequest, "pager.offset", 0); bean.setOffset(offset); BuckWaRequest request = new BuckWaRequest(); request.put("pagingBean", bean); bean.put("holiday", holiday); BuckWaResponse response = yearService.getAll(); List<Year> years = null; if (response.getStatus() == BuckWaConstants.SUCCESS) { years = (List) response.getResObj("yearList"); response = holidayService.getByOffset(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { PagingBean beanReturn = (PagingBean) response.getResObj("pagingBean"); bean.setCurrentPageItem(beanReturn.getCurrentPageItem()); bean.setTotalItems(beanReturn.getTotalItems()); mav.addObject("pagingBean", bean); mav.addObject("doSearch", "true"); if (years != null) { Calendar calendar = Calendar.getInstance(); for (Year year : years) { calendar.set(Calendar.YEAR, Integer.parseInt(year.getName())); year.setName( BuckWaDateUtils.getCustomFormat_thai_from_date(calendar.getTime(), "yyyy")); } mav.addObject("yearList", years); } mav.addObject("holidayCriteria", holiday); } } else { mav.addObject("errorCode", response.getErrorCode()); } } catch (Exception ex) { ex.printStackTrace(); mav.addObject("errorCode", "E001"); } return mav; }
@Override @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) public BuckWaResponse update(BuckWaRequest request) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-update-"); } BuckWaResponse response = new BuckWaResponse(); try { Holiday holiday = (Holiday) request.get("holiday"); response.setStatus(BuckWaConstants.FAIL); if (holiday.getHolidayName().length() < 1) { response.setErrorCode("E017"); } else { Holiday oldHoliday = holidayDao.getHolidayById(holiday.getHolidayId()); boolean isExist = holidayDao.isHolidayExist(holiday); boolean isSameYear = oldHoliday.getYearId().equals(holiday.getYearId()); boolean isSameDate = oldHoliday.getHolidayDate().equals(holiday.getHolidayDate()); boolean isSameDesc = oldHoliday.getHolidayDesc().equals(holiday.getHolidayDesc()); boolean isSameName = oldHoliday.getHolidayName().equals(holiday.getHolidayName()); boolean isSameEnable = oldHoliday.isEnable() == holiday.isEnable(); boolean isDirty = !(isSameYear && isSameDate && isSameDesc && isSameEnable && isSameName); if (!isExist || isDirty) { holidayDao.update(holiday); response.setSuccessCode("S002"); response.setStatus(BuckWaConstants.SUCCESS); } else { response.setErrorCode("E002"); } } } catch (Exception ex) { ex.printStackTrace(); response.setStatus(BuckWaConstants.FAIL); response.setErrorCode("E001"); } return response; }
private ModelAndView gotoList(ModelAndView mav) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-goToList-"); } mav.addObject(BuckWaConstants.PAGE_SELECT, BuckWaConstants.LEAVE_INIT); PagingBean bean = new PagingBean(); mav.addObject("holidayCriteria", new HolidayCriteria()); mav.addObject("pagingBean", bean); mav.setViewName("holidayList"); int offset = 0; bean.setOffset(offset); BuckWaRequest request = new BuckWaRequest(); request.put("pagingBean", bean); bean.put("holiday", new HolidayCriteria()); BuckWaResponse response = yearService.getAll(); List<Year> years = null; if (response.getStatus() == BuckWaConstants.SUCCESS) { years = (List) response.getResObj("yearList"); response = holidayService.getByOffset(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { PagingBean beanReturn = (PagingBean) response.getResObj("pagingBean"); bean.setCurrentPageItem(beanReturn.getCurrentPageItem()); bean.setTotalItems(beanReturn.getTotalItems()); mav.addObject("pagingBean", bean); if (years != null) { Calendar calendar = Calendar.getInstance(); for (Year year : years) { calendar.set(Calendar.YEAR, Integer.parseInt(year.getName())); year.setName( BuckWaDateUtils.getCustomFormat_thai_from_date(calendar.getTime(), "yyyy")); } mav.addObject("yearList", years); } } } else { mav.addObject("errorCode", response.getErrorCode()); } return mav; }
@RequestMapping(value = "edit.htm", method = RequestMethod.POST) public ModelAndView submitEdit(@ModelAttribute Holiday holiday, BindingResult result) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-EDIT-"); } ModelAndView mav = new ModelAndView(); try { // new HolidayValidator().validate(holiday, result); mav.setViewName("holidayEdit"); if (!result.hasErrors()) { BuckWaResponse response = yearService.getAll(); List<Year> years = null; if (response.getStatus() == BuckWaConstants.SUCCESS) { years = (List) response.getResObj("yearList"); BuckWaRequest request = new BuckWaRequest(); request.put("holiday", holiday); response = holidayService.update(request); if (years != null) { mav.addObject("yearList", years); } if (response.getStatus() == BuckWaConstants.SUCCESS) { mav.addObject("successCode", response.getSuccessCode()); mav.setView(new RedirectView("/PAM/admin/holiday/init.htm")); } else { mav.addObject("errorCode", response.getErrorCode()); } } else { mav.addObject("errorCode", response.getErrorCode()); } } } catch (Exception ex) { ex.printStackTrace(); mav.addObject("errorCode", "E001"); } return mav; }
@RequestMapping(value = "edit.htm", method = RequestMethod.GET) public ModelAndView initEdit(@RequestParam("tumbonId") String tumbonId) { logger.info(" Start "); ModelAndView mav = new ModelAndView(); BuckWaRequest request = new BuckWaRequest(); request.put("tumbonId", tumbonId); BuckWaResponse response = tumbonService.getById(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { Tumbon tumbon = (Tumbon) response.getResObj("tumbon"); mav.addObject("tumbon", tumbon); } else { logger.info(" Fail !!!! :" + response.getErrorCode() + " : " + response.getErrorDesc()); mav.addObject("errorCode", response.getErrorCode()); } mav.setViewName("tumbonEdit"); return mav; }
@RequestMapping(value = "delete.htm", method = RequestMethod.GET) public ModelAndView delete( @RequestParam("holidayId") String holidayId, HttpServletRequest httpRequest, @ModelAttribute HolidayCriteria holiday, @ModelAttribute PagingBean bean) { logger.info(" Start "); ModelAndView mav = new ModelAndView(); mav.addObject(BuckWaConstants.PAGE_SELECT, BuckWaConstants.LEAVE_INIT); mav.setViewName("holidayList"); BuckWaRequest request = new BuckWaRequest(); request.put("holidayId", holidayId); BuckWaResponse response = holidayService.deleteById(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { mav.addObject("successCode", "S004"); } else { mav.addObject("errorCode", response.getErrorCode()); mav.addObject("pagingBean", bean); } int offset = ServletRequestUtils.getIntParameter(httpRequest, "pager.offset", 0); bean.setOffset(offset); request.put("pagingBean", bean); bean.put("holiday", holiday); response = holidayService.getByOffset(request); if (response.getStatus() == BuckWaConstants.SUCCESS) { PagingBean beanReturn = (PagingBean) response.getResObj("pagingBean"); bean.setCurrentPageItem(beanReturn.getCurrentPageItem()); bean.setTotalItems(beanReturn.getTotalItems()); mav.addObject("pagingBean", bean); } else { mav.addObject("errorCode", response.getErrorCode()); } return mav; }
@Override @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) public BuckWaResponse create(BuckWaRequest request) { if (logger.isInfoEnabled()) { logger.info(this.getClass().toString() + "-create-"); } BuckWaResponse response = new BuckWaResponse(); try { HolidayCriteria holidayCriteria = (HolidayCriteria) request.get("holidayCriteria"); boolean isExist = false; if (holidayCriteria != null && holidayCriteria.getHolidayName().length() > 1) { DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); List<Date> listDuration = new ArrayList<Date>(); if (holidayCriteria.getIsDurationDate().equalsIgnoreCase("true") && holidayCriteria.getMinDate() != null && holidayCriteria.getMinDate().length() > 0 && holidayCriteria.getMaxDate() != null && holidayCriteria.getMaxDate().length() > 0) { if (logger.isInfoEnabled()) { logger.info("- duration Date -"); logger.info("- minDate: " + holidayCriteria.getMinDate()); logger.info("- maxDate: " + holidayCriteria.getMaxDate()); } /* BEGIN: try from * http://stackoverflow.com/questions/2689379/how-to-get-a-list-of-dates-between-two-dates-in-java */ Date startDate = (Date) formatter.parse(holidayCriteria.getMinDate()); Date endDate = (Date) formatter.parse(holidayCriteria.getMaxDate()); long interval = 24 * 1000 * 60 * 60; // 1 Day in millis long endTime = endDate.getTime(); // create your endtime here, possibly using Calendar or Date long curTime = startDate.getTime(); while (curTime <= endTime) { listDuration.add(new Date(curTime)); curTime += interval; } /* END: try */ } else if (!holidayCriteria.getIsDurationDate().equalsIgnoreCase("true") && holidayCriteria.getHolidayDate() != null && holidayCriteria.getHolidayDate().length() > 0) { if (logger.isInfoEnabled()) { logger.info("- singleDate: " + holidayCriteria.getHolidayDate()); } listDuration.add((Date) formatter.parse(holidayCriteria.getHolidayDate())); } else { throw new Exception("Something Abnormal!"); } if (logger.isInfoEnabled()) { for (int i = 0; i < listDuration.size(); i++) { Date lDate = (Date) listDuration.get(i); String ds = formatter.format(lDate); logger.info(" Date is ..." + ds); } } for (int i = 0; i < listDuration.size(); i++) { Holiday holiday = new Holiday(); holiday.setYearId(holidayCriteria.getYearId()); holiday.setHolidayDate(formatter.format(listDuration.get(i))); holiday.setHolidayName(holidayCriteria.getHolidayName()); holiday.setHolidayDesc(holidayCriteria.getHolidayDesc()); isExist = holidayDao.isHolidayExist(holiday); if (isExist) { response.setErrorCode("E002"); response.setStatus(BuckWaConstants.FAIL); break; } } if (!isExist) { for (int i = 0; i < listDuration.size(); i++) { Holiday holiday = new Holiday(); holiday.setYearId(holidayCriteria.getYearId()); holiday.setHolidayDate(formatter.format(listDuration.get(i))); holiday.setHolidayName(holidayCriteria.getHolidayName()); holiday.setHolidayDesc(holidayCriteria.getHolidayDesc()); holiday.setEnable(holidayCriteria.isEnable()); holidayDao.create(holiday); } response.setSuccessCode("S001"); } } else { response.setErrorCode("E017"); response.setStatus(BuckWaConstants.FAIL); } } catch (DuplicateKeyException dx) { response.setStatus(BuckWaConstants.FAIL); response.setErrorCode("E002"); } catch (Exception ex) { ex.printStackTrace(); if (ex.getMessage().equals("Something Abnormal!")) { response.setErrorCode("E017"); } else { response.setErrorCode("E001"); } response.setStatus(BuckWaConstants.FAIL); } // Success return S001 response.setSuccessCode("S001"); return response; }