@Test public void createPatientFromSummaryWithNoCurrentUserPerformsCorrectly() throws Exception { when(this.users.getCurrentUser()).thenReturn(null); when(this.access.hasAccess(null, Right.VIEW, this.patientReference1)).thenReturn(true); Date createdOn = new Date(); Date modifiedOn = new Date(); DateTime createdOnDateTime = new DateTime(createdOn).withZone(DateTimeZone.UTC); DateTime modifiedOnDateTime = new DateTime(modifiedOn).withZone(DateTimeZone.UTC); Object[] summary = { "data.P0000001", this.eid, "XWiki.padams", createdOn, "version", "XWiki.hmccoy", modifiedOn }; PatientSummary patientSummary = this.mocker.getComponentUnderTest().createPatientSummary(summary, this.uriInfo); assertEquals(this.patientReference1.getName(), patientSummary.getId()); assertEquals(this.eid, patientSummary.getEid()); assertEquals("XWiki.padams", patientSummary.getCreatedBy()); assertEquals("XWiki.hmccoy", patientSummary.getLastModifiedBy()); assertEquals("version", patientSummary.getVersion()); assertEquals(createdOnDateTime, patientSummary.getCreatedOn()); assertEquals(modifiedOnDateTime, patientSummary.getLastModifiedOn()); assertEquals(1, patientSummary.getLinks().size()); assertEquals(this.uri1, patientSummary.getLinks().get(0).getHref()); }
@Override public PatientSummary createPatientSummary(Patient patient, UriInfo uriInfo) { if (patient == null) { return null; } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { return null; } PatientSummary result = new PatientSummary(); XWikiDocument doc = patient.getXDocument(); result.withId(patient.getId()).withEid(patient.getExternalId()); result.withCreatedBy(String.valueOf(patient.getReporter())).withLastModifiedBy( String.valueOf(doc.getAuthorReference())); result.withVersion(doc.getVersion()); result.withCreatedOn(new DateTime(doc.getCreationDate()).withZone(DateTimeZone.UTC)); result.withLastModifiedOn(new DateTime(doc.getDate()).withZone(DateTimeZone.UTC)); result.withLinks(this.autolinker.get().forSecondaryResource(PatientResource.class, uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .build()); return result; }
DefaultDomainObjectFactory implements DomainObjectFactory { @Override public PatientSummary createPatientSummary(Patient patient, UriInfo uriInfo) { if (patient == null) { return null; } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { return null; } PatientSummary result = new PatientSummary(); XWikiDocument doc = patient.getXDocument(); result.withId(patient.getId()).withEid(patient.getExternalId()); result.withCreatedBy(String.valueOf(patient.getReporter())).withLastModifiedBy( String.valueOf(doc.getAuthorReference())); result.withVersion(doc.getVersion()); result.withCreatedOn(new DateTime(doc.getCreationDate()).withZone(DateTimeZone.UTC)); result.withLastModifiedOn(new DateTime(doc.getDate()).withZone(DateTimeZone.UTC)); result.withLinks(this.autolinker.get().forSecondaryResource(PatientResource.class, uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .build()); return result; } }
DefaultDomainObjectFactory implements DomainObjectFactory { @Override public PatientSummary createPatientSummary(Patient patient, UriInfo uriInfo) { if (patient == null) { return null; } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { return null; } PatientSummary result = new PatientSummary(); XWikiDocument doc = patient.getXDocument(); result.withId(patient.getId()).withEid(patient.getExternalId()); result.withCreatedBy(String.valueOf(patient.getReporter())).withLastModifiedBy( String.valueOf(doc.getAuthorReference())); result.withVersion(doc.getVersion()); result.withCreatedOn(new DateTime(doc.getCreationDate()).withZone(DateTimeZone.UTC)); result.withLastModifiedOn(new DateTime(doc.getDate()).withZone(DateTimeZone.UTC)); result.withLinks(this.autolinker.get().forSecondaryResource(PatientResource.class, uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .build()); return result; }  }
DefaultDomainObjectFactory implements DomainObjectFactory { @Override public PatientSummary createPatientSummary(Patient patient, UriInfo uriInfo) { if (patient == null) { return null; } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { return null; } PatientSummary result = new PatientSummary(); XWikiDocument doc = patient.getXDocument(); result.withId(patient.getId()).withEid(patient.getExternalId()); result.withCreatedBy(String.valueOf(patient.getReporter())).withLastModifiedBy( String.valueOf(doc.getAuthorReference())); result.withVersion(doc.getVersion()); result.withCreatedOn(new DateTime(doc.getCreationDate()).withZone(DateTimeZone.UTC)); result.withLastModifiedOn(new DateTime(doc.getDate()).withZone(DateTimeZone.UTC)); result.withLinks(this.autolinker.get().forSecondaryResource(PatientResource.class, uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .build()); return result; }  @Override PatientSummary createPatientSummary(Patient patient, UriInfo uriInfo); @Override PatientSummary createPatientSummary(Object[] summaryData, UriInfo uriInfo); @Override Alternatives createAlternatives(List<String> alternativeIdentifiers, UriInfo uriInfo); @Override Alternative createAlternative(String id, UriInfo uriInfo); }
DefaultDomainObjectFactory implements DomainObjectFactory { @Override public PatientSummary createPatientSummary(Patient patient, UriInfo uriInfo) { if (patient == null) { return null; } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.VIEW, patient.getDocumentReference())) { return null; } PatientSummary result = new PatientSummary(); XWikiDocument doc = patient.getXDocument(); result.withId(patient.getId()).withEid(patient.getExternalId()); result.withCreatedBy(String.valueOf(patient.getReporter())).withLastModifiedBy( String.valueOf(doc.getAuthorReference())); result.withVersion(doc.getVersion()); result.withCreatedOn(new DateTime(doc.getCreationDate()).withZone(DateTimeZone.UTC)); result.withLastModifiedOn(new DateTime(doc.getDate()).withZone(DateTimeZone.UTC)); result.withLinks(this.autolinker.get().forSecondaryResource(PatientResource.class, uriInfo) .withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .build()); return result; }  @Override PatientSummary createPatientSummary(Patient patient, UriInfo uriInfo); @Override PatientSummary createPatientSummary(Object[] summaryData, UriInfo uriInfo); @Override Alternatives createAlternatives(List<String> alternativeIdentifiers, UriInfo uriInfo); @Override Alternative createAlternative(String id, UriInfo uriInfo);  }