use of com.mongodb.BasicDBObjectBuilder in project morphia by mongodb.
the class StandardGeoFieldCriteria method addTo.
@Override
public void addTo(final DBObject obj) {
BasicDBObjectBuilder query;
FilterOperator operator = getOperator();
switch(operator) {
case NEAR:
if (maxDistanceMeters != null) {
geometryAsDBObject.put("$maxDistance", maxDistanceMeters);
}
query = BasicDBObjectBuilder.start(NEAR.val(), geometryAsDBObject);
break;
case GEO_WITHIN:
case INTERSECTS:
query = BasicDBObjectBuilder.start(operator.val(), geometryAsDBObject);
if (crs != null) {
((DBObject) geometryAsDBObject.get("$geometry")).put("crs", new NamedCoordinateReferenceSystemConverter().encode(crs));
}
break;
default:
throw new UnsupportedOperationException(String.format("Operator %s not supported for geo-query", operator.val()));
}
obj.put(getField(), query.get());
}
use of com.mongodb.BasicDBObjectBuilder in project incubator-rya by apache.
the class MongoEventStorage method search.
@Override
public Collection<Event> search(final Optional<RyaURI> subject, final Optional<Collection<IndexingExpr>> geoFilters, final Optional<Collection<IndexingExpr>> temporalFilters) throws EventStorageException {
requireNonNull(subject);
try {
final Collection<IndexingExpr> geos = (geoFilters.isPresent() ? geoFilters.get() : new ArrayList<>());
final Collection<IndexingExpr> tempos = (temporalFilters.isPresent() ? temporalFilters.get() : new ArrayList<>());
final DBObject filterObj = queryAdapter.getFilterQuery(geos, tempos);
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(filterObj.toMap());
if (subject.isPresent()) {
builder.append(EventDocumentConverter.SUBJECT, subject.get().getData());
}
final MongoCursor<Document> results = mongo.getDatabase(ryaInstanceName).getCollection(COLLECTION_NAME).find(BsonDocument.parse(builder.get().toString())).iterator();
final List<Event> events = new ArrayList<>();
while (results.hasNext()) {
events.add(EVENT_CONVERTER.fromDocument(results.next()));
}
return events;
} catch (final MongoException | DocumentConverterException | GeoTemporalIndexException e) {
throw new EventStorageException("Could not get the Event.", e);
}
}
use of com.mongodb.BasicDBObjectBuilder in project incubator-rya by apache.
the class GeoTemporalMongoDBStorageStrategy method serialize.
@Override
public DBObject serialize(final RyaStatement ryaStatement) {
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("_id", ryaStatement.getSubject().hashCode());
final URI 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) {
builder.add(GEO_KEY, geoStrategy.getCorrespondingPoints(geo));
} else {
builder.add(GEO_KEY, geoStrategy.getDBPoint(geo));
}
} catch (final ParseException e) {
LOG.error("Could not create geometry for statement " + ryaStatement, e);
return null;
}
} else {
builder.add(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData()));
}
return builder.get();
}
use of com.mongodb.BasicDBObjectBuilder in project incubator-rya by apache.
the class DocumentVisibilityAdapter method toDBObject.
/**
* Serializes a {@link DocumentVisibility} to a MongoDB {@link DBObject}.
* @param documentVisibility the {@link DocumentVisibility} to be
* serialized.
* @return The MongoDB {@link DBObject}.
*/
public static BasicDBObject toDBObject(final DocumentVisibility documentVisibility) {
DocumentVisibility dv;
if (documentVisibility == null) {
dv = MongoDbRdfConstants.EMPTY_DV;
} else {
dv = documentVisibility;
}
Object[] dvArray = null;
try {
dvArray = DocumentVisibilityUtil.toMultidimensionalArray(dv);
} catch (final DocumentVisibilityConversionException e) {
log.error("Unable to convert document visibility");
}
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
builder.add(DOCUMENT_VISIBILITY_KEY, dvArray);
return (BasicDBObject) builder.get();
}
use of com.mongodb.BasicDBObjectBuilder in project incubator-rya by apache.
the class MongoDetailsAdapter method toDBObject.
private static DBObject toDBObject(final PCJIndexDetails pcjIndexDetails) {
requireNonNull(pcjIndexDetails);
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
// Is Enabled
builder.add(PCJ_ENABLED_KEY, pcjIndexDetails.isEnabled());
// Add the PCJDetail objects.
final List<DBObject> pcjDetailsList = new ArrayList<>();
for (final PCJDetails pcjDetails : pcjIndexDetails.getPCJDetails().values()) {
pcjDetailsList.add(toDBObject(pcjDetails));
}
builder.add(PCJ_PCJS_KEY, pcjDetailsList.toArray());
return builder.get();
}
Aggregations