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();
}
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();
}
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);
}
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);
}
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);
}
Aggregations