Exemplo n.º 1
0
  public void passName() {
    FacesContext context = FacesContext.getCurrentInstance();
    Map map = context.getExternalContext().getRequestParameterMap();
    this.nameClicked = (String) map.get("nameClicked");
    this.countDocsCurrNameClicked = (String) map.get("countDocs");

    Iterator<Author> setAuthorsIterator = controllerBean.getSetAuthors().iterator();
    Author currAuthor = null;
    while (setAuthorsIterator.hasNext()) {
      currAuthor = setAuthorsIterator.next();
      if (currAuthor.getFullnameWithComma().equals(nameClicked)) {
        break;
      }
    }
    authorClicked = currAuthor;
    this.countDocsCurrNameClicked = String.valueOf(authorClicked.getTimesMentioned());

    FacesContext.getCurrentInstance()
        .getExternalContext()
        .getApplicationMap()
        .put("clickedAuthor", this.nameClicked);
    FacesContext.getCurrentInstance()
        .getExternalContext()
        .getApplicationMap()
        .put("uuid", controllerBean.uuid.toString());
  }
Exemplo n.º 2
0
 @PostConstruct
 private void init() {
   this.json = controllerBean.getJson();
   authorClicked = new Author("fake name");
   authorClicked.setYearFirstCollab(0);
   authorClicked.setYearLastCollab(3000);
   authorClicked.setTimesMentioned(888);
 }
Exemplo n.º 3
0
 public String getClickedAuthorLaius() {
   StringBuilder sb = new StringBuilder();
   sb.append("They have ");
   if (authorClicked.getTimesMentioned() == 1) {
     sb.append("one shared publication, in ");
     sb.append(authorClicked.getYearFirstCollab());
   } else {
     sb.append(authorClicked.getTimesMentioned());
     sb.append(" shared publications");
     if (authorClicked.getYearFirstCollab() == authorClicked.getYearLastCollab()) {
       if (authorClicked.getTimesMentioned() == 2) {
         sb.append(", both in ");
       } else {
         sb.append(", all in ");
       }
       sb.append(authorClicked.getYearLastCollab());
     } else {
       sb.append(", from ");
       sb.append(authorClicked.getYearFirstCollab());
       sb.append(" to ");
       sb.append(authorClicked.getYearLastCollab());
     }
   }
   sb.append(".");
   return sb.toString();
 }
Exemplo n.º 4
0
  @RequestMapping(value = "/comiclist/{name}")
  public String ComicInfo(@PathVariable("name") String name, Model m) {
    String propertyName[] = {"comicId"};
    String valueName[] = new String[1];
    valueName[0] = name;

    Comic c = comicService.GetComicInfo(name);

    List<Comment> comments = comicService.GetComicComment(propertyName, valueName, 0, maxComment);
    Author a = c.getAuthorId();

    Set<ComicPart> comicParts = c.getComicParts();
    int comentSum = comicService.GetCommentSum(propertyName, valueName);
    comentSum = comentSum % maxComment == 0 ? comentSum / maxComment : comentSum / maxComment + 1;
    String tabs = "";
    String comicTop3 = "";
    for (ComicTab ct : c.getComicTabs()) {
      tabs += "|" + ct.getTabId().getTabName();
    }

    Iterator<Comic> iterator = a.getComicCollection().iterator();
    int count = 0;
    while (iterator.hasNext()) {
      if (count == 3) break;
      Comic cTmp = iterator.next();
      comicTop3 += cTmp.getComicName() + " ";
      count++;
    }

    // int comicPartsSum=1;
    int comicPartsSum = comicParts.size();
    int comicPartsPage =
        comicPartsSum % maxComic == 0 ? comicPartsSum / maxComic : comicPartsSum / maxComic + 1;
    ComicPart[] tmp = new ComicPart[comicParts.size()];
    ComicPart[] cps = (ComicPart[]) comicParts.toArray(tmp);

    m.addAttribute("comicTop3", comicTop3);
    m.addAttribute("comicSum", a.getComicCollection().size());
    m.addAttribute("loveSum", c.getUserComics().size());
    m.addAttribute("author", a);
    m.addAttribute("comic", c);
    m.addAttribute("comicParts", cps);
    m.addAttribute("comicPartsSum", comicPartsSum);
    m.addAttribute("comicPartsPage", comicPartsPage);
    m.addAttribute("comments", comments);
    m.addAttribute("tabs", tabs);
    m.addAttribute("comment_sum", comentSum);
    m.addAttribute("comment_currentPage", 1);
    m.addAttribute("maxComic", maxComic);
    return "Comic/ComicInfo";
  }
