io.dropwizard.jersey.caching.CacheControl Java Examples

The following examples show how to use io.dropwizard.jersey.caching.CacheControl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RuleResource.java    From notification with Apache License 2.0 7 votes vote down vote up
@GET
@JSONP
@Timed
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public Response fetch() {

  final Optional<Map<String, Rule>> rules;
  try {
    rules = store.fetch();
  } catch (NotificationStoreException e) {
    throw new NotificationException(
        Response.Status.INTERNAL_SERVER_ERROR, "Unable to fetch rules", e);
  }

  if (!rules.isPresent()) {
    throw new NotificationException(Response.Status.NOT_FOUND, "No rules found");
  }

  return Response.ok(rules.get()).build();
}
 
Example #2
Source File: IdResource.java    From snowizard with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get one or more IDs as a Google Protocol Buffer response
 *
 * @param agent
 *            User Agent
 * @param count
 *            Number of IDs to return
 * @return generated IDs
 */
@GET
@Timed
@Produces(ProtocolBufferMediaType.APPLICATION_PROTOBUF)
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public SnowizardResponse getIdAsProtobuf(
        @HeaderParam(HttpHeaders.USER_AGENT) final String agent,
        @QueryParam("count") final Optional<IntParam> count) {

    final List<Long> ids = Lists.newArrayList();
    if (count.isPresent()) {
        for (int i = 0; i < count.get().get(); i++) {
            ids.add(getId(agent));
        }
    } else {
        ids.add(getId(agent));
    }
    return SnowizardResponse.newBuilder().addAllId(ids).build();
}
 
Example #3
Source File: VocabularyService.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/id/{id}")
@ApiOperation(value = "Find a concept by its ID",
notes = "Find concepts that match either a IRI or a CURIE. ",
response = ConceptDTO.class)
@ApiResponses({
  @ApiResponse(code = 404, message = "Concept with ID could not be found")
})
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public ConceptDTO findById(
    @ApiParam( value = "ID to find", required = true)
    @PathParam("id") String id) throws Exception {
  Vocabulary.Query query = new Vocabulary.Query.Builder(id).build();
  Optional<Concept> concept = vocabulary.getConceptFromId(query);
  if (!concept.isPresent()) {
    throw new WebApplicationException(404);
  } else {
    ConceptDTO dto = conceptDtoTransformer.apply(concept.get());
    return dto;
  }
}
 
Example #4
Source File: VocabularyService.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/suggestions/{term}")
@ApiOperation(value = "Suggest terms",
notes = "Suggests terms based on a mispelled or mistyped term.",
response = String.class,
responseContainer = "List")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public Object suggestFromTerm(
    @ApiParam( value = "Mispelled term", required = true )
    @PathParam("term") String term,
    @ApiParam( value = DocumentationStrings.RESULT_LIMIT_DOC, required = false )
    @QueryParam("limit") @DefaultValue("1") IntParam limit) {
  List<String> suggestions = newArrayList(Iterables.limit(vocabulary.getSuggestions(term), limit.get()));
  return suggestions;
}
 
Example #5
Source File: GraphService.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/{id}")
@ApiOperation(value = "Get all properties of a node", response = Graph.class)
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
@Produces({MediaType.APPLICATION_JSON, CustomMediaTypes.APPLICATION_GRAPHSON,
    MediaType.APPLICATION_XML, CustomMediaTypes.APPLICATION_GRAPHML,
    CustomMediaTypes.APPLICATION_XGMML, CustomMediaTypes.TEXT_GML, CustomMediaTypes.TEXT_CSV,
    CustomMediaTypes.TEXT_TSV, CustomMediaTypes.IMAGE_JPEG, CustomMediaTypes.IMAGE_PNG})
public Object getNode(
    @ApiParam(value = DocumentationStrings.GRAPH_ID_DOC,
        required = true) @PathParam("id") String id,
    @ApiParam(value = DocumentationStrings.PROJECTION_DOC,
        required = false) @QueryParam("project") @DefaultValue("*") Set<String> projection,
    @ApiParam(value = DocumentationStrings.JSONP_DOC,
        required = false) @QueryParam("callback") String callback) {
  return getNeighbors(id, new IntParam("0"), new BooleanParam("false"), new HashSet<String>(),
      "BOTH", new BooleanParam("false"), projection, callback);
}
 
