Search in sources :

Example 1 with Consumes

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);
}
Also used : EftarFile(org.opengrok.indexer.web.EftarFile) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes)

Example 2 with Consumes

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);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Query(org.apache.lucene.search.Query) List(java.util.List) ParseException(org.apache.lucene.queryparser.classic.ParseException) URL(java.net.URL) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes)

Example 3 with Consumes

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;
    }));
}
Also used : Project(org.opengrok.indexer.configuration.Project) Repository(org.opengrok.indexer.history.Repository) RepositoryFactory.getRepository(org.opengrok.indexer.history.RepositoryFactory.getRepository) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) NotFoundException(jakarta.ws.rs.NotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) ApiTask(org.opengrok.web.api.ApiTask) Path(jakarta.ws.rs.Path) Consumes(jakarta.ws.rs.Consumes) PUT(jakarta.ws.rs.PUT)

Example 4 with Consumes

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));
}
Also used : ApiTask(org.opengrok.web.api.ApiTask) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes)

Aggregations

Consumes (jakarta.ws.rs.Consumes)4 POST (jakarta.ws.rs.POST)3 Path (jakarta.ws.rs.Path)3 List (java.util.List)2 ApiTask (org.opengrok.web.api.ApiTask)2 NotFoundException (jakarta.ws.rs.NotFoundException)1 PUT (jakarta.ws.rs.PUT)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 Query (org.apache.lucene.search.Query)1 Project (org.opengrok.indexer.configuration.Project)1 Repository (org.opengrok.indexer.history.Repository)1 RepositoryFactory.getRepository (org.opengrok.indexer.history.RepositoryFactory.getRepository)1 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)1 EftarFile (org.opengrok.indexer.web.EftarFile)1