Exemplo n.º 5
0
  @Override
  public void updateBook(String oldisbn, Book book) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String date = sdf.format(book.getPubDate());
    this.jdbcTemplate.update(
        new PreparedStatementCreator() {

          @Override
          public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            String query =
                "update "
                    + bookTable
                    + " set isbn = ?, title = ?, description = ?, price = ?, publisher = ?, pubDate = ?, edition = ?, pages = ? where isbn = ?";
            PreparedStatement ps = con.prepareStatement(query);
            ps.setString(1, book.getIsbn());
            ps.setString(2, book.getTitle());
            ps.setString(3, book.getDescription());
            ps.setDouble(4, book.getPrice());
            ps.setString(5, book.getPublisher());
            ps.setString(6, date);
            ps.setInt(7, book.getEdition());
            ps.setInt(8, book.getPages());
            ps.setString(9, oldisbn);
            return ps;
          }
        });

    this.jdbcTemplate.update(getPSCForRemoving(bookCategoriesTable, "isbn", book.getIsbn()));
    this.jdbcTemplate.update(getPSCForRemoving(bookAuthorTable, "isbn", book.getIsbn()));

    List<Category> categories = book.getCategories();
    for (Category category : categories) {
      this.jdbcTemplate.update(
          getPSCForInsertingBookCategory(book.getIsbn(), category.getCategoryId()));
    }

    List<Author> authors = book.getAuthors();
    for (Author author : authors) {
      this.jdbcTemplate.update(getPSCForInsertingBookAuthor(book.getIsbn(), author.getAuthorID()));
    }
  }
Exemplo n.º 6
0
  @Override
  public void insertBook(Book book) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String date = sdf.format(book.getPubDate());
    this.jdbcTemplate.update(
        new PreparedStatementCreator() {

          @Override
          public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            String query =
                "insert into "
                    + bookTable
                    + " (isbn, title, description, price, publisher, pubdate, edition, pages) values (?, ?, ?, ?, ?, ?, ?, ?);";
            PreparedStatement ps = con.prepareStatement(query);
            ps.setString(1, book.getIsbn());
            ps.setString(2, book.getTitle());
            ps.setString(3, book.getDescription());
            ps.setDouble(4, book.getPrice());
            ps.setString(5, book.getPublisher());
            ps.setString(6, date);
            ps.setInt(7, book.getEdition());
            ps.setInt(8, book.getPages());
            return ps;
          }
        });

    List<Category> categories = book.getCategories();
    for (Category category : categories) {

      this.jdbcTemplate.update(
          getPSCForInsertingBookCategory(book.getIsbn(), category.getCategoryId()));
    }

    List<Author> authors = book.getAuthors();
    for (Author author : authors) {
      this.jdbcTemplate.update(getPSCForInsertingBookAuthor(book.getIsbn(), author.getAuthorID()));
    }
  }
Exemplo n.º 7
0
  public boolean updateAuthor(int id, Author author) {
    conn = DBConnection.getConn().getConnection();
    String query =
        "update tblauthor set name = ?, dateOfBirth = ?, description = ? , imageurl = ?"
            + "where id = ?";
    try {
      PreparedStatement pr = conn.prepareStatement(query);
      pr.setString(1, author.getName());
      pr.setDate(2, (Date) author.getDateOfBirth());
      pr.setString(3, author.getDescription());
      pr.setString(4, author.getImageLink());
      pr.setInt(5, id);
      int i = pr.executeUpdate();
      if (i != -1) {
        return true;
      }

    } catch (SQLException e) {
      e.printStackTrace();
    }

    return false;
  }
