Search in sources :

Example 11 with QueryResponseImpl

use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.

the class QueryMonitorPluginImpl method process.

/**
     * Method that is implemented for {@link PostFederatedQueryPlugin}. Uses the given {@link QueryResponse} information
     * to remove the {@link ActiveSearch} from the {@link ActiveSearch} {@link Map}.
     *
     * @param input {@link QueryResponse} that corresponds to response from the source that was queried
     *              by the user's original {@link QueryRequest}
     * @return {@link QueryResponse} that was given as a parameter
     */
@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
    if (!removeSearchAfterComplete) {
        LOGGER.debug("Not removing active search from map due to catalog:removeSearchAfterComplete false. To enable removing searches as searches finish, use command catalog:removesearchaftercomplete true.");
        return input;
    }
    if (input == null) {
        LOGGER.debug("Cannot remove ActiveSearch from the ActiveSearch Map. QueryResponse received in QueryMonitorPluginImpl was null.");
        return null;
    }
    if (!removeActiveSearch((UUID) input.getRequest().getPropertyValue(SEARCH_ID))) {
        QueryResponseImpl queryResponse = new QueryResponseImpl(input.getRequest(), new ArrayList<>(), 0);
        queryResponse.closeResultQueue();
        Set<ProcessingDetails> processingDetails = Collections.singleton(new ProcessingDetailsImpl(QueryMonitorPlugin.class.getCanonicalName(), new StopProcessingException("Query was cancelled by administrator")));
        queryResponse.setProcessingDetails(processingDetails);
        return queryResponse;
    }
    return input;
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) StopProcessingException(ddf.catalog.plugin.StopProcessingException) UUID(java.util.UUID) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl)

Example 12 with QueryResponseImpl

use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testDelete.

/**
     * Tests that the framework properly passes a delete request to the local provider.
     */
@Test
public void testDelete() throws Exception {
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    metacards.add(newCard);
    // create the entry manually in the provider
    Metacard insertedCard = provider.create(new CreateRequestImpl(metacards, null)).getCreatedMetacards().iterator().next();
    String[] ids = new String[1];
    ids[0] = insertedCard.getId();
    Result mockFederationResult = mock(Result.class);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(ids[0]);
    when(mockFederationResult.getMetacard()).thenReturn(metacard);
    QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), Collections.singletonList(mockFederationResult), 1);
    when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
    when(mockRemoteDeleteOperations.performRemoteDelete(any(), any())).then(returnsSecondArg());
    deleteOperations.setRemoteDeleteOperations(mockRemoteDeleteOperations);
    // send delete to framework
    List<Metacard> returnedCards = framework.delete(new DeleteRequestImpl(ids)).getDeletedMetacards();
    assertEquals(ids.length, returnedCards.size());
    // make sure that the event was posted correctly
    Metacard[] array = {};
    array = returnedCards.toArray(array);
    assertTrue(eventAdmin.wasEventPosted());
    assertEquals(eventAdmin.getLastEvent(), array[array.length - 1]);
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ArrayList(java.util.ArrayList) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Matchers.anyString(org.mockito.Matchers.anyString) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 13 with QueryResponseImpl

use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.

the class SolrCacheTest method query.

@Test
public void query() throws UnsupportedQueryException {
    QueryRequest mockQuery = mock(QueryRequest.class);
    SourceResponse expectedResponse = new QueryResponseImpl(mockQuery);
    when(mockCacheSolrMetacardClient.query(mockQuery)).thenReturn(expectedResponse);
    SourceResponse actualResponse = solrCache.query(mockQuery);
    assertThat(actualResponse, is(expectedResponse));
    verify(mockSolrClientAdaptor).getSolrMetacardClient();
    verify(mockCacheSolrMetacardClient).query(mockQuery);
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Test(org.junit.Test)

Example 14 with QueryResponseImpl

use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.

the class FilterPluginTest method testNoRequestSubject.

@Test(expected = StopProcessingException.class)
public void testNoRequestSubject() throws Exception {
    QueryResponseImpl response = new QueryResponseImpl(null);
    plugin.processPostQuery(response);
    fail("Plugin should have thrown exception when no subject was sent in.");
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Test(org.junit.Test)

Example 15 with QueryResponseImpl

use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.

the class FilterPluginTest method testNoRequestSubjectNoStrategies.

@Test(expected = StopProcessingException.class)
public void testNoRequestSubjectNoStrategies() throws Exception {
    QueryResponseImpl response = new QueryResponseImpl(null);
    plugin = new FilterPlugin();
    plugin.processPostQuery(response);
    fail("Plugin should have thrown exception when no subject was sent in.");
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) Test(org.junit.Test)

Aggregations

QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)49 Result (ddf.catalog.data.Result)32 QueryRequest (ddf.catalog.operation.QueryRequest)31 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)27 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)25 QueryResponse (ddf.catalog.operation.QueryResponse)24 ResultImpl (ddf.catalog.data.impl.ResultImpl)23 Metacard (ddf.catalog.data.Metacard)22 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)20 Query (ddf.catalog.operation.Query)15 SourceResponse (ddf.catalog.operation.SourceResponse)15 Source (ddf.catalog.source.Source)15 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)14 HashMap (java.util.HashMap)14 FederationStrategy (ddf.catalog.federation.FederationStrategy)12 StopProcessingException (ddf.catalog.plugin.StopProcessingException)12 FederationException (ddf.catalog.federation.FederationException)10 ByteSource (com.google.common.io.ByteSource)9 ValidationQueryFactory (ddf.catalog.cache.solr.impl.ValidationQueryFactory)9