コード例 #1
0
  @RequestMapping(value = "/availableAreas", method = RequestMethod.GET)
  public ModelAndView available() {

    Map<String, Boolean> map = new HashMap<>();

    String stalker = FileUtils.readFile(Conf.RESOURSES_PATH + "stalker.json");
    if (stalker != null && !stalker.isEmpty()) {
      Area area = new Gson().fromJson(stalker, Area.class);
      Optional<Area> areaDb = areaService.getArea(area.getName());
      map.put(area.getTranslitName(), areaDb.isPresent());
    }

    String monrepo = FileUtils.readFile(Conf.RESOURSES_PATH + "monrepo.json");
    if (monrepo != null && !monrepo.isEmpty()) {
      Area area = new Gson().fromJson(monrepo, Area.class);
      Optional<Area> areaDb = areaService.getArea(area.getName());
      map.put(area.getTranslitName(), areaDb.isPresent());
    }

    String triangular = FileUtils.readFile(Conf.RESOURSES_PATH + "triangular_lake.json");
    if (triangular != null && !triangular.isEmpty()) {
      //            areas.add("triangular_lake");
      Area area = new Gson().fromJson(triangular, Area.class);
      Optional<Area> areaDb = areaService.getArea(area.getName());
      map.put(area.getTranslitName(), areaDb.isPresent());
    }

    ModelAndView mv = new ModelAndView("available_areas");
    mv.addObject("areas", map.entrySet());
    return mv;
  }
コード例 #2
0
  @RequestMapping(value = "/add_to_db", method = RequestMethod.GET)
  public ModelAndView available(@RequestParam(value = "name", required = true) String name) {

    String area = FileUtils.readFile(Conf.RESOURSES_PATH + name + ".json");

    Area areaObj = new Gson().fromJson(area, Area.class);
    areaService.saveArea(areaObj);

    return new ModelAndView("redirect:/availableAreas");
  }