Search in sources :

Example 26 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project teiid by teiid.

the class MongoDBSelectVisitor method buildGeoNearFunction.

private DBObject buildGeoNearFunction(Function function) throws TranslatorException {
    List<Expression> args = function.getParameters();
    // Column Name
    int paramIndex = 0;
    ColumnDetail column = getExpressionAlias(args.get(paramIndex++));
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.push(column.documentFieldName);
    builder.push(function.getName());
    append(args.get(paramIndex++));
    Object object = this.onGoingExpression.pop();
    if (object instanceof GeometryType) {
        convertGeometryToJson(builder, (GeometryType) object);
    } else {
        // $NON-NLS-1$
        builder.push("$geometry");
        // $NON-NLS-1$
        builder.add("type", SpatialType.Point.name());
        // walk the co-ordinates
        BasicDBList coordinates = new BasicDBList();
        coordinates.add(object);
        // $NON-NLS-1$
        builder.add("coordinates", coordinates);
    }
    // maxdistance
    append(args.get(paramIndex++));
    BasicDBObjectBuilder b = builder.pop();
    // $NON-NLS-1$
    b.add("$maxDistance", this.onGoingExpression.pop());
    if (this.executionFactory.getVersion().compareTo(MongoDBExecutionFactory.TWO_6) >= 0) {
        // mindistance
        append(args.get(paramIndex++));
        // $NON-NLS-1$
        b.add("$minDistance", this.onGoingExpression.pop());
    }
    return builder.get();
}
Also used : GeometryType(org.teiid.core.types.GeometryType) BasicDBList(com.mongodb.BasicDBList) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 27 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project teiid by teiid.

the class MongoDBSelectVisitor method buildGeoFunction.

private DBObject buildGeoFunction(Function function) throws TranslatorException {
    List<Expression> args = function.getParameters();
    // Column Name
    int paramIndex = 0;
    ColumnDetail column = getExpressionAlias(args.get(paramIndex++));
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.push(column.documentFieldName);
    builder.push(function.getName());
    append(args.get(paramIndex++));
    Object object = this.onGoingExpression.pop();
    if (object instanceof GeometryType) {
        convertGeometryToJson(builder, (GeometryType) object);
    } else {
        // Type: Point, LineString, Polygon..
        SpatialType type = SpatialType.valueOf((String) object);
        append(args.get(paramIndex++));
        // $NON-NLS-1$
        builder.push("$geometry");
        // $NON-NLS-1$
        builder.add("type", type.name());
        // walk the co-ordinates
        BasicDBList coordinates = new BasicDBList();
        coordinates.add(this.onGoingExpression.pop());
        // $NON-NLS-1$
        builder.add("coordinates", coordinates);
    }
    return builder.get();
}
Also used : GeometryType(org.teiid.core.types.GeometryType) BasicDBList(com.mongodb.BasicDBList) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 28 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project records-management by Alfresco.

the class PrepareRMSite method processEvent.

/**
 * @see org.alfresco.bm.event.AbstractEventProcessor#processEvent(org.alfresco.bm.event.Event)
 */
