Search in sources :

Example 21 with BasicDBObjectBuilder

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());
}
Also used : NamedCoordinateReferenceSystemConverter(org.mongodb.morphia.geo.NamedCoordinateReferenceSystemConverter) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject)

Example 22 with BasicDBObjectBuilder

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);
    }
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) MongoException(com.mongodb.MongoException) ArrayList(java.util.ArrayList) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) DBObject(com.mongodb.DBObject) DocumentConverterException(org.apache.rya.indexing.entity.storage.mongo.DocumentConverter.DocumentConverterException) GeoTemporalIndexException(org.apache.rya.indexing.geotemporal.GeoTemporalIndexException) Event(org.apache.rya.indexing.geotemporal.model.Event) IndexingExpr(org.apache.rya.indexing.IndexingExpr)

Example 23 with BasicDBObjectBuilder

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();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) GmlParser(org.apache.rya.indexing.mongodb.geo.GmlParser) ParseException(com.vividsolutions.jts.io.ParseException) URI(org.openrdf.model.URI)

Example 24 with BasicDBObjectBuilder

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();
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DocumentVisibilityConversionException(org.apache.rya.mongodb.document.util.DocumentVisibilityConversionException) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 25 with BasicDBObjectBuilder

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();
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) ArrayList(java.util.ArrayList) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)

Aggregations

BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)44 DBObject (com.mongodb.DBObject)30 Test (org.junit.Test)21 DBCollection (com.mongodb.DBCollection)18 BasicDBObject (com.mongodb.BasicDBObject)12 ArrayList (java.util.ArrayList)7 BasicDBList (com.mongodb.BasicDBList)6 List (java.util.List)4 ResourceFieldSchema (org.apache.pig.ResourceSchema.ResourceFieldSchema)4 HiveTest (com.mongodb.hadoop.hive.HiveTest)3 IOException (java.io.IOException)3 Map (java.util.Map)3 MongoException (com.mongodb.MongoException)2 Configuration (org.apache.hadoop.conf.Configuration)2 JobConf (org.apache.hadoop.mapred.JobConf)2 InputSplit (org.apache.hadoop.mapreduce.InputSplit)2 ResourceSchema (org.apache.pig.ResourceSchema)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 BasicBSONObject (org.bson.BasicBSONObject)2 GeometryType (org.teiid.core.types.GeometryType)2