Search in sources :

Example 21 with ContentType

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

the class SolrMetacardClientImpl method getContentTypes.

@Override
public Set<ContentType> getContentTypes() {
    Set<ContentType> finalSet = new HashSet<>();
    String contentTypeField = resolver.getField(Metacard.CONTENT_TYPE, AttributeType.AttributeFormat.STRING, true);
    String contentTypeVersionField = resolver.getField(Metacard.CONTENT_TYPE_VERSION, AttributeType.AttributeFormat.STRING, true);
    /*
         * If we didn't find the field, it most likely means it does not exist. If it does not
         * exist, then we can safely say that no content types are in this catalog provider
         */
    if (contentTypeField == null || contentTypeVersionField == null) {
        return finalSet;
    }
    SolrQuery query = new SolrQuery(contentTypeField + ":[* TO *]");
    query.setFacet(true);
    query.addFacetField(contentTypeField);
    query.addFacetPivotField(contentTypeField + "," + contentTypeVersionField);
    try {
        QueryResponse solrResponse = client.query(query, SolrRequest.METHOD.POST);
        List<FacetField> facetFields = solrResponse.getFacetFields();
        for (Map.Entry<String, List<PivotField>> entry : solrResponse.getFacetPivot()) {
            // however, the content type names can still be obtained via the facet fields.
            if (CollectionUtils.isEmpty(entry.getValue())) {
                LOGGER.debug("No content type versions found associated with any available content types.");
                if (CollectionUtils.isNotEmpty(facetFields)) {
                    // values (content type names).
                    for (FacetField.Count currContentType : facetFields.get(0).getValues()) {
                        // unknown version, so setting it to null
                        ContentType contentType = new ContentTypeImpl(currContentType.getName(), null);
                        finalSet.add(contentType);
                    }
                }
            } else {
                for (PivotField pf : entry.getValue()) {
                    String contentTypeName = pf.getValue().toString();
                    LOGGER.debug("contentTypeName: {}", contentTypeName);
                    if (CollectionUtils.isEmpty(pf.getPivot())) {
                        // if there are no sub-pivots, that means that there are no content type
                        // versions
                        // associated with this content type name
                        LOGGER.debug("Content type does not have associated contentTypeVersion: {}", contentTypeName);
                        ContentType contentType = new ContentTypeImpl(contentTypeName, null);
                        finalSet.add(contentType);
                    } else {
                        for (PivotField innerPf : pf.getPivot()) {
                            LOGGER.debug("contentTypeVersion: {}. For contentTypeName: {}", innerPf.getValue(), contentTypeName);
                            ContentType contentType = new ContentTypeImpl(contentTypeName, innerPf.getValue().toString());
                            finalSet.add(contentType);
                        }
                    }
                }
            }
        }
    } catch (SolrServerException | IOException e) {
        LOGGER.info("Solr exception getting content types", e);
    }
    return finalSet;
}
Also used : ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) ContentType(ddf.catalog.data.ContentType) SolrServerException(org.apache.solr.client.solrj.SolrServerException) FacetField(org.apache.solr.client.solrj.response.FacetField) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) PivotField(org.apache.solr.client.solrj.response.PivotField) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashSet(java.util.HashSet)

Example 22 with ContentType

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

the class WfsSource method buildGetFeatureRequest.

