use of ddf.catalog.data.impl.ContentTypeImpl in project ddf by codice.
the class AbstractCswSource method addContentTypes.
/**
* Searches every query response for previously unknown content types
*
* @param response A Query Response
*/
private void addContentTypes(SourceResponse response) {
if (response == null || response.getResults() == null) {
return;
}
for (Result result : response.getResults()) {
Metacard metacard = result.getMetacard();
if (metacard != null) {
final String name = metacard.getContentTypeName();
String version = metacard.getContentTypeVersion();
final URI namespace = metacard.getContentTypeNamespace();
if (!StringUtils.isEmpty(name) && !contentTypes.containsKey(name)) {
if (version == null) {
version = "";
}
contentTypes.put(name, new ContentTypeImpl(name, version, namespace));
}
}
}
}
use of ddf.catalog.data.impl.ContentTypeImpl 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.impl.ContentTypeImpl 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)));
}
Aggregations