org.opengis.temporal.Period Java Examples

The following examples show how to use org.opengis.temporal.Period. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testTContains() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    TContains filter = ff.tcontains(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("range", ImmutableMap.of("dateAttr", 
            ImmutableMap.of("gt", "1970-07-19T01:02:03.456Z", "lt", "1970-07-19T07:08:09.101Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #2
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testEndedBy() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    EndedBy filter = ff.endedBy(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("term",
            ImmutableMap.of("dateAttr", "1970-07-19T07:08:09.101Z"));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #3
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testEnds() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    Ends filter = ff.ends(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("term",
            ImmutableMap.of("dateAttr", "1970-07-19T07:08:09.101Z"));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #4
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDuring() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    During filter = ff.during(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("range", ImmutableMap.of("dateAttr", 
            ImmutableMap.of("gt", "1970-07-19T01:02:03.456Z", "lt", "1970-07-19T07:08:09.101Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #5
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBegunBy() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    BegunBy filter = ff.begunBy(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("term",
            ImmutableMap.of("dateAttr", "1970-07-19T01:02:03.456Z"));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #6
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBegins() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    Begins filter = ff.begins(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("term",
            ImmutableMap.of("dateAttr", "1970-07-19T01:02:03.456Z"));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #7
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBeforeFilterPeriodSwapped() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    org.opengis.filter.temporal.Before filter = ff.before(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("range",
            ImmutableMap.of("dateAttr", ImmutableMap.of("gt", "1970-07-19T07:08:09.101Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #8
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBeforeFilterPeriod() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    org.opengis.filter.temporal.Before filter = ff.before(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("range",
            ImmutableMap.of("dateAttr", ImmutableMap.of("lt", "1970-07-19T01:02:03.456Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #9
Source File: CriteriaVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Object visit(During during, Object userData) {
	String propertyName = getPropertyName(during.getExpression1());
	String finalName = parsePropertyName(propertyName, userData);
	Object literal = getLiteralValue(during.getExpression2());
	if (literal instanceof Period) {
		Period p = (Period) literal;
		Date begin = p.getBeginning().getPosition().getDate();
		Date end = p.getEnding().getPosition().getDate();
		return Restrictions.between(finalName, begin, end);
	} else {
		throw new UnsupportedOperationException("visit(Object userData)");
	}
}
 
Example #10
Source File: TimeUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * @param startTimeMillis start time (inclusive)
 * @param endTimeMillis end time (exclusive)
 * @param singleTimeField
 * @return the during filter
 */
public static Filter toDuringFilter(
    final long startTimeMillis,
    final long endTimeMillis,
    final String singleTimeField) {
  final FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2();
  final Position ip1 = new DefaultPosition(new Date(startTimeMillis - 1));
  final Position ip2 = new DefaultPosition(new Date(endTimeMillis));
  final Period period = new DefaultPeriod(new DefaultInstant(ip1), new DefaultInstant(ip2));
  return factory.during(factory.property(singleTimeField), factory.literal(period));
}
 
Example #11
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testTEqualsWithPeriod() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    TEquals filter = ff.tequals(ff.property("dateAttr"), ff.literal(period));

    builder.visit(filter, null);
}
 
Example #12
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testBeginsWithSwap() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);

    Begins filter = ff.begins(ff.literal(period), ff.property("dateAttr"));

    builder.visit(filter, null);
}
 
Example #13
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAfterFilterPeriodSwapped() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);
    After filter = ff.after(ff.literal(period), ff.property("dateAttr"));
    Map<String,Object> expected = ImmutableMap.of("range",
            ImmutableMap.of("dateAttr", ImmutableMap.of("lt", "1970-07-19T01:02:03.456Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #14
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAfterFilterPeriod() throws ParseException {
    Date date1 = dateFormat.parse("1970-07-19T01:02:03.456Z");
    Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
    Date date2 = dateFormat.parse("1970-07-19T07:08:09.101Z");
    Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
    Period period = new DefaultPeriod(temporalInstant, temporalInstant2);
    After filter = ff.after(ff.property("dateAttr"), ff.literal(period));
    Map<String,Object> expected = ImmutableMap.of("range",
            ImmutableMap.of("dateAttr", ImmutableMap.of("gt", "1970-07-19T07:08:09.101Z")));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #15
Source File: ElasticTemporalFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTContains() throws Exception {
    init();
    Period period = period("2004-19-06 03:44:56", "2004-20-06 03:44:58");
    FilterFactory ff = dataStore.getFilterFactory();
    Filter f = ff.tcontains(ff.literal(period), ff.property("installed_tdt"));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
}
 
Example #16
Source File: ElasticTemporalFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDuring() throws Exception {
    init();
    Period period = period("2004-19-06 03:44:56", "2004-20-06 03:44:58");
    FilterFactory ff = dataStore.getFilterFactory();
    Filter f = ff.during(ff.property("installed_tdt"), ff.literal(period));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
}
 
Example #17
Source File: ElasticTemporalFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEndedBy() throws Exception {
    init();
    Period period = period("2004-11-06 03:44:56", "2004-20-06 03:44:56");
    FilterFactory ff = dataStore.getFilterFactory();
    Filter f = ff.endedBy(ff.literal(period), ff.property("installed_tdt"));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
}
 
Example #18
Source File: ElasticTemporalFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEnds() throws Exception {
    init();
    Period period = period("2002-20-06 03:44:56", "2004-20-06 03:44:56");
    FilterFactory ff = dataStore.getFilterFactory();
    Filter f = ff.ends(ff.property("installed_tdt"), ff.literal(period));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
}
 
Example #19
Source File: ElasticTemporalFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBegunBy() throws Exception {
    init();
    Period period = period("2004-20-06 03:44:56", "2014-22-06 03:44:56");
    FilterFactory ff = dataStore.getFilterFactory();
    Filter f = ff.begunBy(ff.literal(period), ff.property("installed_tdt"));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
}
 
Example #20
Source File: ElasticTemporalFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBegins() throws Exception {
    init();
    Period period = period("2004-20-06 03:44:56", "2014-22-06 03:44:56");
    FilterFactory ff = dataStore.getFilterFactory();
    Filter f = ff.begins(ff.property("installed_tdt"), ff.literal(period));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
}
 
Example #21
Source File: ElasticTemporalFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBeforeInterval() throws Exception {
    init();
    Period period = period("2000-12-11 00:00:00", "2011-05-21 00:00:00");
    FilterFactory ff = dataStore.getFilterFactory();
    Filter f = ff.before(ff.property("installed_tdt"), ff.literal(period));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
}
 
Example #22
Source File: ElasticTemporalFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAfterInterval() throws Exception {
    init();
    Period period = period("2011-21-05 00:00:00", "2011-15-09 00:00:00");
    FilterFactory ff = dataStore.getFilterFactory();
    Filter f = ff.after(ff.property("installed_tdt"), ff.literal(period));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(4, features.size());
}
 
Example #23
Source File: ElasticTestSupport.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
Period period(String d1, String d2) throws ParseException {
    return new DefaultPeriod(instant(d1), instant(d2));
}
 
Example #24
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
private void visitEnd(Period p, Object extraData) {
    filterFactory.literal(p.getEnding().getPosition().getDate()).accept(this, extraData);
}
 
Example #25
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
private void visitBegin(Period p, Object extraData) {
    filterFactory.literal(p.getBeginning().getPosition().getDate()).accept(this, extraData);
}