private GetFeatureType buildGetFeatureRequest(Query query) throws UnsupportedQueryException {
    List<ContentType> contentTypes = getContentTypesFromQuery(query);
    List<QueryType> queries = new ArrayList<QueryType>();
    for (Entry<QName, WfsFilterDelegate> filterDelegateEntry : featureTypeFilters.entrySet()) {
        if (contentTypes.isEmpty() || isFeatureTypeInQuery(contentTypes, filterDelegateEntry.getKey().getLocalPart())) {
            QueryType wfsQuery = new QueryType();
            wfsQuery.setTypeName(filterDelegateEntry.getKey());
            FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
            if (filter != null) {
                if (areAnyFiltersSet(filter)) {
                    wfsQuery.setFilter(filter);
                }
                queries.add(wfsQuery);
            } else {
                LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
            }
        }
    }
    if (queries != null && !queries.isEmpty()) {
        GetFeatureType getFeatureType = new GetFeatureType();
        getFeatureType.setMaxFeatures(BigInteger.valueOf(query.getPageSize()));
        getFeatureType.getQuery().addAll(queries);
        getFeatureType.setService(Wfs10Constants.WFS);
        getFeatureType.setVersion(Wfs10Constants.VERSION_1_0_0);
        logMessage(getFeatureType);
        return getFeatureType;
    } else {
        throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
    }
}
Also used : FilterType(ogc.schema.opengis.filter.v_1_0_0.FilterType) ContentType(ddf.catalog.data.ContentType) QName(javax.xml.namespace.QName) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)

Example 23 with ContentType

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

the class TestWfsSource method testGetContentTypes.

@Test
public void testGetContentTypes() throws WfsException, SecurityServiceException {
    setUp(ONE_TEXT_PROPERTY_SCHEMA, null, null, 2, null);
    Set<ContentType> contentTypes = source.getContentTypes();
    assertTrue(contentTypes.size() == TWO_FEATURES);
    for (ContentType contentType : contentTypes) {
        assertTrue(sampleFeatures.get(0).getLocalPart().equals(contentType.getName()) || sampleFeatures.get(1).getLocalPart().equals(contentType.getName()));
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) Test(org.junit.Test)

Example 24 with ContentType

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

the class SolrProviderTest method testGetContentTypesSimple.

@Test
public void testGetContentTypesSimple() throws Exception {
    deleteAllIn(provider);
    MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    MockMetacard metacard2 = new MockMetacard(Library.getShowLowRecord());
    MockMetacard metacard3 = new MockMetacard(Library.getTampaRecord());
    metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
    metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
    metacard3.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
    metacard3.setContentTypeVersion(SAMPLE_CONTENT_VERSION_3);
    List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
    create(list);
    Set<ContentType> contentTypes = provider.getContentTypes();
    assertEquals(3, contentTypes.size());
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_1, MockMetacard.DEFAULT_VERSION)));
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_2, MockMetacard.DEFAULT_VERSION)));
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_2, SAMPLE_CONTENT_VERSION_3)));
}
Also used : ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) Metacard(ddf.catalog.data.Metacard) ContentType(ddf.catalog.data.ContentType) Test(org.junit.Test)

Example 25 with ContentType

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

the class SourceOperations method getFanoutSourceInfo.

/**
     * Retrieves the {@link SourceDescriptor} info for all {@link FederatedSource}s in the fanout
     * configuration, but the all of the source info, e.g., content types, for all of the available
     * {@link FederatedSource}s is packed into one {@link SourceDescriptor} for the
     * fanout configuration with the fanout's site name in it. This keeps the individual
     * {@link FederatedSource}s' source info hidden from the external client.
     */
