Search in sources :

Example 36 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class CachingFederationStrategyTest method setup.

@Before
public void setup() throws Exception {
    cacheExecutor = MoreExecutors.newDirectExecutorService();
    queryExecutor = MoreExecutors.newDirectExecutorService();
    preQueryPlugin = mock(PreFederatedQueryPlugin.class);
    when(preQueryPlugin.process(any(), any())).thenAnswer(invocation -> invocation.getArguments()[1]);
    clientAdaptor = mock(SolrClientAdaptor.class);
    cache = mock(SolrCache.class);
    cacheBulkProcessor = mock(CacheBulkProcessor.class);
    cacheCommitPhaser = mock(CacheCommitPhaser.class);
    cacheArgs = ArgumentCaptor.forClass((Class) List.class);
    validationQueryFactory = mock(ValidationQueryFactory.class);
    strategy = new CachingFederationStrategy(queryExecutor, Arrays.asList(preQueryPlugin), new ArrayList<>(), cache, cacheExecutor, validationQueryFactory, new CacheQueryFactory(new GeotoolsFilterBuilder()));
    mockSortedQueryMonitorFactory = mock(SortedQueryMonitorFactory.class);
    mockSortedQueryMonitor = mock(SortedQueryMonitor.class);
    responseArgumentCaptor = ArgumentCaptor.forClass(QueryResponseImpl.class);
    requestArgumentCaptor = ArgumentCaptor.forClass(QueryRequestImpl.class);
    when(mockSortedQueryMonitorFactory.createMonitor(any(CompletionService.class), any(Map.class), responseArgumentCaptor.capture(), requestArgumentCaptor.capture(), any(List.class))).thenReturn(mockSortedQueryMonitor);
    strategy.setSortedQueryMonitorFactory(mockSortedQueryMonitorFactory);
    strategy.setCacheCommitPhaser(cacheCommitPhaser);
    strategy.setCacheBulkProcessor(cacheBulkProcessor);
    mockQuery = mock(Query.class);
    when(mockQuery.getTimeoutMillis()).thenReturn(LONG_TIMEOUT);
    when(mockQuery.getPageSize()).thenReturn(-1);
    mockMetacard = new MetacardImpl();
    mockMetacard.setId("mock metacard");
    mockResult = new ResultImpl(mockMetacard);
    mockResponse = mock(SourceResponse.class);
    results = Arrays.asList(mockResult);
    when(mockResponse.getResults()).thenReturn(results);
    // Set general properties
    properties = new HashMap<>();
    properties.put(QUERY_MODE, NATIVE_QUERY_MODE);
}
Also used : PreFederatedQueryPlugin(ddf.catalog.plugin.PreFederatedQueryPlugin) Query(ddf.catalog.operation.Query) SourceResponse(ddf.catalog.operation.SourceResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) CompletionService(java.util.concurrent.CompletionService) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Before(org.junit.Before)

Example 37 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class FanoutCatalogFrameworkTest method testReplaceRelevance.

