Search in sources :

Example 61 with QueryRequest

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));
}
Also used : ParserConfigurator(org.codice.ddf.parser.ParserConfigurator) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) QueryResponse(ddf.catalog.operation.QueryResponse) JAXBElement(javax.xml.bind.JAXBElement) Test(org.junit.Test)

Example 62 with QueryRequest

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);
    }
}
Also used : FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) PropertyName(org.opengis.filter.expression.PropertyName) SecurityServiceException(ddf.security.service.SecurityServiceException) QueryRequest(ddf.catalog.operation.QueryRequest) SortBy(org.opengis.filter.sort.SortBy) InvocationTargetException(java.lang.reflect.InvocationTargetException) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(org.geotools.filter.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl)

Example 63 with QueryRequest

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 64 with QueryRequest

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) TagsFilterDelegate(ddf.catalog.filter.delegate.TagsFilterDelegate) QueryRequest(ddf.catalog.operation.QueryRequest) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 65 with QueryRequest

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));
}
Also used : TagsFilterDelegate(ddf.catalog.filter.delegate.TagsFilterDelegate) QueryRequest(ddf.catalog.operation.QueryRequest) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

QueryRequest (ddf.catalog.operation.QueryRequest)153 Test (org.junit.Test)98 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)86 QueryImpl (ddf.catalog.operation.impl.QueryImpl)66 QueryResponse (ddf.catalog.operation.QueryResponse)57 ArrayList (java.util.ArrayList)41 SourceResponse (ddf.catalog.operation.SourceResponse)39 Metacard (ddf.catalog.data.Metacard)33 Result (ddf.catalog.data.Result)31 Filter (org.opengis.filter.Filter)31 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)30 Query (ddf.catalog.operation.Query)29 Source (ddf.catalog.source.Source)24 FederationException (ddf.catalog.federation.FederationException)20 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)15 InputStream (java.io.InputStream)15 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)13 SortByImpl (ddf.catalog.filter.impl.SortByImpl)11 HashMap (java.util.HashMap)11