Search in sources :

Example 21 with QueryResponseImpl

use of ddf.catalog.operation.impl.QueryResponseImpl 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 22 with QueryResponseImpl

use of ddf.catalog.operation.impl.QueryResponseImpl 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 23 with QueryResponseImpl

use of ddf.catalog.operation.impl.QueryResponseImpl 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 24 with QueryResponseImpl

use of ddf.catalog.operation.impl.QueryResponseImpl 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)

Example 25 with QueryResponseImpl

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

the class TestCswEndpoint method setUpBeforeClass.

@org.junit.Before
public void setUpBeforeClass() throws URISyntaxException, SourceUnavailableException, UnsupportedQueryException, FederationException, ParseException, IngestException {
    URI mockUri = new URI("http://example.com/services/csw");
    when(mockUriInfo.getBaseUri()).thenReturn(mockUri);
    URL resourceUrl = TestCswEndpoint.class.getResource("/record.xsd");
    URL resourceUrlDot = TestCswEndpoint.class.getClass().getResource(".");
    when(mockBundle.getResource("record.xsd")).thenReturn(resourceUrl);
    when(mockBundle.getResource("csw/2.0.2/record.xsd")).thenReturn(resourceUrl);
    when(mockBundle.getResource("gmd/record_gmd.xsd")).thenReturn(resourceUrl);
    when(mockBundle.getResource(".")).thenReturn(resourceUrlDot);
    csw = new CswEndpointStub(catalogFramework, mockMimeTypeManager, mockSchemaManager, mockInputManager, validator, queryFactory, mockBundle);
    csw.setUri(mockUriInfo);
    when(mockMimeTypeManager.getAvailableMimeTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_XML));
    when(mockSchemaManager.getAvailableSchemas()).thenReturn(new ArrayList<>(Arrays.asList(CswConstants.CSW_OUTPUT_SCHEMA)));
    when(mockSchemaManager.getTransformerBySchema(CswConstants.CSW_OUTPUT_SCHEMA)).thenReturn(mockTransformer);
    when(mockInputManager.getAvailableIds()).thenReturn(Arrays.asList(CswConstants.CSW_RECORD));
    QueryResponseImpl response = new QueryResponseImpl(null, new LinkedList<>(), 0);
    argument = ArgumentCaptor.forClass(QueryRequest.class);
    reset(catalogFramework);
    when(catalogFramework.query(argument.capture())).thenReturn(response);
    when(catalogFramework.getSourceIds()).thenReturn(new HashSet<>(Arrays.asList("source1", "source2", "source3")));
    CreateResponseImpl createResponse = new CreateResponseImpl(null, null, Arrays.asList(new MetacardImpl()));
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) CreateRequest(ddf.catalog.operation.CreateRequest) URI(java.net.URI) URL(java.net.URL) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

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