Search in sources :

Example 1 with SearchRequest

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);
}
Also used : Mutable(org.cometd.bayeux.server.ServerMessage.Mutable) SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) ServerSession(org.cometd.bayeux.server.ServerSession) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) ServerMessage(org.cometd.bayeux.server.ServerMessage) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with SearchRequest

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);
}
Also used : Mutable(org.cometd.bayeux.server.ServerMessage.Mutable) SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) ServerSession(org.cometd.bayeux.server.ServerSession) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) ServerMessage(org.cometd.bayeux.server.ServerMessage) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with SearchRequest

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);
    }
}
Also used : SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) Query(ddf.catalog.operation.Query) Filter(org.opengis.filter.Filter) CQLException(org.geotools.filter.text.cql2.CQLException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 4 with SearchRequest

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());
}
Also used : SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) QueryRequest(ddf.catalog.operation.QueryRequest) ActionRegistryImpl(org.codice.ddf.ui.searchui.query.actions.ActionRegistryImpl) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) QueryResponse(ddf.catalog.operation.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with SearchRequest

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;
}
Also used : SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) QueryRequest(ddf.catalog.operation.QueryRequest) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel)

Aggregations

SearchRequest (org.codice.ddf.ui.searchui.query.model.SearchRequest)6 BayeuxServer (org.cometd.bayeux.server.BayeuxServer)5 ServerChannel (org.cometd.bayeux.server.ServerChannel)5 Matchers.anyString (org.mockito.Matchers.anyString)5 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 QueryRequest (ddf.catalog.operation.QueryRequest)3 ServerMessage (org.cometd.bayeux.server.ServerMessage)2 Mutable (org.cometd.bayeux.server.ServerMessage.Mutable)2 ServerSession (org.cometd.bayeux.server.ServerSession)2 CatalogFramework (ddf.catalog.CatalogFramework)1 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 Query (ddf.catalog.operation.Query)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)1 ArrayList (java.util.ArrayList)1 ActionRegistryImpl (org.codice.ddf.ui.searchui.query.actions.ActionRegistryImpl)1 CQLException (org.geotools.filter.text.cql2.CQLException)1 Filter (org.opengis.filter.Filter)1