Search in sources :

Example 6 with Produces

use of jakarta.ws.rs.Produces in project page-factory-2 by sbtqa.

the class ClientJsonEndpoint method requestFromFeature2.

@POST
@Path("request-from-feature-2")
@Produces(MediaType.APPLICATION_JSON)
public Response requestFromFeature2(@QueryParam("q2") String query1, @QueryParam("query-parameter-value-1") String query2, @HeaderParam("h") String header1, @HeaderParam("Content-Type") String header2, Client client) {
    SimpleResult result = new SimpleResult();
    result.setResult(String.format("q1=%s|q2=%s|h1=%s|h2=%s|id=%s|name=%s|email=%s|", query1, query2, header1, header2, client.getId(), client.getName(), client.getEmail()));
    return Response.ok(result).header(Default.HEADER_PARAMETER_NAME_1, header1).header(Default.HEADER_PARAMETER_NAME_2, header2).build();
}
Also used : SimpleResult(ru.sbtqa.tag.api.dto.SimpleResult) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Produces(jakarta.ws.rs.Produces)

Example 7 with Produces

use of jakarta.ws.rs.Produces in project OpenGrok by OpenGrok.

the class ProjectsController method getRepositories.

@GET
@Path("/{project}/repositories")
@Produces(MediaType.APPLICATION_JSON)
public List<String> getRepositories(@PathParam("project") String projectName) {
    // Avoid classification as a taint bug.
    projectName = Laundromat.launderInput(projectName);
    Project project = env.getProjects().get(projectName);
    if (project != null) {
        List<RepositoryInfo> infos = env.getProjectRepositoriesMap().get(project);
        if (infos != null) {
            return infos.stream().map(RepositoryInfo::getDirectoryNameRelative).collect(Collectors.toList());
        }
    }
    return Collections.emptyList();
}
Also used : Project(org.opengrok.indexer.configuration.Project) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Example 8 with Produces

use of jakarta.ws.rs.Produces in project OpenGrok by OpenGrok.

the class ProjectsController method get.

@GET
@Path("/{project}/property/{field}")
@Produces(MediaType.APPLICATION_JSON)
public Object get(@PathParam("project") String projectName, @PathParam("field") String field) throws IOException {
    // Avoid classification as a taint bug.
    projectName = Laundromat.launderInput(projectName);
    field = Laundromat.launderInput(field);
    Project project = env.getProjects().get(projectName);
    if (project == null) {
        throw new WebApplicationException("cannot find project " + projectName + " to get a property", Response.Status.BAD_REQUEST);
    }
    return ClassUtil.getFieldValue(project, field);
}
Also used : Project(org.opengrok.indexer.configuration.Project) WebApplicationException(jakarta.ws.rs.WebApplicationException) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Example 9 with Produces

use of jakarta.ws.rs.Produces in project OpenGrok by OpenGrok.

the class SearchController method search.

@GET
@CorsEnable
@Produces(MediaType.APPLICATION_JSON)
public SearchResult search(@Context final HttpServletRequest req, @QueryParam(QueryParameters.FULL_SEARCH_PARAM) final String full, // Nearly QueryParameters.DEFS_SEARCH_PARAM
@QueryParam("def") final String def, // Akin to QueryBuilder.REFS_SEARCH_PARAM
@QueryParam("symbol") final String symbol, @QueryParam(QueryParameters.PATH_SEARCH_PARAM) final String path, @QueryParam(QueryParameters.HIST_SEARCH_PARAM) final String hist, @QueryParam(QueryParameters.TYPE_SEARCH_PARAM) final String type, @QueryParam("projects") final List<String> projects, // Akin to QueryParameters.COUNT_PARAM
@QueryParam("maxresults") @DefaultValue(MAX_RESULTS + "") final int maxResults, @QueryParam(QueryParameters.START_PARAM) @DefaultValue(0 + "") final int startDocIndex) {
    try (SearchEngineWrapper engine = new SearchEngineWrapper(full, def, symbol, path, hist, type)) {
        if (!engine.isValid()) {
            throw new WebApplicationException("Invalid request", Response.Status.BAD_REQUEST);
        }
        Instant startTime = Instant.now();
        suggester.onSearch(projects, engine.getQuery());
        Map<String, List<SearchHit>> hits = engine.search(req, projects, startDocIndex, maxResults).stream().collect(Collectors.groupingBy(Hit::getPath, Collectors.mapping(h -> new SearchHit(h.getLine(), h.getLineno()), Collectors.toList())));
        long duration = Duration.between(startTime, Instant.now()).toMillis();
        int endDocument = startDocIndex + hits.size() - 1;
        return new SearchResult(duration, engine.numResults, hits, startDocIndex, endDocument);
    }
}
Also used : WebApplicationException(jakarta.ws.rs.WebApplicationException) Instant(java.time.Instant) ArrayList(java.util.ArrayList) List(java.util.List) CorsEnable(org.opengrok.web.api.v1.filter.CorsEnable) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Example 10 with Produces