Example #6
Source File: VersionResource.java    From snowizard with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@GET
@Produces(MediaType.TEXT_PLAIN)
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public Response getVersion() {
    return Response.ok(getClass().getPackage().getImplementationVersion())
            .type(MediaType.TEXT_PLAIN).build();
}
 
Example #7
Source File: IdResource.java    From snowizard with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get a new ID as JSON
 *
 * @param agent
 *            User Agent
 * @return generated ID
 */
@GET
@Timed
@JSONP(callback = "callback", queryParam = "callback")
@Produces({ MediaType.APPLICATION_JSON,
    MediaTypeAdditional.APPLICATION_JAVASCRIPT })
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public Id getIdAsJSON(
        @HeaderParam(HttpHeaders.USER_AGENT) final String agent) {
    return new Id(getId(agent));
}
 
Example #8
Source File: IdResource.java    From snowizard with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get a new ID as plain text
 *
 * @param agent
 *            User Agent
 * @return generated ID
 */
@GET
@Timed
@Produces(MediaType.TEXT_PLAIN)
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public String getIdAsString(
        @HeaderParam(HttpHeaders.USER_AGENT) final String agent) {
    return String.valueOf(getId(agent));
}
 
Example #9
Source File: HealthResource.java    From airpal with Apache License 2.0 5 votes vote down vote up
@GET
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public Response health() {
    final SortedMap<String, HealthCheck.Result> results = registry.runHealthChecks();
    if (results.isEmpty()) {
        return Response.status(new NotImplementedStatus()).entity(results).build();
    } else {
        if (isAllHealthy(results)) {
            return Response.status(Response.Status.OK).entity(results).build();
        } else {
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(results).build();
        }
    }
}
 
Example #10
Source File: AnnotateService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
/***
 * A convenience call for retrieving both a list of entities and annotated content
 * 
 * @param content The content to annotate
 * @param includeCategories A set of categories to include
 * @param excludeCategories A set of categories to exclude
 * @param minLength The minimum length of annotated entities
 * @param longestOnly Should only the longest entity be returned for an overlapping group
 * @param includeAbbrev Should abbreviations be included
 * @param includeAcronym Should acronyms be included
 * @param includeNumbers Should numbers be included
 * @return A list of entities and the annotated content
 * @throws IOException 
 */
@POST
@Path("/complete")
@Consumes("application/x-www-form-urlencoded")
@ApiOperation(value = "Get embedded annotations as well as a separate list", 
response = Annotations.class, 
notes="A convenience resource for retrieving both a list of entities and annotated content. " + DocumentationStrings.REST_ABUSE_DOC)
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public Annotations postEntitiesAndContent(
    @ApiParam( value = DocumentationStrings.CONTENT_DOC, required = true)
    final @FormParam("content") @DefaultValue("") String content,
    @ApiParam( value = DocumentationStrings.INCLUDE_CATEGORIES_DOC, required = false)
    final @FormParam("includeCat") Set<String> includeCategories,
    @ApiParam( value = DocumentationStrings.EXCLUDE_CATEGORIES_DOC, required = false)
    final @FormParam("excludeCat") Set<String> excludeCategories,
    @ApiParam( value = DocumentationStrings.MINIMUM_LENGTH_DOC, required = false)
    final @FormParam("minLength") @DefaultValue("4") IntParam minLength,
    @ApiParam( value = DocumentationStrings.LONGEST_ENTITY_DOC, required = false)
    final @FormParam("longestOnly") @DefaultValue("false") BooleanParam longestOnly,
    @ApiParam( value = DocumentationStrings.INCLUDE_ABBREV_DOC, required = false)
    final @FormParam("includeAbbrev") @DefaultValue("false") BooleanParam includeAbbrev,
    @ApiParam( value = DocumentationStrings.INCLUDE_ACRONYMS_DOC, required = false)
    final @FormParam("includeAcronym") @DefaultValue("false") BooleanParam includeAcronym,
    @ApiParam( value = DocumentationStrings.INCLUDE_NUMBERS_DOC, required = false)
    final @FormParam("includeNumbers") @DefaultValue("false") BooleanParam includeNumbers) throws IOException {
  return this.getEntitiesAndContent(content, includeCategories, excludeCategories, minLength, longestOnly, includeAbbrev, includeAcronym, includeNumbers);
}
 
