@Test public void getPatientsPerformsCorrectlySeveralPatientRecordsAccessToSome() throws QueryException { final List<Object> eidList = ImmutableList.<Object>of(EID1, EID2); final List<String> idList = ImmutableList.of(ID_3); doReturn(eidList).when(this.request).getProperties(EID_LABEL); doReturn(idList).when(this.request).getProperties(ID_LABEL); when(this.query.execute()).thenReturn(ImmutableList.<Object>of(ID_1, ID_2)); doThrow(SecurityException.class).when(this.repository).get(ID_2); final Response response = this.component.fetchPatients(); final JSONArray expected = new JSONArray().put(new JSONObject().put(ID_LABEL, ID_1).put(LINKS_LABEL, this.uriList)) .put(new JSONObject().put(ID_LABEL, ID_3).put(LINKS_LABEL, this.uriList)); final JSONArray actual = new JSONArray(response.getEntity().toString()); verify(this.logger).warn("Failed to retrieve patient with ID [{}]: {}", ID_2, null); assertTrue(expected.similar(actual)); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); }
@Override public Response fetchPatients() { final Request request = this.container.getRequest(); final List<Object> eids = request.getProperties("eid"); final List<Object> ids = request.getProperties("id"); this.slf4Jlogger.debug("Retrieving patient records with external IDs [{}] and internal IDs [{}]", eids, ids); final ImmutableSet.Builder<PrimaryEntity> patientsBuilder = ImmutableSet.builder(); try { addEids(patientsBuilder, eids); addIds(patientsBuilder, ids); final String json = this.objectMapper.writeValueAsString(patientsBuilder.build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final JsonProcessingException ex) { this.slf4Jlogger.error("Failed to serialize patients [{}] to JSON: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (final QueryException ex) { this.slf4Jlogger.error("Failed to retrieve patients with external ids [{}]: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }
DefaultPatientsFetchResourceImpl extends XWikiResource implements PatientsFetchResource { @Override public Response fetchPatients() { final Request request = this.container.getRequest(); final List<Object> eids = request.getProperties("eid"); final List<Object> ids = request.getProperties("id"); this.slf4Jlogger.debug("Retrieving patient records with external IDs [{}] and internal IDs [{}]", eids, ids); final ImmutableSet.Builder<PrimaryEntity> patientsBuilder = ImmutableSet.builder(); try { addEids(patientsBuilder, eids); addIds(patientsBuilder, ids); final String json = this.objectMapper.writeValueAsString(patientsBuilder.build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final JsonProcessingException ex) { this.slf4Jlogger.error("Failed to serialize patients [{}] to JSON: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (final QueryException ex) { this.slf4Jlogger.error("Failed to retrieve patients with external ids [{}]: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } }
DefaultPatientsFetchResourceImpl extends XWikiResource implements PatientsFetchResource { @Override public Response fetchPatients() { final Request request = this.container.getRequest(); final List<Object> eids = request.getProperties("eid"); final List<Object> ids = request.getProperties("id"); this.slf4Jlogger.debug("Retrieving patient records with external IDs [{}] and internal IDs [{}]", eids, ids); final ImmutableSet.Builder<PrimaryEntity> patientsBuilder = ImmutableSet.builder(); try { addEids(patientsBuilder, eids); addIds(patientsBuilder, ids); final String json = this.objectMapper.writeValueAsString(patientsBuilder.build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final JsonProcessingException ex) { this.slf4Jlogger.error("Failed to serialize patients [{}] to JSON: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (final QueryException ex) { this.slf4Jlogger.error("Failed to retrieve patients with external ids [{}]: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }  }
DefaultPatientsFetchResourceImpl extends XWikiResource implements PatientsFetchResource { @Override public Response fetchPatients() { final Request request = this.container.getRequest(); final List<Object> eids = request.getProperties("eid"); final List<Object> ids = request.getProperties("id"); this.slf4Jlogger.debug("Retrieving patient records with external IDs [{}] and internal IDs [{}]", eids, ids); final ImmutableSet.Builder<PrimaryEntity> patientsBuilder = ImmutableSet.builder(); try { addEids(patientsBuilder, eids); addIds(patientsBuilder, ids); final String json = this.objectMapper.writeValueAsString(patientsBuilder.build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final JsonProcessingException ex) { this.slf4Jlogger.error("Failed to serialize patients [{}] to JSON: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (final QueryException ex) { this.slf4Jlogger.error("Failed to retrieve patients with external ids [{}]: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }  @Override Response fetchPatients(); }
DefaultPatientsFetchResourceImpl extends XWikiResource implements PatientsFetchResource { @Override public Response fetchPatients() { final Request request = this.container.getRequest(); final List<Object> eids = request.getProperties("eid"); final List<Object> ids = request.getProperties("id"); this.slf4Jlogger.debug("Retrieving patient records with external IDs [{}] and internal IDs [{}]", eids, ids); final ImmutableSet.Builder<PrimaryEntity> patientsBuilder = ImmutableSet.builder(); try { addEids(patientsBuilder, eids); addIds(patientsBuilder, ids); final String json = this.objectMapper.writeValueAsString(patientsBuilder.build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final JsonProcessingException ex) { this.slf4Jlogger.error("Failed to serialize patients [{}] to JSON: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (final QueryException ex) { this.slf4Jlogger.error("Failed to retrieve patients with external ids [{}]: {}", eids, ex.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }  @Override Response fetchPatients();  }