@RequestMapping(value = "/move", method = RequestMethod.POST)
  @ResponseBody
  public String moveCalendar(
      @RequestParam("id") Long id,
      @RequestParam(value = "start", required = false) @DateTimeFormat(pattern = dataFormat)
          Date start,
      @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = dataFormat)
          Date end) {
    Calendar calendar = calendarService.findOne(id);

    if (end == null) {
      end = start;
    }

    calendar.setStartDate(start);
    calendar.setLength((int) Math.ceil(1.0 * (end.getTime() - start.getTime()) / oneDayMillis));
    if (DateUtils.isSameDay(start, end)) {
      calendar.setLength(1);
    }
    if (!"00:00:00".equals(DateFormatUtils.format(start, "HH:mm:ss"))) {
      calendar.setStartTime(start);
    }
    if (!"00:00:00".equals(DateFormatUtils.format(end, "HH:mm:ss"))) {
      calendar.setEndTime(end);
    }
    calendarService.copyAndRemove(calendar);

    return "ok";
  }
  @RequestMapping(value = "/new", method = RequestMethod.GET)
  public String showNewForm(
      @RequestParam(value = "start", required = false) @DateTimeFormat(pattern = dataFormat)
          Date start,
      @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = dataFormat) Date end,
      Model model) {

    setColorList(model);

    Calendar calendar = new Calendar();
    calendar.setLength(1);
    if (start != null) {
      calendar.setStartDate(start);
      calendar.setLength((int) Math.ceil(1.0 * (end.getTime() - start.getTime()) / oneDayMillis));
      if (DateUtils.isSameDay(start, end)) {
        calendar.setLength(1);
      }
      if (!"00:00:00".equals(DateFormatUtils.format(start, "HH:mm:ss"))) {
        calendar.setStartTime(start);
      }
      if (!"00:00:00".equals(DateFormatUtils.format(end, "HH:mm:ss"))) {
        calendar.setEndTime(end);
      }
    }
    model.addAttribute("model", calendar);
    return viewName("newForm");
  }
Ejemplo n.º 3
0
  @RequestMapping(value = "", method = RequestMethod.GET)
  @ApiOperation(
      value = "Get All LunchMenus.",
      notes = "Returns list of all existed LunchMenus by page.")
  @ApiResponses(
      value = {
        @ApiResponse(code = 401, message = "Only authenticated access allowed."),
      })
  public Page<LunchMenu> getAllLunchMenus(
      @RequestParam(value = "page", required = true, defaultValue = DEFAULT_PAGE_NUM)
          @ApiParam(value = "Page number of LunchMenus list", required = false)
          Integer page,
      @ApiParam(
              value = "Size of Page of LunchMenus list. ",
              allowableValues = "range[1,1000]",
              required = false)
          @RequestParam(value = "size", required = true, defaultValue = DEFAULT_PAGE_SIZE)
          Integer size,
      @ApiParam(value = "", hidden = true) Authentication authentication) {
    SpringUser springUser = (SpringUser) authentication.getPrincipal();
    LOGGER.debug(
        "Get all LunchMenu on page {} with size {} by {}", page, size, springUser.getUsername());

    size = Math.min(1000, size);
    return lunchMenusService.getAllLunchMenus(page, size, springUser.getRole());
  }
Ejemplo n.º 4
0
  @RequestMapping("/drug")
  public String search(
      @RequestParam(value = "name", defaultValue = "") String name,
      @RequestParam(value = "limit", defaultValue = "10") int limit,
      @RequestParam(value = "skip", defaultValue = "0") int skip)
      throws IOException {
    name = fixTerm.makeFdaSafe(name);
    if (name.length() == 0) {
      return "[]";
    }

    List<DrugSearchResult> rv = new LinkedList<DrugSearchResult>();

    Set<String> uniis = this.getUniisByName(name);
    Map<String, Set<String>> brandNames = this.getBrandNamesByNameAndUniis(name, uniis);

    // create full list of drug search results
    for (String unii : uniis) {
      for (String brandName : brandNames.get(unii)) {
        DrugSearchResult res = new DrugSearchResult();
        res.setUnii(unii);
        res.setBrandName(brandName);
        rv.add(res);
      }
    }

    // sort the list of drug search results by custom comparator
    Collections.sort(rv, new DrugSearchComparator(name));

    // implement skip/limit
    if (rv.size() > 0) {
      rv = rv.subList(skip, Math.min(rv.size(), skip + limit));
    }

    // fill in details for all the results we're returning
    for (DrugSearchResult res : rv) {
      res.setRxcui(this.getRxcuiByUnii(res.getUnii()));
      res.setGenericName(this.getGenericNameByRxcui(res.getRxcui()));
      if (res.getActiveIngredients().isEmpty() && res.getGenericName() != null) {
        res.setActiveIngredients(
            new TreeSet<String>(Arrays.asList(res.getGenericName().split(", "))));
      }
    }

    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(rv);
  }