Example #11
Source File: AnnotateService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@POST
@Path("/entities")
@Consumes("application/x-www-form-urlencoded")
@ApiOperation(value = "Get entities from text", 
response = EntityAnnotation.class, 
responseContainer = "List",
notes = "Get the entities from content without embedding them in the source - only the entities are returned. " +
    DocumentationStrings.REST_ABUSE_DOC)
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public Object postEntities(
    @ApiParam( value = DocumentationStrings.CONTENT_DOC, required = true)
    final @FormParam("content") @DefaultValue("") String content,
    @ApiParam( value = DocumentationStrings.INCLUDE_CATEGORIES_DOC, required = false)
    final @FormParam("includeCat") Set<String> includeCategories,
    @ApiParam( value = DocumentationStrings.EXCLUDE_CATEGORIES_DOC, required = false)
    final @FormParam("excludeCat") Set<String> excludeCategories,
    @ApiParam( value = DocumentationStrings.MINIMUM_LENGTH_DOC, required = false)
    final @FormParam("minLength") @DefaultValue("4") IntParam minLength,
    @ApiParam( value = DocumentationStrings.LONGEST_ENTITY_DOC, required = false)
    final @FormParam("longestOnly") @DefaultValue("false") BooleanParam longestOnly,
    @ApiParam( value = DocumentationStrings.INCLUDE_ABBREV_DOC, required = false)
    final @FormParam("includeAbbrev") @DefaultValue("false") BooleanParam includeAbbrev,
    @ApiParam( value = DocumentationStrings.INCLUDE_ACRONYMS_DOC, required = false)
    final @FormParam("includeAcronym") @DefaultValue("false") BooleanParam includeAcronym,
    @ApiParam( value = DocumentationStrings.INCLUDE_NUMBERS_DOC, required = false)
    final @FormParam("includeNumbers") @DefaultValue("false") BooleanParam includeNumbers) {
  return getEntities(content, includeCategories, excludeCategories, minLength, 
      longestOnly, includeAbbrev, includeAcronym, includeNumbers);
}
 
Example #12
Source File: RefineService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@POST
@Path("/reconcile")
@ApiOperation(value = "Reconcile terms",
notes = DocumentationStrings.RECONCILE_NOTES,
response = RefineResult.class)
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public Object suggestFromTerm_POST(
    @ApiParam( value = DocumentationStrings.RECONCILE_QUERY_DOC, required = false)
    @FormParam("query") String query,
    @ApiParam( value = DocumentationStrings.RECONCILE_QUERIES_DOC, required = false )
    @FormParam("queries") String queries) {
  return suggestFromTerm(query, queries, null);
}
 
Example #13
Source File: GraphService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/properties")
@ApiOperation(value = "Get all property keys", response = String.class,
    responseContainer = "List")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
@Produces({MediaType.APPLICATION_JSON})
public Object getProperties(@ApiParam(value = DocumentationStrings.JSONP_DOC,
    required = false) @QueryParam("callback") String callback) {
  List<String> propertyKeys = new ArrayList<>(api.getAllPropertyKeys());
  sort(propertyKeys);
  return JaxRsUtil.wrapJsonp(request.get(), new GenericEntity<List<String>>(propertyKeys) {},
      callback);
}
 
Example #14
Source File: GraphService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/relationship_types")
@ApiOperation(value = "Get all relationship types", response = String.class,
    responseContainer = "List")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
@Produces({MediaType.APPLICATION_JSON})
public Object getRelationships(@ApiParam(value = DocumentationStrings.JSONP_DOC,
    required = false) @QueryParam("callback") String callback) {
  List<String> relationships = getRelationshipTypeNames();
  sort(relationships);
  return JaxRsUtil.wrapJsonp(request.get(), new GenericEntity<List<String>>(relationships) {},
      callback);
}
 
Example #15
Source File: GraphService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/neighbors/{id}")
@ApiOperation(value = "Get neighbors", response = Graph.class)
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
@Produces({MediaType.APPLICATION_JSON, CustomMediaTypes.APPLICATION_GRAPHSON,
    MediaType.APPLICATION_XML, CustomMediaTypes.APPLICATION_GRAPHML,
    CustomMediaTypes.APPLICATION_XGMML, CustomMediaTypes.TEXT_GML, CustomMediaTypes.TEXT_CSV,
    CustomMediaTypes.TEXT_TSV, CustomMediaTypes.IMAGE_JPEG, CustomMediaTypes.IMAGE_PNG})
