use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.
the class GeoTemporalMongoDBStorageStrategy method getTemporalObjs.
private DBObject[] getTemporalObjs(final Collection<IndexingExpr> temporalFilters) {
final List<DBObject> objs = new ArrayList<>();
temporalFilters.forEach(filter -> {
final TemporalPolicy policy = TemporalPolicy.fromURI(filter.getFunction());
final String timeStr = ((Value) filter.getArguments()[0]).stringValue();
final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(timeStr);
if (matcher.find()) {
final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(timeStr);
if (policy == TemporalPolicy.INSTANT_AFTER_INSTANT || policy == TemporalPolicy.INSTANT_BEFORE_INSTANT || policy == TemporalPolicy.INSTANT_EQUALS_INSTANT) {
if (interval == null) {
LOG.error("Cannot perform temporal interval based queries on an instant.");
}
}
objs.add(getTemporalObject(interval, policy));
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(timeStr));
if (policy != TemporalPolicy.INSTANT_AFTER_INSTANT && policy != TemporalPolicy.INSTANT_BEFORE_INSTANT && policy != TemporalPolicy.INSTANT_EQUALS_INSTANT) {
LOG.error("Cannot perform temporal instant based queries on an interval.");
}
objs.add(getTemporalObject(instant, policy));
}
});
return objs.toArray(new DBObject[] {});
}
use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.
the class MongoGeoTemporalIndexer method deleteStatement.
@Override
public void deleteStatement(final RyaStatement statement) throws IOException {
requireNonNull(statement);
final RyaURI subject = statement.getSubject();
try {
final EventStorage eventStore = events.get();
checkState(events != null, "Must set this indexers configuration before storing statements.");
new EventUpdater(eventStore).update(subject, old -> {
final Event.Builder updated;
if (!old.isPresent()) {
return Optional.empty();
} else {
updated = Event.builder(old.get());
}
final Event currentEvent = updated.build();
final URI pred = statement.getObject().getDataType();
if ((pred.equals(GeoConstants.GEO_AS_WKT) || pred.equals(GeoConstants.GEO_AS_GML) || pred.equals(GeoConstants.XMLSCHEMA_OGC_WKT) || pred.equals(GeoConstants.XMLSCHEMA_OGC_GML)) && currentEvent.getGeometry().isPresent()) {
// is geo and needs to be removed.
try {
if (currentEvent.getGeometry().get().equals(GeoParseUtils.getGeometry(RyaToRdfConversions.convertStatement(statement), new GmlParser()))) {
updated.setGeometry(null);
}
} catch (final Exception e) {
LOG.debug("Unable to parse the stored geometry.");
}
} else {
// is time
final String dateTime = statement.getObject().getData();
final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(dateTime);
if (matcher.find()) {
final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(dateTime);
if (currentEvent.getInterval().get().equals(interval)) {
updated.setTemporalInterval(null);
}
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
if (currentEvent.getInstant().get().equals(instant)) {
updated.setTemporalInstant(null);
}
}
}
return Optional.of(updated.build());
});
} catch (final IndexingException e) {
throw new IOException("Failed to update the Entity index.", e);
}
}
use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.
the class TemporalInstantTest method zoneTestTest.
@Test
public void zoneTestTest() throws Exception {
// arbitrary zone, BRST=Brazil, better if not local.
final String ZONETestDateInBRST = "2014-12-31T23:59:59-02:00";
final String ZONETestDateInZulu = "2015-01-01T01:59:59Z";
final String ZONETestDateInET = "2014-12-31T20:59:59-05:00";
TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(ZONETestDateInBRST));
Assert.assertEquals("Test our test Zulu, ET strings.", ZONETestDateInET, DateTime.parse(ZONETestDateInZulu).withZone(DateTimeZone.forID("-05:00")).toString(ISODateTimeFormat.dateTimeNoMillis()));
Assert.assertEquals("Test our test BRST,Zulu strings.", ZONETestDateInZulu, DateTime.parse(ZONETestDateInBRST).withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.dateTimeNoMillis()));
Assert.assertTrue("Key must be normalized to time zone Zulu: " + instant.getAsKeyString(), instant.getAsKeyString().endsWith("Z"));
Assert.assertEquals("Key must be normalized from BRST -02:00", ZONETestDateInZulu, instant.getAsKeyString());
Assert.assertArrayEquals(StringUtils.getBytesUtf8(instant.getAsKeyString()), instant.getAsKeyBytes());
Assert.assertTrue("Ignore original time zone.", !ZONETestDateInBRST.equals(instant.getAsReadable(DateTimeZone.forID("-07:00"))));
Assert.assertEquals("Use original time zone.", ZONETestDateInBRST, instant.getAsDateTime().toString(TemporalInstantRfc3339.FORMATTER));
Assert.assertEquals("Time at specified time zone.", ZONETestDateInET, instant.getAsReadable(DateTimeZone.forID("-05:00")));
instant = new TemporalInstantRfc3339(DateTime.parse(ZONETestDateInZulu));
Assert.assertEquals("expect a time with specified time zone.", ZONETestDateInET, instant.getAsReadable(DateTimeZone.forID("-05:00")));
}
use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.
the class TemporalInstantTest method constructorTest.
@Test
public void constructorTest() throws Exception {
TemporalInstant instant = new //
TemporalInstantRfc3339(//
2014, //
12, //
30, 12, 59, 59);
// YYYY-MM-DDThh:mm:ssZ
String stringTestDate01 = "2014-12-30T12:59:59Z";
Date dateTestDate01 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(stringTestDate01);
Assert.assertEquals(stringTestDate01, instant.getAsKeyString());
Assert.assertArrayEquals(StringUtils.getBytesUtf8(instant.getAsKeyString()), instant.getAsKeyBytes());
Assert.assertTrue("Key must be normalized to time zone Zulu", instant.getAsKeyString().endsWith("Z"));
// show the local time us.
// Warning, if test is run in the London, or Zulu time zone, this test will be same as above, with the Z.
// TimeZone.setDefault(TimeZone.getTimeZone("UTC")); // this does not affect the library, don't use.
String stringLocalTestDate01 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(dateTestDate01);
// for ET, will be: "2014-12-30T07:59:59-05:00"
// instant.getAsDateTime().withZone(null);
// System.out.println("===System.getProperty(user.timezone)="+System.getProperty("user.timezone")); //=ET
// System.out.println("===============TimeZone.getDefault()="+TimeZone.getDefault()); //=ET
// System.out.println("===========DateTimeZone.getDefault()="+DateTimeZone.getDefault()); //=UTC (wrong!)
// the timezone default gets set to UTC by some prior test, fix it here.
DateTimeZone newTimeZone = null;
try {
String id = System.getProperty("user.timezone");
if (id != null) {
newTimeZone = DateTimeZone.forID(id);
}
} catch (RuntimeException ex) {
// ignored
}
if (newTimeZone == null) {
newTimeZone = DateTimeZone.forTimeZone(TimeZone.getDefault());
}
DateTimeZone.setDefault(newTimeZone);
// null timezone means use the default:
Assert.assertEquals("Joda time library (actual) should use same local timezone as Java date (expected).", stringLocalTestDate01, instant.getAsReadable(null));
}
Aggregations