@Override
protected EventResult processEvent(Event event) throws Exception {
    StringBuilder msg = new StringBuilder("Preparing Records Management: \n");
    List<Event> events = new ArrayList<Event>(10);
    UserModel userModel = new UserModel(getUsername(), getPassword());
    // authenticate with provided credentials and verify that they are valid
    restCoreAPI.authenticateUser(userModel);
    restCoreAPI.withCoreAPI().usingAuthUser().getPerson();
    String statusCode = restCoreAPI.getStatusCode();
    if (HttpStatus.valueOf(Integer.parseInt(statusCode)) != HttpStatus.OK) {
        return new EventResult("Provided RM Site Creator does not exist, or provided credentials are not valid.", false);
    }
    UserData rmAdmin = userDataService.findUserByUsername(getUsername());
    if (rmAdmin == null) {
        rmAdmin = new UserData();
        rmAdmin.setCreationState(Created);
        rmAdmin.setDomain(RM_SITE_DOMAIN);
        rmAdmin.setUsername(getUsername());
        rmAdmin.setPassword(getPassword());
        userDataService.createNewUser(rmAdmin);
    } else {
        // Check for creation
        if (rmAdmin.getCreationState() != Created) {
            userDataService.setUserCreationState(getUsername(), Created);
            msg.append("   Updating user " + getUsername() + " state to created.\n");
        }
    }
    SiteData rmSite = siteDataService.getSite(RM_SITE_ID);
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.add(FIELD_SITE_ID, RM_SITE_ID).add(FIELD_SITE_MANAGER_NAME, getUsername()).add(FIELD_SITE_MANAGER_PASSWORD, getPassword());
    boolean existsRMSite = restAPIFactory.getRMSiteAPI(userModel).existsRMSite();
    // RM site exists and it is loaded in MongoDB
    if (existsRMSite && rmSite != null && rmSite.getCreationState() == Created) {
        return new EventResult("RM Site already created, continue loading data.", new Event(getEventNameContinueLoadingData(), null));
    }
    // RM site exists and it is not loaded in MongoDB
    if (existsRMSite && rmSite == null) {
        builder.add(FIELD_ONLY_DB_LOAD, true);
        DBObject data = builder.get();
        events.add(new Event(getEventNameLoadRMSiteIntoDB(), data));
    }
    // RM site does not exist and will be created
    if (!existsRMSite) {
        DBObject data = builder.get();
        events.add(new Event(getEventNameRMSitePrepared(), data));
    }
    // Done
    return new EventResult(msg.toString(), events);
}
Also used : UserModel(org.alfresco.utility.model.UserModel) SiteData(org.alfresco.bm.site.SiteData) EventResult(org.alfresco.bm.event.EventResult) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) UserData(org.alfresco.bm.user.UserData) ArrayList(java.util.ArrayList) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject)

Example 29 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project records-management by Alfresco.

the class BaseMongoService method createMongoIndex.

/**
 * Utility method that creates a Mongo DB index
 *
 * @param indexName  the name of the index to create
 * @param unique  whether the index is unique. A unique index causes MongoDB to reject all documents
 *                that contain a duplicate value for the indexed field.
 * @param fields  the fields to add in the compound index.
 */
protected void createMongoIndex(String indexName, boolean unique, List<String> fields) {
    BasicDBObjectBuilder keysBuilder = BasicDBObjectBuilder.start();
    for (String field : fields) {
        keysBuilder.add(field, INDEX_SORT_ASSCENDING);
    }
    DBObject options = BasicDBObjectBuilder.start().add("name", indexName).add("unique", unique).get();
    collection.createIndex(keysBuilder.get(), options);
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject)

Example 30 with BasicDBObjectBuilder

use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.

the class ClusterEventPeriodicalTest method testRun.

@Test
public void testRun() throws Exception {
    DBObject event = new BasicDBObjectBuilder().add("timestamp", TIME.getMillis()).add("producer", "TEST-PRODUCER").add("consumers", Collections.emptyList()).add("event_class", SimpleEvent.class.getCanonicalName()).add("payload", ImmutableMap.of("payload", "test")).get();
    @SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(ClusterEventPeriodical.COLLECTION_NAME);
    collection.save(event);
    assertThat(collection.count()).isEqualTo(1L);
    clusterEventPeriodical.run();
    assertThat(collection.count()).isEqualTo(1L);
    @SuppressWarnings("unchecked") final List<String> consumers = (List<String>) collection.findOne().get("consumers");
    assertThat(consumers).containsExactly(nodeId.toString());
    verify(serverEventBus, times(1)).post(new SimpleEvent("test"));
    verify(clusterEventBus, never()).post(event);
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) BasicDBList(com.mongodb.BasicDBList) List(java.util.List) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

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