Package evolaris.framework.blog.datamodel

Examples of evolaris.framework.blog.datamodel.Blog


   * @param commentRoles roles a user has to be assigned to in order to comment within the blog; may be empty or null
   * @return the new blog object containing a valid database ID
   */
  public Blog createBlog(String name,  List<Role> readRoles,List<Role> writeRoles,List<Role> commentRoles){
    Group group = mgblGroup();
    Blog blog = new Blog();
    blog.setName(name);
    blog.setGroup(group);
    blog.setCode("blogcode"+(new Date().getTime()));
    PermissionManager permissionManager = new PermissionManager(locale, session);
    blog.setAccessControlledClass(permissionManager.getAccessControlledClass("BLOG"));
    blog.setCreatedAt(new Date());
    session.save(blog);
   
    // create permissions according to parameters
   
    for (Role readRole : readRoles) {
View Full Code Here


   * @param author The currently logged in user
   * @param labels An array of labels, used to tag the article. 
   * @return
   */
  public Article createGameBlogArticle(GameHiber game, User author, String[] labels) {
    Blog gameBlog = getGameBlog();
    Article article = new Article();
    article.setTitle(game.getName());
    article.setContent(game.getDescription());
    article.setAuthor(author);
    article.setCreatedAt(new Date());
    article.setBlog(gameBlog);
    gameBlog.getArticles().add(article);
    session.save(article);
    session.saveOrUpdate(gameBlog);
   
    // attach labels
    article.setLabels(new HashSet<Label>());
View Full Code Here

    adminRole = umgr.getRole("administrator");
    userRole = umgr.getRole("user");
   
    javaDevelopers = usmgr.getUserSet(1L)// adminUser is member, userUser is not
   
    testObject = new Blog();
    testObject.setName("test");
    testObject.setGroup(adminUser.getGroup());
    session.save(testObject);
   
  }
View Full Code Here

   *      javax.servlet.http.HttpServletRequest,
   *      javax.servlet.http.HttpServletResponse)
   */
  public ActionForward create(ActionMapping mapping, ActionForm form,HttpServletRequest req, HttpServletResponse resp)  {
    BlogEnterOrEditForm f = (BlogEnterOrEditForm)form;
    Blog blog = new Blog();
    Group group = this.getCurrentGroup(req);
    checkAccessRights(req, group);
    formToBlog(f, blog);
    blog.setGroup(group);
    ensureUniqueCodePerGroup(blog, req);
    BlogManager mgr = new BlogManager(locale, session);
    mgr.createBlog(blog);
    LOGGER.info("User " + req.getUserPrincipal().getName().toLowerCase() + ": created blog `"+ blog.getCode() + "`");
    return mapping.findForward("created");
  }
View Full Code Here

 
  public ActionForward edit(ActionMapping mapping, ActionForm form,HttpServletRequest req, HttpServletResponse resp) {
    String idParam = req.getParameter("id");
    BlogManager mgr = new BlogManager(locale, session);
    Blog blog = mgr.getBlog(Long.parseLong(idParam));
    if (blog == null) {
      throw new InputException(getResources(req).getMessage(locale, "admin.BlogNotFound", idParam));
    }
    checkAccessRights(req, blog.getGroup());   
    blogToForm(blog, (BlogEnterOrEditForm)form);
    return mapping.findForward("edit");
  }
View Full Code Here

   *      javax.servlet.http.HttpServletResponse)
   */
  public ActionForward modify(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    BlogEnterOrEditForm f = (BlogEnterOrEditForm)form;
    BlogManager mgr = new BlogManager(locale,session);
    Blog blog = mgr.getBlog(f.getId());
    if (blog == null) {
      throw new InputException(getResources(req).getMessage(locale, "admin.BlogNotFound", f.getId()));
    }
    checkAccessRights(req, blog.getGroup());
    formToBlog(f, blog);
    ensureUniqueCodePerGroup(blog, req);
    mgr.modifyBlog(blog);
    LOGGER.info("User " + req.getUserPrincipal().getName().toLowerCase() + ": modified blog `"+ blog.getCode() + "`");
    return mapping.findForward("modified");
  }
View Full Code Here

   *      javax.servlet.http.HttpServletResponse)
   */
  public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    String idParam = req.getParameter("id");
    BlogManager mgr = new BlogManager(locale, session);
    Blog blog = mgr.getBlog(Long.parseLong(idParam));
    if (blog == null) {
      throw new InputException(getResources(req).getMessage(locale, "admin.BlogNotFound",  idParam));
    }
    checkAccessRights(req, blog.getGroup());
    mgr.deleteBlog(blog);
    String code = blog.getCode();
    LOGGER.info("User " + req.getUserPrincipal().getName().toLowerCase() + ": deleted blog `"+ code + "`");
    return mapping.findForward("deleted");
  }
