Package com.apress.prospring3.springblog

Examples of com.apress.prospring3.springblog.MyBatisCategoryServiceTest


    ctx.load("classpath:mybatis-app-context.xml");
    ctx.refresh();
   
    System.out.println("App context initialized successfully");   
   
    EntryService entryService = ctx.getBean("entryService", EntryService.class);
   
    List<Entry> entries = entryService.findAll();
   
    //System.err.println("Size: " + entries.size());
    for (Entry entry: entries) System.out.println("Entry: " + entry);

  }
View Full Code Here


    ctx.load("classpath:mybatis-app-context.xml");
    ctx.refresh();
   
    System.out.println("App context initialized successfully");       

    UserService userService = ctx.getBean("userService", UserService.class);
   
    AppUser appUser = userService.findByUserName("clarence");
   
    System.out.println("User name: " + appUser.getUserName());
  }
View Full Code Here

    logger.info("Retrieving audit records for Entry with id: {}", id);
   
    List<Entry> auditEntries = entryAuditService.findAuditById(id);
   
    // Construct the grid data that will return as JSON data
    EntryGrid entryGrid = new EntryGrid();
    entryGrid.setCurrentPage(1);
    entryGrid.setTotalPages(1);
    entryGrid.setTotalRecords(auditEntries.size());
    entryGrid.setEntryData(auditEntries);   
   
    return entryGrid;
  }
View Full Code Here

       
    //Page<Entry> entryPage = entryService.findAllByPage(pageRequest);
    Page<Entry> entryPage = entryService.findEntryByCriteria(searchCriteria, pageRequest);
   
    // Construct the grid data that will return as JSON data
    EntryGrid entryGrid = new EntryGrid();
   
    entryGrid.setCurrentPage(entryPage.getNumber() + 1);
    entryGrid.setTotalPages(entryPage.getTotalPages());
    entryGrid.setTotalRecords(entryPage.getTotalElements());
    entryGrid.setEntryData(Lists.newArrayList(entryPage.iterator()));
   
    return entryGrid;
 
