/** * Retrieves the {@link JSONObject} for the provided {@code term} with all the relevant links. * * @param term the {@link VocabularyTerm} of interest * @return the {@link JSONObject} representation of the {@code term} with links */ @Nonnull private JSONObject getTermJsonWithLinks(@Nonnull final VocabularyTerm term) { return term.toJSON() .put(LINKS, this.autolinker.get().forSecondaryResource(VocabularyTermResource.class, this.uriInfo).build()); } }
/** * Retrieves the {@link JSONObject} for the provided {@code term} with all the relevant links. * * @param term the {@link VocabularyTerm} of interest * @return the {@link JSONObject} representation of the {@code term} with links */ @Nonnull private JSONObject getTermJsonWithLinks(@Nonnull final VocabularyTerm term) { return term.toJSON() .put(LINKS, this.autolinker.get().forSecondaryResource(VocabularyTermResource.class, this.uriInfo).build()); } }
/** * Returns the autolinker with all resources common to all categories set. * * @return an {@link Autolinker} */ private Autolinker getCategoryLinks() { return this.autolinker.get() .forSecondaryResource(CategoryResource.class, this.uriInfo) .withActionableResources(CategoryTermSuggestionsResource.class) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW); }
/** * Returns the autolinker with all resources common to all vocabularies set. * * @return an {@link Autolinker} */ private Autolinker getVocabularyLinks() { return this.autolinker.get() .forSecondaryResource(VocabularyResource.class, this.uriInfo) .withActionableResources(VocabularyTermSuggestionsResource.class) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW); }
/** * Returns the autolinker with all resources common to all categories set. * * @return an {@link Autolinker} */ private Autolinker getCategoryLinks() { return this.autolinker.get() .forSecondaryResource(CategoryResource.class, this.uriInfo) .withActionableResources(CategoryTermSuggestionsResource.class) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW); }
/** * Returns the autolinker with all resources common to all vocabularies set. * * @return an {@link Autolinker} */ private Autolinker getVocabularyLinks() { return this.autolinker.get() .forSecondaryResource(VocabularyResource.class, this.uriInfo) .withActionableResources(VocabularyTermSuggestionsResource.class) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW); }
/** * Returns the autolinker with all resources common to all categories set. * * @return an {@link Autolinker} */ private Autolinker getCategoryLinks() { return this.autolinker.get() .forSecondaryResource(CategoryResource.class, this.uriInfo) .withActionableResources(CategoryTermSuggestionsResource.class) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW); }
/** * Returns the autolinker with all resources common to all vocabularies set. * * @return an {@link Autolinker} */ private Autolinker getVocabularyLinks() { return this.autolinker.get() .forSecondaryResource(VocabularyResource.class, uriInfo) .withActionableResources(VocabularyTermSuggestionsResource.class) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW); }
final JSONObject term = termSuggest.toJSON(); term.put("links", this.autolinker.get() .forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .build()); terms.put(term);
@Override public Response 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); JSONObject rep = new JSONObject(); JSONArray trms = new JSONArray(); for (VocabularyTerm term : termSuggestions) { JSONObject trm = term.toJSON(); trm.put("links", this.autolinker.get().forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .build()); trms.put(trm); } rep.put("rows", trms); rep.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).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 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 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; }
owner.withLinks(this.autolinker.get().forSecondaryResource(OwnerResource.class, this.uriInfo) .withGrantedRight(accessLevel.getGrantedRight()) .build()); visibility.withLinks(this.autolinker.get().forSecondaryResource(VisibilityResource.class, this.uriInfo) .withGrantedRight(accessLevel.getGrantedRight()) .build()); collaborators.withLinks(this.autolinker.get().forSecondaryResource(CollaboratorsResource.class, this.uriInfo) .withGrantedRight(accessLevel.getGrantedRight()) .build());
owner.withLinks(this.autolinker.get().forSecondaryResource(OwnerResource.class, this.uriInfo) .withGrantedRight(accessLevel.getGrantedRight()) .build()); visibility.withLinks(this.autolinker.get().forSecondaryResource(VisibilityResource.class, this.uriInfo) .withGrantedRight(accessLevel.getGrantedRight()) .build()); collaborators.withLinks(this.autolinker.get().forSecondaryResource(CollaboratorsResource.class, this.uriInfo) .withGrantedRight(accessLevel.getGrantedRight()) .build());
@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 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(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; }