Пример #1
0
  /**
   * Fonction tableauBord Gere la page tableau de bord de l'application
   *
   * @param req : HttpServletRequest
   */
  public HttpServletRequest tableaubord(HttpServletRequest req, HttpServletResponse response) {
    User user = User.getInstance();
    if (user == null) {
      this.parent.redirect("login", true);
      return req;
    } else {
      List<Tag> tags = user.getAllTag();
      int nbTags = tags.size();
      List<Url> urls = user.getAllUrl();
      int nbUrls = urls.size();
      List<Url> untaggedUrls = user.getUntaggedUrl();
      int nbUntaggedUrls = untaggedUrls.size();
      Map<Tag, List<Url>> mapTagUrls = new HashMap<Tag, List<Url>>();

      if (tags != null) {
        Iterator<Tag> it = tags.iterator();
        while (it.hasNext()) {
          Tag tag = it.next();
          mapTagUrls.put(tag, tag.getUrls());
        }
      }
      req.setAttribute("tags", tags);
      req.setAttribute("urls", urls);
      req.setAttribute("untaggedurls", untaggedUrls);
      req.setAttribute("mapTagUrls", mapTagUrls);
      req.setAttribute("nbTags", nbTags);
      req.setAttribute("nbUrls", nbUrls);
      req.setAttribute("nbUntaggedUrls", nbUntaggedUrls);
      return req;
    }
  }
Пример #2
0
  public HttpServletRequest tagbyid(HttpServletRequest req, HttpServletResponse response) {
    User user = User.getInstance();
    if (user == null) {
      this.parent.redirect("login", true);
      return req;
    } else {

      String id = req.getParameter("id");
      List<Tag> tags = user.getAllTag();
      int nbTags = tags.size();
      List<Url> urls = user.getAllUrl();
      int nbUrls = urls.size();
      List<Url> untaggedUrls = user.getUntaggedUrl();
      int nbUntaggedUrls = untaggedUrls.size();
      Tag tag = user.getTagById(Integer.valueOf(id));
      List<Url> listUrls = tag.getUrls();

      req.setAttribute("tag", tag);
      req.setAttribute("nbTags", nbTags);
      req.setAttribute("nbUrls", nbUrls);
      req.setAttribute("nbUntaggedUrls", nbUntaggedUrls);
      req.setAttribute("listUrls", listUrls);
      return req;
    }
  }
Пример #3
0
  public HttpServletRequest graph(HttpServletRequest req, HttpServletResponse response)
      throws SQLException {
    User user = User.getInstance();
    if (user == null) {
      this.parent.redirect("login", true);
      return req;
    } else {
      List<Tag> listTags = user.getAllTag();
      Iterator<Tag> it = listTags.iterator();
      node instTag = null;
      Tag currentTag = null;
      List<node> nodes = new ArrayList<node>();
      List<edge> links = new ArrayList<edge>();
      int ind = 0;
      double maxUrl = 0;
      while (it.hasNext()) {
        currentTag = (Tag) it.next();
        if (currentTag.getUrls().size() != 0) {
          instTag =
              new node(
                  currentTag.getTid(),
                  currentTag.gettName(),
                  currentTag.getUrls().size(),
                  currentTag);
          if (maxUrl < currentTag.getUrls().size()) maxUrl = currentTag.getUrls().size();
          instTag.setIndex(ind);
          instTag.setColorId(ind);
          nodes.add(instTag);
          instTag = null;
          ind++;
        }
      }

      // ratio taille des noeuds
      for (int i = 0; i < nodes.size(); i++) {
        nodes.get(i).setSize(nodes.get(i).getSize() / maxUrl);
      }

      List<Url> listUrls = user.getAllUrl();
      // Iterator<Url> itUri=listUrls.iterator();
      Url currentUrl;
      for (int k = 0; k < listUrls.size(); k++) {
        currentUrl = (Url) listUrls.get(k);
        if (currentUrl.getTags().size() > 1) {
          edge instEdge = null;
          for (int i = 0; i < nodes.size(); i++) {
            for (int j = i + 1; j < nodes.size(); j++) {
              if (currentUrl.getTags().contains((Tag) nodes.get(i).getTag())
                  && currentUrl.getTags().contains((Tag) nodes.get(j).getTag())) {
                instEdge = new edge(nodes.get(i).getIndex(), nodes.get(j).getIndex());
                links.add(instEdge);
                instEdge = null;
              }
            }
          }
        }
      }
      coloration(nodes, links);
      req.setAttribute("json_links", links.toString());
      req.setAttribute("json_nodes", nodes.toString());

      return req;
    }
  }