@Test public void getPatientPerformsCorrectly() throws ComponentLookupException { JSONObject jsonObject = new JSONObject(); when(this.patient.toJSON()).thenReturn(jsonObject); when(this.uriInfo.getBaseUriBuilder()).thenReturn(this.uriBuilder); when(this.uriBuilder.path(PatientResource.class)).thenReturn(this.uriBuilder); when(this.uriBuilder.build(this.patient.getId())).thenReturn(this.uri); Response response = this.component.getPatient(EID); verify(this.logger).debug("Retrieving patient record with external ID [{}] via REST", EID); JSONObject links = new JSONObject().accumulate("rel", "self").accumulate("href", "uri") .put("allowedMethods", new JSONArray(Collections.singletonList("GET"))); JSONObject json = new JSONObject().put("links", Collections.singletonList(links)); assertTrue(json.similar(response.getEntity())); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); }
@Override public Response getPatient(String eid) { this.slf4Jlogger.debug("Retrieving patient record with external ID [{}] via REST", eid); Patient patient = this.repository.getByName(eid); if (patient == null) { return checkForMultipleRecords(patient, eid); } User currentUser = this.users.getCurrentUser(); Right grantedRight; if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { this.slf4Jlogger.debug("View access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(PatientResource.class, this.uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight) .build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); }
DefaultPatientByExternalIdResourceImpl extends XWikiResource implements PatientByExternalIdResource { @Override public Response getPatient(String eid) { this.slf4Jlogger.debug("Retrieving patient record with external ID [{}] via REST", eid); Patient patient = this.repository.getByName(eid); if (patient == null) { return checkForMultipleRecords(patient, eid); } User currentUser = this.users.getCurrentUser(); Right grantedRight; if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { this.slf4Jlogger.debug("View access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(PatientResource.class, this.uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight) .build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } }
DefaultPatientByExternalIdResourceImpl extends XWikiResource implements PatientByExternalIdResource { @Override public Response getPatient(String eid) { this.slf4Jlogger.debug("Retrieving patient record with external ID [{}] via REST", eid); Patient patient = this.repository.getByName(eid); if (patient == null) { return checkForMultipleRecords(patient, eid); } User currentUser = this.users.getCurrentUser(); Right grantedRight; if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { this.slf4Jlogger.debug("View access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(PatientResource.class, this.uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight) .build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); }  }
DefaultPatientByExternalIdResourceImpl extends XWikiResource implements PatientByExternalIdResource { @Override public Response getPatient(String eid) { this.slf4Jlogger.debug("Retrieving patient record with external ID [{}] via REST", eid); Patient patient = this.repository.getByName(eid); if (patient == null) { return checkForMultipleRecords(patient, eid); } User currentUser = this.users.getCurrentUser(); Right grantedRight; if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { this.slf4Jlogger.debug("View access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(PatientResource.class, this.uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight) .build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); }  @Override Response getPatient(String eid); @Override Response updatePatient(final String json, final String eid, final String policy); @Override Response patchPatient(final String json, final String eid); @Override Response deletePatient(String eid); }
DefaultPatientByExternalIdResourceImpl extends XWikiResource implements PatientByExternalIdResource { @Override public Response getPatient(String eid) { this.slf4Jlogger.debug("Retrieving patient record with external ID [{}] via REST", eid); Patient patient = this.repository.getByName(eid); if (patient == null) { return checkForMultipleRecords(patient, eid); } User currentUser = this.users.getCurrentUser(); Right grantedRight; if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { this.slf4Jlogger.debug("View access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(PatientResource.class, this.uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight) .build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); }  @Override Response getPatient(String eid); @Override Response updatePatient(final String json, final String eid, final String policy); @Override Response patchPatient(final String json, final String eid); @Override Response deletePatient(String eid);  }