use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class FederationAdminServiceImplTest method testGetRegistryObjectsWithEmptyMetadata.
@Test(expected = FederationAdminException.class)
public void testGetRegistryObjectsWithEmptyMetadata() throws Exception {
Metacard metacard = getTestMetacard();
metacard.setAttribute(new AttributeImpl(Metacard.METADATA, ""));
QueryRequest request = getTestQueryRequest();
QueryResponse response = getPopulatedTestQueryResponse(request, metacard);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
federationAdminServiceImpl.getRegistryObjects();
verify(catalogFramework).query(any(QueryRequest.class));
verify(parser, never()).unmarshal(any(ParserConfigurator.class), eq(JAXBElement.class), any(InputStream.class));
}
use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class FederationAdminServiceImpl method getRegistryMetacardsByFilter.
private List<Metacard> getRegistryMetacardsByFilter(Filter filter, Set<String> sourceIds) throws FederationAdminException {
if (filter == null) {
throw new FederationAdminException("Error getting registry metacards. Null filter provided.");
}
PropertyName propertyName = new PropertyNameImpl(Metacard.MODIFIED);
SortBy sortBy = new SortByImpl(propertyName, SortOrder.ASCENDING);
QueryImpl query = new QueryImpl(filter);
query.setSortBy(sortBy);
query.setPageSize(PAGE_SIZE);
QueryRequest queryRequest = new QueryRequestImpl(query, sourceIds);
try {
QueryResponse queryResponse = security.runWithSubjectOrElevate(() -> catalogFramework.query(queryRequest));
return queryResponse.getResults().stream().map(Result::getMetacard).filter(Objects::nonNull).collect(Collectors.toList());
} catch (SecurityServiceException | InvocationTargetException e) {
String message = "Error querying for registry metacards.";
LOGGER.debug("{} For Filter: {}", message, filter);
throw new FederationAdminException(message, e);
}
}
use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class FederationAdminServiceImplTest method testGetRegistryMetacards.
@Test
public void testGetRegistryMetacards() throws Exception {
Metacard findThisMetacard = testMetacard;
findThisMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, true));
QueryRequest request = getTestQueryRequest();
QueryResponse response = getPopulatedTestQueryResponse(request, findThisMetacard, getTestMetacard());
when(security.getSystemSubject()).thenReturn(subject);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
List<Metacard> metacards = federationAdminServiceImpl.getRegistryMetacards();
assertThat(metacards, hasSize(2));
}
use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class FederationAdminServiceImplTest method testGetRegistryMetacardsByRegistryIds.
@Test
public void testGetRegistryMetacardsByRegistryIds() throws Exception {
ArgumentCaptor<QueryRequest> captor = ArgumentCaptor.forClass(QueryRequest.class);
QueryRequest request = getTestQueryRequest();
QueryResponse response = getPopulatedTestQueryResponse(request, getTestMetacard(), getTestMetacard(), getTestMetacard());
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
List<String> ids = new ArrayList<>();
ids.add(RegistryObjectMetacardType.REGISTRY_ID);
ids.add(RegistryObjectMetacardType.REGISTRY_ID + "1");
ids.add(RegistryObjectMetacardType.REGISTRY_ID + "2");
List<Metacard> metacards = federationAdminServiceImpl.getRegistryMetacardsByRegistryIds(ids);
assertThat(metacards, hasSize(3));
verify(catalogFramework).query(captor.capture());
assertThat("Filter didn't contain the 'registry' and 'registry-remote' tag", filterAdapter.adapt(captor.getValue().getQuery(), new TagsFilterDelegate(RegistryConstants.REGISTRY_TAG)), is(true));
}
use of ddf.catalog.operation.QueryRequest in project ddf by codice.
the class FederationAdminServiceImplTest method testGetRegistryMetacardsByRegistryIdsIncludeInternal.
@Test
public void testGetRegistryMetacardsByRegistryIdsIncludeInternal() throws Exception {
ArgumentCaptor<QueryRequest> captor = ArgumentCaptor.forClass(QueryRequest.class);
QueryRequest request = getTestQueryRequest();
QueryResponse response = getPopulatedTestQueryResponse(request, getTestMetacard());
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
List<String> ids = new ArrayList<>();
ids.add(RegistryObjectMetacardType.REGISTRY_ID);
federationAdminServiceImpl.getRegistryMetacardsByRegistryIds(ids, true);
verify(catalogFramework).query(captor.capture());
HashSet<String> tags = new HashSet<>();
tags.add(RegistryConstants.REGISTRY_TAG);
tags.add(RegistryConstants.REGISTRY_TAG_INTERNAL);
assertThat("Filter didn't contain the 'registry' and 'registry-remote' tag", filterAdapter.adapt(captor.getValue().getQuery(), new TagsFilterDelegate(tags)), is(true));
}
Aggregations