Search in sources :

Example 16 with Instant

use of org.opengis.temporal.Instant in project ddf by codice.

the class CatalogFrameworkQueryTest method testAfterQuery.

@Test
public void testAfterQuery() throws Exception {
    Calendar afterCal = Calendar.getInstance();
    Calendar card1Exp = Calendar.getInstance();
    card1Exp.add(Calendar.YEAR, 1);
    Calendar card2Exp = Calendar.getInstance();
    card2Exp.add(Calendar.YEAR, 3);
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard1 = new MetacardImpl();
    newCard1.setId(null);
    newCard1.setExpirationDate(card1Exp.getTime());
    metacards.add(newCard1);
    MetacardImpl newCard2 = new MetacardImpl();
    newCard2.setId(null);
    newCard2.setExpirationDate(card2Exp.getTime());
    metacards.add(newCard2);
    String mcId1 = null;
    String mcId2 = null;
    CreateResponse createResponse = null;
    createResponse = framework.create(new CreateRequestImpl(metacards, null));
    assertEquals(createResponse.getCreatedMetacards().size(), metacards.size());
    for (Metacard curCard : createResponse.getCreatedMetacards()) {
        if (curCard.getExpirationDate().equals(card1Exp.getTime())) {
            mcId1 = curCard.getId();
        } else {
            mcId2 = curCard.getId();
        }
        assertNotNull(curCard.getId());
    }
    FilterFactory filterFactory = new FilterFactoryImpl();
    Instant afterInstant = new DefaultInstant(new DefaultPosition(afterCal.getTime()));
    QueryImpl query = new QueryImpl(filterFactory.after(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(afterInstant)));
    QueryRequest queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        LOGGER.info("Response:{}", response);
        assertEquals("Expecting return 2 results.", 2, response.getHits());
    } catch (UnsupportedQueryException e) {
        LOGGER.error("Failure!!!", e);
        fail();
    } catch (FederationException e) {
        fail();
    }
    afterInstant = new DefaultInstant(new DefaultPosition(card1Exp.getTime()));
    query = new QueryImpl(filterFactory.after(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(afterInstant)));
    queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("After filter should return 1 result", 1, response.getHits());
        assertEquals("After filter should return metacard[" + mcId2 + "]", mcId2, response.getResults().get(0).getMetacard().getId());
    } catch (UnsupportedQueryException e) {
        fail();
    } catch (FederationException e) {
        fail();
    }
    afterInstant = new DefaultInstant(new DefaultPosition(card2Exp.getTime()));
    query = new QueryImpl(filterFactory.after(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(afterInstant)));
    queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("After filter should return 0 results.", 0, response.getHits());
    } catch (UnsupportedQueryException e) {
        fail();
    } catch (FederationException e) {
        fail();
    }
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) CreateResponse(ddf.catalog.operation.CreateResponse) Calendar(java.util.Calendar) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) DefaultInstant(org.geotools.temporal.object.DefaultInstant) FederationException(ddf.catalog.federation.FederationException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FilterFactory(org.opengis.filter.FilterFactory) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DefaultPosition(org.geotools.temporal.object.DefaultPosition) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Example 17 with Instant

use of org.opengis.temporal.Instant in project ddf by codice.

the class TestSolrFilterBuilder method makePeriod.

private Period makePeriod(Date start, Date end) {
    DefaultPosition defaultPosition = new DefaultPosition(start);
    Instant startInstant = new DefaultInstant(defaultPosition);
    Instant endInstant = new DefaultInstant(new DefaultPosition(end));
    Period period = new DefaultPeriod(startInstant, endInstant);
    return period;
}
Also used : DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod)

Aggregations

Instant (org.opengis.temporal.Instant)17 DefaultInstant (org.geotools.temporal.object.DefaultInstant)14 DefaultPosition (org.geotools.temporal.object.DefaultPosition)14 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)13 Period (org.opengis.temporal.Period)10 Filter (org.opengis.filter.Filter)7 Date (java.util.Date)6 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)4 Expression (org.opengis.filter.expression.Expression)4 Literal (org.opengis.filter.expression.Literal)4 SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)3 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)3 QueryImpl (ddf.catalog.operation.impl.QueryImpl)3 Test (org.junit.Test)3 AttributeType (ddf.catalog.data.AttributeType)2 Metacard (ddf.catalog.data.Metacard)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 FederationException (ddf.catalog.federation.FederationException)2 CreateResponse (ddf.catalog.operation.CreateResponse)2 QueryRequest (ddf.catalog.operation.QueryRequest)2