@Override public Response resolveTerm(String termId) { VocabularyTerm term = this.vm.resolveTerm(termId); if (term == null) { return Response.status(Response.Status.NOT_FOUND).build(); } JSONObject rep = term.toJSON(); rep.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("vocabulary-id", term.getVocabulary().getIdentifier()).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
@Override public void serialize(final PrimaryEntity primaryEntity, final JsonGenerator jgen, final SerializerProvider provider) throws IOException { final JSONObject json = primaryEntity.toJSON(); json.put("links", DefaultPatientsFetchResourceImpl.this.autolinker.get() .forSecondaryResource(PatientResource.class, DefaultPatientsFetchResourceImpl.this.uriInfo) .withExtraParameters("entity-id", primaryEntity.getId()) .withExtraParameters("entity-type", "patients") .build()); jgen.writeRawValue(json.toString()); } }
@Override public Alternative createAlternative(String id, UriInfo uriInfo) { Alternative result = new Alternative(); result.withId(id); result.withLinks(this.autolinker.get().forSecondaryResource(PatientResource.class, uriInfo) .withExtraParameters("entity-id", id) .withExtraParameters("entity-type", "patients") .build()); return result; } }
@Override public Response resolveTerm(String termId) { VocabularyTerm term = this.vm.resolveTerm(termId); if (term == null) { return Response.status(Response.Status.NOT_FOUND).build(); } JSONObject rep = term.toJSON(); rep.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("vocabulary-id", term.getVocabulary().getIdentifier()).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
@Override public org.phenotips.vocabularies.rest.model.Category createLinkedCategoryRepresentation( final String categoryId, final Autolinker linker, final Function<String, List<org.phenotips.vocabularies.rest.model.Vocabulary>> vocabularySupplier) { final Category categoryRep = vocabularySupplier != null ? createCategoryRepresentation(categoryId).withVocabularies(vocabularySupplier.apply(categoryId)) : createCategoryRepresentation(categoryId); categoryRep.withLinks(linker.withExtraParameters(CATEGORY_LABEL, categoryId).build()); return categoryRep; } }
@Override public VocabularyTerms suggest(String vocabularyId, String input, @DefaultValue("10") int maxResults, String sort, String customFilter) { if (StringUtils.isEmpty(input) || StringUtils.isEmpty(vocabularyId)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } List<VocabularyTerm> termSuggestions = vocabulary.search(input, maxResults, sort, customFilter); List<VocabularyTermSummary> termReps = new ArrayList<>(); for (VocabularyTerm term : termSuggestions) { VocabularyTermSummary termRep = this.objectFactory.createVocabularyTermRepresentation(term); termRep.withLinks(this.autolinker.get().forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .withActionableResources(VocabularyResource.class) .withExtraParameters("vocabulary-id", vocabularyId) .withExtraParameters("term-id", term.getId()) .build()); termReps.add(termRep); } VocabularyTerms result = new VocabularyTerms().withVocabularyTerms(termReps); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; } }
@Override public org.phenotips.vocabularies.rest.model.Vocabulary createLinkedVocabularyRepresentation( final Vocabulary vocabulary, final Autolinker linker, final Function<Vocabulary, List<org.phenotips.vocabularies.rest.model.Category>> categorySupplier) { final org.phenotips.vocabularies.rest.model.Vocabulary vocabularyRep = categorySupplier != null ? createVocabularyRepresentation(vocabulary).withCategories(categorySupplier.apply(vocabulary)) : createVocabularyRepresentation(vocabulary); vocabularyRep.withLinks(linker.withExtraParameters(VOCABULARY_ID_LABEL, vocabulary.getIdentifier()).build()); return vocabularyRep; }
@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(); }
.withExtraParameters("entity-id", patient.getId()) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight) .build());
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 public PatientSummary createPatientSummary(Object[] summaryData, UriInfo uriInfo) { if (summaryData == null || summaryData.length != 7 || !(summaryData[3] instanceof Date && summaryData[6] instanceof Date)) { return null; } PatientSummary result = new PatientSummary(); User currentUser = this.users.getCurrentUser(); DocumentReference doc = this.stringResolver.resolve(String.valueOf(summaryData[0])); if (!this.access.hasAccess(currentUser, Right.VIEW, doc)) { return null; } result.withId(doc.getName()).withEid(StringUtils.defaultString((String) summaryData[1])); result.withCreatedBy(String.valueOf(summaryData[2])).withLastModifiedBy( String.valueOf(summaryData[5])); result.withVersion(String.valueOf(summaryData[4])); result.withCreatedOn(new DateTime(summaryData[3]).withZone(DateTimeZone.UTC)); result.withLastModifiedOn(new DateTime(summaryData[6]).withZone(DateTimeZone.UTC)); result.withLinks(this.autolinker.get().forSecondaryResource(PatientResource.class, uriInfo) .withExtraParameters("entity-id", doc.getName()) .withExtraParameters("entity-type", "patients") .build()); return result; }
@Override public Vocabularies getAllVocabularies() { Vocabularies result = new Vocabularies(); List<String> vocabularyIDs = this.vm.getAvailableVocabularies(); List<org.phenotips.vocabularies.rest.model.Vocabulary> availableVocabs = new ArrayList<>(); for (String vocabularyID : vocabularyIDs) { Vocabulary vocab = this.vm.getVocabulary(vocabularyID); org.phenotips.vocabularies.rest.model.Vocabulary rep = this.objectFactory.createVocabularyRepresentation(vocab); rep.withLinks(this.autolinker.get().forSecondaryResource(VocabularyResource.class, this.uriInfo) .withActionableResources(VocabularyTermSuggestionsResource.class) .withExtraParameters("vocabulary-id", vocabularyID) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW) .build()); availableVocabs.add(rep); } result.withVocabularies(availableVocabs); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; }
@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 public CollaboratorsRepresentation createCollaboratorsRepresentation(Patient patient, UriInfo uriInfo) { PatientAccess patientAccess = this.manager.getPatientAccess(patient); Collection<Collaborator> collaborators = patientAccess.getCollaborators(); CollaboratorsRepresentation result = new CollaboratorsRepresentation(); for (Collaborator collaborator : collaborators) { CollaboratorRepresentation collaboratorObject = this.createCollaboratorRepresentation(patientAccess, collaborator); collaboratorObject.withLinks(this.autolinker.get().forSecondaryResource(CollaboratorResource.class, uriInfo) .withExtraParameters("collaborator-id", this.entitySerializer.serialize(collaborator.getUser())) .withGrantedRight(patientAccess.getAccessLevel().getGrantedRight()) .build()); result.withCollaborators(collaboratorObject); } return result; }
@Override public CollaboratorsRepresentation createCollaboratorsRepresentation(PrimaryEntity entity, UriInfo uriInfo) { EntityAccess entityAccess = this.manager.getEntityAccess(entity); Collection<Collaborator> collaborators = entityAccess.getCollaborators(); CollaboratorsRepresentation result = new CollaboratorsRepresentation(); for (Collaborator collaborator : collaborators) { CollaboratorRepresentation collaboratorObject = this.createCollaboratorRepresentation(collaborator); collaboratorObject.withLinks(this.autolinker.get() .forSecondaryResource(CollaboratorResource.class, uriInfo) .withExtraParameters("collaborator-id", this.entitySerializer.serialize(collaborator.getUser())) .withGrantedRight(entityAccess.getAccessLevel().getGrantedRight()) .build()); result.withCollaborators(collaboratorObject); } return result; }