Search in sources :

Example 71 with Metacard

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

the class SolrProviderTest method testSpatialDistanceCalculationExactPoint.

@Test
public void testSpatialDistanceCalculationExactPoint() throws Exception {
    deleteAllIn(provider);
    // given
    double radiusInKilometers = 50;
    double radiusInMeters = radiusInKilometers * METERS_PER_KM;
    Filter positiveFilter = filterBuilder.attribute(Metacard.GEOGRAPHY).withinBuffer().wkt(LAS_VEGAS_POINT_WKT, radiusInMeters);
    MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
    metacard.setLocation(LAS_VEGAS_POINT_WKT);
    List<Metacard> list = Arrays.asList((Metacard) metacard);
    create(list);
    QueryImpl query = new QueryImpl(positiveFilter);
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Result.DISTANCE, SortOrder.ASCENDING));
    // when
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    // then
    assertEquals("Failed to find metacard WKT with filter", 1, sourceResponse.getResults().size());
    Result result = sourceResponse.getResults().get(0);
    assertThat(result.getDistanceInMeters(), is(notNullValue()));
    assertThat("Point radius search should be less than the radius given.", result.getDistanceInMeters(), is(lessThanOrEqualTo(radiusInMeters)));
    double oneMeter = 1.0;
    assertThat("The distance should be close to zero since we are right upon the point.", result.getDistanceInMeters(), is(lessThanOrEqualTo(oneMeter)));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 72 with Metacard

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

the class SolrProviderTest method spatialDistanceCalculationBetweenTwoPoints.

private void spatialDistanceCalculationBetweenTwoPoints(String attribute, String sortBy) throws Exception {
    deleteAllIn(provider);
    // given
    double radiusInKilometers = 500;
    double radiusInMeters = radiusInKilometers * METERS_PER_KM;
    Filter positiveFilter = filterBuilder.attribute(attribute).withinBuffer().wkt(PHOENIX_POINT_WKT, radiusInMeters);
    MetacardImpl metacard;
    if (attribute.equals(Metacard.GEOGRAPHY)) {
        metacard = new MockMetacard(Library.getFlagstaffRecord());
    } else {
        metacard = new MockMetacard(Library.getFlagstaffRecord(), new MetacardTypeImpl("distanceTest", BasicTypes.BASIC_METACARD, Sets.newSet(new AttributeDescriptorImpl(attribute, true, true, true, true, BasicTypes.GEO_TYPE))));
    }
    metacard.setAttribute(attribute, LAS_VEGAS_POINT_WKT);
    List<Metacard> list = Arrays.asList((Metacard) metacard);
    create(list);
    QueryImpl query = new QueryImpl(positiveFilter);
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(sortBy, SortOrder.ASCENDING));
    // when
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    // then
    assertEquals("Failed to find metacard WKT with filter", 1, sourceResponse.getResults().size());
    Result result = sourceResponse.getResults().get(0);
    assertThat(result.getDistanceInMeters(), is(notNullValue()));
    assertThat("Point radius search should be less than the radius given.", result.getDistanceInMeters(), is(lessThanOrEqualTo(radiusInMeters)));
    // expected distance calculated from
    // http://www.movable-type.co.uk/scripts/latlong.html
    double expectedDistanceBetweenCitiesInMeters = 412700;
    // +/-0.1%
    double precisionPercentage = .001;
    double lowerBound = expectedDistanceBetweenCitiesInMeters * (1 - precisionPercentage);
    double upperBound = expectedDistanceBetweenCitiesInMeters * (1 + precisionPercentage);
    assertThat("The distance returned should at least be above the lower bound of error.", result.getDistanceInMeters(), is(greaterThanOrEqualTo(lowerBound)));
    assertThat("The distance returned should at least be below the upper bound of error.", result.getDistanceInMeters(), is(lessThanOrEqualTo(upperBound)));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 73 with Metacard

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

the class SolrProviderTest method testPropertyIsEqualTo.

@Test
public void testPropertyIsEqualTo() throws Exception {
    deleteAllIn(provider);
    List<Metacard> list = new ArrayList<Metacard>();
    /* STRINGS */
    MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setTitle("Mary");
    Date exactEffectiveDate = new DateTime().minusMinutes(1).toDate();
    metacard1.setEffectiveDate(exactEffectiveDate);
    list.add(metacard1);
    MockMetacard metacard2 = new MockMetacard(Library.getTampaRecord());
    metacard2.setTitle("Mary had a little");
    list.add(metacard2);
    MockMetacard metacard3 = new MockMetacard(Library.getShowLowRecord());
    metacard3.setTitle("Mary had a little l!@#$%^&*()_mb");
    list.add(metacard3);
    create(list);
    queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().equalTo().text("Mary"));
    queryAndVerifyCount(0, filterBuilder.attribute(Metacard.TITLE).is().equalTo().text("Mar"));
    queryAndVerifyCount(0, filterBuilder.attribute(Metacard.TITLE).is().equalTo().text("Mary had"));
    queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().equalTo().text("Mary had a little"));
    queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().equalTo().text("Mary had a little l!@#$%^&*()_mb"));
    /* DATES */
    queryAndVerifyCount(1, filterBuilder.attribute(Metacard.EFFECTIVE).is().equalTo().date(exactEffectiveDate));
    /* EMPTY ATTRIBUTE */
    queryAndVerifyCount(3, filterBuilder.attribute(Metacard.DESCRIPTION).is().equalTo().text(""));
    queryAndVerifyCount(0, filterBuilder.attribute(Metacard.TITLE).is().equalTo().text(""));
}
Also used : Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 74 with Metacard

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

