Search in sources :

Example 36 with SourceResponse

use of ddf.catalog.operation.SourceResponse in project ddf by codice.

the class SolrProviderTest method assertNotFilter.

private void assertNotFilter(Filter filter) throws UnsupportedQueryException {
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Found a metacard and should not have.", 0, sourceResponse.getResults().size());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 37 with SourceResponse

use of ddf.catalog.operation.SourceResponse in project ddf by codice.

the class SolrProviderTest method queryXpathExists.

private SourceResponse queryXpathExists(String xpath) throws UnsupportedQueryException {
    Filter filter = filterBuilder.xpath(xpath).exists();
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    return sourceResponse;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 38 with SourceResponse

use of ddf.catalog.operation.SourceResponse in project ddf by codice.

the class RegistryStoreImpl method registryInfoQuery.

void registryInfoQuery() throws UnsupportedQueryException {
    List<Filter> filters = new ArrayList<>();
    filters.add(filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG));
    filters.add(filterBuilder.not(filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE).empty()));
    Filter filter = filterBuilder.allOf(filters);
    Map<String, Serializable> queryProps = new HashMap<>();
    queryProps.put(SecurityConstants.SECURITY_SUBJECT, getSystemSubject());
    Query newQuery = new QueryImpl(filter);
    QueryRequest queryRequest = new QueryRequestImpl(newQuery, queryProps);
    SourceResponse identityMetacard = query(queryRequest);
    if (identityMetacard.getResults().size() > 0) {
        String metacardTitle = identityMetacard.getResults().get(0).getMetacard().getTitle();
        registryId = RegistryUtility.getRegistryId(identityMetacard.getResults().get(0).getMetacard());
        updateConfiguration(metacardTitle);
    }
}
Also used : Serializable(java.io.Serializable) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) HashMap(java.util.HashMap) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ArrayList(java.util.ArrayList)

Example 39 with SourceResponse

use of ddf.catalog.operation.SourceResponse in project ddf by codice.

the class RegistryStoreImpl method create.

@Override
public CreateResponse create(CreateRequest request) throws IngestException {
    if (request.getMetacards().stream().map(RegistryUtility::getRegistryId).anyMatch(Objects::isNull)) {
        throw new IngestException("One or more of the metacards is not a registry metacard");
    }
    validateOperation();
    List<Filter> regIdFilters = request.getMetacards().stream().map(e -> filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(e.getId())).collect(Collectors.toList());
    Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
    Map<String, Serializable> queryProps = new HashMap<>();
    queryProps.put(SecurityConstants.SECURITY_SUBJECT, request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT));
    QueryImpl query = new QueryImpl(filterBuilder.allOf(tagFilter, filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_LOCAL_NODE).empty(), filterBuilder.anyOf(regIdFilters)));
    QueryRequest queryRequest = new QueryRequestImpl(query, queryProps);
    try {
        SourceResponse queryResponse = super.query(queryRequest);
        Map<String, Metacard> responseMap = queryResponse.getResults().stream().collect(Collectors.toMap(e -> RegistryUtility.getRegistryId(e.getMetacard()), Result::getMetacard));
        List<Metacard> metacardsToCreate = request.getMetacards().stream().filter(e -> !responseMap.containsKey(RegistryUtility.getRegistryId(e))).collect(Collectors.toList());
        List<Metacard> allMetacards = new ArrayList<>(responseMap.values());
        if (CollectionUtils.isNotEmpty(metacardsToCreate)) {
            CreateResponse createResponse = super.create(new CreateRequestImpl(metacardsToCreate, request.getProperties()));
            allMetacards.addAll(createResponse.getCreatedMetacards());
        }
        return new CreateResponseImpl(request, request.getProperties(), allMetacards);
    } catch (UnsupportedQueryException e) {
        LOGGER.warn("Unable to perform pre-create remote query. Proceeding with original query. Error was {}", e.getMessage());
    }
    return super.create(request);
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) TagsFilterDelegate(ddf.catalog.filter.delegate.TagsFilterDelegate) Locale(java.util.Locale) Map(java.util.Map) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) Converter(com.thoughtworks.xstream.converters.Converter) ImmutableSet(com.google.common.collect.ImmutableSet) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) SourceMonitor(ddf.catalog.source.SourceMonitor) ParserException(org.codice.ddf.parser.ParserException) AbstractCswStore(org.codice.ddf.spatial.ogc.csw.catalog.common.source.AbstractCswStore) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Serializable(java.io.Serializable) Objects(java.util.Objects) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) DeleteRequest(ddf.catalog.operation.DeleteRequest) List(java.util.List) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) UpdateResponse(ddf.catalog.operation.UpdateResponse) Dictionary(java.util.Dictionary) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) HashMap(java.util.HashMap) DeleteResponse(ddf.catalog.operation.DeleteResponse) OperationTransaction(ddf.catalog.operation.OperationTransaction) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation) ArrayList(java.util.ArrayList) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Configuration(org.osgi.service.cm.Configuration) CreateResponse(ddf.catalog.operation.CreateResponse) CollectionUtils(org.apache.commons.collections.CollectionUtils) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) SecurityConstants(ddf.security.SecurityConstants) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) EncryptionService(ddf.security.encryption.EncryptionService) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) Result(ddf.catalog.data.Result) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) IngestException(ddf.catalog.source.IngestException) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) IOException(java.io.IOException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) MetaTypeService(org.osgi.service.metatype.MetaTypeService) Consumer(java.util.function.Consumer) Query(ddf.catalog.operation.Query) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) Serializable(java.io.Serializable) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Objects(java.util.Objects) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Example 40 with SourceResponse

