@Test public void getPatientIgnoresMissingPatient() { doReturn(null).when(this.repository).get(anyString()); Response response = this.patientResource.getPatient(PATIENT_ID); verify(this.logger).debug("No such patient record: [{}]", PATIENT_ID); Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); }
@Override public Response getPatient(String id) { this.slf4Jlogger.debug("Retrieving patient record [{}] via REST", id); Patient patient = this.repository.get(id); if (patient == null) { this.slf4Jlogger.debug("No such patient record: [{}]", id); return Response.status(Status.NOT_FOUND).build(); } 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, id); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } Right manageRight = Right.toRight("manage"); if (manageRight != Right.ILLEGAL && this.access.hasAccess(currentUser, manageRight, patient.getDocumentReference())) { grantedRight = manageRight; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight).build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); }
DefaultPatientResourceImpl extends XWikiResource implements PatientResource { @Override public Response getPatient(String id) { this.slf4Jlogger.debug("Retrieving patient record [{}] via REST", id); Patient patient = this.repository.get(id); if (patient == null) { this.slf4Jlogger.debug("No such patient record: [{}]", id); return Response.status(Status.NOT_FOUND).build(); } 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, id); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } Right manageRight = Right.toRight("manage"); if (manageRight != Right.ILLEGAL && this.access.hasAccess(currentUser, manageRight, patient.getDocumentReference())) { grantedRight = manageRight; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight).build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } }
DefaultPatientResourceImpl extends XWikiResource implements PatientResource { @Override public Response getPatient(String id) { this.slf4Jlogger.debug("Retrieving patient record [{}] via REST", id); Patient patient = this.repository.get(id); if (patient == null) { this.slf4Jlogger.debug("No such patient record: [{}]", id); return Response.status(Status.NOT_FOUND).build(); } 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, id); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } Right manageRight = Right.toRight("manage"); if (manageRight != Right.ILLEGAL && this.access.hasAccess(currentUser, manageRight, patient.getDocumentReference())) { grantedRight = manageRight; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight).build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); }  }
DefaultPatientResourceImpl extends XWikiResource implements PatientResource { @Override public Response getPatient(String id) { this.slf4Jlogger.debug("Retrieving patient record [{}] via REST", id); Patient patient = this.repository.get(id); if (patient == null) { this.slf4Jlogger.debug("No such patient record: [{}]", id); return Response.status(Status.NOT_FOUND).build(); } 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, id); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } Right manageRight = Right.toRight("manage"); if (manageRight != Right.ILLEGAL && this.access.hasAccess(currentUser, manageRight, patient.getDocumentReference())) { grantedRight = manageRight; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight).build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); }  @Override Response getPatient(String id); @Override Response updatePatient(String json, String id, String policy); @Override Response patchPatient(final String json, final String id); @Override Response deletePatient(String id); }
DefaultPatientResourceImpl extends XWikiResource implements PatientResource { @Override public Response getPatient(String id) { this.slf4Jlogger.debug("Retrieving patient record [{}] via REST", id); Patient patient = this.repository.get(id); if (patient == null) { this.slf4Jlogger.debug("No such patient record: [{}]", id); return Response.status(Status.NOT_FOUND).build(); } 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, id); return Response.status(Status.FORBIDDEN).build(); } else { grantedRight = Right.VIEW; } if (this.access.hasAccess(currentUser, Right.EDIT, patient.getDocumentReference())) { grantedRight = Right.EDIT; } Right manageRight = Right.toRight("manage"); if (manageRight != Right.ILLEGAL && this.access.hasAccess(currentUser, manageRight, patient.getDocumentReference())) { grantedRight = manageRight; } JSONObject json = patient.toJSON(); json.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight).build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); }  @Override Response getPatient(String id); @Override Response updatePatient(String json, String id, String policy); @Override Response patchPatient(final String json, final String id); @Override Response deletePatient(String id);  }