use of ddf.catalog.data.ContentType in project ddf by codice.
the class CatalogFrameworkImplTest method testProviderUnavailableUpdateByIdentifier.
/**
* Tests that the framework properly throws a catalog exception when the local provider is not
* available for update by identifier.
*
* @throws IngestException
* @throws SourceUnavailableException
*/
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableUpdateByIdentifier() throws SourceUnavailableException {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
List<Metacard> metacards = new ArrayList<Metacard>();
List<URI> uris = new ArrayList<URI>();
// expected to throw exception due to catalog provider being unavailable
try {
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
newCard.setResourceURI(new URI("uri:///1234"));
metacards.add(newCard);
uris.add(new URI("uri:////1234"));
UpdateRequest update = new UpdateRequestImpl((URI[]) uris.toArray(new URI[uris.size()]), metacards);
framework.update(update);
} catch (URISyntaxException e) {
fail();
} catch (IngestException e) {
fail();
}
}
use of ddf.catalog.data.ContentType in project ddf by codice.
the class CatalogFrameworkImplTest method testMetacardTransformWithBadShortname.
@Ignore
@Test(expected = CatalogTransformerException.class)
public void testMetacardTransformWithBadShortname() throws CatalogTransformerException {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
// TODO pass in bundle context
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
framework.transform(newCard, "NONE", new HashMap<String, Serializable>());
}
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, Collections.emptyMap());
String contentTypeVersionField = resolver.getField(Metacard.CONTENT_TYPE_VERSION, AttributeType.AttributeFormat.STRING, true, Collections.emptyMap());
/*
* 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, 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 | SolrException | 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 SolrProviderContentTypes method testGetContentTypesVersionsAndNullVersions.
@Test
public void testGetContentTypesVersionsAndNullVersions() throws Exception {
deleteAll(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);
metacard1.setContentTypeVersion(null);
metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
metacard3.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
metacard3.setContentTypeVersion(SAMPLE_CONTENT_VERSION_3);
List<Metacard> list = Arrays.asList(metacard1, metacard2, metacard3);
create(list, provider);
Set<ContentType> contentTypes = provider.getContentTypes();
assertEquals(3, contentTypes.size());
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_1, null)));
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 WfsSource method buildGetFeatureRequest.
private ExtendedGetFeatureType buildGetFeatureRequest(Query query, ResultTypeType resultType, BigInteger maxFeatures) throws UnsupportedQueryException {
List<ContentType> contentTypes = getContentTypesFromQuery(query);
List<QueryType> queries = new ArrayList<>();
for (Entry<QName, WfsFilterDelegate> filterDelegateEntry : featureTypeFilters.entrySet()) {
if (contentTypes.isEmpty() || isFeatureTypeInQuery(contentTypes, filterDelegateEntry.getKey().getLocalPart())) {
QueryType wfsQuery = new QueryType();
wfsQuery.setTypeName(Collections.singletonList(filterDelegateEntry.getKey()));
if (StringUtils.isNotBlank(srsName)) {
wfsQuery.setSrsName(srsName);
}
FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
if (filter != null) {
if (areAnyFiltersSet(filter)) {
wfsQuery.setFilter(filter);
}
if (!this.disableSorting && query.getSortBy() != null && query.getSortBy().getPropertyName() != null && query.getSortBy().getPropertyName().getPropertyName() != null) {
SortByType sortByType = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
if (sortByType != null && sortByType.getSortProperty() != null && sortByType.getSortProperty().size() > 0) {
LOGGER.debug("Sorting using sort property [{}] and sort order [{}].", sortByType.getSortProperty().get(0).getPropertyName(), sortByType.getSortProperty().get(0).getSortOrder());
wfsQuery.setSortBy(sortByType);
} else {
throw new UnsupportedQueryException("Source " + this.getId() + " does not support specified sort property " + query.getSortBy().getPropertyName().getPropertyName());
}
} else {
LOGGER.debug("Sorting is disabled or sort not specified.");
}
queries.add(wfsQuery);
} else {
LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
}
}
}
if (!queries.isEmpty()) {
ExtendedGetFeatureType getFeatureType = new ExtendedGetFeatureType();
getFeatureType.setMaxFeatures(maxFeatures);
getFeatureType.getQuery().addAll(queries);
getFeatureType.setService(Wfs11Constants.WFS);
getFeatureType.setVersion(Wfs11Constants.VERSION_1_1_0);
getFeatureType.setResultType(resultType);
if (supportsStartIndex && resultType.equals(ResultTypeType.RESULTS)) {
// Convert DDF index of 1 back to index of 0 for WFS
getFeatureType.setStartIndex(BigInteger.valueOf(query.getStartIndex() - 1));
}
logMessage(getFeatureType);
return getFeatureType;
} else {
throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
}
}
Aggregations