use of org.opengrok.web.api.v1.filter.CorsEnable 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 org.opengrok.web.api.v1.filter.CorsEnable 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());
}
use of org.opengrok.web.api.v1.filter.CorsEnable in project OpenGrok by OpenGrok.
the class HistoryController method get.
@GET
@CorsEnable
@PathAuthorized
@Produces(MediaType.APPLICATION_JSON)
public HistoryDTO get(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("path") final String path, @QueryParam("withFiles") final boolean withFiles, @QueryParam("max") @DefaultValue(MAX_RESULTS + "") final int maxEntries, @QueryParam("start") @DefaultValue(0 + "") final int startIndex) throws HistoryException, IOException, NoPathParameterException {
File file = toFile(path);
History history = HistoryGuru.getInstance().getHistory(file, withFiles, true);
if (history == null) {
return null;
}
return getHistoryDTO(history.getHistoryEntries(maxEntries, startIndex), history.getTags(), startIndex, maxEntries, history.getHistoryEntries().size());
}
use of org.opengrok.web.api.v1.filter.CorsEnable in project OpenGrok by OpenGrok.
the class AnnotationController method getContent.
@GET
@CorsEnable
@PathAuthorized
@Produces(MediaType.APPLICATION_JSON)
public List<AnnotationDTO> getContent(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("path") final String path, @QueryParam("revision") final String revision) throws IOException, NoPathParameterException {
File file = toFile(path);
Annotation annotation = HistoryGuru.getInstance().annotate(file, revision == null || revision.isEmpty() ? null : revision);
ArrayList<AnnotationDTO> annotationList = new ArrayList<>();
for (int i = 1; i <= annotation.size(); i++) {
annotationList.add(new AnnotationDTO(annotation.getRevision(i), annotation.getAuthor(i), annotation.getDesc(annotation.getRevision(i)), annotation.getFileVersion(annotation.getRevision(i)) + "/" + annotation.getRevisions().size()));
}
return annotationList;
}
use of org.opengrok.web.api.v1.filter.CorsEnable in project OpenGrok by OpenGrok.
the class FileController method getGenre.
@GET
@CorsEnable
@PathAuthorized
@Path("/genre")
@Produces(MediaType.TEXT_PLAIN)
public String getGenre(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("path") final String path) throws IOException, ParseException, NoPathParameterException {
File file = toFile(path);
Document doc;
if ((doc = getDocument(file)) == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot get document for file");
return null;
}
AbstractAnalyzer.Genre genre = AbstractAnalyzer.Genre.get(doc.get(QueryBuilder.T));
if (genre == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot get genre from the document");
return null;
}
return genre.toString();
}
Aggregations