Search in sources :

Example 46 with ContentType

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();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) IngestException(ddf.catalog.source.IngestException) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 47 with ContentType

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>());
}
Also used : Serializable(java.io.Serializable) ContentType(ddf.catalog.data.ContentType) CatalogFramework(ddf.catalog.CatalogFramework) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 48 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, 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;
}
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) List(java.util.List) ArrayList(java.util.ArrayList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) SolrException(org.apache.solr.common.SolrException) HashSet(java.util.HashSet)

Example 49 with ContentType

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)));
}
Also used : ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) Metacard(ddf.catalog.data.Metacard) ContentType(ddf.catalog.data.ContentType) Test(org.junit.Test) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest)

Example 50 with ContentType

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.");
    }
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) ContentType(ddf.catalog.data.ContentType) QName(javax.xml.namespace.QName) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) SortByType(net.opengis.filter.v_1_1_0.SortByType) QueryType(net.opengis.wfs.v_1_1_0.QueryType)

Aggregations

ContentType (ddf.catalog.data.ContentType)55 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)20 CatalogFramework (ddf.catalog.CatalogFramework)18 ContentTypeImpl (ddf.catalog.data.impl.ContentTypeImpl)18 Metacard (ddf.catalog.data.Metacard)17 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 Date (java.util.Date)10 HashSet (java.util.HashSet)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 Source (ddf.catalog.source.Source)7 QName (javax.xml.namespace.QName)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.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 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)4 SolrProviderTest (ddf.catalog.source.solr.SolrProviderTest)4