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
}
Aggregations