@Test(expected = WebApplicationException.class) public void suggestThrowsExceptionWhenInputIsBlank() throws Exception { this.component.suggest(CATEGORY_A, " ", 11); verify(this.logger).error("Both input and category must be provided."); Assert.fail("An exception should be thrown if input is blank."); }
@Override public Response suggest(@Nonnull final String category, @Nonnull final String input, int maxResults) { if (StringUtils.isBlank(input) || StringUtils.isBlank(category)) { this.logger.error("Both input and category must be provided."); throw new WebApplicationException(Response.Status.BAD_REQUEST); } if (!this.vm.hasCategory(category)) { this.logger.error("The requested vocabulary category [{}] does not exist.", category); throw new WebApplicationException(Response.Status.NOT_FOUND); } final List<VocabularyTerm> termSuggestions = this.vm.search(input, category, maxResults); final JSONObject rep = new JSONObject(); final JSONArray terms = new JSONArray(); termSuggestions.forEach(termSuggest -> { final JSONObject term = termSuggest.toJSON(); term.put("links", this.autolinker.get() .forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .build()); terms.put(term); }); rep.put("rows", terms).put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); }
DefaultCategoryTermSuggestionsResource extends XWikiResource implements CategoryTermSuggestionsResource { @Override public Response suggest(@Nonnull final String category, @Nonnull final String input, int maxResults) { if (StringUtils.isBlank(input) || StringUtils.isBlank(category)) { this.logger.error("Both input and category must be provided."); throw new WebApplicationException(Response.Status.BAD_REQUEST); } if (!this.vm.hasCategory(category)) { this.logger.error("The requested vocabulary category [{}] does not exist.", category); throw new WebApplicationException(Response.Status.NOT_FOUND); } final List<VocabularyTerm> termSuggestions = this.vm.search(input, category, maxResults); final JSONObject rep = new JSONObject(); final JSONArray terms = new JSONArray(); termSuggestions.forEach(termSuggest -> { final JSONObject term = termSuggest.toJSON(); term.put("links", this.autolinker.get() .forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .build()); terms.put(term); }); rep.put("rows", terms).put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
DefaultCategoryTermSuggestionsResource extends XWikiResource implements CategoryTermSuggestionsResource { @Override public Response suggest(@Nonnull final String category, @Nonnull final String input, int maxResults) { if (StringUtils.isBlank(input) || StringUtils.isBlank(category)) { this.logger.error("Both input and category must be provided."); throw new WebApplicationException(Response.Status.BAD_REQUEST); } if (!this.vm.hasCategory(category)) { this.logger.error("The requested vocabulary category [{}] does not exist.", category); throw new WebApplicationException(Response.Status.NOT_FOUND); } final List<VocabularyTerm> termSuggestions = this.vm.search(input, category, maxResults); final JSONObject rep = new JSONObject(); final JSONArray terms = new JSONArray(); termSuggestions.forEach(termSuggest -> { final JSONObject term = termSuggest.toJSON(); term.put("links", this.autolinker.get() .forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .build()); terms.put(term); }); rep.put("rows", terms).put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); }  }
DefaultCategoryTermSuggestionsResource extends XWikiResource implements CategoryTermSuggestionsResource { @Override public Response suggest(@Nonnull final String category, @Nonnull final String input, int maxResults) { if (StringUtils.isBlank(input) || StringUtils.isBlank(category)) { this.logger.error("Both input and category must be provided."); throw new WebApplicationException(Response.Status.BAD_REQUEST); } if (!this.vm.hasCategory(category)) { this.logger.error("The requested vocabulary category [{}] does not exist.", category); throw new WebApplicationException(Response.Status.NOT_FOUND); } final List<VocabularyTerm> termSuggestions = this.vm.search(input, category, maxResults); final JSONObject rep = new JSONObject(); final JSONArray terms = new JSONArray(); termSuggestions.forEach(termSuggest -> { final JSONObject term = termSuggest.toJSON(); term.put("links", this.autolinker.get() .forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .build()); terms.put(term); }); rep.put("rows", terms).put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); }  @Override Response suggest(@Nonnull final String category, @Nonnull final String input, int maxResults); }
DefaultCategoryTermSuggestionsResource extends XWikiResource implements CategoryTermSuggestionsResource { @Override public Response suggest(@Nonnull final String category, @Nonnull final String input, int maxResults) { if (StringUtils.isBlank(input) || StringUtils.isBlank(category)) { this.logger.error("Both input and category must be provided."); throw new WebApplicationException(Response.Status.BAD_REQUEST); } if (!this.vm.hasCategory(category)) { this.logger.error("The requested vocabulary category [{}] does not exist.", category); throw new WebApplicationException(Response.Status.NOT_FOUND); } final List<VocabularyTerm> termSuggestions = this.vm.search(input, category, maxResults); final JSONObject rep = new JSONObject(); final JSONArray terms = new JSONArray(); termSuggestions.forEach(termSuggest -> { final JSONObject term = termSuggest.toJSON(); term.put("links", this.autolinker.get() .forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .build()); terms.put(term); }); rep.put("rows", terms).put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); }  @Override Response suggest(@Nonnull final String category, @Nonnull final String input, int maxResults);  }