Package evolaris.framework.blog.business

Examples of evolaris.framework.blog.business.BlogManager


    return null;
 
 
  public ActionForward enterArticle(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    BlogArticleForm f = (BlogArticleForm)form;
    BlogManager blogMgr = new BlogManager(locale, session);
    Long id = Long.parseLong(req.getParameter("id"));
    Blog blog = blogMgr.getBlog(id);
    if (blog == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.BlogNotFound", id, ""));
    }
    Set<Long> permissions = getPermissions(blog, webUser);
    if (!permissions.contains(PermissionManager.WRITE_PERMISSION)) {
View Full Code Here


    return mapping.findForward("enter");
 
 
  public ActionForward addArticle(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    BlogArticleForm f = (BlogArticleForm)form;
    BlogManager blogMgr = new BlogManager(locale, session);
    Blog blog = blogMgr.getBlog(f.getBlogId());
    if (blog == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.BlogNotFound", f.getBlogId(), ""));
    }
    Set<Long> permissions = getPermissions(blog, webUser);
    if (!permissions.contains(PermissionManager.WRITE_PERMISSION)) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.insufficientRights"));
    }
    Article article = new Article();
    article.setTitle(f.getTitle());
    article.setContent(f.getContent());
    article.setAuthor(webUser);
    article.setCreatedAt(new Date());   
    article = blogMgr.addArticle(blog, article);
    blogMgr.setLabels(article, f.getLabels());
    blogMgr.updateArticle(article);
    LOGGER.info("User "+UserManagerBase.toString(webUser)+" added article #"+article.getId()+" ("+article.getTitle()+") to blog #"+blog.getId()+" ("+blog.getName()+")");
    return injectId(mapping.findForward("added"), f.getBlogId());
 
View Full Code Here

  public ActionForward editArticle(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    if (webUser == null){
      throw new InputException(getResources(req).getMessage(locale, "blog.AnonymousEditingNotAllowed"));
    }
    BlogArticleForm f = (BlogArticleForm)form;
    BlogManager blogMgr = new BlogManager(locale, session);
    String idParam = req.getParameter("id");
   
    Article article = blogMgr.getArticle(Long.parseLong(idParam));
    if (article == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.ArticleNotFound", idParam));
    }
    Blog blog = blogMgr.getBlog(article.getBlog().getId())// fetch blog, so we have it after session is closed
    Set<Long> permissions = getPermissions(blog, webUser);
    if (!((article.getAuthor() != null && webUser.getId() == article.getAuthor().getId() && permissions.contains(PermissionManager.WRITE_PERMISSION))
        || permissions.contains(PermissionManager.EDIT_OTHERS_PERMISSION))) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.insufficientRights"));
    }
View Full Code Here

  public ActionForward modifyArticle(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    if (webUser == null){
      throw new InputException(getResources(req).getMessage(locale, "blog.AnonymousEditingNotAllowed"));
    }
    BlogArticleForm f = (BlogArticleForm)form;
    BlogManager blogMgr = new BlogManager(locale, session);
    Article article = blogMgr.getArticle(f.getArticleId());
    if (article == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.ArticleNotFound", f.getArticleId(), ""));
    }
    Set<Long> permissions = getPermissions(article.getBlog(), webUser);
    if (!((article.getAuthor() != null && webUser.getId() == article.getAuthor().getId() && permissions.contains(PermissionManager.WRITE_PERMISSION))
        || permissions.contains(PermissionManager.EDIT_OTHERS_PERMISSION))) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.insufficientRights"));
   
    article.setTitle(f.getTitle());
    article.setContent(f.getContent());
    article.setModifiedBy(webUser);
    article.setModifiedAt(new Date());
    blogMgr.setLabels(article, f.getLabels());
    blogMgr.updateArticle(article);
    LOGGER.info("User "+UserManagerBase.toString(webUser)+" modified article #"+article.getId()+" ("+article.getTitle()+") of blog #"+article.getBlog().getId()+" ("+article.getBlog().getName()+")");
    return injectId(mapping.findForward("modified"), f.getArticleId());
  }
View Full Code Here

  public ActionForward deleteArticle(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    if (webUser == null){
      throw new InputException(getResources(req).getMessage(locale, "blog.AnonymousEditingNotAllowed"));
    }
    BlogArticleForm f = (BlogArticleForm)form;
    BlogManager blogMgr = new BlogManager(locale, session);
    Article article = blogMgr.getArticle(f.getArticleId());
    if (article == null) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.ArticleNotFound", f.getArticleId(), ""));
    }
    Set<Long> permissions = getPermissions(article.getBlog(), webUser);
    if (!((article.getAuthor() != null && webUser.getId() == article.getAuthor().getId() && permissions.contains(PermissionManager.WRITE_PERMISSION))
        || permissions.contains(PermissionManager.EDIT_OTHERS_PERMISSION))) {
      throw new InputException(getLocalizedMessage("BloggingWeb", "blog.insufficientRights"));
   
    blogMgr.deleteArticle(article);
    LOGGER.info("User "+UserManagerBase.toString(webUser)+" deleted article #"+article.getId()+" ("+article.getTitle()+", "+article.getContent()+") of blog #"+article.getBlog().getId()+" ("+article.getBlog().getName()+")");
    return injectId(mapping.findForward("deleted"), f.getBlogId());
  }
View Full Code Here

      item.addElement("author", "");
      item.addElement("description").addCDATA("");
      item.addElement("guid").setText(blog.getId()+"-accessdenied");
    } else {
      int n = 0;
      BlogManager blogMgr = new BlogManager(locale, session);
      for (Comment c : blogMgr.getComments(blog)) {
        DisplayableComment co = new DisplayableComment(c);
        String authorName = co.getAuthorName() != null ? co.getAuthorName() : "("+getResources(req).getMessage("um.anonymousUser")+")";
        Element item = channel.addElement("item");
        String title = getLocalizedMessage("BloggingWeb", "blog.rssCommentEntry", c.getArticle().getTitle(), authorName);
        item.addElement("title").setText(title);
View Full Code Here

    try {
      labelParam = new String(req.getParameter("label").getBytes(), "UTF-8");
    } catch (UnsupportedEncodingException e1) {
      throw new BugException(e1.getMessage());
    }
    BlogManager blogMgr = new BlogManager(locale, session);
    List<Article> articles = blogMgr.getArticlesByLabel(labelParam);   
    List<DisplayableArticle> entries = new ArrayList<DisplayableArticle>();
    PermissionManager permissionMgr = new PermissionManager(locale, session);
    Map<Long, Set<Long>> blogPermissions = new HashMap<Long, Set<Long>>()// cache permissions, as computing them is expensive
    for (Article a : articles) {
      // only add articles, the user is allowed to see
      Set<Long> permissions = blogPermissions.get(a.getBlog().getId());
      if (permissions == null) {
        permissions = permissionMgr.getPermissions(a.getBlog(), webUser);
        // if group specified, only allow articles of blogs of that group!
        if (group != null && a.getBlog().getGroup() != group) {
          permissions = new HashSet<Long>();
        }
        blogPermissions.put(a.getBlog().getId(), permissions);
      }
      if (permissions.contains(PermissionManager.READ_PERMISSION)) {
        DisplayableArticle e = new DisplayableArticle(a, true);
        entries.add(e);
      }
    }       
    req.setAttribute("articleList", entries);
    req.setAttribute("label", labelParam);
    req.setAttribute("labelCloud", blogMgr.getLabelCloud(null, webUser, group, 20))// top 20 labels
    return mapping.findForward("list");
  }
View Full Code Here

   * @see BlogAction#view()
   */
  @SuppressWarnings("unchecked")
  protected ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    GroupManager groupMgr = new GroupManager(locale, session);
    BlogManager blogMgr = new BlogManager(locale, session);
    Group mgblGroup = groupMgr.getGroup("mgbl");
    Blog gameStyleBlog = blogMgr.getBlog("mgblgamestyles", mgblGroup);
    if (req.getParameter("id") == null) {
      req.setAttribute("id", Long.toString(gameStyleBlog.getId()));
    }
    super.view(mapping, form, req, resp);
    List<DisplayableArticle> displayArticles = (List<DisplayableArticle>)req.getAttribute("articleList");
    List<DisplayableApplicationType> gameStyles = new ArrayList<DisplayableApplicationType>();
    Blog gameBlog = blogMgr.getBlog("mgblgameinstances", mgblGroup);
    for (DisplayableArticle a : displayArticles) {
      Article blogArticle = blogMgr.getArticle(a.getId());
      DisplayableApplicationType entry = new DisplayableApplicationType(blogArticle);
      Label label = blogMgr.getLabel(gameBlog, blogArticle.getTitle());
      Collection<Article> gameList = label != null ? blogMgr.getArchivedArticles(gameBlog, label) : null;
      entry.setGameCount(gameList != null ? gameList.size() : 0);
      gameStyles.add(entry);
    }
    Collections.sort(gameStyles, new Comparator<DisplayableApplicationType>() {
      public int compare(DisplayableApplicationType o1, DisplayableApplicationType o2) {
View Full Code Here

    return super.enterArticle(mapping, form, req, resp);
  }   
 
  @SuppressWarnings("unchecked")
  protected ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    BlogManager blogMgr = new BlogManager(locale, session);
    GroupManager groupMgr = new GroupManager(locale, session);
    Group mgblGroup = groupMgr.getGroup("mgbl");
    Blog blog = blogMgr.getBlog("mgblgameinstances", mgblGroup);
    req.setAttribute("id", Long.toString(blog.getId()));
   
    // inject labelarchive param if mgblpresetlabel is there
    String labelArchiveParam = req.getParameter("labelarchive");
    if (labelArchiveParam == null) {  // try mgblPresetLabel
      String presetLabelString = (String)req.getSession().getAttribute("mgblPresetLabel");
      if (presetLabelString != null) {
        Label presetLabel = blogMgr.getLabel(blog, presetLabelString);
        if (presetLabel != null) {
          labelArchiveParam = Long.toString(presetLabel.getId());
          req.setAttribute("labelarchive", labelArchiveParam);
        }
      }
    }
   
    ActionForward fwd = super.view(mapping, form, req, resp);

    if (labelArchiveParam != null && labelArchiveParam.length() > 0) {
      Label label = blogMgr.getLabel(blog, Long.parseLong(labelArchiveParam));
      req.getSession().setAttribute("mgblPresetLabel", label.getLabel());
      Blog gameStyleBlog = blogMgr.getBlog("mgblgamestyles", blog.getGroup());
      req.getSession().removeAttribute("mgblCurrentGameStyle");
      req.getSession().removeAttribute("mgblCurrentGameStyleBelongsToSearchResult");
      for (Article style : gameStyleBlog.getArticles()) {
        if (label.getLabel().equals(style.getTitle())) {
          req.getSession().setAttribute("mgblCurrentGameStyle", new DisplayableArticle(style));
View Full Code Here

  /**
   * view an article specified by id
   */
  @SuppressWarnings("unchecked")
  protected ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp) {
    BlogManager blogMgr = new BlogManager(locale, session);
    String idParam = req.getParameter("id");
    Article article = blogMgr.getArticle(Long.parseLong(idParam));
    if (article == null) {
      throw new InputException(getResources(req).getMessage(locale, "blog.ArticleNotFound", idParam));
    }
    Blog blog = blogMgr.getBlog(article.getBlog().getId());
    Set<Long> permissions = getPermissions(blog, webUser);
    if (!permissions.contains(PermissionManager.READ_PERMISSION)) {
      throw new InputException(getResources(req).getMessage("um.insufficientRights"));
    }
    req.setAttribute("blog", blog);
    DisplayableArticle displayableArticle = new DisplayableArticle(article, true)
    req.setAttribute("article", displayableArticle);
    req.setAttribute("mayEditArticle", permissions.contains(PermissionManager.WRITE_PERMISSION));
    req.setAttribute("mayAddComment", permissions.contains(PermissionManager.ADD_COMMENT_PERMISSION));
    if (article.getAuthor() != null) {
      session.load(User.class, article.getAuthor().getId());
    }
    List<DisplayableComment> comments = new ArrayList<DisplayableComment>();
    for (Comment c : article.getComments()) {
      DisplayableComment dc = new DisplayableComment(c);
      comments.add(dc);
    }
    req.setAttribute("commentList", comments);

    // list of game instances
    Blog gameBlog = blogMgr.getBlog("mgblgameinstances", blog.getGroup());
    List<DisplayableArticle> gameList = new ArrayList<DisplayableArticle>();
    Label label = blogMgr.getLabel(gameBlog, article.getTitle());
    if (label == null) {
      // do some self healing magic ...
      label = new Label();
      label.setLabel(article.getTitle());
      blogMgr.addLabel(gameBlog, label);
    }
    Collection<Article> gameArticles = blogMgr.getArchivedArticles(gameBlog, label);
    for (Article gameArticle : gameArticles) {
      DisplayableArticle entry = new DisplayableArticle(gameArticle);
      gameList.add(entry);
    }
    req.setAttribute("gameList", gameList);
View Full Code Here

TOP

Related Classes of evolaris.framework.blog.business.BlogManager

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.