@Test public void deletePatientCatchesException() throws WebApplicationException { doThrow(Exception.class).when(this.repository).delete(this.patient); when(this.repository.getByName(EID)).thenReturn(this.patient); when(this.access.hasAccess(null, Right.DELETE, null)).thenReturn(true); WebApplicationException ex = null; try { this.component.deletePatient(EID); } catch (WebApplicationException temp) { ex = temp; } assertNotNull("deletePatient did not throw a WebApplicationException as expected " + "when catching an Exception", ex); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ex.getResponse().getStatus()); verify(this.logger).warn(eq("Failed to delete patient record with external id [{}]: {}"), eq(EID), anyString()); }
@Override public Response deletePatient(String eid) { this.slf4Jlogger.debug("Deleting 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(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.slf4Jlogger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } try { this.repository.delete(patient); } catch (Exception ex) { this.slf4Jlogger.warn("Failed to delete patient record with external id [{}]: {}", eid, ex.getMessage()); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } this.slf4Jlogger.debug("Deleted patient record with external id [{}]", eid); return Response.noContent().build(); }
DefaultPatientByExternalIdResourceImpl extends XWikiResource implements PatientByExternalIdResource { @Override public Response deletePatient(String eid) { this.slf4Jlogger.debug("Deleting 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(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.slf4Jlogger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } try { this.repository.delete(patient); } catch (Exception ex) { this.slf4Jlogger.warn("Failed to delete patient record with external id [{}]: {}", eid, ex.getMessage()); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } this.slf4Jlogger.debug("Deleted patient record with external id [{}]", eid); return Response.noContent().build(); } }
DefaultPatientByExternalIdResourceImpl extends XWikiResource implements PatientByExternalIdResource { @Override public Response deletePatient(String eid) { this.slf4Jlogger.debug("Deleting 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(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.slf4Jlogger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } try { this.repository.delete(patient); } catch (Exception ex) { this.slf4Jlogger.warn("Failed to delete patient record with external id [{}]: {}", eid, ex.getMessage()); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } this.slf4Jlogger.debug("Deleted patient record with external id [{}]", eid); return Response.noContent().build(); }  }
DefaultPatientByExternalIdResourceImpl extends XWikiResource implements PatientByExternalIdResource { @Override public Response deletePatient(String eid) { this.slf4Jlogger.debug("Deleting 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(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.slf4Jlogger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } try { this.repository.delete(patient); } catch (Exception ex) { this.slf4Jlogger.warn("Failed to delete patient record with external id [{}]: {}", eid, ex.getMessage()); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } this.slf4Jlogger.debug("Deleted patient record with external id [{}]", eid); return Response.noContent().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 deletePatient(String eid) { this.slf4Jlogger.debug("Deleting 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(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.slf4Jlogger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); return Response.status(Status.FORBIDDEN).build(); } try { this.repository.delete(patient); } catch (Exception ex) { this.slf4Jlogger.warn("Failed to delete patient record with external id [{}]: {}", eid, ex.getMessage()); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } this.slf4Jlogger.debug("Deleted patient record with external id [{}]", eid); return Response.noContent().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);  }