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();
}
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();
}
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);
}
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);
}
}
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());
}
Aggregations