List of usage examples for org.joda.time DateTime parse
@FromString public static DateTime parse(String str)
From source file:org.apache.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer.java
License:Apache License
/** * parse the literal dates from the object of a statement. * * @param statement/*www . ja v a2 s .c o m*/ * @param outputDateTimes */ private void extractDateTime(final Statement statement, final DateTime[] outputDateTimes) { if (!(statement.getObject() instanceof Literal)) { throw new RuntimeException("Statement's object must be a literal: " + statement); } // throws IllegalArgumentException NumberFormatException if can't parse String logThis = null; final Literal literalValue = (Literal) statement.getObject(); // First attempt to parse a interval in the form "[date1,date2]" final Matcher matcher = Pattern.compile("\\[(.*)\\,(.*)\\].*").matcher(literalValue.stringValue()); if (matcher.find()) { try { // Got a datetime pair, parse into an interval. outputDateTimes[0] = new DateTime(matcher.group(1)); outputDateTimes[1] = new DateTime(matcher.group(2)); return; } catch (final java.lang.IllegalArgumentException e) { logThis = e.getMessage() + " " + logThis; outputDateTimes[0] = null; outputDateTimes[1] = null; } } try { final XMLGregorianCalendar calendarValue = literalValue.calendarValue(); outputDateTimes[0] = new DateTime(calendarValue.toGregorianCalendar()); outputDateTimes[1] = null; return; } catch (final java.lang.IllegalArgumentException e) { logThis = e.getMessage(); } // Try again using Joda Time DateTime.parse() try { outputDateTimes[0] = DateTime.parse(literalValue.stringValue()); outputDateTimes[1] = null; //System.out.println(">>>>>>>Joda parsed: "+literalValue.stringValue()); return; } catch (final java.lang.IllegalArgumentException e) { logThis = e.getMessage() + " " + logThis; } logger.warn("TemporalIndexer is unable to parse the date/time from statement=" + statement.toString() + " " + logThis); return; }
From source file:org.apache.rya.indexing.geotemporal.mongo.GeoTemporalMongoDBStorageStrategy.java
License:Apache License
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."); }//from www . j a v a 2s. co m } 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[] {}); }
From source file:org.apache.rya.indexing.geotemporal.mongo.MongoGeoTemporalIndexer.java
License:Apache License
@Override public void deleteStatement(final RyaStatement statement) throws IOException { requireNonNull(statement);//from w w w . j a v a2s . c o m 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); } }
From source file:org.apache.rya.indexing.geotemporal.mongo.MongoGeoTemporalIndexer.java
License:Apache License
private void updateEvent(final RyaURI subject, final RyaStatement statement) throws IndexingException, ParseException { 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()) { updated = Event.builder().setSubject(subject); } else {/*from www . j ava 2 s .c om*/ updated = Event.builder(old.get()); } 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)) { //is geo try { final Statement geoStatement = RyaToRdfConversions.convertStatement(statement); final Geometry geometry = GeoParseUtils.getGeometry(geoStatement, new GmlParser()); updated.setGeometry(geometry); } catch (final ParseException e) { LOG.error(e.getMessage(), e); } } 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); updated.setTemporalInterval(interval); } else { final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime)); updated.setTemporalInstant(instant); } } return Optional.of(updated.build()); }); }
From source file:org.apache.sqoop.shell.utils.ConfigFiller.java
License:Apache License
private static DateTime parseDateTime(String value) { DateTime dt = null;/*from w ww . j a va 2 s .co m*/ try { dt = new DateTime(Long.parseLong(value)); } catch (NumberFormatException nfe) { // value is not numeric string try { dt = DateTime.parse(value); } catch (IllegalArgumentException iae) { // value is not valid ISO8601 format } } return dt; }
From source file:org.apache.streams.converter.LineReadWriteUtil.java
License:Apache License
/** * parseTs//from w w w.j av a 2s .c om * @param field - dateTime string to be parsed * @return {@link DateTime} */ public DateTime parseTs(String field) { DateTime timestamp = null; try { long longts = Long.parseLong(field); timestamp = new DateTime(longts); } catch (Exception e1) { try { timestamp = DateTime.parse(field); } catch (Exception e2) { try { timestamp = MAPPER.readValue(field, DateTime.class); } catch (Exception e3) { LOGGER.warn("Could not parse timestamp:{} ", field); } } } return timestamp; }
From source file:org.apache.streams.data.util.MoreoverUtils.java
License:Apache License
public static Activity convert(Article article) { Activity activity = new Activity(); Source source = article.getSource(); activity.setActor(convert(article.getAuthor(), source.getName())); activity.setProvider(convert(source)); activity.setTarget(convertTarget(source)); activity.setObject(convertObject(article)); activity.setPublished(DateTime.parse(article.getPublishedDate())); activity.setContent(article.getContent()); activity.setTitle(article.getTitle()); activity.setVerb("posted"); fixActivityId(activity);/* w w w .ja va 2 s . c o m*/ addLocationExtension(activity, source); addLanguageExtension(activity, article); activity.setLinks(convertLinks(article)); return activity; }
From source file:org.apache.streams.data.util.MoreoverUtils.java
License:Apache License
public static ActivityObject convertObject(Article article) { ActivityObject object = new ActivityObject(); object.setContent(article.getContent()); object.setSummary(article.getTitle()); object.setUrl(article.getOriginalUrl()); object.setObjectType(article.getDataFormat()); String type = article.getDataFormat().equals("text") ? "article" : article.getDataFormat(); object.setId(getObjectId(getProviderID(article.getSource().getFeed()), type, article.getId())); object.setPublished(DateTime.parse(article.getPublishedDate())); return object; }
From source file:org.apache.streams.moreover.MoreoverUtils.java
License:Apache License
/** * convert article into Activity./* w w w . jav a2 s . c o m*/ * @param article article * @return Activity */ public static Activity convert(Article article) { Activity activity = new Activity(); Source source = article.getSource(); activity.setActor(convert(article.getAuthor(), source.getName())); activity.setProvider(convert(source)); activity.setTarget(convertTarget(source)); activity.setObject(convertObject(article)); activity.setPublished(DateTime.parse(article.getPublishedDate())); activity.setContent(article.getContent()); activity.setTitle(article.getTitle()); activity.setVerb("posted"); fixActivityId(activity); addLocationExtension(activity, source); addLanguageExtension(activity, article); activity.setLinks(convertLinks(article)); return activity; }
From source file:org.apache.streams.moreover.MoreoverUtils.java
License:Apache License
/** * convertObject.//w w w. j av a 2 s . co m * @param article article * @return ActivityObject $.object */ public static ActivityObject convertObject(Article article) { ActivityObject object = new ActivityObject(); object.setContent(article.getContent()); object.setSummary(article.getTitle()); object.setUrl(article.getOriginalUrl()); object.setObjectType(article.getDataFormat()); String type = article.getDataFormat().equals("text") ? "article" : article.getDataFormat(); object.setId(getObjectId(getProviderId(article.getSource().getFeed()), type, article.getId())); object.setPublished(DateTime.parse(article.getPublishedDate())); return object; }