Search in sources :

Example 41 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class ResourceOperations method getLocalResourceOptions.

public Map<String, Set<String>> getLocalResourceOptions(String metacardId, boolean fanoutEnabled) throws ResourceNotFoundException {
    LOGGER.trace("ENTERING: getLocalResourceOptions");
    Map<String, Set<String>> optionsMap;
    try {
        QueryRequest queryRequest = new QueryRequestImpl(createMetacardIdQuery(metacardId), false, Collections.singletonList(getId()), null);
        QueryResponse queryResponse = queryOperations.query(queryRequest, null, false, fanoutEnabled);
        List<Result> results = queryResponse.getResults();
        if (!results.isEmpty()) {
            Metacard metacard = results.get(0).getMetacard();
            optionsMap = Collections.singletonMap(ResourceRequest.OPTION_ARGUMENT, getOptionsFromLocalProvider(metacard));
        } else {
            String message = "Could not find metacard " + metacardId + " on local source";
            ResourceNotFoundException resourceNotFoundException = new ResourceNotFoundException(message);
            LOGGER.trace("EXITING: getLocalResourceOptions");
            throw resourceNotFoundException;
        }
    } catch (UnsupportedQueryException e) {
        LOGGER.debug("Error finding metacard {}", metacardId, e);
        LOGGER.trace("EXITING: getLocalResourceOptions");
        throw new ResourceNotFoundException("Error finding metacard due to Unsuppported Query", e);
    } catch (FederationException e) {
        LOGGER.debug("Error federating query for metacard {}", metacardId, e);
        LOGGER.trace("EXITING: getLocalResourceOptions");
        throw new ResourceNotFoundException("Error finding metacard due to Federation issue", e);
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Metacard couldn't be found {}", metacardId, e);
        LOGGER.trace("EXITING: getLocalResourceOptions");
        throw new ResourceNotFoundException("Query returned null metacard", e);
    }
    LOGGER.trace("EXITING: getLocalResourceOptions");
    return optionsMap;
}
Also used : Set(java.util.Set) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 42 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class PointOfContactUpdatePluginTest method testPassthroughMethods.

@Test
public void testPassthroughMethods() throws Exception {
    CreateRequest createRequest = mock(CreateRequest.class);
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    QueryRequest queryRequest = mock(QueryRequest.class);
    ResourceRequest resourceRequest = mock(ResourceRequest.class);
    DeleteResponse deleteResponse = mock(DeleteResponse.class);
    QueryResponse queryResponse = mock(QueryResponse.class);
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    assertThat(pointOfContactUpdatePlugin.processPreCreate(createRequest), is(createRequest));
    assertThat(pointOfContactUpdatePlugin.processPreDelete(deleteRequest), is(deleteRequest));
    assertThat(pointOfContactUpdatePlugin.processPostDelete(deleteResponse), is(deleteResponse));
    assertThat(pointOfContactUpdatePlugin.processPreQuery(queryRequest), is(queryRequest));
    assertThat(pointOfContactUpdatePlugin.processPostQuery(queryResponse), is(queryResponse));
    assertThat(pointOfContactUpdatePlugin.processPreResource(resourceRequest), is(resourceRequest));
    assertThat(pointOfContactUpdatePlugin.processPostResource(resourceResponse, mock(Metacard.class)), is(resourceResponse));
    verifyZeroInteractions(createRequest, deleteRequest, queryRequest, resourceRequest, deleteResponse, queryResponse, resourceResponse);
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) ResourceResponse(ddf.catalog.operation.ResourceResponse) CreateRequest(ddf.catalog.operation.CreateRequest) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceRequest(ddf.catalog.operation.ResourceRequest) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 43 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class MetacardIngestNetworkPluginTest method testPassthroughMethods.

