Search in sources :

Example 66 with Metacard

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

the class SolrProviderTest method testXpathCompoundContextualQuery.

@Test
public void testXpathCompoundContextualQuery() throws Exception {
    ConfigurationStore.getInstance().setDisableTextPath(false);
    deleteAllIn(provider);
    String nonexistentXpath = "/this/xpath[does/not/@ex:exist]";
    MockMetacard tampa = new MockMetacard(Library.getTampaRecord());
    tampa.setTitle("Tampa");
    tampa.setLocation(TAMPA_AIRPORT_POINT_WKT);
    MockMetacard flagstaff = new MockMetacard(Library.getFlagstaffRecord());
    flagstaff.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
    create(Arrays.asList((Metacard) tampa, flagstaff));
    /* XPath AND temporal AND spatial. */
    Filter filter = filterBuilder.allOf(filterBuilder.xpath("/rss/channel[item/link]").exists(), filterBuilder.attribute(Metacard.MODIFIED).before().date(new DateTime().plus(1).toDate()), filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT));
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("XPath AND temporal AND spatial", ONE_HIT, sourceResponse.getResults().size());
    /* temporal AND (Bad XPath OR XPath) */
    filter = filterBuilder.allOf(filterBuilder.attribute(Metacard.MODIFIED).before().date(new DateTime().plus(1).toDate()), filterBuilder.anyOf(filterBuilder.xpath(nonexistentXpath).exists(), filterBuilder.xpath("//channel/image/title").is().like().text(FLAGSTAFF_QUERY_PHRASE)));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("temporal AND (Bad XPath OR XPath)", ONE_HIT, sourceResponse.getResults().size());
    /* Bad XPath OR (spatial AND XPath) */
    filter = filterBuilder.anyOf(filterBuilder.xpath(nonexistentXpath).is().like().text("any phrase"), filterBuilder.allOf(filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(TAMPA_AIRPORT_POINT_WKT), filterBuilder.xpath("/rss//item/enclosure/@url").exists()));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Bad XPath OR (spatial AND XPath)", ONE_HIT, sourceResponse.getResults().size());
    assertEquals("Tampa", sourceResponse.getResults().get(0).getMetacard().getTitle());
    /* spatial AND (Bad XPath OR Bad XPath) */
    filter = filterBuilder.allOf(filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT), filterBuilder.anyOf(filterBuilder.xpath(nonexistentXpath).exists(), filterBuilder.xpath("//also/does/not[@exist]").is().like().text(FLAGSTAFF_QUERY_PHRASE)));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("spatial AND (Bad XPath OR Bad XPath)", 0, 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) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 67 with Metacard

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

the class SolrProviderTest method testDeleteAlternativeAttribute.

/**
     * Testing if another attribute can be used to delete records other than {@link Metacard#ID}
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
@Test
public void testDeleteAlternativeAttribute() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    CreateResponse createResponse = create(metacard);
    DeleteResponse deleteResponse = provider.delete(new DeleteRequest() {

        @Override
        public boolean hasProperties() {
            return false;
        }

        @Override
        public Serializable getPropertyValue(String name) {
            return null;
        }

        @Override
        public Set<String> getPropertyNames() {
            return null;
        }

        @Override
        public Map<String, Serializable> getProperties() {
            return null;
        }

        @Override
        public boolean containsPropertyName(String name) {
            return false;
        }

        @Override
        public List<? extends Serializable> getAttributeValues() {
            return Arrays.asList(MockMetacard.DEFAULT_TITLE);
        }

        @Override
        public String getAttributeName() {
            return Metacard.TITLE;
        }
    });
    Metacard deletedMetacard = deleteResponse.getDeletedMetacards().get(0);
    verifyDeletedRecord(metacard, createResponse, deleteResponse, deletedMetacard);
    // verify it is really not in SOLR
    Filter filter = filterBuilder.attribute(Metacard.TITLE).like().text(MockMetacard.DEFAULT_TITLE);
    QueryImpl query = new QueryImpl(filter);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    List<Result> results = sourceResponse.getResults();
    assertEquals(0, results.size());
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DeleteRequest(ddf.catalog.operation.DeleteRequest) Map(java.util.Map) Test(org.junit.Test)

Example 68 with Metacard

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

the class SolrProviderTest method testNumericSort.

@Test
public void testNumericSort() throws Exception {
    deleteAllIn(provider);
    /* SETUP */
    String doubleField = "hertz";
    double doubleFieldValue = 16065.435;
    String floatField = "inches";
    float floatFieldValue = 4.435f;
    String intField = "count";
    int intFieldValue = 4;
    String longField = "milliseconds";
    long longFieldValue = 9876543293L;
    String shortField = "daysOfTheWeek";
    short shortFieldValue = 1;
    int factor = 5;
    List<Metacard> list = new ArrayList<Metacard>();
    DateTime now = new DateTime();
    for (int i = 0; i < 5; i++) {
        Set<AttributeDescriptor> descriptors = numericalDescriptors(doubleField, floatField, intField, longField, shortField);
        MetacardTypeImpl mType = new MetacardTypeImpl("numberMetacardType", descriptors);
        MetacardImpl customMetacard1 = new MetacardImpl(mType);
        customMetacard1.setAttribute(Metacard.ID, "");
        customMetacard1.setAttribute(doubleField, doubleFieldValue + factor * i);
        customMetacard1.setAttribute(floatField, floatFieldValue + factor * i);
        customMetacard1.setAttribute(intField, intFieldValue + factor * i);
        customMetacard1.setAttribute(longField, longFieldValue + factor * i);
        customMetacard1.setAttribute(shortField, shortFieldValue + factor * i);
        list.add(customMetacard1);
    }
    create(list);
    Filter filter = null;
    QueryImpl query = null;
    SourceResponse sourceResponse = null;
    // Sort all Double ASCENDING
    filter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("*");
    query = new QueryImpl(filter);
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(doubleField, SortOrder.ASCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    for (int i = 0; i < list.size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals(doubleFieldValue + factor * i, r.getMetacard().getAttribute(doubleField).getValue());
    }
    // Sort all double DESCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(doubleField, SortOrder.DESCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    int counter = 0;
    for (int i = (list.size() - 1); i >= 0; i--) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals(doubleFieldValue + factor * counter, r.getMetacard().getAttribute(doubleField).getValue());
        counter++;
    }
    // Sort all Float ASCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(floatField, SortOrder.ASCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    for (int i = 0; i < list.size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals(floatFieldValue + factor * i, r.getMetacard().getAttribute(floatField).getValue());
    }
    // Sort all Float DESCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(floatField, SortOrder.DESCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    counter = 0;
    for (int i = (list.size() - 1); i >= 0; i--) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals(floatFieldValue + factor * counter, r.getMetacard().getAttribute(floatField).getValue());
        counter++;
    }
    // Sort all int ASCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(intField, SortOrder.ASCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    for (int i = 0; i < list.size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals(intFieldValue + factor * i, r.getMetacard().getAttribute(intField).getValue());
    }
    // Sort all int DESCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(intField, SortOrder.DESCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    counter = 0;
    for (int i = (list.size() - 1); i >= 0; i--) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals(intFieldValue + factor * counter, r.getMetacard().getAttribute(intField).getValue());
        counter++;
    }
    // Sort all long ASCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(longField, SortOrder.ASCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    for (int i = 0; i < list.size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals(longFieldValue + factor * i, r.getMetacard().getAttribute(longField).getValue());
    }
    // Sort all long DESCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(longField, SortOrder.DESCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    counter = 0;
    for (int i = (list.size() - 1); i >= 0; i--) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals(longFieldValue + factor * counter, r.getMetacard().getAttribute(longField).getValue());
        counter++;
    }
    // Sort all short ASCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(shortField, SortOrder.ASCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    for (int i = 0; i < list.size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals((short) (shortFieldValue + factor * i), r.getMetacard().getAttribute(shortField).getValue());
    }
    // Sort all short DESCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(shortField, SortOrder.DESCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    counter = 0;
    for (int i = (list.size() - 1); i >= 0; i--) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals((short) (shortFieldValue + factor * counter), r.getMetacard().getAttribute(shortField).getValue());
        counter++;
    }
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTime(org.joda.time.DateTime) 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 69 with Metacard

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

