/** * 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(); } }
/** * Returns the autolinker with all resources common to all vocabularies set. * * @return an {@link Autolinker} */ private Autolinker getVocabularyLinks() { 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 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 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 Vocabularies getAllVocabularies() { Vocabularies result = new Vocabularies(); List<String> vocabularyIDs = this.vm.getAvailableVocabularies(); List<org.phenotips.vocabularies.rest.model.Vocabulary> availableVocabs = vocabularyIDs.stream() .map(vocabularyID -> this.vm.getVocabulary(vocabularyID)) .map(vocab -> this.objectFactory.createLinkedVocabularyRepresentation(vocab, getVocabularyLinks(), this::getCategoriesForVocabulary)) .collect(Collectors.toList()); result.withVocabularies(availableVocabs); 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 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 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 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 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; } }
@Override public Alternatives createAlternatives(List<String> alternativeIdentifiers, UriInfo uriInfo) { Alternatives result = new Alternatives(); User currentUser = this.users.getCurrentUser(); result.withLinks(this.autolinker.get().forResource(getClass(), uriInfo).build()); for (String id : alternativeIdentifiers) { DocumentReference reference = this.stringResolver.resolve(id, Patient.DEFAULT_DATA_SPACE); if (!this.access.hasAccess(currentUser, Right.VIEW, reference)) { continue; } result.getPatients().add(createAlternative(reference.getName(), uriInfo)); } return result; }
@Override public VisibilityRepresentation getVisibility(String entityId, String entityType) { this.logger.debug("Retrieving entity record's visibility [{}] via REST", entityId); // besides getting the entity, checks that the user has view access EntityAccessContext entityAccessContext = this.secureContextFactory.getReadContext(entityId, entityType); VisibilityRepresentation result = this.factory.createVisibilityRepresentation(entityAccessContext.getEntity()); AccessLevel accessLevel = entityAccessContext.getEntityAccess().getAccessLevel(); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(accessLevel.getGrantedRight()) .build()); return result; }