public Object getNeighbors(
    @ApiParam(value = DocumentationStrings.GRAPH_ID_DOC,
        required = true) @PathParam("id") String id,
    @ApiParam(value = "How far to traverse neighbors",
        required = false) @QueryParam("depth") @DefaultValue("1") IntParam depth,
    @ApiParam(value = "Traverse blank nodes",
        required = false) @QueryParam("blankNodes") @DefaultValue("false") BooleanParam traverseBlankNodes,
    @ApiParam(value = "Which relationship to traverse",
        required = false) @QueryParam("relationshipType") Set<String> relationshipTypes,
    @ApiParam(value = DocumentationStrings.DIRECTION_DOC, required = false,
        allowableValues = DocumentationStrings.DIRECTION_ALLOWED) @QueryParam("direction") @DefaultValue("BOTH") String direction,
    @ApiParam(value = "Should subproperties and equivalent properties be included",
        required = false) @QueryParam("entail") @DefaultValue("false") BooleanParam entail,
    @ApiParam(value = DocumentationStrings.PROJECTION_DOC,
        required = false) @QueryParam("project") @DefaultValue("*") Set<String> projection,
    @ApiParam(value = DocumentationStrings.JSONP_DOC,
        required = false) @QueryParam("callback") String callback) {
  return getNeighborsFromMultipleRoots(newHashSet(id), depth, traverseBlankNodes,
      relationshipTypes, direction, entail, projection, callback);
}
 
Example #16
Source File: LexicalService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
/***
 * Extract "chunks" from input text. Chunks are based on POS heuristics.
 * 
 * @param text The source text
 * @param callback The name of the JSONP callback function
 * @return A list of chunks
 */
@GET
@Path("/chunks")
@ApiOperation(value = "Extract entities from text.", response = Token.class,
responseContainer = "List",
notes = "The extracted chunks are based upon POS tagging. This may result in different results that extracting entities.")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public  List<Token<String>> getChunks(
    @ApiParam( value = "The text from which to extract chunks", required = true )
    @QueryParam("text") @DefaultValue("") String text) {
  List<Token<String>> chunks = lexicalLib.getChunks(text);
  return chunks;
}
 
Example #17
Source File: LexicalService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
/***
 * Extract POS tags from input text
 * 
 * @param text The source text
 * @param callback The name of the JSONP callback function
 * @return A list of POS tokens
 */
@GET
@Path("/pos")
@ApiOperation(value = "Tag parts of speech.", 
response = PosToken.class,
responseContainer = "List")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public List<PosToken> getPos(
    @ApiParam( value = "The text to tag", required = true )
    @QueryParam("text") @DefaultValue("") String text) {
  List<PosToken> tokens = lexicalLib.tagPOS(text);
  return tokens;
}
 
Example #18
Source File: LexicalService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
/***
 * Break text into sentences.
 * 
 * @param text The source text
 * @param callback The name of the JSONP callback function
 * @return A list of sentences
 */
@GET
@Path("/sentences")
@ApiOperation(value = "Split text into sentences.", 
response = String.class,
responseContainer = "List")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public Object getSentences(
    @ApiParam( value = "The text to split", required = true )
    @QueryParam("text") @DefaultValue("") String text) {
  List<String> sentences = lexicalLib.extractSentences(text);
  return sentences;
}
 
Example #19
Source File: VocabularyService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/prefixes")
@ApiOperation(value = "Get all CURIE prefixes",
notes = "CURIE prefixes can be used to limit results",
response = String.class,
responseContainer = "Set")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public Set<String> getCuriePrefixes() {
  Set<String> prefixes = vocabulary.getAllCuriePrefixes();
  return prefixes;
}
 
Example #20
Source File: VocabularyService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/categories")
@ApiOperation(value = "Get all categories",
notes = "Categories can be used to limit results",
response = String.class,
responseContainer = "Set")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public Set<String> getCategories() {
  Set<String> categories = vocabulary.getAllCategories();
  return categories;
}
 