the class SolrProviderTest method testSpatialQueryAcrossInternationalDateLine.

@Test
public void testSpatialQueryAcrossInternationalDateLine() throws Exception {
    deleteAllIn(provider);
    MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
    metacard.setLocation(MIDWAY_ISLANDS_POINT_WKT);
    List<Metacard> list = Arrays.asList((Metacard) metacard);
    create(list);
    /** POSITIVE - Counter Clockwise Orientation **/
    Filter filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(ACROSS_INTERNATIONAL_DATELINE_LARGE_CCW_WKT);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed to find the correct record. ", 1, sourceResponse.getResults().size());
    for (Result r : sourceResponse.getResults()) {
        assertTrue("Wrong record, Flagstaff keyword was not found.", ALL_RESULTS != r.getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE));
    }
    /** POSITIVE - Clockwise Orientation **/
    filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(ACROSS_INTERNATIONAL_DATELINE_LARGE_CW_WKT);
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed to find the correct record. ", 1, sourceResponse.getResults().size());
    for (Result r : sourceResponse.getResults()) {
        assertTrue("Wrong record, Flagstaff keyword was not found.", ALL_RESULTS != r.getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE));
    }
    /** NEGATIVE **/
    filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(ACROSS_INTERNATIONAL_DATELINE_SMALL_WKT);
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Should not find a record. ", 0, 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) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 70 with Metacard

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

the class SolrProviderTest method testUpdateNonUniqueAttributeValue2.

/**
     * Tests if we catch a rare case where some attribute value match multiple Metacards while
     * others do not match any records.
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
@Test(expected = IngestException.class)
public void testUpdateNonUniqueAttributeValue2() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    MockMetacard m1 = new MockMetacard(Library.getFlagstaffRecord());
    MockMetacard m2 = new MockMetacard(Library.getFlagstaffRecord());
    List<Metacard> list = Arrays.asList((Metacard) m1, m2);
    create(list);
    provider.update(new UpdateRequest() {

        @Override
        public boolean hasProperties() {
            return false;
        }

        @Override
        public Serializable getPropertyValue(String name) {
            return null;
        }

        @Override
        public Set<String> getPropertyNames() {
            return null;
        }

        @Override
        public Map<String, Serializable> getProperties() {
            return null;
        }

        @Override
        public boolean containsPropertyName(String name) {
            return false;
        }

        @Override
        public List<Entry<Serializable, Metacard>> getUpdates() {
            MockMetacard newMetacard = new MockMetacard(Library.getShowLowRecord());
            List<Entry<Serializable, Metacard>> updateList = new ArrayList<Entry<Serializable, Metacard>>();
            updateList.add(new SimpleEntry<Serializable, Metacard>(MockMetacard.DEFAULT_TITLE, newMetacard));
            updateList.add(new SimpleEntry<Serializable, Metacard>(TAMPA_QUERY_PHRASE, newMetacard));
            return updateList;
        }

        @Override
        public String getAttributeName() {
            return Metacard.TITLE;
        }
    });
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) UpdateRequest(ddf.catalog.operation.UpdateRequest) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.containsString(org.hamcrest.Matchers.containsString) Metacard(ddf.catalog.data.Metacard) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) 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