@Test
public void testPassthroughMethods() throws Exception {
    ThreadContext.put(CLIENT_INFO_KEY, INFO_MAP);
    when(mockMetacardCondition.applies(INFO_MAP)).thenReturn(true);
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    QueryRequest queryRequest = mock(QueryRequest.class);
    ResourceRequest resourceRequest = mock(ResourceRequest.class);
    DeleteResponse deleteResponse = mock(DeleteResponse.class);
    QueryResponse queryResponse = mock(QueryResponse.class);
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    assertThat(plugin.processPreUpdate(updateRequest, mock(Map.class)), is(updateRequest));
    assertThat(plugin.processPreDelete(deleteRequest), is(deleteRequest));
    assertThat(plugin.processPreQuery(queryRequest), is(queryRequest));
    assertThat(plugin.processPreResource(resourceRequest), is(resourceRequest));
    assertThat(plugin.processPostDelete(deleteResponse), is(deleteResponse));
    assertThat(plugin.processPostQuery(queryResponse), is(queryResponse));
    assertThat(plugin.processPostResource(resourceResponse, mock(Metacard.class)), is(resourceResponse));
    verifyZeroInteractions(mockMetacardCondition, mockMetacardServices, updateRequest, deleteRequest, queryRequest, resourceRequest, deleteResponse, queryResponse, resourceResponse);
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) ResourceResponse(ddf.catalog.operation.ResourceResponse) UpdateRequest(ddf.catalog.operation.UpdateRequest) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceRequest(ddf.catalog.operation.ResourceRequest) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 44 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class TestQueryMonitor method testQueryMonitorPluginImplRemoveActiveSearchUsingUUIDValidUUID.

@Test
public void testQueryMonitorPluginImplRemoveActiveSearchUsingUUIDValidUUID() throws StopProcessingException, PluginExecutionException {
    QueryRequest mockQR = mock(QueryRequest.class);
    Query mockQuery = mock(Query.class);
    propertyMap = new ConcurrentHashMap<>();
    when(mockQR.getProperties()).thenReturn(propertyMap);
    when(mockQR.toString()).thenReturn(QUERY_REQUEST_TEXT);
    when(mockQR.getQuery()).thenReturn(mockQuery);
    when(mockQuery.accept(any(), any())).thenReturn(new StringBuilder());
    qmpi.setRemoveSearchAfterComplete(true);
    qmpi.process(null, mockQR);
    Map<UUID, ActiveSearch> activeSearchTable = qmpi.getActiveSearches();
    assertThat(activeSearchTable, notNullValue());
    assertThat(activeSearchTable.size(), is(1));
    UUID u = activeSearchTable.keySet().iterator().next();
    assertThat(qmpi.removeActiveSearch(u), is(true));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) Query(ddf.catalog.operation.Query) UUID(java.util.UUID) Test(org.junit.Test)

Example 45 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class TestQueryMonitor method testQueryMonitorPluginImplRemoveActiveSearchUsingUUIDNullUUID.

@Test
public void testQueryMonitorPluginImplRemoveActiveSearchUsingUUIDNullUUID() throws StopProcessingException, PluginExecutionException {
    QueryRequest mockQR = mock(QueryRequest.class);
    Query mockQuery = mock(Query.class);
    propertyMap = new ConcurrentHashMap<>();
    when(mockQR.getProperties()).thenReturn(propertyMap);
    when(mockQR.toString()).thenReturn(QUERY_REQUEST_TEXT);
    when(mockQR.getQuery()).thenReturn(mockQuery);
    when(mockQuery.accept(any(), any())).thenReturn(new StringBuilder());
    qmpi.setRemoveSearchAfterComplete(true);
    qmpi.process(null, mockQR);
    UUID u = null;
    assertThat(qmpi.removeActiveSearch(u), is(false));
    UUID uuid = qmpi.getActiveSearches().values().iterator().next().getUniqueID();
    assertThat(qmpi.removeActiveSearch(uuid), is(true));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) Query(ddf.catalog.operation.Query) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

QueryRequest (ddf.catalog.operation.QueryRequest)153 Test (org.junit.Test)98 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)86 QueryImpl (ddf.catalog.operation.impl.QueryImpl)66 QueryResponse (ddf.catalog.operation.QueryResponse)57 ArrayList (java.util.ArrayList)41 SourceResponse (ddf.catalog.operation.SourceResponse)39 Metacard (ddf.catalog.data.Metacard)33 Result (ddf.catalog.data.Result)31 Filter (org.opengis.filter.Filter)31 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)30 Query (ddf.catalog.operation.Query)29 Source (ddf.catalog.source.Source)24 FederationException (ddf.catalog.federation.FederationException)20 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)15 InputStream (java.io.InputStream)15 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)13 SortByImpl (ddf.catalog.filter.impl.SortByImpl)11 HashMap (java.util.HashMap)11