private SourceInfoResponse getFanoutSourceInfo(SourceInfoRequest sourceInfoRequest) throws SourceUnavailableException {
    SourceInfoResponse response;
    SourceDescriptorImpl sourceDescriptor;
    try {
        // request
        if (sourceInfoRequest == null) {
            throw new IllegalArgumentException("SourceInfoRequest was null");
        }
        Set<SourceDescriptor> sourceDescriptors = new LinkedHashSet<>();
        Set<String> ids = sourceInfoRequest.getSourceIds();
        // specified
        if (ids != null) {
            Optional<String> notLocal = ids.stream().filter(s -> !s.equals(getId())).findFirst();
            if (notLocal.isPresent()) {
                SourceUnavailableException sourceUnavailableException = new SourceUnavailableException("Unknown source: " + notLocal.get());
                LOGGER.debug("Throwing SourceUnavailableException for unknown source: {}", notLocal.get(), sourceUnavailableException);
                throw sourceUnavailableException;
            }
        }
        // Fanout will only add one source descriptor with all the contents
        Set<Source> availableSources = frameworkProperties.getFederatedSources().values().stream().map(source -> frameworkProperties.getSourcePoller().getCachedSource(source)).filter(source -> source != null && source.isAvailable()).collect(Collectors.toSet());
        Set<ContentType> contentTypes = availableSources.stream().map(source -> frameworkProperties.getSourcePoller().getCachedSource(source)).filter(source -> source.getContentTypes() != null).map(Source::getContentTypes).flatMap(Collection::stream).collect(Collectors.toSet());
        if (catalog != null) {
            Source localSource = frameworkProperties.getSourcePoller().getCachedSource(catalog);
            if (localSource != null && localSource.isAvailable()) {
                availableSources.add(localSource);
                contentTypes.addAll(localSource.getContentTypes());
            }
        }
        // only reveal this sourceDescriptor, not the federated sources
        sourceDescriptor = new SourceDescriptorImpl(this.getId(), contentTypes);
        if (this.getVersion() != null) {
            sourceDescriptor.setVersion(this.getVersion());
        }
        sourceDescriptor.setAvailable(availableSources.size() > 0);
        sourceDescriptors.add(sourceDescriptor);
        response = new SourceInfoResponseImpl(sourceInfoRequest, null, sourceDescriptors);
    } catch (RuntimeException re) {
        throw new SourceUnavailableException("Exception during runtime while performing getSourceInfo", re);
    }
    return response;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) LoggerFactory(org.slf4j.LoggerFactory) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Source(ddf.catalog.source.Source) SourceDescriptor(ddf.catalog.source.SourceDescriptor) StorageProvider(ddf.catalog.content.StorageProvider) SourceInfoResponseImpl(ddf.catalog.operation.impl.SourceInfoResponseImpl) SourceDescriptorComparator(ddf.catalog.util.impl.SourceDescriptorComparator) LinkedHashSet(java.util.LinkedHashSet) DescribableImpl(ddf.catalog.util.impl.DescribableImpl) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) ContentType(ddf.catalog.data.ContentType) Logger(org.slf4j.Logger) SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) Collection(java.util.Collection) FederatedSource(ddf.catalog.source.FederatedSource) Set(java.util.Set) Collectors(java.util.stream.Collectors) FrameworkProperties(ddf.catalog.impl.FrameworkProperties) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) List(java.util.List) CatalogProvider(ddf.catalog.source.CatalogProvider) ServiceUnavailableException(org.osgi.service.blueprint.container.ServiceUnavailableException) Optional(java.util.Optional) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) ContentType(ddf.catalog.data.ContentType) SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) Source(ddf.catalog.source.Source) FederatedSource(ddf.catalog.source.FederatedSource) SourceInfoResponseImpl(ddf.catalog.operation.impl.SourceInfoResponseImpl) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse)

Aggregations

ContentType (ddf.catalog.data.ContentType)45 Test (org.junit.Test)34 CatalogFramework (ddf.catalog.CatalogFramework)17 ArrayList (java.util.ArrayList)17 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 Metacard (ddf.catalog.data.Metacard)12 ContentTypeImpl (ddf.catalog.data.impl.ContentTypeImpl)12 Source (ddf.catalog.source.Source)10 Date (java.util.Date)10 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 HashSet (java.util.HashSet)8 Matchers.anyString (org.mockito.Matchers.anyString)7 IngestException (ddf.catalog.source.IngestException)6 URI (java.net.URI)5 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)4 CatalogProvider (ddf.catalog.source.CatalogProvider)4 SourceDescriptor (ddf.catalog.source.SourceDescriptor)4 SourcePoller (ddf.catalog.util.impl.SourcePoller)4 URISyntaxException (java.net.URISyntaxException)4 QName (javax.xml.namespace.QName)4