Example #21
Source File: LexicalService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
/***
 * Extract entities from text. Entities are based on a HMM.
 * 
 * @param text The source text
 * @param callback The name of the JSONP callback function
 * @return A list of entities
 */
@GET
@Path("/entities")
@ApiOperation(value = "Extract entities from text.", response = Token.class,
responseContainer = "List",
notes = "The extracted entites are based upon a Hidden Markov Model. This may result in different results that extracting chunks.")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public Object getEntities(
    @ApiParam( value = "The text from which to extract entities", required = true )
    @QueryParam("text") @DefaultValue("") String text) {
  List<Token<String>> chunks = lexicalLib.getEntities(text);
  return chunks;
}
 
Example #22
Source File: MenuResource.java    From robe with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * get menu for logged user
 *
 * @param credentials injected by {@link RobeAuth} annotation for authentication.
 * @return user {@link MenuItem} as collection
 */

@RobeService(group = "Menu", description = "Get menu for logged user")
@Path("user")
@GET
@UnitOfWork(readOnly = true, cacheMode = GET, flushMode = FlushMode.MANUAL)
@CacheControl(noCache = true)
public List<MenuItem> getUserHierarchicalMenu(@RobeAuth Credentials credentials) {
    Optional<User> user = userDao.findByUsername(credentials.getUsername());
    Set<Permission> permissions = new HashSet<Permission>();

    Role parent = roleDao.findById(user.get().getRoleOid());
    getAllRolePermissions(parent, permissions);
    Set<String> menuOids = new HashSet<String>();

    List<MenuItem> items = convertMenuToMenuItem(menuDao.findHierarchicalMenu());
    items = readMenuHierarchical(items);

    for (Permission permission : permissions) {
        if (permission.getType().equals(Permission.Type.MENU)) {
            menuOids.add(permission.getRestrictedItemOid());
        }
    }
    List<MenuItem> permittedItems = new LinkedList<MenuItem>();

    createMenuWithPermissions(menuOids, items, permittedItems);

    return permittedItems;
}
 
Example #23
Source File: CypherUtilService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/curies")
@ApiOperation(value = "Get the curie map", response = String.class, responseContainer = "Map")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
@Produces({MediaType.APPLICATION_JSON})
public Object getCuries(
    @ApiParam(value = DocumentationStrings.JSONP_DOC, required = false) @QueryParam("callback") String callback) {
  return JaxRsUtil.wrapJsonp(request.get(),
      new GenericEntity<Map<String, String>>(cypherUtil.getCurieMap()) {}, callback);
}
 
Example #24
Source File: PingResource.java    From notification with Apache License 2.0 4 votes vote down vote up
@GET
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public Response ping() {
  return Response.ok("pong").type(MediaType.TEXT_PLAIN).build();
}
 
Example #25
Source File: PingResource.java    From snowizard with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@GET
@Produces(MediaType.TEXT_PLAIN)
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public Response ping() {
    return Response.ok("pong").type(MediaType.TEXT_PLAIN).build();
}
 
Example #26
Source File: VersionResource.java    From notification with Apache License 2.0 4 votes vote down vote up
@GET
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public Response getVersion() {
  return Response.ok(version).type(MediaType.TEXT_PLAIN).build();
}
 
