Search in sources :

Example 21 with Result

use of ddf.catalog.data.Result in project ddf by codice.

the class TestWfsSource method testPagingPageSizeExceedsMaxFeaturesThatCanBeReturned.

/**
     * Given 1010 features (and metacards) exist that match search criteria, since page size=1001
     * (which is larger than max number of features the WfsSource allows to be returned) and
     * startIndex=1, should get 1000 results back, but a total hits of 1010.
     *
     * @throws WfsException,                     SecurityServiceException
     * @throws TransformerConfigurationException
     * @throws UnsupportedQueryException
     */
@Test
public void testPagingPageSizeExceedsMaxFeaturesThatCanBeReturned() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    int pageSize = WfsSource.WFS_MAX_FEATURES_RETURNED + 1;
    int startIndex = 1;
    int numResults = WfsSource.WFS_MAX_FEATURES_RETURNED + 10;
    setUp(ONE_TEXT_PROPERTY_SCHEMA, null, null, 1, numResults);
    SourceResponse response = executeQuery(startIndex, pageSize);
    List<Result> results = response.getResults();
    assertThat(results.size(), is(WfsSource.WFS_MAX_FEATURES_RETURNED));
    assertThat(response.getHits(), equalTo(new Long(numResults)));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 22 with Result

use of ddf.catalog.data.Result in project ddf by codice.

the class TestWfsSource method testPaging.

// Simulates query by ID (which is analogous to clicking on link in search
// results to
// view associated metacard in XML)
@Test
public void testPaging() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    int pageSize = 4;
    int startIndex = 1;
    int numFeatures = 1;
    setUp(ONE_TEXT_PROPERTY_SCHEMA, null, null, numFeatures, null);
    SourceResponse response = executeQuery(startIndex, pageSize);
    List<Result> results = response.getResults();
    assertThat(results.size(), is(1));
    assertThat(response.getHits(), equalTo(new Long(numFeatures)));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 23 with Result

use of ddf.catalog.data.Result in project ddf by codice.

the class TestWorkspaceServiceImpl method mockCatalogFrameworkQuery.

private void mockCatalogFrameworkQuery(String id, String subject) throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    when(securityService.addSystemSubject(any())).thenReturn(Collections.singletonMap(SecurityConstants.SECURITY_SUBJECT, subject));
    QueryResponse queryResponse = mock(QueryResponse.class);
    Result result = mock(Result.class);
    Metacard metacard = mock(Metacard.class);
    when(metacard.getMetacardType()).thenReturn(BasicTypes.BASIC_METACARD);
    Attribute attribute = mock(Attribute.class);
    when(attribute.getValue()).thenReturn(id);
    when(metacard.getAttribute(Metacard.ID)).thenReturn(attribute);
    when(metacard.getTags()).thenReturn(Collections.singleton(WorkspaceAttributes.WORKSPACE_TAG));
    when(result.getMetacard()).thenReturn(metacard);
    List<Result> resultList = Collections.singletonList(result);
    when(queryResponse.getResults()).thenReturn(resultList);
    when(catalogFramework.query(any())).thenReturn(queryResponse);
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) Result(ddf.catalog.data.Result)

Example 24 with Result

use of ddf.catalog.data.Result in project ddf by codice.

the class MigrationTaskManager method exportMetacardQuery.

/**
     * Creates a sublist from the given results and a destination file for metacards based on
     * the {@link CatalogMigratableConfig} object used by this task manager. An asynchronous
     * task is started for exporting the metacards and is deferred to the appropriate instance
     * of {@link MigrationFileWriter} for processing.
     *
     * @param results          The results of a catalog query that need to be exported.
     * @param exportGroupCount The group or page number of the query. This value is not monitored
     *                         or audited for repeats and is strictly for record keeping by naming
     *                         the resulting export files appropriately.
     * @throws MigrationException Thrown if one of the writing threads fails or throws an exception
     *                            itself.
     */
public void exportMetacardQuery(final List<Result> results, long exportGroupCount) throws MigrationException {
    for (int i = 0; i < results.size(); i += catalogConfig.getExportCardsPerFile()) {
        final List<Result> fileResults = results.subList(i, Math.min((i + catalogConfig.getExportCardsPerFile()), results.size()));
        final File exportFile = catalogConfig.getExportPath().resolve(makeFileName(exportGroupCount, i)).toFile();
        Callable<Void> writerCallable = () -> {
            fileWriter.writeMetacards(exportFile, fileResults);
            return null;
        };
        ListenableFuture<Void> task = taskExecutor.submit(writerCallable);
        Futures.addCallback(task, createFutureCallback());
        if (failureFlag) {
            throw new ExportMigrationException("Error in file writing thread");
        }
    }
}
Also used : ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) File(java.io.File) Result(ddf.catalog.data.Result)

Example 25 with Result

use of ddf.catalog.data.Result in project ddf by codice.

the class TestMetacardResourceSizePlugin method testWhenNoCachedResourceFound.

@Test
public void testWhenNoCachedResourceFound() throws Exception {
    ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
    when(cache.getValid(anyString(), (Metacard) anyObject())).thenReturn(null);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId("abc123");
    metacard.setSourceId("ddf-1");
    metacard.setResourceSize("N/A");
    Result result = new ResultImpl(metacard);
    List<Result> results = new ArrayList<Result>();
    results.add(result);
    QueryResponse input = mock(QueryResponse.class);
    when(input.getResults()).thenReturn(results);
    MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
    QueryResponse queryResponse = plugin.process(input);
    assertThat(queryResponse.getResults().size(), is(1));
    Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
    assertThat(metacard, is(notNullValue()));
    // Since using Metacard vs. MetacardImpl have to get resource-size as an
    // Attribute vs. Long
    Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
    assertThat((String) resourceSizeAttr.getValue(), equalTo("N/A"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

Result (ddf.catalog.data.Result)361 Test (org.junit.Test)205 Metacard (ddf.catalog.data.Metacard)159 SourceResponse (ddf.catalog.operation.SourceResponse)153 ArrayList (java.util.ArrayList)137 ResultImpl (ddf.catalog.data.impl.ResultImpl)120 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)119 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)102 QueryImpl (ddf.catalog.operation.impl.QueryImpl)91 Filter (org.opengis.filter.Filter)91 QueryResponse (ddf.catalog.operation.QueryResponse)87 QueryRequest (ddf.catalog.operation.QueryRequest)84 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)50 Serializable (java.io.Serializable)50 BinaryContent (ddf.catalog.data.BinaryContent)48 HashMap (java.util.HashMap)45 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)43 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)39 Map (java.util.Map)36 DateTime (org.joda.time.DateTime)33