use of jakarta.ws.rs.Produces in project OpenGrok by OpenGrok.

the class SuggesterController method getSuggestions.

/**
 * Returns suggestions based on the search criteria specified in {@code data}.
 * @param data suggester form data
 * @return list of suggestions and other related information
 * @throws ParseException if the Lucene query created from {@code data} could not be parsed
 */
@GET
@Authorized
@CorsEnable
@Produces(MediaType.APPLICATION_JSON)
public Result getSuggestions(@Valid @BeanParam final SuggesterQueryData data) throws ParseException {
    Instant start = Instant.now();
    SuggesterData suggesterData = SuggesterQueryDataParser.parse(data);
    if (suggesterData.getSuggesterQuery() == null) {
        throw new ParseException("Could not determine suggester query");
    }
    SuggesterConfig config = env.getSuggesterConfig();
    modifyDataBasedOnConfiguration(suggesterData, config);
    if (!satisfiesConfiguration(suggesterData, config)) {
        logger.log(Level.FINER, "Suggester request with data {0} does not satisfy configuration settings", data);
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    Suggestions suggestions = suggester.getSuggestions(suggesterData.getProjects(), suggesterData.getSuggesterQuery(), suggesterData.getQuery());
    Instant end = Instant.now();
    long timeInMs = Duration.between(start, end).toMillis();
    return new Result(suggestions.getItems(), suggesterData.getIdentifier(), suggesterData.getSuggesterQueryFieldText(), timeInMs, suggestions.isPartialResult());
}
Also used : Suggestions(org.opengrok.suggest.Suggester.Suggestions) WebApplicationException(jakarta.ws.rs.WebApplicationException) Instant(java.time.Instant) ParseException(org.apache.lucene.queryparser.classic.ParseException) SuggesterData(org.opengrok.web.api.v1.suggester.model.SuggesterData) SuggesterConfig(org.opengrok.indexer.configuration.SuggesterConfig) CorsEnable(org.opengrok.web.api.v1.filter.CorsEnable) Authorized(org.opengrok.web.api.v1.suggester.provider.filter.Authorized) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Aggregations

Produces (jakarta.ws.rs.Produces)22 Path (jakarta.ws.rs.Path)18 GET (jakarta.ws.rs.GET)12 SimpleResult (ru.sbtqa.tag.api.dto.SimpleResult)11 POST (jakarta.ws.rs.POST)7 CorsEnable (org.opengrok.web.api.v1.filter.CorsEnable)6 Consumes (jakarta.ws.rs.Consumes)4 File (java.io.File)4 PathAuthorized (org.opengrok.web.api.v1.filter.PathAuthorized)4 FileUtil.toFile (org.opengrok.web.util.FileUtil.toFile)4 WebApplicationException (jakarta.ws.rs.WebApplicationException)3 Project (org.opengrok.indexer.configuration.Project)3 BasicDBObject (com.mongodb.BasicDBObject)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Document (org.apache.lucene.document.Document)2 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)2 IndexDatabase.getDocument (org.opengrok.indexer.index.IndexDatabase.getDocument)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StdDateFormat (com.fasterxml.jackson.databind.util.StdDateFormat)1