use of org.codice.ddf.ui.searchui.query.model.SearchRequest in project ddf by codice.
the class SearchControllerTest method testMetacardTypeValuesCacheDisabled.
@Test
public void testMetacardTypeValuesCacheDisabled() throws Exception {
final String ID = "id";
Set<String> srcIds = new HashSet<String>();
srcIds.add(ID);
BayeuxServer bayeuxServer = mock(BayeuxServer.class);
ServerChannel channel = mock(ServerChannel.class);
ArgumentCaptor<ServerMessage.Mutable> reply = ArgumentCaptor.forClass(ServerMessage.Mutable.class);
when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
searchController.setBayeuxServer(bayeuxServer);
// Disable Cache
searchController.setCacheDisabled(true);
searchController.executeQuery(request, mockServerSession, null);
verify(channel, timeout(1000).only()).publish(any(ServerSession.class), reply.capture());
List<Mutable> replies = reply.getAllValues();
assertReplies(replies);
}
use of org.codice.ddf.ui.searchui.query.model.SearchRequest in project ddf by codice.
the class SearchControllerTest method testMetacardTypeValuesCacheEnabled.
@Test
public void testMetacardTypeValuesCacheEnabled() throws Exception {
final String ID = "id";
Set<String> srcIds = new HashSet<>();
srcIds.add(ID);
BayeuxServer bayeuxServer = mock(BayeuxServer.class);
ServerChannel channel = mock(ServerChannel.class);
ArgumentCaptor<ServerMessage.Mutable> reply = ArgumentCaptor.forClass(ServerMessage.Mutable.class);
when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
searchController.setBayeuxServer(bayeuxServer);
searchController.setCacheDisabled(false);
searchController.executeQuery(request, mockServerSession, null);
verify(channel, timeout(1000).times(2)).publish(any(ServerSession.class), reply.capture());
List<Mutable> replies = reply.getAllValues();
assertReplies(replies);
}
use of org.codice.ddf.ui.searchui.query.model.SearchRequest in project ddf by codice.
the class SearchService method executeQuery.
/**
* Creates the query requests for each source and hands off the query to the Search Controller
*
* @param queryMessage
* - JSON message received from cometd
*/
public void executeQuery(Map<String, Object> queryMessage, Subject subject) {
String sources = castObject(String.class, queryMessage.get(SOURCES));
Long maxTimeout = castObject(Long.class, queryMessage.get(MAX_TIMEOUT));
Long startIndex = castObject(Long.class, queryMessage.get(START_INDEX));
Long count = castObject(Long.class, queryMessage.get(COUNT));
String cql = castObject(String.class, queryMessage.get(CQL_FILTER));
String sort = castObject(String.class, queryMessage.get(SORT));
String id = castObject(String.class, queryMessage.get(ID));
Set<String> sourceIds = getSourceIds(sources);
Filter filter = null;
try {
if (StringUtils.isNotBlank(cql)) {
filter = ECQL.toFilter(cql);
}
} catch (CQLException e) {
LOGGER.debug("Unable to parse CQL filter", e);
return;
}
Query query = createQuery(filter, startIndex, count, sort, maxTimeout);
SearchRequest searchRequest = new SearchRequest(sourceIds, query, id);
try {
// Hand off to the search controller for the actual query
searchController.executeQuery(searchRequest, serverSession, subject);
} catch (Exception e) {
LOGGER.debug("Exception while executing a query", e);
}
}
use of org.codice.ddf.ui.searchui.query.model.SearchRequest in project ddf by codice.
the class SearchControllerTest method testFailingQuery.
@Test
public void testFailingQuery() throws Exception {
// Setup
framework = mock(CatalogFramework.class);
QueryResponse response = mock(QueryResponse.class);
when(response.getResults()).thenThrow(new RuntimeException("Getting results failed"));
when(framework.query(any(QueryRequest.class))).thenReturn(response);
searchController = new SearchController(framework, new ActionRegistryImpl(Collections.emptyList(), Collections.emptyList()), new GeotoolsFilterAdapterImpl(), new SequentialExecutorService());
final String ID = "id";
Set<String> srcIds = new HashSet<>();
srcIds.add(ID);
SearchRequest request = new SearchRequest(srcIds, getQueryRequest("anyText LIKE '*'"), "queryId");
BayeuxServer bayeuxServer = mock(BayeuxServer.class);
ServerChannel channel = mock(ServerChannel.class);
when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
searchController.setBayeuxServer(bayeuxServer);
searchController.setCacheDisabled(true);
// Perform Test
searchController.executeQuery(request, mockServerSession, null);
// Verify
verify(channel, times(1)).publish(any(), any());
}
use of org.codice.ddf.ui.searchui.query.model.SearchRequest in project ddf by codice.
the class SearchControllerTest method cacheQuery.
private List<String> cacheQuery(Set<String> srcIds, int queryRequestCount) throws CQLException, UnsupportedQueryException, SourceUnavailableException, FederationException {
SearchRequest request = new SearchRequest(srcIds, getQueryRequest("anyText LIKE '*'"), "queryId");
BayeuxServer bayeuxServer = mock(BayeuxServer.class);
ServerChannel channel = mock(ServerChannel.class);
when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
ArgumentCaptor<QueryRequest> queryRequestCaptor = ArgumentCaptor.forClass(QueryRequest.class);
searchController.setCacheDisabled(false);
searchController.setNormalizationDisabled(false);
searchController.setBayeuxServer(bayeuxServer);
// Perform Test
searchController.executeQuery(request, mockServerSession, null);
// Verify
verify(framework, times(queryRequestCount)).query(queryRequestCaptor.capture());
List<QueryRequest> capturedQueryRequests = queryRequestCaptor.getAllValues();
List<String> modes = new ArrayList<>(queryRequestCount);
for (QueryRequest queryRequest : capturedQueryRequests) {
for (String key : queryRequest.getProperties().keySet()) {
modes.add((String) queryRequest.getPropertyValue(key));
}
}
return modes;
}
Aggregations