@Test public void deletePatientReturnsNotFoundStatus() throws QueryException { Query query = mock(DefaultQuery.class); when(this.repository.getByName(EID)).thenReturn(null); when(this.qm.createQuery(Matchers.anyString(), Matchers.anyString())).thenReturn(query); when(query.execute()).thenReturn(new ArrayList<>()); Response response = this.component.deletePatient(EID); verify(this.logger).debug("No patient record with external ID [{}] exists yet", EID); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); }
@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);  }