@Test
public void testReplaceRelevance() {
    QueryRequest request = new QueryRequestImpl(null);
    List<Result> results = new ArrayList<Result>();
    MetacardImpl newCard1 = new MetacardImpl();
    ResultImpl result1 = new ResultImpl(newCard1);
    result1.setRelevanceScore(RELEVANCE_SCORE);
    MetacardImpl newCard2 = new MetacardImpl();
    ResultImpl result2 = new ResultImpl(newCard2);
    result2.setRelevanceScore(RELEVANCE_SCORE);
    results.add(result1);
    results.add(result2);
    QueryResponse response = new QueryResponseImpl(request, results, 2);
    QueryResponse newResponse = framework.getQueryOperations().replaceSourceId(response);
    assertNotNull(newResponse);
    List<Result> newResults = newResponse.getResults();
    assertNotNull(newResponse);
    assertEquals(2, newResults.size());
    Metacard card = new MetacardImpl();
    // Make sure the relevance score was copied over
    for (Result newResult : newResults) {
        card = newResult.getMetacard();
        assertNotNull(card);
        assertEquals(RELEVANCE_SCORE, newResult.getRelevanceScore());
    }
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 38 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class FanoutCatalogFrameworkTest method testQueryReplacesSourceId.

@Test
public void testQueryReplacesSourceId() throws Exception {
    ConnectedSource source1 = mock(ConnectedSource.class);
    ConnectedSource source2 = mock(ConnectedSource.class);
    when(source1.getId()).thenReturn("source1");
    when(source2.getId()).thenReturn("source2");
    frameworkProperties.setConnectedSources(ImmutableList.of(source1, source2));
    frameworkProperties.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class));
    MetacardImpl meta1 = new MetacardImpl();
    MetacardImpl meta2 = new MetacardImpl();
    meta1.setSourceId("source1");
    meta2.setSourceId("source2");
    ResultImpl result1 = new ResultImpl(meta1);
    ResultImpl result2 = new ResultImpl(meta2);
    List<Result> results = new ArrayList<>();
    results.add(result1);
    results.add(result2);
    QueryResponseImpl queryResponse = new QueryResponseImpl(queryRequest, results, 2);
    FederationStrategy strategy = mock(FederationStrategy.class);
    when(strategy.federate(anyList(), any())).thenReturn(queryResponse);
    QueryResponse response = framework.query(queryRequest, strategy);
    for (Result result : response.getResults()) {
        assertEquals(result.getMetacard().getSourceId(), NEW_SOURCE_ID);
    }
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ConnectedSource(ddf.catalog.source.ConnectedSource) Query(ddf.catalog.operation.Query) FederationStrategy(ddf.catalog.federation.FederationStrategy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 39 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestCswEndpoint method testDeleteTransaction.

@Test
public void testDeleteTransaction() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
    DeleteType deleteType = mock(DeleteType.class);
    doReturn(CswConstants.CSW_RECORD).when(deleteType).getTypeName();
    doReturn("").when(deleteType).getHandle();
    QueryConstraintType queryConstraintType = new QueryConstraintType();
    queryConstraintType.setCqlText("title = \"foo\"");
    doReturn(queryConstraintType).when(deleteType).getConstraint();
    List<Result> results = new ArrayList<>();
    results.add(new ResultImpl(new MetacardImpl()));
    results.add(new ResultImpl(new MetacardImpl()));
    QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
    doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
    List<Metacard> deletedMetacards = new ArrayList<>();
    deletedMetacards.add(new MetacardImpl());
    deletedMetacards.add(new MetacardImpl());
    DeleteResponse deleteResponse = new DeleteResponseImpl(null, null, deletedMetacards);
    doReturn(deleteResponse).when(catalogFramework).delete(any(DeleteRequest.class));
    DeleteAction deleteAction = new DeleteAction(deleteType, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
    CswTransactionRequest deleteRequest = new CswTransactionRequest();
    deleteRequest.getDeleteActions().add(deleteAction);
    deleteRequest.setVersion(CswConstants.VERSION_2_0_2);
    deleteRequest.setService(CswConstants.CSW);
    deleteRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(deleteRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(2));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(0));
    verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 40 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestCswEndpoint method testGetRecordById.

@Test
public void testGetRecordById() throws CswException, FederationException, SourceUnavailableException, UnsupportedQueryException {
    final GetRecordByIdRequest getRecordByIdRequest = new GetRecordByIdRequest();
    getRecordByIdRequest.setId("123");
    getRecordByIdRequest.setOutputFormat(MediaType.APPLICATION_XML);
    getRecordByIdRequest.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    getRecordByIdRequest.setElementSetName("full");
    final Metacard metacard = new MetacardImpl();
    final List<Result> mockResults = Collections.singletonList(new ResultImpl(metacard));
    final QueryResponseImpl queryResponse = new QueryResponseImpl(null, mockResults, mockResults.size());
    doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
    final CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdRequest, null);
    verifyCswRecordCollection(cswRecordCollection, metacard);
    assertThat(cswRecordCollection.getElementSetType(), is(ElementSetType.FULL));
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ResultImpl(ddf.catalog.data.impl.ResultImpl) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

ResultImpl (ddf.catalog.data.impl.ResultImpl)114 Result (ddf.catalog.data.Result)74 Test (org.junit.Test)73 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)61 Metacard (ddf.catalog.data.Metacard)47 ArrayList (java.util.ArrayList)45 QueryRequest (ddf.catalog.operation.QueryRequest)33 SourceResponse (ddf.catalog.operation.SourceResponse)30 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)23 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)21 QueryResponse (ddf.catalog.operation.QueryResponse)20 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)18 DAG (org.codice.alliance.nsili.common.UCO.DAG)17 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 BinaryContent (ddf.catalog.data.BinaryContent)10 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 Product (org.codice.alliance.nsili.common.UID.Product)9 Query (ddf.catalog.operation.Query)7 PolicyResponse (ddf.catalog.plugin.PolicyResponse)7