Exemplo n.º 8
0
  public boolean addAuthor(Author author) {
    conn = DBConnection.getConn().getConnection();

    String query = "insert into tblauthor values (?,?,?,?,?)";
    PreparedStatement pr;
    try {
      pr = conn.prepareStatement(query);
      pr.setInt(1, author.getId());
      pr.setString(2, author.getName());
      pr.setDate(3, author.getDateOfBirth());
      pr.setString(4, author.getDescription());
      pr.setString(5, author.getImageLink());

      int i = pr.executeUpdate();
      if (i != -1) {
        return true;
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return false;
  }
Exemplo n.º 9
0
 public String obtainFullName() {
   return authorClicked.getFullname();
 }
Exemplo n.º 10
0
 public Integer getCountDocsCurrNameClicked() {
   return authorClicked.getTimesMentioned();
 }
Exemplo n.º 11
0
  public String getMostFrequentCoAuthors() {
    Set<Author> mostFrequentCoAuthors = controllerBean.getSearch().getSetMostFrequentCoAuthors();
    StringBuilder toReturn = new StringBuilder();

    if (mostFrequentCoAuthors == null || mostFrequentCoAuthors.isEmpty()) {
      return toReturn.toString();
    }

    toReturn.append("<div style=\"font-size:120%;\">");
    toReturn.append("<b>Most frequent co-author(s)</b><br>");
    toReturn.append("</div>");

    if (mostFrequentCoAuthors.size() == 1) {
      Author mostFrequentCoAuthor = mostFrequentCoAuthors.iterator().next();
      int nbCollab = mostFrequentCoAuthor.getTimesMentioned();
      toReturn.append("<b>");
      toReturn.append(mostFrequentCoAuthor.getFullname());
      toReturn.append("</b>");
      toReturn.append(".<br>");
      toReturn.append("Together, they have written ");
      toReturn.append(mostFrequentCoAuthor.getTimesMentioned());
      if (nbCollab == 1) {
        toReturn.append(" document");
      } else {
        toReturn.append(" documents");
      }
      if (controllerBean.getSearch().getYearFirstCollab()
          == controllerBean.getSearch().getYearLastCollab()) {
        toReturn.append(" in  ");
        toReturn.append(mostFrequentCoAuthor.getYearFirstCollab());
      } else {
        toReturn.append(" from ");
        toReturn.append(mostFrequentCoAuthor.getYearFirstCollab());
        toReturn.append(" to ");
        toReturn.append(mostFrequentCoAuthor.getYearLastCollab());
        toReturn.append(".");
      }

    } else {
      Iterator<Author> mostFrequentCoAuthorsIterator = mostFrequentCoAuthors.iterator();
      Author currAuthor;
      int maxNbCollab = 0;
      while (mostFrequentCoAuthorsIterator.hasNext()) {
        currAuthor = mostFrequentCoAuthorsIterator.next();
        maxNbCollab = Math.max(currAuthor.getTimesMentioned(), maxNbCollab);
      }
      if (maxNbCollab == 1) {
        toReturn.append(
            "- multiple coauthors, did not write more than one paper with the same coauthor.");

      } else {
        mostFrequentCoAuthorsIterator = mostFrequentCoAuthors.iterator();
        while (mostFrequentCoAuthorsIterator.hasNext()) {
          currAuthor = mostFrequentCoAuthorsIterator.next();
          toReturn.append("- <b>");
          toReturn.append(currAuthor.getFullname());
          toReturn.append("</b>, with ");
          toReturn.append(currAuthor.getTimesMentioned());
          if (currAuthor.getYearFirstCollab() == currAuthor.getYearLastCollab()) {
            toReturn.append(" shared publications in ");
            toReturn.append(currAuthor.getYearFirstCollab());
          } else {
            toReturn.append(" shared publications from ");
            toReturn.append(currAuthor.getYearFirstCollab());
            toReturn.append(" to ");
            toReturn.append(currAuthor.getYearLastCollab());
            toReturn.append(".<br>");
          }
        }
      }
    }
    toReturn.append("<p></p>");
    return toReturn.toString();
  }