Example #27
Source File: VocabularyService.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/autocomplete/{term}")
@ApiOperation(value = "Find a concept by its prefix",
notes = "This resource is designed for autocomplete services.",
response = Completion.class,
responseContainer = "List")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public List<Completion> findByPrefix(
    @ApiParam( value = "Term prefix to find", required = true )
    @PathParam("term") String termPrefix,
    @ApiParam( value = DocumentationStrings.RESULT_LIMIT_DOC, required = false )
    @QueryParam("limit") @DefaultValue("20") IntParam limit,
    @ApiParam( value = DocumentationStrings.SEARCH_SYNONYMS, required = false )
    @QueryParam("searchSynonyms") @DefaultValue("true") BooleanParam searchSynonyms,
    @ApiParam( value = DocumentationStrings.SEARCH_ABBREVIATIONS, required = false )
    @QueryParam("searchAbbreviations") @DefaultValue("false") BooleanParam searchAbbreviations,
    @ApiParam( value = DocumentationStrings.SEARCH_ACRONYMS, required = false )
    @QueryParam("searchAcronyms") @DefaultValue("false") BooleanParam searchAcronyms,
    @ApiParam( value = DocumentationStrings.INCLUDE_DEPRECATED_CLASSES, required = false )
    @QueryParam("includeDeprecated") @DefaultValue("false") BooleanParam includeDeprecated,
    @ApiParam( value = "Categories to search (defaults to all)", required = false )
    @QueryParam("category") List<String> categories,
    @ApiParam( value = "CURIE prefixes to search (defaults to all)", required = false )
    @QueryParam("prefix") List<String> prefixes) {
  Vocabulary.Query.Builder builder = new Vocabulary.Query.Builder(termPrefix).
      categories(categories).
      prefixes(prefixes).
      includeDeprecated(includeDeprecated.get()).
      includeSynonyms(searchSynonyms.get()).
      includeAbbreviations(searchAbbreviations.get()).
      includeAcronyms(searchAcronyms.get()).
      limit(1000);
  List<Concept> concepts = vocabulary.getConceptsFromPrefix(builder.build());
  List<Completion> completions = getCompletions(builder.build(), concepts);
  // TODO: Move completions to scigraph-core for #51
  sort(completions);
  int endIndex = limit.get() > completions.size() ? completions.size() : limit.get();
  completions = completions.subList(0, endIndex);
  return completions;
}
 
Example #28
Source File: VocabularyService.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/term/{term}")
@ApiOperation(value = "Find a concept from a term",
notes = "Makes a best effort to provide \"exactish\" matching. " +
    "Individual tokens within multi-token labels are not matched" + 
    " (ie: \"foo bar\" would not be returned by a search for \"bar\")."
    + " Results are not guaranteed to be unique.",
    response = Concept.class,
    responseContainer="List")
@ApiResponses({
  @ApiResponse(code = 404, message = "Concept with term could not be found")
})
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public List<ConceptDTO> findByTerm(
    @ApiParam( value = "Term to find", required = true )
    @PathParam("term") String term,
    @ApiParam( value = DocumentationStrings.RESULT_LIMIT_DOC, required = false )
    @QueryParam("limit") @DefaultValue("20") IntParam limit,
    @ApiParam( value = DocumentationStrings.SEARCH_SYNONYMS, required = false )
    @QueryParam("searchSynonyms") @DefaultValue("true") BooleanParam searchSynonyms,
    @ApiParam( value = DocumentationStrings.SEARCH_ABBREVIATIONS, required = false )
    @QueryParam("searchAbbreviations") @DefaultValue("false") BooleanParam searchAbbreviations,
    @ApiParam( value = DocumentationStrings.SEARCH_ACRONYMS, required = false )
    @QueryParam("searchAcronyms") @DefaultValue("false") BooleanParam searchAcronyms,
    @ApiParam( value = "Categories to search (defaults to all)", required = false )
    @QueryParam("category") List<String> categories,
    @ApiParam( value = "CURIE prefixes to search (defaults to all)", required = false )
    @QueryParam("prefix") List<String> prefixes) {
  Vocabulary.Query.Builder builder = new Vocabulary.Query.Builder(term).
      categories(categories).
      prefixes(prefixes).
      includeSynonyms(searchSynonyms.get()).
      includeAbbreviations(searchAbbreviations.get()).
      includeAcronyms(searchAcronyms.get()).
      limit(limit.get());
  List<Concept> concepts = vocabulary.getConceptsFromTerm(builder.build());
  if (concepts.isEmpty()) {
    throw new WebApplicationException(404);
  } else {
    List<ConceptDTO> dtos = transform(concepts, conceptDtoTransformer);
    return dtos;
  }
}
 
Example #29
Source File: AnnotateService.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
/*** 
 * @return A list of entities and the annotated content
 */
