@Test public void suggestAsJSONReturnsEmptyListOnExceptions() throws QueryException { when(this.query.execute()).thenThrow(new QueryException("", this.query, null)); JSONObject response = new JSONObject(this.component.suggestAsJSON("dOe", 200, "view", ID, "asc")); JSONArray suggestions = response.getJSONArray("matchedPatients"); Assert.assertEquals(0, suggestions.length()); }
@Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); }
DefaultPatientsSuggestionsResourceImpl extends XWikiResource implements PatientsSuggestionsResource { @Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); } }
DefaultPatientsSuggestionsResourceImpl extends XWikiResource implements PatientsSuggestionsResource { @Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); }  }
DefaultPatientsSuggestionsResourceImpl extends XWikiResource implements PatientsSuggestionsResource { @Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); }  @Override String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField,
        String order); @Override String suggestAsXML(String input, int maxResults, String requiredPermission, String orderField, String order); }
DefaultPatientsSuggestionsResourceImpl extends XWikiResource implements PatientsSuggestionsResource { @Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); }  @Override String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField,
        String order); @Override String suggestAsXML(String input, int maxResults, String requiredPermission, String orderField, String order);  }