Exemplo n.º 1
0
 // Pushed this aspect in to add logged in user as the time owner
 @RequestMapping(params = "form", produces = "text/html")
 public String createForm(Model uiModel) {
   UsedTime usedTime = new UsedTime();
   AppUser owner =
       AppUser.findAppUser(
           SecurityUtils.getLoggedInUser().getId()); // need to refresh hibernate binding
   usedTime.setOwner(owner);
   usedTime.setHours(0);
   usedTime.setWorkDate(new Date());
   populateEditForm(uiModel, usedTime);
   return "usedtimes/create";
 }
Exemplo n.º 2
0
 @RequestMapping(method = RequestMethod.POST, produces = "text/html")
 public String create(
     @Valid UsedTime usedTime,
     BindingResult bindingResult,
     Model uiModel,
     HttpServletRequest httpServletRequest) {
   if (bindingResult.hasErrors()) {
     populateEditForm(uiModel, usedTime);
     return "usedtimes/create";
   }
   uiModel.asMap().clear();
   if (!SecurityUtils.getLoggedInUser().isAdmin()) {
     usedTime.setOwner(SecurityUtils.getLoggedInUser());
   }
   usedTime.persist();
   return "redirect:/usedtimes/"
       + encodeUrlPathSegment(usedTime.getId().toString(), httpServletRequest);
 }
Exemplo n.º 3
0
 @RequestMapping(produces = "text/html")
 public String list(
     @RequestParam(value = "page", required = false) Integer page,
     @RequestParam(value = "size", required = false) Integer size,
     Model uiModel) {
   TypedQuery<UsedTime> q = UsedTime.findUsedTimesByOwner(SecurityUtils.getLoggedInUser());
   if (page != null || size != null) {
     int sizeNo = size == null ? 10 : size.intValue();
     final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo;
     uiModel.addAttribute(
         "usedtimes", q.setFirstResult(firstResult).setMaxResults(sizeNo).getResultList());
     float nrOfPages = (float) UsedTime.countUsedTimes() / sizeNo;
     uiModel.addAttribute(
         "maxPages",
         (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
   } else {
     uiModel.addAttribute("usedtimes", q.getResultList());
   }
   addDateTimeFormatPatterns(uiModel);
   return "usedtimes/list";
 }