Search in sources :

Example 91 with Metacard

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

the class SolrProviderTest method testSortedPointRadiusWithComplexQuery.

@Test
public void testSortedPointRadiusWithComplexQuery() throws Exception {
    deleteAllIn(provider);
    MetacardImpl metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    MetacardImpl metacard2 = new MockMetacard(Library.getTampaRecord());
    MetacardImpl metacard3 = new MockMetacard(Library.getShowLowRecord());
    // Add in the geometry
    metacard1.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
    metacard2.setLocation(TAMPA_AIRPORT_POINT_WKT);
    metacard3.setLocation(SHOW_LOW_AIRPORT_POINT_WKT);
    // Add in a content type
    metacard1.setAttribute(Metacard.CONTENT_TYPE, "product");
    List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
    /** CREATE **/
    create(list);
    // create a filter that has spatial and content type criteria
    Filter contentFilter = filterBuilder.attribute(Metacard.CONTENT_TYPE).is().text("product");
    Filter spatialFilter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
    Filter finalFilter = filterBuilder.allOf(filterBuilder.attribute(Metacard.ANY_TEXT).like().text("flagstaff"), filterBuilder.allOf(contentFilter, spatialFilter));
    // sort by distance
    QueryImpl query = new QueryImpl(finalFilter);
    SortBy sortby = new ddf.catalog.filter.impl.SortByImpl(Result.DISTANCE, org.opengis.filter.sort.SortOrder.DESCENDING);
    query.setSortBy(sortby);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(1, sourceResponse.getResults().size());
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) SortByImpl(org.geotools.filter.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 92 with Metacard

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

the class CachedResourceMetacardComparator method allMetacardAttributesEqual.

private static boolean allMetacardAttributesEqual(Metacard cachedMetacard, Metacard updatedMetacard) {
    MetacardType cachedMetacardType = cachedMetacard.getMetacardType();
    MetacardType updatedMetacardType = updatedMetacard.getMetacardType();
    if (!Objects.equals(cachedMetacardType, updatedMetacardType)) {
        return false;
    }
    // attributes need to be compared so we can return true.
    if (cachedMetacardType == null) {
        return true;
    }
    Set<AttributeDescriptor> cachedDescriptors = cachedMetacardType.getAttributeDescriptors();
    // as well and no attributes need to be compared so we can return true.
    if (cachedDescriptors == null) {
        return true;
    }
    Optional<String> difference = cachedDescriptors.stream().map(AttributeDescriptor::getName).filter(attributeName -> !ATTRIBUTES_TO_IGNORE.contains(attributeName)).filter(attributeName -> !Objects.equals(cachedMetacard.getAttribute(attributeName), updatedMetacard.getAttribute(attributeName))).findFirst();
    if (LOGGER.isDebugEnabled() && difference.isPresent()) {
        String attributeName = difference.get();
        LOGGER.debug("Metacard updated. Attribute changed: {}, cached value: {}, updated value: {}", attributeName, cachedMetacard.getAttribute(attributeName), updatedMetacard.getAttribute(attributeName));
    }
    return !difference.isPresent();
}
Also used : Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Function(java.util.function.Function) MetacardType(ddf.catalog.data.MetacardType) Objects(java.util.Objects) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Metacard(ddf.catalog.data.Metacard) Optional(java.util.Optional) Nullable(javax.annotation.Nullable) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType)

Example 93 with Metacard

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

the class ResourceCacheImpl method validateCacheEntry.

/**
     * Compares the {@link Metacard} in a {@link ReliableResource} pulled from cache with a Metacard obtained directly
     * from the Catalog to ensure they are the same. Typically used to determine if the cache entry is out-of-date based
     * on the Catalog having an updated Metacard.
     *
     * @param cachedResource
     * @param latestMetacard
     * @return true if the cached ReliableResource still matches the most recent Metacard from the Catalog, false otherwise
     */
protected boolean validateCacheEntry(ReliableResource cachedResource, Metacard latestMetacard) {
    LOGGER.trace("ENTERING: validateCacheEntry");
    if (cachedResource == null || latestMetacard == null) {
        throw new IllegalArgumentException("Neither the cachedResource nor the metacard retrieved from the catalog can be null.");
    }
    Metacard cachedMetacard = cachedResource.getMetacard();
    MetacardImpl latestMetacardImpl = new MetacardImpl(latestMetacard);
    if (isSame(cachedMetacard, latestMetacardImpl)) {
        LOGGER.debug("Metacard has not changed");
        LOGGER.trace("EXITING: validateCacheEntry");
        return true;
    }
    LOGGER.debug("Metacard has changed");
    File cachedFile = new File(cachedResource.getFilePath());
    if (!FileUtils.deleteQuietly(cachedFile)) {
        LOGGER.debug("File was not removed from cache directory.  File Path: {}", cachedResource.getFilePath());
    }
    cache.remove(cachedResource.getKey());
    LOGGER.trace("EXITING: validateCacheEntry");
    return false;
}
Also used : Metacard(ddf.catalog.data.Metacard) File(java.io.File) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 94 with Metacard

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