the class SolrProviderTest method testGetContentTypesOne.

@Test
public void testGetContentTypesOne() throws Exception {
    deleteAllIn(provider);
    MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
    List<Metacard> list = Arrays.asList((Metacard) metacard1);
    create(list);
    Set<ContentType> contentTypes = provider.getContentTypes();
    assertEquals(1, contentTypes.size());
    assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_1, MockMetacard.DEFAULT_VERSION)));
}
Also used : ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) Metacard(ddf.catalog.data.Metacard) ContentType(ddf.catalog.data.ContentType) Test(org.junit.Test)

Example 75 with Metacard

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

the class SolrProviderTest method testStartIndexWithSorting.

@Test
public void testStartIndexWithSorting() throws Exception {
    deleteAllIn(provider);
    List<Metacard> metacards = new ArrayList<Metacard>();
    DateTime dt = new DateTime(1985, 1, 1, 1, 1, 1, 1, DateTimeZone.UTC);
    TreeSet<Date> calculatedDates = new TreeSet<Date>();
    for (int j = 0; j < 10; j++) {
        for (int i = 0; i < 100; i = i + 10) {
            MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
            // ingest sporadically the effective dates so the default return
            // order won't be ordered
            Date calculatedDate = dt.plusDays(100 - i + 10 - j).toDate();
            calculatedDates.add(calculatedDate);
            metacard.setEffectiveDate(calculatedDate);
            metacards.add(metacard);
        }
    }
    // The TreeSet will sort them, the array will give me access to everyone
    // without an iterator
    Date[] dates = new Date[calculatedDates.size()];
    calculatedDates.toArray(dates);
    /** CREATE **/
    CreateResponse response = create(metacards);
    LOGGER.info("CREATED {} records.", response.getCreatedMetacards().size());
    CommonQueryBuilder queryBuilder = new CommonQueryBuilder();
    QueryImpl query = queryBuilder.queryByProperty(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE);
    int maxSize = 20;
    int startIndex = 2;
    // STARTINDEX=2, MAXSIZE=20
    query.setPageSize(maxSize);
    query.setStartIndex(startIndex);
    SortByImpl sortBy = new SortByImpl(queryBuilder.filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(maxSize, sourceResponse.getResults().size());
    for (int i = 0; i < sourceResponse.getResults().size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        Date effectiveDate = r.getMetacard().getEffectiveDate();
        DateTime currentDate = new DateTime(effectiveDate.getTime());
        LOGGER.debug("Testing current index: {}", startIndex + i);
        assertEquals(new DateTime(dates[startIndex - 1 + i].getTime()).getDayOfYear(), currentDate.getDayOfYear());
    }
    // STARTINDEX=20, MAXSIZE=5
    // a match-all queryByProperty
    query = queryBuilder.queryByProperty(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE);
    maxSize = 5;
    startIndex = 20;
    query.setPageSize(maxSize);
    query.setStartIndex(startIndex);
    sortBy = new SortByImpl(queryBuilder.filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(maxSize, sourceResponse.getResults().size());
    for (int i = 0; i < sourceResponse.getResults().size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        Date effectiveDate = r.getMetacard().getEffectiveDate();
        DateTime currentDate = new DateTime(effectiveDate.getTime());
        LOGGER.debug("Testing current index: {}", startIndex + i);
        assertEquals(new DateTime(dates[startIndex - 1 + i].getTime()).getDayOfYear(), currentDate.getDayOfYear());
    }
    // STARTINDEX=80, MAXSIZE=20
    // a match-all queryByProperty
    query = queryBuilder.queryByProperty(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE);
    maxSize = 20;
    startIndex = 80;
    query.setPageSize(maxSize);
    query.setStartIndex(startIndex);
    sortBy = new SortByImpl(queryBuilder.filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(maxSize, sourceResponse.getResults().size());
    for (int i = 0; i < sourceResponse.getResults().size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        Date effectiveDate = r.getMetacard().getEffectiveDate();
        DateTime currentDate = new DateTime(effectiveDate.getTime());
        LOGGER.debug("Testing current index: {}", startIndex + i);
        assertEquals(new DateTime(dates[startIndex - 1 + i].getTime()).getDayOfYear(), currentDate.getDayOfYear());
    }
    // STARTINDEX=1, MAXSIZE=100
    // a match-all queryByProperty
    query = queryBuilder.queryByProperty(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE);
    maxSize = 100;
    startIndex = 1;
    query.setPageSize(maxSize);
    query.setStartIndex(startIndex);
    sortBy = new SortByImpl(queryBuilder.filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(maxSize, sourceResponse.getResults().size());
    for (int i = 0; i < sourceResponse.getResults().size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        Date effectiveDate = r.getMetacard().getEffectiveDate();
        DateTime currentDate = new DateTime(effectiveDate.getTime());
        LOGGER.debug("Testing current index: {}", startIndex + i);
        assertEquals(new DateTime(dates[startIndex - 1 + i].getTime()).getDayOfYear(), currentDate.getDayOfYear());
    }
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(org.geotools.filter.SortByImpl) TreeSet(java.util.TreeSet) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) 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