Search in sources :

Example 6 with DefaultPeriod

use of org.geotools.temporal.object.DefaultPeriod in project ddf by codice.

the class CommonQueryBuilder method during.

// public QueryImpl fuzzy(String searchPhrase, boolean isCaseSensitive) {
//
// QueryImpl query = new QueryImpl(
// filterFactory.like(
// new FuzzyFunction(
// Arrays.asList((Expression)(filterFactory.property(Metacard.ANY_TEXT))),
// filterFactory.literal("")),
// searchPhrase,
// "*", "?", "\\",
// isCaseSensitive) ) ;
//
// query.setStartIndex(1) ;
//
// query.setRequestsTotalResultsCount(true);
//
// return query;
// }
public QueryImpl during(String property, Date start, Date end) {
    Instant startInstant = new DefaultInstant(new DefaultPosition(start));
    Instant endInstant = new DefaultInstant(new DefaultPosition(end));
    Period period = new DefaultPeriod(startInstant, endInstant);
    Filter filter = filterFactory.during(filterFactory.property(property), filterFactory.literal(period));
    QueryImpl query = new QueryImpl(filter);
    query.setStartIndex(1);
    query.setRequestsTotalResultsCount(true);
    return query;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) Filter(org.opengis.filter.Filter) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod)

Example 7 with DefaultPeriod

use of org.geotools.temporal.object.DefaultPeriod in project ddf by codice.

the class MockQuery method addTemporalFilter.

public void addTemporalFilter(TemporalFilter temporalFilter) {
    if (temporalFilter != null) {
        // t1.start < timeType instance < t1.end
        Instant startInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getStartDate()));
        Instant endInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getEndDate()));
        Period period = new DefaultPeriod(startInstant, endInstant);
        Filter filter = FILTER_FACTORY.during(FILTER_FACTORY.property(MODIFIED_DATE), FILTER_FACTORY.literal(period));
        filters.add(filter);
        this.filter = getFilter();
    }
}
Also used : DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod)

Example 8 with DefaultPeriod

use of org.geotools.temporal.object.DefaultPeriod in project ddf by codice.

the class OpenSearchQuery method addTemporalFilter.

public void addTemporalFilter(TemporalFilter temporalFilter) {
    String methodName = "addTemporalFilter";
    if (temporalFilter != null) {
        // t1.start < timeType instance < t1.end
        Instant startInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getStartDate()));
        Instant endInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getEndDate()));
        Period period = new DefaultPeriod(startInstant, endInstant);
        Filter filter = FILTER_FACTORY.during(FILTER_FACTORY.property(Metacard.MODIFIED), FILTER_FACTORY.literal(period));
        LOGGER.debug("Adding temporal filter");
        filters.add(filter);
    }
}
Also used : DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod)

Example 9 with DefaultPeriod

use of org.geotools.temporal.object.DefaultPeriod in project ddf by codice.

the class MockQuery method addTemporalFilter.

public void addTemporalFilter(XMLGregorianCalendar start, XMLGregorianCalendar end, String timeType) {
    Filter filter = null;
    String timeProperty = Metacard.MODIFIED;
    if (timeType != null && timeType.toLowerCase().equals(Metacard.EFFECTIVE)) {
        timeProperty = Metacard.EFFECTIVE;
    }
    if (start != null && end != null) {
        int compareTo = start.toGregorianCalendar().compareTo(end.toGregorianCalendar());
        if (compareTo > 0) {
            throw new IllegalArgumentException("start date [" + start + "] should not be later than" + " end date [" + end + "]");
        } else if (compareTo == 0) {
            filter = FILTER_FACTORY.equals(FILTER_FACTORY.property(timeProperty), FILTER_FACTORY.literal(start.toGregorianCalendar().getTime()));
        } else {
            // t1.start < timeType instance < t1.end
            DefaultPosition defaultPosition = new DefaultPosition(start.toGregorianCalendar().getTime());
            Instant startInstant = new DefaultInstant(defaultPosition);
            Instant endInstant = new DefaultInstant(new DefaultPosition(end.toGregorianCalendar().getTime()));
            Period period = new DefaultPeriod(startInstant, endInstant);
            filter = FILTER_FACTORY.during(FILTER_FACTORY.property(timeProperty), FILTER_FACTORY.literal(period));
        }
        filters.add(filter);
    }
}
Also used : SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) Filter(org.opengis.filter.Filter) 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)

Example 10 with DefaultPeriod

use of org.geotools.temporal.object.DefaultPeriod in project ddf by codice.

the class CatalogFrameworkQueryTest method testDuringQuery.

@Test
public void testDuringQuery() {
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard1 = new MetacardImpl();
    newCard1.setId(null);
    Calendar duringStart = Calendar.getInstance();
    Calendar card1Exp = Calendar.getInstance();
    card1Exp.add(Calendar.YEAR, 1);
    Calendar duringEnd1 = Calendar.getInstance();
    duringEnd1.add(Calendar.YEAR, 2);
    Calendar card2Exp = Calendar.getInstance();
    card2Exp.add(Calendar.YEAR, 3);
    Calendar duringEnd2 = Calendar.getInstance();
    duringEnd2.add(Calendar.YEAR, 4);
    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;
    try {
        createResponse = framework.create(new CreateRequestImpl(metacards, null));
    } catch (IngestException e1) {
        LOGGER.error("Failure", e1);
        fail();
    } catch (SourceUnavailableException e1) {
        LOGGER.error("Failure", e1);
        fail();
    }
    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();
    Period duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(duringStart.getTime())), new DefaultInstant(new DefaultPosition(duringEnd1.getTime())));
    QueryImpl query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
    QueryRequest queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("Expecting return 1 result.", 1, response.getHits());
        assertEquals("During filter should return metacard[" + mcId1 + "]", mcId1, response.getResults().get(0).getMetacard().getId());
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        LOGGER.error("Failure", e);
        fail();
    }
    duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(card1Exp.getTime())), new DefaultInstant(new DefaultPosition(duringEnd2.getTime())));
    query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
    queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("During filter should return 1 result", 1, response.getHits());
        assertEquals("During filter should return metacard[" + mcId2 + "]", mcId2, response.getResults().get(0).getMetacard().getId());
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        LOGGER.error("Failure", e);
        fail();
    }
    duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(duringStart.getTime())), new DefaultInstant(new DefaultPosition(duringEnd2.getTime())));
    query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
    queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("During filter should return 2 result", 2, response.getHits());
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        LOGGER.error("Failure", e);
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryRequest(ddf.catalog.operation.QueryRequest) CreateResponse(ddf.catalog.operation.CreateResponse) Calendar(java.util.Calendar) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) 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) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) DefaultPosition(org.geotools.temporal.object.DefaultPosition) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Aggregations

DefaultInstant (org.geotools.temporal.object.DefaultInstant)10 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)10 DefaultPosition (org.geotools.temporal.object.DefaultPosition)10 Instant (org.opengis.temporal.Instant)8 Period (org.opengis.temporal.Period)8 Filter (org.opengis.filter.Filter)5 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)3 QueryImpl (ddf.catalog.operation.impl.QueryImpl)3 Date (java.util.Date)3 Expression (org.opengis.filter.expression.Expression)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 SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)2 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)2 CreateResponse (ddf.catalog.operation.CreateResponse)2 QueryRequest (ddf.catalog.operation.QueryRequest)2 QueryResponse (ddf.catalog.operation.QueryResponse)2 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)2