View Full Code Here

  /**
   * view a blog specified by id or code
   */
  protected ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp, int selection) {
    BlogManager blogMgr = new BlogManager(locale, session);
    Blog blog = null;
    String idParam = req.getAttribute("id") != null ? (String)req.getAttribute("id") : req.getParameter("id"); // allow parameter injection
    String codeParam = req.getAttribute("code") != null ? (String)req.getAttribute("code") : req.getParameter("code");
    String groupParam = req.getAttribute("group_id") != null ? (String)req.getAttribute("group_id") : req.getParameter("group_id");
    String dateArchiveParam = req.getAttribute("datearchive") != null ? (String)req.getAttribute("datearchive") : req.getParameter("datearchive");
    String labelArchiveParam = req.getAttribute("labelarchive") != null ? (String)req.getAttribute("labelarchive") : req.getParameter("labelarchive");
    String unlabelledParam = req.getAttribute("unlabelled") != null ? (String)req.getAttribute("unlabelled") : req.getParameter("unlabelled");
    if (idParam != null) {
      blog = blogMgr.getBlog(Long.parseLong(idParam));
    } else if (codeParam != null && groupParam != null) {
      try {
        long groupId = Long.parseLong(groupParam);
        GroupManager groupMgr = new GroupManager(locale, session);
        Group group = groupMgr.getGroup(groupId);
        blog = blogMgr.getBlog(codeParam, group);
      } catch (Exception e) {
        blog = null;
      }
    } else {
      if (webUser != null) {
        blog = blogMgr.getBlog(webUser.getUsername(), webUser.getGroup());
      }
    }
    if (blog == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.BlogNotFound", idParam, codeParam));
    }
    Set<Long> permissions = getPermissions(blog, webUser);
    if (!permissions.contains(PermissionManager.READ_PERMISSION)) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.insufficientRights"));
    }
    req.setAttribute("blog", blog);   
    Collection<Article> articles = null;
    List<DisplayableArticle> displayArticles = new ArrayList<DisplayableArticle>();
    Date from = null, to = null;
    if (dateArchiveParam != null && dateArchiveParam.length() > 0) {
      Date archiveDate = new Date(Long.parseLong(dateArchiveParam));
      articles = blogMgr.getArchivedArticles(blog, archiveDate);
      SimpleDateFormat df = new SimpleDateFormat("yyyy");
      String yearStr = df.format(archiveDate);
      df = new SimpleDateFormat("MMMM");
      String monthStr = df.format(archiveDate);
      req.setAttribute("subheader", getLocalizedMessage("BloggingWeb", "blog.ArchiveForMonth", monthStr, yearStr));
      Calendar cal = Calendar.getInstance();
      df = new SimpleDateFormat("yyyy-MMMM");
      try {
        cal.setTime(df.parse(yearStr+"-"+monthStr));
        from = cal.getTime();
        cal.add(Calendar.MONTH, 1);
        to = cal.getTime();
      } catch (ParseException e) {
        from = to = null;
      }     
    } else if (labelArchiveParam != null && labelArchiveParam.length() > 0) {
      Label label = blogMgr.getLabel(blog, Long.parseLong(labelArchiveParam));
      articles = blogMgr.getArchivedArticles(blog, label);
      req.setAttribute("subheader", getLocalizedMessage("BloggingWeb", "blog.ArchiveForLabel", label.getLabel()));     
    } else if (unlabelledParam != null) {
      articles = blogMgr.getUnlabelledArticles(blog);
      req.setAttribute("subheader", getLocalizedMessage("BloggingWeb", "blog.ArchiveForUnlabelled"));     
    } else {
      articles = blog.getArticles();
    }
    for (Article a : articles) {
     
      boolean display = true;
     
      if(selection==BLOCKED) {
        if(isArticleBlocked(a) || isACommentBlocked(a)){
          display = true;
        } else {
          display = false;
        }
      }
     
      if(selection==NOT_REVIEWED){
        if(isArticleBlocked(a)){
          display = false;
        }else if(isArticleNotReviewed(a)){
          display = true;
        } else if(isACommentNotReviewed(a)){
          display = true;
        } else {
          display = false;
        }
      }
       
      if(selection==RELEASED){
        if(isArticleReleased(a)){
          display = true;
        } else {
          display = false;
        }
      }
     
      if(display){
        DisplayableArticle da = new DisplayableArticle(a, true)
        if (da.getTitle() == null || da.getTitle().trim().length()==0) {
          da.setTitle(getLocalizedMessage("BloggingWeb", "blog.noTitle"));
        }
        displayArticles.add(da);
      }

    }
    req.setAttribute("mayAddArticles", permissions.contains(PermissionManager.WRITE_PERMISSION));
    req.setAttribute("articleList", displayArticles);
    req.setAttribute("countArticles", displayArticles.size());
    req.setAttribute("countPosters", blogMgr.countAuthors(blog, from, to));
    req.setAttribute("countComments", blogMgr.countComments(blog, from, to));
    req.setAttribute("dateArchiveList", blogMgr.getArchives(blog));
    req.setAttribute("labelCloud", blogMgr.getLabelCloud(blog, webUser, null, 20));
   
    try {
      req.setAttribute("articleRssUrl", getBaseUrl(req)+"/viewBlog.do?method=rss&id="+blog.getId());
      req.setAttribute("commentRssUrl", getBaseUrl(req)+"/viewBlog.do?method=commentrss&id="+blog.getId());
    } catch (Exception e) {
      LOGGER.error("Failure creating RSS Urls: "+e.getMessage(), e);
    }
    return mapping.findForward("view");
  }
View Full Code Here

   * Based on anonymous user.
   * 
   */
  protected ActionForward rss(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    BlogManager blogMgr = new BlogManager(locale, session);
    Blog blog = null;
    String idParam = req.getParameter("id");
    String codeParam = req.getParameter("code");
    String groupParam = req.getParameter("group_id");
    if (idParam != null) {
      blog = blogMgr.getBlog(Long.parseLong(idParam));
View Full Code Here

   * Based on anonymous user.
   * 
   */
  protected ActionForward commentRss(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    BlogManager blogMgr = new BlogManager(locale, session);
    Blog blog = null;
    String idParam = req.getParameter("id");
    String codeParam = req.getParameter("code");
    String groupParam = req.getParameter("group_id");
    if (idParam != null) {
      blog = blogMgr.getBlog(Long.parseLong(idParam));
View Full Code Here

TOP

Related Classes of evolaris.framework.blog.datamodel.Blog

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.