View Full Code Here

  @RequestMapping(method = RequestMethod.POST)
    public String create(@Valid Comment comment, BindingResult bindingResult, @PathVariable("blogid") Long blogid, Model uiModel,
        HttpServletRequest httpServletRequest, RedirectAttributes redirectAttributes, Locale locale) {
    logger.info("Creating comment for entry id: " + blogid);
        if (bindingResult.hasErrors()) {
      uiModel.addAttribute("message", new Message("error", messageSource.getMessage("comment_save_fail", new Object[]{}, locale)));
            uiModel.addAttribute("comment", comment);
            populateSelectBox(uiModel, blogid);
            return "blogs/" + UrlUtil.encodeUrlPathSegment(blogid.toString(), httpServletRequest) + "/comments/create";
        }
        uiModel.asMap().clear();
        redirectAttributes.addFlashAttribute("message", new Message("success", messageSource.getMessage("comment_save_success", new Object[]{}, locale)));
       
        Entry entry = entryService.findById(blogid);
        logger.info("Comment id: " + comment.getId());
        comment.setId(null);
        comment.setEntry(entry);
View Full Code Here

  @RequestMapping(value = "/{id}", params = "form", method = RequestMethod.POST)
    public String update(@Valid Comment comment, BindingResult bindingResult, @PathVariable("blogid") Long blogid, Model uiModel,
        HttpServletRequest httpServletRequest, RedirectAttributes redirectAttributes, Locale locale) {
    logger.info("Updating comment");
        if (bindingResult.hasErrors()) {
          uiModel.addAttribute("message", new Message("error", messageSource.getMessage("comment_save_fail", new Object[]{}, locale)));         
            uiModel.addAttribute("comment", comment);
            populateSelectBox(uiModel, blogid);
            return "blogs/" + UrlUtil.encodeUrlPathSegment(blogid.toString(), httpServletRequest) + "/comments/update";
        }
        uiModel.asMap().clear();
        redirectAttributes.addFlashAttribute("message", new Message("success", messageSource.getMessage("comment_save_success", new Object[]{}, locale)));       
       
        Entry entry = entryService.findById(blogid);
        comment.setEntry(entry);
        commentService.save(comment);
        return "redirect:/blogs/" + UrlUtil.encodeUrlPathSegment(blogid.toString(), httpServletRequest);
View Full Code Here

  private MessageSource messageSource; 
 
  @RequestMapping("/loginfail")
  public String loginFail(Model uiModel, Locale locale) {
    logger.info("Login failed detected");
    uiModel.addAttribute("message", new Message("error", messageSource.getMessage("message_login_fail", new Object[]{}, locale)));
    return "blogs/list";
 
View Full Code Here

  @RequestMapping(method = RequestMethod.POST)
    public String create(@Valid Entry entry, BindingResult bindingResult, Model uiModel,
        HttpServletRequest httpServletRequest, RedirectAttributes redirectAttributes, Locale locale) {
    logger.info("Creating entry");
        if (bindingResult.hasErrors()) {
      uiModel.addAttribute("message", new Message("error", messageSource.getMessage("entry_save_fail", new Object[]{}, locale)));
            uiModel.addAttribute("entry", entry);
            populateSelectBox(uiModel, entry);
            return "blogs/create";
        }
        uiModel.asMap().clear();
        redirectAttributes.addFlashAttribute("message", new Message("success", messageSource.getMessage("entry_save_success", new Object[]{}, locale)));

        logger.info("Entry id: " + entry.getId());
        entryService.save(entry);
        return "redirect:/blogs/" + UrlUtil.encodeUrlPathSegment(entry.getId().toString(), httpServletRequest);
    }
View Full Code Here

  @RequestMapping(value = "/{id}", params = "form", method = RequestMethod.POST)
    public String update(@Valid Entry entry, BindingResult bindingResult, Model uiModel,
        HttpServletRequest httpServletRequest, RedirectAttributes redirectAttributes, Locale locale) {
    logger.info("Updating entry");
        if (bindingResult.hasErrors()) {
          uiModel.addAttribute("message", new Message("error", messageSource.getMessage("entry_save_fail", new Object[]{}, locale)));         
            uiModel.addAttribute("entry", entry);
            populateSelectBox(uiModel, entry);
            return "blogs/update";
        }
        uiModel.asMap().clear();
        redirectAttributes.addFlashAttribute("message", new Message("success", messageSource.getMessage("entry_save_success", new Object[]{}, locale)));
        entryService.save(entry);
        return "redirect:/blogs/" + UrlUtil.encodeUrlPathSegment(entry.getId().toString(), httpServletRequest);
    }
View Full Code Here

    Long blogId = uploadItem.getBlogId();
    Long commentId = uploadItem.getCommentId();
    // MultipartFile file = uploadItem.getFileData();
    String uploadType = uploadItem.getUploadType();
    Message message;

    if (file.getSize() > 0) {
      if (uploadType.equalsIgnoreCase("entry")) {
        // Construct Attachment object
        EntryAttachment entryAttachment = new EntryAttachment();
        entryAttachment.setFileName(getFileName(file));
        entryAttachment.setFileData(IOUtils.toByteArray(file.getInputStream()));
        entryAttachment.setContentType(file.getContentType());
       
        Entry entry = entryService.findById(blogId);
        entryAttachment.setEntry(entry);
        entry.addAttachment(entryAttachment);
        entryService.save(entry);
      } else {
        // Construct Attachment object
        CommentAttachment commentAttachment = new CommentAttachment();
        commentAttachment.setFileName(getFileName(file));
        commentAttachment.setFileData(IOUtils.toByteArray(file.getInputStream()));
        commentAttachment.setContentType(file.getContentType())
       
        Comment comment = commentService.findById(commentId);
        commentAttachment.setComment(comment);
        comment.addAttachment(commentAttachment);
        commentService.save(comment);
      }

      message = new Message("success", "File '" + getFileName(file)
          + "' uploaded successfully");
      redirectAttributes.addFlashAttribute("message", message);
    } else {
      redirectAttributes.addFlashAttribute("validationResult", "error");
      message = new Message("error", "Please select a file for upload");
      redirectAttributes.addFlashAttribute("message", message);
    }

    return "redirect:/blogs/"
        + UrlUtil.encodeUrlPathSegment(blogId.toString(), request);
View Full Code Here

TOP

Related Classes of com.apress.prospring3.springblog.MyBatisCategoryServiceTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.