@GET
@Path("/complete")
@Consumes("application/x-www-form-urlencoded")
@ApiOperation(value = "Get embedded annotations as well as a separate list", 
response = Annotations.class, 
notes="A convenience resource for retrieving both a list of entities and annotated content")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public Annotations getEntitiesAndContent(
    @ApiParam( value = DocumentationStrings.CONTENT_DOC, required = true)
    final @QueryParam("content") @DefaultValue("") String content,
    @ApiParam( value = DocumentationStrings.INCLUDE_CATEGORIES_DOC, required = false)
    final @QueryParam("includeCat") Set<String> includeCategories,
    @ApiParam( value = DocumentationStrings.EXCLUDE_CATEGORIES_DOC, required = false)
    final @QueryParam("excludeCat") Set<String> excludeCategories,
    @ApiParam( value = DocumentationStrings.MINIMUM_LENGTH_DOC, required = false)
    final @QueryParam("minLength") @DefaultValue("4") IntParam minLength,
    @ApiParam( value = DocumentationStrings.LONGEST_ENTITY_DOC, required = false)
    final @QueryParam("longestOnly") @DefaultValue("false") BooleanParam longestOnly,
    @ApiParam( value = DocumentationStrings.INCLUDE_ABBREV_DOC, required = false)
    final @QueryParam("includeAbbrev") @DefaultValue("false") BooleanParam includeAbbrev,
    @ApiParam( value = DocumentationStrings.INCLUDE_ACRONYMS_DOC, required = false)
    final @QueryParam("includeAcronym") @DefaultValue("false") BooleanParam includeAcronym,
    @ApiParam( value = DocumentationStrings.INCLUDE_NUMBERS_DOC, required = false)
    final @QueryParam("includeNumbers") @DefaultValue("false") BooleanParam includeNumbers
    ) throws IOException {
  Annotations annotations = new Annotations();
  StringWriter writer = new StringWriter();
  EntityFormatConfiguration.Builder configBuilder = new EntityFormatConfiguration.Builder(new StringReader(content));
  configBuilder.includeCategories(includeCategories);
  configBuilder.excludeCategories(excludeCategories);
  configBuilder.includeAbbreviations(includeAbbrev.get());
  configBuilder.includeAncronyms(includeAcronym.get());
  configBuilder.includeNumbers(includeNumbers.get());
  configBuilder.minLength(minLength.get());
  configBuilder.longestOnly(longestOnly.get());
  configBuilder.writeTo(writer);
  annotations.delegate = processor.annotateEntities(configBuilder.get());
  annotations.content = writer.toString();

  return annotations;
}
 
Example #30
Source File: VocabularyService.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/search/{term}")
@ApiOperation(value = "Find a concept from a term fragment",
notes = "Searches the complete text of the term. "
    + "Individual tokens within multi-token labels are matched" + 
    " (ie: \"foo bar\" would be returned by a search for \"bar\"). Results are not guaranteed to be unique.",
    response = ConceptDTO.class,
    responseContainer= "List")
@ApiResponses({
  @ApiResponse(code = 404, message = "Concept with term could not be found")
})
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
public List<ConceptDTO> searchByTerm(
    @ApiParam( value = "Term to find", required = true )
    @PathParam("term") String term,
    @ApiParam( value = DocumentationStrings.RESULT_LIMIT_DOC, required = false )
    @QueryParam("limit") @DefaultValue("20") IntParam limit,
    @ApiParam( value = DocumentationStrings.SEARCH_SYNONYMS, required = false )
    @QueryParam("searchSynonyms") @DefaultValue("true") BooleanParam searchSynonyms,
    @ApiParam( value = DocumentationStrings.SEARCH_ABBREVIATIONS, required = false )
    @QueryParam("searchAbbreviations") @DefaultValue("false") BooleanParam searchAbbreviations,
    @ApiParam( value = DocumentationStrings.SEARCH_ACRONYMS, required = false )
    @QueryParam("searchAcronyms") @DefaultValue("false") BooleanParam searchAcronyms,
    @ApiParam( value = "Categories to search (defaults to all)", required = false )
    @QueryParam("category") List<String> categories,
    @ApiParam( value = "CURIE prefixes to search (defaults to all)", required = false )
    @QueryParam("prefix") List<String> prefixes) {
  Vocabulary.Query.Builder builder = new Vocabulary.Query.Builder(term).
      categories(categories).
      prefixes(prefixes).
      includeSynonyms(searchSynonyms.get()).
      includeAbbreviations(searchAbbreviations.get()).
      includeAcronyms(searchAcronyms.get()).
      limit(limit.get());
  List<Concept> concepts = vocabulary.searchConcepts(builder.build());
  if (concepts.isEmpty()) {
    throw new WebApplicationException(404);
  } else {
    List<ConceptDTO> dtos = transform(concepts, conceptDtoTransformer);
    return dtos;
  }
}