@Test public void serializeTest() { final Resource subject = VF.createIRI("foo:subj"); final Resource context = VF.createIRI("foo:context"); IRI predicate = GeoConstants.GEO_AS_WKT; Value object = VF.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); Statement statement = VF.createStatement(subject, predicate, object, context); RyaStatement ryaStatement = RdfToRyaConversions.convertStatement(statement); int expectedId = ryaStatement.getSubject().hashCode(); Document actual = adapter.serialize(ryaStatement); String expectedString = "{ " + "\"_id\" : " + expectedId + ", " + "\"location\" : { " + "\"coordinates\" : [ -77.03524 , 38.889468] , " + "\"type\" : \"Point\"" + "}" + "}"; Document expected = Document.parse(expectedString); assertEqualMongo(expected, actual); predicate = VF.createIRI("Property:event:time"); object = VF.createLiteral("2015-12-30T12:00:00Z"); statement = VF.createStatement(subject, predicate, object, context); ryaStatement = RdfToRyaConversions.convertStatement(statement); expectedId = ryaStatement.getSubject().hashCode(); actual = adapter.serialize(ryaStatement); expectedString = "{" +"_id : " + expectedId + ", " +"time: {" + "instant : {" +"\"$date\" : \"2015-12-30T12:00:00.000Z\"" + "}" + "}" + "}"; expected = Document.parse(expectedString); assertEqualMongo(expected, actual); predicate = VF.createIRI("Property:circa"); object = VF.createLiteral("[1969-12-31T19:00:00-05:00,1969-12-31T19:00:01-05:00]"); statement = VF.createStatement(subject, predicate, object, context); ryaStatement = RdfToRyaConversions.convertStatement(statement); expectedId = ryaStatement.getSubject().hashCode(); actual = adapter.serialize(ryaStatement); expectedString = "{" +"_id : " + expectedId + ", " +"time: {" + "start : {" +"\"$date\" : \"1970-01-01T00:00:00.000Z\"" + "}," + "end : {" +"\"$date\" : \"1970-01-01T00:00:01.000Z\"" + "}" + "}" + "}"; expected = Document.parse(expectedString); assertEqualMongo(expected, actual); }
@Override public Document serialize(final RyaStatement ryaStatement) { final Document doc = new Document("_id", ryaStatement.getSubject().hashCode()); final IRI obj = ryaStatement.getObject().getDataType(); if(obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) { try { final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser()); if (geo.getNumPoints() > 1) { doc.append(GEO_KEY, geoStrategy.getCorrespondingPoints(geo)); } else { doc.append(GEO_KEY, geoStrategy.getDBPoint(geo)); } } catch (final ParseException e) { LOG.error("Could not create geometry for statement " + ryaStatement, e); return null; } } else { doc.append(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData())); } return doc; }
GeoTemporalMongoDBStorageStrategy extends IndexingMongoDBStorageStrategy { @Override public Document serialize(final RyaStatement ryaStatement) { final Document doc = new Document("_id", ryaStatement.getSubject().hashCode()); final IRI obj = ryaStatement.getObject().getDataType(); if(obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) { try { final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser()); if (geo.getNumPoints() > 1) { doc.append(GEO_KEY, geoStrategy.getCorrespondingPoints(geo)); } else { doc.append(GEO_KEY, geoStrategy.getDBPoint(geo)); } } catch (final ParseException e) { LOG.error("Could not create geometry for statement " + ryaStatement, e); return null; } } else { doc.append(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData())); } return doc; } }
GeoTemporalMongoDBStorageStrategy extends IndexingMongoDBStorageStrategy { @Override public Document serialize(final RyaStatement ryaStatement) { final Document doc = new Document("_id", ryaStatement.getSubject().hashCode()); final IRI obj = ryaStatement.getObject().getDataType(); if(obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) { try { final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser()); if (geo.getNumPoints() > 1) { doc.append(GEO_KEY, geoStrategy.getCorrespondingPoints(geo)); } else { doc.append(GEO_KEY, geoStrategy.getDBPoint(geo)); } } catch (final ParseException e) { LOG.error("Could not create geometry for statement " + ryaStatement, e); return null; } } else { doc.append(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData())); } return doc; } GeoTemporalMongoDBStorageStrategy(); }
GeoTemporalMongoDBStorageStrategy extends IndexingMongoDBStorageStrategy { @Override public Document serialize(final RyaStatement ryaStatement) { final Document doc = new Document("_id", ryaStatement.getSubject().hashCode()); final IRI obj = ryaStatement.getObject().getDataType(); if(obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) { try { final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser()); if (geo.getNumPoints() > 1) { doc.append(GEO_KEY, geoStrategy.getCorrespondingPoints(geo)); } else { doc.append(GEO_KEY, geoStrategy.getDBPoint(geo)); } } catch (final ParseException e) { LOG.error("Could not create geometry for statement " + ryaStatement, e); return null; } } else { doc.append(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData())); } return doc; } GeoTemporalMongoDBStorageStrategy(); @Override void createIndices(final MongoCollection<Document> coll); Document getFilterQuery(final Collection<IndexingExpr> geoFilters, final Collection<IndexingExpr> temporalFilters); @Override Document serialize(final RyaStatement ryaStatement); }
GeoTemporalMongoDBStorageStrategy extends IndexingMongoDBStorageStrategy { @Override public Document serialize(final RyaStatement ryaStatement) { final Document doc = new Document("_id", ryaStatement.getSubject().hashCode()); final IRI obj = ryaStatement.getObject().getDataType(); if(obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) { try { final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser()); if (geo.getNumPoints() > 1) { doc.append(GEO_KEY, geoStrategy.getCorrespondingPoints(geo)); } else { doc.append(GEO_KEY, geoStrategy.getDBPoint(geo)); } } catch (final ParseException e) { LOG.error("Could not create geometry for statement " + ryaStatement, e); return null; } } else { doc.append(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData())); } return doc; } GeoTemporalMongoDBStorageStrategy(); @Override void createIndices(final MongoCollection<Document> coll); Document getFilterQuery(final Collection<IndexingExpr> geoFilters, final Collection<IndexingExpr> temporalFilters); @Override Document serialize(final RyaStatement ryaStatement);  }