use of com.sun.jersey.api.client.AsyncWebResource in project ANNIS by korpling.
the class QueryController method validateQuery.
public void validateQuery() {
QueryPanel qp = searchView.getControlPanel().getQueryPanel();
// reset status
qp.setErrors(null);
qp.setNodes(null);
String query = state.getAql().getValue();
if (query == null || query.isEmpty()) {
qp.setStatus("Empty query");
} else {
// validate query
try {
AsyncWebResource annisResource = Helper.getAnnisAsyncWebResource();
Future<List<QueryNode>> future = annisResource.path("query").path("parse/nodes").queryParam("q", Helper.encodeJersey(query)).get(new GenericType<List<QueryNode>>() {
});
// wait for maximal one seconds
try {
List<QueryNode> nodes = future.get(1, TimeUnit.SECONDS);
qp.setNodes(nodes);
if (state.getSelectedCorpora().getValue() == null || state.getSelectedCorpora().getValue().isEmpty()) {
qp.setStatus("Please select a corpus from the list below, then click on \"Search\".");
} else {
qp.setStatus("Valid query, click on \"Search\" to start searching.");
}
} catch (InterruptedException ex) {
log.warn(null, ex);
} catch (ExecutionException ex) {
if (AnnisBaseUI.handleCommonError(ex, "validate query")) {
log.error(null, ex);
} else if (ex.getCause() instanceof UniformInterfaceException) {
reportServiceException((UniformInterfaceException) ex.getCause(), false);
} else {
// something unknown, report
ExceptionDialog.show(ex);
}
} catch (TimeoutException ex) {
qp.setStatus("Validation of query took too long.");
}
} catch (ClientHandlerException ex) {
log.error("Could not connect to web service", ex);
ExceptionDialog.show(ex, "Could not connect to web service");
}
}
}
use of com.sun.jersey.api.client.AsyncWebResource in project ANNIS by korpling.
the class QueryController method executeSearch.
/**
* Executes a query.
* @param replaceOldTab
* @param freshQuery If true the offset and the selected matches are reset before executing the query.
*/
public void executeSearch(boolean replaceOldTab, boolean freshQuery) {
if (freshQuery) {
getState().getOffset().setValue(0l);
getState().getSelectedMatches().setValue(new TreeSet<Long>());
// get the value for the visible segmentation from the configured context
Set<String> selectedCorpora = getState().getSelectedCorpora().getValue();
CorpusConfig config = new CorpusConfig();
if (selectedCorpora != null && !selectedCorpora.isEmpty()) {
config = ui.getCorpusConfigWithCache(selectedCorpora.iterator().next());
}
if (config.containsKey(SearchOptionsPanel.KEY_DEFAULT_BASE_TEXT_SEGMENTATION)) {
String configVal = config.getConfig(SearchOptionsPanel.KEY_DEFAULT_BASE_TEXT_SEGMENTATION);
if ("".equals(configVal) || "tok".equals(configVal)) {
configVal = null;
}
getState().getVisibleBaseText().setValue(configVal);
} else {
getState().getVisibleBaseText().setValue(getState().getContextSegmentation().getValue());
}
}
// construct a query from the current properties
DisplayedResultQuery displayedQuery = getSearchQuery();
searchView.getControlPanel().getQueryPanel().setStatus("Searching...");
cancelSearch();
// cleanup resources
VaadinSession session = VaadinSession.getCurrent();
session.setAttribute(IFrameResourceMap.class, new IFrameResourceMap());
if (session.getAttribute(MediaController.class) != null) {
session.getAttribute(MediaController.class).clearMediaPlayers();
}
searchView.updateFragment(displayedQuery);
if (displayedQuery.getCorpora() == null || displayedQuery.getCorpora().isEmpty()) {
Notification.show("Please select a corpus", Notification.Type.WARNING_MESSAGE);
return;
}
if ("".equals(displayedQuery.getQuery())) {
Notification.show("Empty query", Notification.Type.WARNING_MESSAGE);
return;
}
addHistoryEntry(displayedQuery);
AsyncWebResource res = Helper.getAnnisAsyncWebResource();
//
// begin execute match fetching
//
ResultViewPanel oldPanel = searchView.getLastSelectedResultView();
if (replaceOldTab) {
// remove old panel from view
searchView.closeTab(oldPanel);
}
ResultViewPanel newResultView = new ResultViewPanel(ui, ui, ui.getInstanceConfig(), displayedQuery);
newResultView.getPaging().addCallback(new SpecificPagingCallback(ui, searchView, newResultView, displayedQuery));
TabSheet.Tab newTab;
List<ResultViewPanel> existingResultPanels = getResultPanels();
String caption = existingResultPanels.isEmpty() ? "Query Result" : "Query Result #" + (existingResultPanels.size() + 1);
newTab = searchView.getMainTab().addTab(newResultView, caption);
newTab.setClosable(true);
newTab.setIcon(FontAwesome.SEARCH);
searchView.getMainTab().setSelectedTab(newResultView);
searchView.notifiyQueryStarted();
Background.run(new ResultFetchJob(displayedQuery, newResultView, ui));
//
// end execute match fetching
//
//
// begin execute count
//
// start count query
searchView.getControlPanel().getQueryPanel().setCountIndicatorEnabled(true);
AsyncWebResource countRes = res.path("query").path("search").path("count").queryParam("q", Helper.encodeJersey(displayedQuery.getQuery())).queryParam("corpora", Helper.encodeJersey(StringUtils.join(displayedQuery.getCorpora(), ",")));
Future<MatchAndDocumentCount> futureCount = countRes.get(MatchAndDocumentCount.class);
state.getExecutedTasks().put(QueryUIState.QueryType.COUNT, futureCount);
Background.run(new CountCallback(newResultView, displayedQuery.getLimit(), ui));
//
// end execute count
//
}
Aggregations