/** * 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()); } }
private static JSONObject exchangeDisorders(JSONObject pedigreePatient, JSONObject phenotipsPatientJSON, Vocabulary omimService, Logger logger) { String disordersKey = "disorders"; JSONArray internalTerms = new JSONArray(); JSONArray externalTerms = pedigreePatient.optJSONArray(disordersKey); if (externalTerms != null) { for (Object termIdObj : externalTerms) { try { VocabularyTerm term = omimService.getTerm(termIdObj.toString()); if (term != null) { internalTerms.put(term.toJSON()); } } catch (Exception ex) { logger.error("Could not convert disorder {} from pedigree JSON to patient JSON", termIdObj); } } } phenotipsPatientJSON.put(disordersKey, internalTerms); return phenotipsPatientJSON; }
@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 getTerm(String vocabularyId, String termId) { if (StringUtils.isEmpty(vocabularyId) || StringUtils.isEmpty(termId)) { return Response.status(Response.Status.BAD_REQUEST).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } VocabularyTerm term = vocabulary.getTerm(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).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
@Override public Response getTerm(String vocabularyId, String termId) { if (StringUtils.isEmpty(vocabularyId) || StringUtils.isEmpty(termId)) { return Response.status(Response.Status.BAD_REQUEST).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } VocabularyTerm term = vocabulary.getTerm(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).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(); } }
final JSONObject term = termSuggest.toJSON(); term.put("links", this.autolinker.get() .forSecondaryResource(VocabularyTermResource.class, this.uriInfo)
@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 VocabularyTermSummary createVocabularyTermRepresentation(VocabularyTerm term) { VocabularyTermSummary rep = new VocabularyTermSummary(); rep.withId(term.getId()); rep.withName(term.getName()); JSONObject jsonObject = term.toJSON(); String symbolKey = "symbol"; if (jsonObject != null && jsonObject.opt(symbolKey) != null) { rep.withSymbol(jsonObject.get(symbolKey).toString()); } rep.withDescription(term.getDescription()); return rep; } }