Search in sources :

Example 1 with PagingComponent

use of annis.gui.paging.PagingComponent in project ANNIS by korpling.

the class ResultFetchJob method run.

@Override
public void run() {
    WebResource subgraphRes = Helper.getAnnisWebResource().path("query/search/subgraph");
    // holds the ids of the matches.
    MatchGroup result;
    try {
        if (Thread.interrupted()) {
            return;
        }
        // set the the progress bar, for given the user some information about the loading process
        ui.accessSynchronously(new Runnable() {

            @Override
            public void run() {
                resultPanel.showMatchSearchInProgress(query);
            }
        });
        // get the matches
        result = futureMatches.get();
        // get the subgraph for each match, when the result is not empty
        if (result.getMatches().isEmpty()) {
            // check if thread was interrupted
            if (Thread.interrupted()) {
                return;
            }
            // nothing found, so inform the user about this.
            ui.access(new Runnable() {

                @Override
                public void run() {
                    resultPanel.showNoResult();
                }
            });
        } else {
            if (Thread.interrupted()) {
                return;
            }
            // since annis found something, inform the user that subgraphs are created
            ui.access(new Runnable() {

                @Override
                public void run() {
                    resultPanel.showSubgraphSearchInProgress(query, 0.0f);
                }
            });
            // prepare fetching subgraphs
            final BlockingQueue<SaltProject> queue = new ArrayBlockingQueue<>(result.getMatches().size());
            int current = 0;
            final ArrayList<Match> matchList = new ArrayList<>(result.getMatches());
            for (Match m : matchList) {
                if (Thread.interrupted()) {
                    return;
                }
                List<Match> subList = new LinkedList<>();
                subList.add(m);
                final SaltProject p = executeQuery(subgraphRes, new MatchGroup(subList), query.getLeftContext(), query.getRightContext(), query.getSegmentation(), SubgraphFilter.all);
                queue.put(p);
                log.debug("added match {} to queue", current + 1);
                if (current == 0) {
                    ui.access(new Runnable() {

                        @Override
                        public void run() {
                            resultPanel.setQueryResultQueue(queue, query, matchList);
                        }
                    });
                }
                if (Thread.interrupted()) {
                    return;
                }
                current++;
            }
        }
    // end if no results
    } catch (InterruptedException ex) {
    // just return
    } catch (final ExecutionException root) {
        ui.accessSynchronously(new Runnable() {

            @Override
            public void run() {
                if (resultPanel != null && resultPanel.getPaging() != null) {
                    PagingComponent paging = resultPanel.getPaging();
                    Throwable cause = root.getCause();
                    if (cause instanceof UniformInterfaceException) {
                        UniformInterfaceException ex = (UniformInterfaceException) cause;
                        if (ex.getResponse().getStatus() == 400) {
                            List<AqlParseError> errors = ex.getResponse().getEntity(new GenericType<List<AqlParseError>>() {
                            });
                            String errMsg = Joiner.on(" | ").join(errors);
                            paging.setInfo("parsing error: " + errMsg);
                        } else if (ex.getResponse().getStatus() == 504) {
                            paging.setInfo("Timeout: query execution took too long");
                        } else if (ex.getResponse().getStatus() == 403) {
                            paging.setInfo("Not authorized to query this corpus.");
                        } else {
                            paging.setInfo("unknown error: " + ex);
                        }
                    } else {
                        log.error("Unexcepted ExecutionException cause", root);
                    }
                    resultPanel.showFinishedSubgraphSearch();
                }
            }
        });
    }
// end catch
}
Also used : ArrayList(java.util.ArrayList) AqlParseError(annis.model.AqlParseError) AsyncWebResource(com.sun.jersey.api.client.AsyncWebResource) WebResource(com.sun.jersey.api.client.WebResource) SaltProject(org.corpus_tools.salt.common.SaltProject) LinkedList(java.util.LinkedList) Match(annis.service.objects.Match) PagingComponent(annis.gui.paging.PagingComponent) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) MatchGroup(annis.service.objects.MatchGroup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

PagingComponent (annis.gui.paging.PagingComponent)1 AqlParseError (annis.model.AqlParseError)1 Match (annis.service.objects.Match)1 MatchGroup (annis.service.objects.MatchGroup)1 AsyncWebResource (com.sun.jersey.api.client.AsyncWebResource)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 WebResource (com.sun.jersey.api.client.WebResource)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 ExecutionException (java.util.concurrent.ExecutionException)1 SaltProject (org.corpus_tools.salt.common.SaltProject)1