@Override public org.phenotips.vocabularies.rest.model.Vocabulary getVocabulary(String vocabularyId) { Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } org.phenotips.vocabularies.rest.model.Vocabulary rep = this.objectFactory.createVocabularyRepresentation(vocabulary); rep.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW).build()); return rep; }
@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; } }
/** * 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 categories set. * * @return an {@link Autolinker} */ private Autolinker getCategoryLinks() { return this.autolinker.get() .forResource(getClass(), this.uriInfo) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW); }
@Override public Response getFamily(String id) { this.logger.debug("Retrieving patient [{}] family information via REST", id); Family family = this.familyTools.getFamilyForPatient(id); if (family == null) { this.logger.debug("No patint with id [{}] or the patient has no family", id); return Response.status(Status.NOT_FOUND).build(); } JSONObject json = family.toJSON(); json.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } }
@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 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(); }
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()); result.withLinks(this.autolinker.get().forResource(this.getClass(), 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 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 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; } }
/** * 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()); } }
@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 Response getFamily(String id) { this.logger.debug("Retrieving patient [{}] family information via REST", id); Family family = this.familyTools.getFamilyForPatient(id); if (family == null) { this.logger.debug("No patint with id [{}] or the patient has no family", id); return Response.status(Status.NOT_FOUND).build(); } JSONObject json = family.toJSON(); json.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); } }
@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; } }
this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("entity-type", "patients") .withGrantedRight(grantedRight).build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).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()); result.withLinks(this.autolinker.get().forResource(this.getClass(), this.uriInfo) .withGrantedRight(accessLevel.getGrantedRight()) .build());
@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; }
final JSONObject term = termSuggest.toJSON(); term.put("links", this.autolinker.get() .forSecondaryResource(VocabularyTermResource.class, this.uriInfo) .build()); terms.put(term); }); rep.put("rows", terms).put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build();