Пример #1
0
  public HttpServletRequest addtagurl(HttpServletRequest req, HttpServletResponse response)
      throws SQLException {
    User user = User.getInstance();
    if (user == null) {
      this.parent.redirect("login", true);
      return req;
    } else {

      String uri = (String) req.getParameter("url");
      String listTag = (String) req.getParameter("list");
      Url url = user.getUrlById(Integer.valueOf(uri));
      String str[] = listTag.split("@");
      for (int i = 0; i < str.length; i++) {
        Tag tag = user.getTagByName(str[i]);
        if (tag == null) {
          // add tag
          tag = new Tag(str[i], user.getuId());
          tag.addTagtoBDD();
          tag.setTid(tag.getTagIdFromBDD());
          user.addOneTag(tag);
        }
        if (!url.hasTag(tag)) {
          TagMap tm = new TagMap(tag, url);
          tm.addTagMaptoBDD(user.getuId());
          tm.setTmId(tm.getIdFromBdd());
          user.addOneMap(tm);
        }
      }
      return req;
    }
  }
Пример #2
0
  public HttpServletRequest addurl(HttpServletRequest req, HttpServletResponse response) {
    int idUser = Integer.parseInt(req.getParameter("id"));
    String siteUrl = req.getParameter("url");
    String nomUrl = req.getParameter("nomUrl");
    Url url = new Url(idUser, siteUrl, nomUrl, 0);
    User userInstance = User.getInstance();
    Url oldurl = userInstance.getUrlByUri(siteUrl);
    if (oldurl == null) {
      try {
        url.addUrlToDBB();
        url.setuId(url.getIdFromBDD());
        User user = (User) this.parent.user();
        user.addOneUrl(url);
        response.setStatus(200);
      } catch (MySQLIntegrityConstraintViolationException e) {
        // URL existe d�j� dans la BDD
        System.out.println("URL duppliquee");
        response.setStatus(201);

      } catch (SQLException e) {
        // erreur dans l'insertion a la BDD
        e.printStackTrace();
        response.setStatus(400);
      }
    } else {
      System.out.println("URL duppliquee");
      response.setStatus(201);
    }

    return req;
  }
Пример #3
0
 public HttpServletRequest addvisit(HttpServletRequest req, HttpServletResponse response) {
   User u = User.getInstance();
   if (u == null) {
     this.parent.redirect("login", true);
     return req;
   } else {
     String id = req.getParameter("id");
     Url url = u.getUrlById(Integer.valueOf(id));
     url.addVisit();
     return req;
   }
 }
Пример #4
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;
    }
  }