Search in sources :

Example 86 with Metacard

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

the class SolrProviderTest method testTextualSort.

@Test
public void testTextualSort() throws Exception {
    deleteAllIn(provider);
    List<Metacard> list = new ArrayList<Metacard>();
    DateTime now = new DateTime();
    for (int i = 65; i < 65 + 5; i++) {
        MockMetacard m = new MockMetacard(Library.getFlagstaffRecord());
        m.setEffectiveDate(now.minus(5L * i).toDate());
        m.setTitle((char) i + " Record ");
        list.add(m);
    }
    create(list);
    Filter filter = null;
    QueryImpl query = null;
    SourceResponse sourceResponse = null;
    // Sort all Textual ASCENDING
    filter = filterBuilder.attribute(Metacard.EFFECTIVE).before().date(now.plusMillis(1).toDate());
    query = new QueryImpl(filter);
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Metacard.TITLE, SortOrder.ASCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    int ascii = 65;
    for (int i = 0; i < list.size(); i++) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals((char) (i + ascii) + " Record ", r.getMetacard().getTitle());
    }
    // Sort all Textual DESCENDING
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Metacard.TITLE, SortOrder.DESCENDING.name()));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(list.size(), sourceResponse.getResults().size());
    int asciiE = 69;
    for (int i = (list.size() - 1); i >= 0; i--) {
        Result r = sourceResponse.getResults().get(i);
        assertEquals((char) (asciiE - i) + " Record ", r.getMetacard().getTitle());
    }
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) 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 87 with Metacard

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

the class SolrProviderTest method testDeleteOperation.

/**
     * Testing that if records are properly deleted.
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
@Test
public void testDeleteOperation() throws IngestException, UnsupportedQueryException {
    // Single Deletion
    deleteAllIn(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    CreateResponse createResponse = create(metacard);
    DeleteResponse deleteResponse = delete(createResponse.getCreatedMetacards().get(0).getId());
    Metacard deletedMetacard = deleteResponse.getDeletedMetacards().get(0);
    verifyDeletedRecord(metacard, createResponse, deleteResponse, deletedMetacard);
}
Also used : Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Test(org.junit.Test)

Example 88 with Metacard

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

the class SolrProviderTest method testUpdateUnknownAttribute.

/**
     * Testing update operation of unknown attribute. Should return no results.
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
public void testUpdateUnknownAttribute() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    UpdateResponse response = 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));
            return updateList;
        }

        @Override
        public String getAttributeName() {
            return "dataAccess";
        }
    });
    assertEquals(0, response.getUpdatedMetacards().size());
}
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) UpdateResponse(ddf.catalog.operation.UpdateResponse) 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)

Example 89 with Metacard

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

the class SolrProviderTest method testWhitespaceTokenizedFieldWithWildcardSearch.

/**
     * Testing Tokenization of the search phrase.
     *
     * @throws Exception
     */
@Test
public void testWhitespaceTokenizedFieldWithWildcardSearch() throws Exception {
    deleteAllIn(provider);
    List<Metacard> list = new ArrayList<Metacard>();
    String title = "AB-12.yz_file";
    MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setTitle(title);
    String searchPhrase1 = "AB*12.yz_file";
    String searchPhrase2 = "AB-12*yz_file";
    String searchPhrase3 = "AB-12.yz*file";
    String searchPhrase4 = "AB-12.*_file";
    String searchPhrase5 = "Flagstaff Chamb*";
    String searchPhrase6 = "Flagstaff Cmmerce";
    list.add(metacard1);
    create(list);
    queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().like().text(searchPhrase1));
    queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().like().text(searchPhrase2));
    queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().like().text(searchPhrase3));
    queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().like().text(searchPhrase4));
    // Matching Phrase with wildcard
    queryAndVerifyCount(1, filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase5));
    // Non-Matching Phrase without wildcard
    queryAndVerifyCount(0, filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase6));
}
Also used : Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 90 with Metacard

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

the class SolrProviderTest method testSpatialQueryWithCounterClockwiseRectangle.

@Test
public void testSpatialQueryWithCounterClockwiseRectangle() throws Exception {
    deleteAllIn(provider);
    MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
    metacard.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
    List<Metacard> list = Arrays.asList((Metacard) metacard);
    /** CREATE **/
    create(list);
    /** POSITIVE **/
    Filter filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(COUNTERCLOCKWISE_ARIZONA_RECTANGLE_WKT);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed to find Flagstaff 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));
    }
}
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)

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