예제 #1
0
  @RequestMapping(value = "/robots", method = RequestMethod.GET)
  public String Robots(Model model) {
    List<Robot> robots = this.robotService.findAll();

    // liste de dates au format francais
    Map<Integer, String> french_dates = new HashMap<Integer, String>();
    // slider d'images
    ArrayList<String> list_images = new ArrayList<String>();

    for (Robot robot : robots) {
      // images
      File image =
          new File(
              "D:/Workspace/insta/jee/WorldOfRobots/src/main/webapp/resources/images/robots/"
                  + robot.getPath_picture());

      if (image.exists() && !image.isDirectory()) {
        list_images.add(robot.getPath_picture());
      }
      // date création
      french_dates.put(
          robot.getId(), new SimpleDateFormat("dd/MM/yyyy HH:mm").format(robot.getCreation_date()));
    }
    if (list_images.isEmpty()) {
      list_images.add("no-image.png");
    }

    model.addAttribute("list_images", list_images);
    model.addAttribute("dates", french_dates);
    model.addAttribute("robots", robots);
    return "robots";
  }
예제 #2
0
  @RequestMapping(value = "/robots/card", method = RequestMethod.GET)
  public String cardRobot(
      Model model, @RequestParam(value = "id") final int id, HttpServletRequest request) {
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");
    Robot robot = this.robotService.findById(id);
    String list_technologies = "";
    // liste de dates au format francais
    Map<Integer, String> french_dates = new HashMap<Integer, String>();

    for (int i = 0; i < robot.getTechnologies().size(); i++) {

      list_technologies += robot.getTechnologies().get(i).getName();
      if (robot.getTechnologies().size() - 1 == i) {
        list_technologies += ".";
      } else {
        list_technologies += ", ";
      }
    }

    File image =
        new File(
            "D:/Workspace/insta/jee/WorldOfRobots/src/main/webapp/resources/images/robots/"
                + robot.getPath_picture());
    String name_file = "";

    if (image.exists() && !image.isDirectory()) {
      name_file = image.getName();
    } else {
      name_file = "no-image.png";
    }

    french_dates.put(
        robot.getId(), new SimpleDateFormat("dd/MM/yyyy HH:mm").format(robot.getCreation_date()));

    Long participate_competition = this.robotService.countCompetitionByRobot(robot.getId());
    Long participate_battle = this.robotService.countBattleByRobot(robot.getId());
    Long win_battle = this.robotService.countWinBalttleByRobot(robot.getId());

    model.addAttribute("technologies", list_technologies);
    model.addAttribute("name_file", name_file);
    model.addAttribute("participate_competition", participate_competition);
    model.addAttribute("participate_battle", participate_battle);
    model.addAttribute("win", win_battle);
    model.addAttribute("lose", (participate_battle - win_battle));
    model.addAttribute("robot", robot);
    model.addAttribute("french_dates", french_dates);
    session.setAttribute("user", user);
    return "robot";
  }