// analyze and store a new reddit comment thread @RequestMapping(value = "frequency/new", method = RequestMethod.POST) public Map<String, String> createNewFrequency(@RequestParam("url") String url) throws IOException { Map<String, Long> wordCountMap = null; wordCountMap = redditWordCountService.getWordCount(new URL(url)); String runid = UUID.randomUUID().toString(); List<WordCount> wcs = new ArrayList<WordCount>(); for (Map.Entry<String, Long> wordEntry : wordCountMap.entrySet()) { wcs.add(new WordCount(null, runid, wordEntry.getKey(), wordEntry.getValue())); } redditWordCountService.saveAll(wcs); return Maps.newHashMap(ImmutableMap.of("runid", runid)); }
// return the word counts for a run in order with a limit @RequestMapping(value = "frequency/{runid}", method = RequestMethod.GET) public List<WordCount> listWordCountsForRunId( @PathVariable("runid") String runid, @RequestParam("count") Integer limit) { return redditWordCountService.getListForRunid(runid, limit); }
// A bad idea in general to just return all the records, but in this case of a small demo project // it's ok @RequestMapping(value = "frequency/all", method = RequestMethod.GET) public List<WordCount> listWordCounts() { return redditWordCountService.getList(); }