use of jakarta.ws.rs.Consumes in project OpenGrok by OpenGrok.
the class SystemController method loadPathDescriptions.
@POST
@Path("/pathdesc")
@Consumes(MediaType.APPLICATION_JSON)
public void loadPathDescriptions(@Valid final PathDescription[] descriptions) throws IOException {
EftarFile ef = new EftarFile();
ef.create(Set.of(descriptions), env.getDtagsEftarPath().toString());
LOGGER.log(Level.INFO, "reloaded path descriptions with {0} entries", descriptions.length);
}
use of jakarta.ws.rs.Consumes in project OpenGrok by OpenGrok.
the class SuggesterController method addSearchCountsQueries.
/**
* Initializes the search data used by suggester to perform most popular completion. The passed {@code urls} are
* decomposed into single terms which search counts are then increased by 1.
* @param urls list of URLs in JSON format, e.g.
* {@code ["http://demo.opengrok.org/search?project=opengrok&full=test"]}
*/
@POST
@Path("/init/queries")
@Consumes(MediaType.APPLICATION_JSON)
public void addSearchCountsQueries(final List<String> urls) {
for (String urlStr : urls) {
try {
URL url = new URL(urlStr);
Map<String, List<String>> params = Util.getQueryParams(url);
List<String> projects = params.get("project");
for (String field : QueryBuilder.getSearchFields()) {
List<String> fieldQueryText = params.get(field);
if (fieldQueryText == null || fieldQueryText.isEmpty()) {
continue;
}
if (fieldQueryText.size() > 2) {
logger.log(Level.WARNING, "Bad format, ignoring {0}", urlStr);
continue;
}
String value = fieldQueryText.get(0);
Query q = null;
try {
q = getQuery(field, value);
} catch (ParseException e) {
logger.log(Level.FINE, "Bad request", e);
}
if (q != null) {
suggester.onSearch(projects, q);
}
}
} catch (MalformedURLException e) {
logger.log(Level.WARNING, "Could not add search counts for " + urlStr, e);
}
}
}
use of jakarta.ws.rs.Consumes in project OpenGrok by OpenGrok.
the class ProjectsController method markIndexed.
@PUT
@Path("/{project}/indexed")
@Consumes(MediaType.TEXT_PLAIN)
public Response markIndexed(@Context HttpServletRequest request, @PathParam("project") String projectNameParam) {
// Avoid classification as a taint bug.
final String projectName = Laundromat.launderInput(projectNameParam);
Project project = env.getProjects().get(projectName);
if (project == null) {
LOGGER.log(Level.WARNING, "cannot find project {0} to mark as indexed", projectName);
throw new NotFoundException(String.format("project '%s' does not exist", projectName));
}
project.setIndexed(true);
return ApiTaskManager.getInstance().submitApiTask(PROJECTS_PATH, new ApiTask(request.getRequestURI(), () -> {
// Refresh current version of the project's repositories.
List<RepositoryInfo> riList = env.getProjectRepositoriesMap().get(project);
if (riList != null) {
for (RepositoryInfo ri : riList) {
Repository repo = getRepository(ri, CommandTimeoutType.RESTFUL);
if (repo != null && repo.getCurrentVersion() != null && repo.getCurrentVersion().length() > 0) {
// getRepository() always creates fresh instance
// of the Repository object so there is no need
// to call setCurrentVersion() on it.
ri.setCurrentVersion(repo.determineCurrentVersion());
}
}
}
CompletableFuture.runAsync(() -> suggester.rebuild(projectName));
// In case this project has just been incrementally indexed,
// its IndexSearcher needs a poke.
env.maybeRefreshIndexSearchers(Collections.singleton(projectName));
env.refreshDateForLastIndexRun();
return null;
}));
}
use of jakarta.ws.rs.Consumes in project OpenGrok by OpenGrok.
the class ProjectsController method addProject.
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response addProject(@Context HttpServletRequest request, String projectNameParam) {
// Avoid classification as a taint bug.
final String projectName = Laundromat.launderInput(projectNameParam);
LOGGER.log(Level.INFO, "adding project {0}", projectName);
return ApiTaskManager.getInstance().submitApiTask(PROJECTS_PATH, new ApiTask(request.getRequestURI(), () -> {
addProjectWorkHorse(projectName);
return null;
}, Response.Status.CREATED));
}
Aggregations