the class SolrProviderTest method testSpatialCreateAndUpdateWithClockwiseRectangle.

@Test
public void testSpatialCreateAndUpdateWithClockwiseRectangle() throws Exception {
    deleteAllIn(provider);
    /** CREATE **/
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    metacard.setLocation(CLOCKWISE_ARIZONA_RECTANGLE_WKT);
    CreateResponse createResponse = create(Arrays.asList((Metacard) metacard));
    assertEquals(1, createResponse.getCreatedMetacards().size());
    Filter filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
    /** UPDATE **/
    MockMetacard updatedMetacard = new MockMetacard(Library.getTampaRecord());
    updatedMetacard.setLocation(CLOCKWISE_ARIZONA_RECTANGLE_WKT);
    String[] ids = { metacard.getId() };
    UpdateResponse updateResponse = update(ids, Arrays.asList((Metacard) updatedMetacard));
    assertEquals(1, updateResponse.getUpdatedMetacards().size());
    filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 95 with Metacard

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

the class SolrProviderTest method testGetContentTypesComplicated.

@Test
public void testGetContentTypesComplicated() throws Exception {
    deleteAllIn(provider);
    List<Metacard> list = new ArrayList<Metacard>();
    // Single content type and version
    MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
    metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_1);
    list.add(metacard1);
    // one content type with multiple versions
    metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
    metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_1);
    list.add(metacard1);
    MockMetacard metacard2 = new MockMetacard(Library.getFlagstaffRecord());
    metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
    metacard2.setContentTypeVersion(SAMPLE_CONTENT_VERSION_2);
    list.add(metacard2);
    // multiple records with different content type but same version
    metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_3);
    metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_3);
    list.add(metacard1);
    metacard2 = new MockMetacard(Library.getFlagstaffRecord());
    metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_3);
    metacard2.setContentTypeVersion(SAMPLE_CONTENT_VERSION_4);
    list.add(metacard2);
    // multiple records with different content type and different version
    metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_4);
    metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_1);
    list.add(metacard1);
    metacard2 = new MockMetacard(Library.getFlagstaffRecord());
    metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
    metacard2.setContentTypeVersion(SAMPLE_CONTENT_VERSION_4);
    list.add(metacard2);
    metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_4);
    metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_1);
    list.add(metacard1);
    metacard2 = new MockMetacard(Library.getFlagstaffRecord());
    metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
    metacard2.setContentTypeVersion(SAMPLE_CONTENT_VERSION_4);
    list.add(metacard2);
    create(list);
    Set<ContentType> contentTypes = provider.getContentTypes();
    assertEquals(7, contentTypes.size());
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_1, SAMPLE_CONTENT_VERSION_1)));
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_2, SAMPLE_CONTENT_VERSION_1)));
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_2, SAMPLE_CONTENT_VERSION_2)));
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_3, SAMPLE_CONTENT_VERSION_3)));
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_3, SAMPLE_CONTENT_VERSION_4)));
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_4, SAMPLE_CONTENT_VERSION_1)));
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_1, SAMPLE_CONTENT_VERSION_4)));
}
Also used : ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) Metacard(ddf.catalog.data.Metacard) ContentType(ddf.catalog.data.ContentType) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Metacard (ddf.catalog.data.Metacard)746 Test (org.junit.Test)470 ArrayList (java.util.ArrayList)206 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)149 InputStream (java.io.InputStream)136 HashMap (java.util.HashMap)129 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)115 Result (ddf.catalog.data.Result)109 Serializable (java.io.Serializable)100 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)90 QueryRequest (ddf.catalog.operation.QueryRequest)84 QueryImpl (ddf.catalog.operation.impl.QueryImpl)80 QueryResponse (ddf.catalog.operation.QueryResponse)78 SourceResponse (ddf.catalog.operation.SourceResponse)76 IOException (java.io.IOException)75 List (java.util.List)74 Map (java.util.Map)67 Filter (org.opengis.filter.Filter)67 CreateResponse (ddf.catalog.operation.CreateResponse)66 HashSet (java.util.HashSet)65