use of annis.gui.controlpanel.QueryPanel 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 annis.gui.controlpanel.QueryPanel in project ANNIS by korpling.
the class QueryController method reportServiceException.
/**
* Show errors that occured during the execution of a query to the user.
*
* @param ex The exception to report in the user interface
* @param showNotification If true a notification is shown instead of only
* displaying the error in the status label.
*/
public void reportServiceException(UniformInterfaceException ex, boolean showNotification) {
QueryPanel qp = searchView.getControlPanel().getQueryPanel();
String caption = null;
String description = null;
if (!AnnisBaseUI.handleCommonError(ex, "execute query")) {
switch(ex.getResponse().getStatus()) {
case 400:
List<AqlParseError> errors = ex.getResponse().getEntity(new GenericType<List<AqlParseError>>() {
});
caption = "Parsing error";
description = Joiner.on("\n").join(errors);
qp.setStatus(description);
qp.setErrors(errors);
break;
case 504:
caption = "Timeout";
description = "Query execution took too long.";
qp.setStatus(caption + ": " + description);
break;
case 403:
if (Helper.getUser() == null) {
// not logged in
qp.setStatus("You don't have the access rights to query this corpus. " + "You might want to login to access more corpora.");
searchView.getMainToolbar().showLoginWindow(true);
} else {
// logged in but wrong user
caption = "You don't have the access rights to query this corpus. " + "You might want to login as another user to access more corpora.";
qp.setStatus(caption);
}
break;
default:
log.error("Exception when communicating with service", ex);
qp.setStatus("Unexpected exception: " + ex.getMessage());
ExceptionDialog.show(ex, "Exception when communicating with service.");
break;
}
if (showNotification && caption != null) {
Notification.show(caption, description, Notification.Type.WARNING_MESSAGE);
}
}
}
use of annis.gui.controlpanel.QueryPanel in project ANNIS by korpling.
the class ResultViewPanel method showFinishedSubgraphSearch.
public void showFinishedSubgraphSearch() {
// Search complete, stop progress bar control
if (sui.getSearchView().getControlPanel().getQueryPanel().getPiCount() != null) {
if (sui.getSearchView().getControlPanel().getQueryPanel().getPiCount().isVisible()) {
sui.getSearchView().getControlPanel().getQueryPanel().getPiCount().setVisible(false);
sui.getSearchView().getControlPanel().getQueryPanel().getPiCount().setEnabled(false);
}
}
// also remove the info how many results have been fetched
QueryPanel qp = sui.getSearchView().getControlPanel().getQueryPanel();
qp.setStatus(qp.getLastPublicStatus());
}
Aggregations