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