/** * 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()); } }
@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 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 Response resolveTerms() { final Request request = this.container.getRequest(); final List<Object> termIds = request.getProperties(TERM_ID); if (CollectionUtils.isEmpty(termIds)) { this.slf4Jlogger.info("No content provided."); return Response.status(Response.Status.NO_CONTENT).build(); } this.slf4Jlogger.debug("Retrieving terms with IDs: [{}]", termIds); final JSONObject rep = new JSONObject() .put(ROWS, this.createRows(termIds)) .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 VisibilityOptionsRepresentation getVisibilityOptions() { List<VisibilityRepresentation> visibilities = new LinkedList<>(); for (Visibility visibility : this.manager.listVisibilityOptions()) { visibilities.add(this.factory.createVisibilityRepresentation(visibility)); } VisibilityOptionsRepresentation result = (new VisibilityOptionsRepresentation()).withVisibilities(visibilities); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; } }
@Override public VisibilityOptionsRepresentation getVisibilityOptions() { List<VisibilityRepresentation> visibilities = new LinkedList<>(); for (Visibility visibility : this.manager.listVisibilityOptions()) { visibilities.add(this.factory.createVisibilityRepresentation(visibility)); } VisibilityOptionsRepresentation result = (new VisibilityOptionsRepresentation()).withVisibilities(visibilities); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; } }
@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 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 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 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 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 CollaboratorsRepresentation getCollaborators(String patientId) { this.logger.debug("Retrieving collaborators of patient record [{}] via REST", patientId); // Besides getting the patient, checks that the user has view access PatientAccessContext patientAccessContext = this.secureContextFactory.getReadContext(patientId); CollaboratorsRepresentation result = this.factory.createCollaboratorsRepresentation(patientAccessContext.getPatient(), this.uriInfo); result.withLinks(this.autolinker.get().forResource(this.getClass(), this.uriInfo) .withGrantedRight(patientAccessContext.getPatientAccess().getAccessLevel().getGrantedRight()) .build()); return result; }
@Override public Categories getAllCategories() { final Categories result = new Categories(); // A list of available category identifiers. final List<String> categoryNames = this.vm.getAvailableCategories(); // A list of vocabulary category objects. final List<Category> categories = this.objectFactory.createCategoriesRepresentation(categoryNames, getCategoryLinks(), this::getVocabulariesForCategory); result.withCategories(categories); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; }
@Override public OwnerRepresentation getOwner(String entityId, String entityType) { this.logger.debug("Retrieving entity record's owner [{}] via REST", entityId); // besides getting the entity, checks that the user has view access EntityAccessContext entityAccessContext = this.secureContextFactory.getReadContext(entityId, entityType); OwnerRepresentation result = this.factory.createOwnerRepresentation(entityAccessContext.getEntity()); // adding links relative to this context result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(entityAccessContext.getEntityAccess().getAccessLevel().getGrantedRight()) .build()); return result; }
@Override public OwnerRepresentation getOwner(String patientId) { this.logger.debug("Retrieving patient record's owner [{}] via REST", patientId); // besides getting the patient, checks that the user has view access PatientAccessContext patientAccessContext = this.secureContextFactory.getReadContext(patientId); OwnerRepresentation result = this.factory.createOwnerRepresentation(patientAccessContext.getPatient()); // adding links relative to this context result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(patientAccessContext.getPatientAccess().getAccessLevel().getGrantedRight()) .build()); return result; }
@Override public VisibilityRepresentation getVisibility(String patientId) { this.logger.debug("Retrieving patient record's visibility [{}] via REST", patientId); // besides getting the patient, checks that the user has view access PatientAccessContext patientAccessContext = this.secureContextFactory.getReadContext(patientId); VisibilityRepresentation result = this.factory.createVisibilityRepresentation(patientAccessContext.getPatient()); AccessLevel accessLevel = patientAccessContext.getPatientAccess().getAccessLevel(); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(accessLevel.getGrantedRight()) .build()); return result; }
@Override public CollaboratorsRepresentation getCollaborators(String entityId, String entityType) { this.logger.debug("Retrieving collaborators of entity record [{}] via REST", entityId); // Besides getting the entity, checks that the user has view access EntityAccessContext entityAccessContext = this.secureContextFactory.getReadContext(entityId, entityType); CollaboratorsRepresentation result = this.factory.createCollaboratorsRepresentation(entityAccessContext.getEntity(), this.uriInfo); result.withLinks(this.autolinker.get().forResource(this.getClass(), this.uriInfo) .withGrantedRight(entityAccessContext.getEntityAccess().getAccessLevel().getGrantedRight()) .build()); return result; }
@Override public PrincipalsRepresentation getPrincipals(String entityType, String entityId) { this.logger.debug("Retrieving principals with access to entity record [{}] via REST", entityId); // Besides getting the entity, checks that the user has view access EntityAccessContext patientAccessContext = this.secureContextFactory.getReadContext(entityId, entityType); PrincipalsRepresentation result = this.factory.createPrincipalsRepresentation(patientAccessContext.getEntity(), entityType, this.uriInfo); result.withLinks(this.autolinker.get().forResource(this.getClass(), this.uriInfo) .withGrantedRight(patientAccessContext.getEntityAccess().getAccessLevel().getGrantedRight()) .build()); return result; } }