use of ddf.catalog.operation.SourceResponse in project ddf by codice.

the class RefreshRegistryEntriesTest method testSubscriptionEntityRemoval.

@Test
public void testSubscriptionEntityRemoval() throws Exception {
    Metacard localMetacard = getPopulatedTestRegistryMetacard("mcardId", "testRegId", 0, true);
    when(federationAdminService.getInternalRegistryMetacards()).thenReturn(Collections.singletonList(localMetacard));
    Metacard remoteMetacard = getPopulatedTestRegistryMetacard("mcardId2", "testRegId2", 0, true);
    SourceResponse response = new SourceResponseImpl(null, Collections.singletonList(new ResultImpl(remoteMetacard)));
    when(registryStore.query(any(QueryRequest.class))).thenReturn(response);
    when(registryStore.isPullAllowed()).thenReturn(true);
    when(registryStore.getId()).thenReturn(TEST_ID);
    when(registryStore.getRegistryId()).thenReturn("remoteRegId");
    when(registryStore.isAvailable()).thenReturn(true);
    refreshRegistryEntries.setRegistryStores(Collections.singletonList(registryStore));
    refreshRegistryEntries.refreshRegistryEntries();
    verify(federationAdminService).deleteRegistryEntriesByMetacardIds(Collections.singletonList(localMetacard.getId()));
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Aggregations

SourceResponse (ddf.catalog.operation.SourceResponse)199 Test (org.junit.Test)146 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)99 QueryImpl (ddf.catalog.operation.impl.QueryImpl)95 Result (ddf.catalog.data.Result)79 Metacard (ddf.catalog.data.Metacard)73 Filter (org.opengis.filter.Filter)58 QueryRequest (ddf.catalog.operation.QueryRequest)52 BinaryContent (ddf.catalog.data.BinaryContent)40 ResultImpl (ddf.catalog.data.impl.ResultImpl)29 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)25 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)24 Matchers.containsString (org.hamcrest.Matchers.containsString)24 Matchers.anyString (org.mockito.Matchers.anyString)21 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 Serializable (java.io.Serializable)20 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)19 SortByImpl (ddf.catalog.filter.impl.SortByImpl)18 Map (java.util.Map)16