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)));
}
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)));
}
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);
}
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");
}
}
}
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"));
}
Aggregations