use of com.mongodb.client.MongoCollection in project graylog2-server by Graylog2.
the class V20190127111728_MigrateWidgetFormatSettingsTest method testMigrationWithOneChartColorMapping.
@Test
@MongoDBFixtures("V20190127111728_MigrateWidgetFormatSettings.json")
public void testMigrationWithOneChartColorMapping() {
final BasicDBObject dbQuery1 = new BasicDBObject();
dbQuery1.put("_id", new ObjectId("5e2ee372b22d7970576b2eb3"));
final MongoCollection<Document> collection = mongoDB.mongoConnection().getMongoDatabase().getCollection("views");
migration.upgrade();
final FindIterable<Document> views = collection.find(dbQuery1);
final Document view1 = views.first();
@SuppressWarnings("unchecked") final List<Document> widgets1 = (List) view1.get("state", Document.class).get("2c67cc0f-c62e-47c1-8b70-e3198925e6bc", Document.class).get("widgets");
assertThat(widgets1.size()).isEqualTo(2);
Set<Document> aggregationWidgets = widgets1.stream().filter(w -> w.getString("type").equals("aggregation")).collect(Collectors.toSet());
assertThat(aggregationWidgets.size()).isEqualTo(1);
final Document aggregationWidget = aggregationWidgets.iterator().next();
final Document config = aggregationWidget.get("config", Document.class);
final Document formattingSettings = config.get("formatting_settings", Document.class);
@SuppressWarnings("unchecked") final List<Document> chartColors = (List) formattingSettings.get("chart_colors", List.class);
assertThat(chartColors.size()).isEqualTo(1);
final Document chartColor = chartColors.get(0);
assertThat(chartColor.getString("field_name")).isEqualTo("count()");
assertThat(chartColor.getString("chart_color")).isEqualTo("#e91e63");
}
use of com.mongodb.client.MongoCollection in project graylog2-server by Graylog2.
the class V20190304102700_MigrateMessageListStructureTest method testMigratingViewStructure.
@Test
@MongoDBFixtures("V20190304102700_MigrateMessageListStructureTest.json")
public void testMigratingViewStructure() {
final BasicDBObject dbQuery1 = new BasicDBObject();
dbQuery1.put("_id", new ObjectId("58458e442f857c314491344e"));
final MongoCollection<Document> collection = mongodb.mongoConnection().getMongoDatabase().getCollection("views");
migration.upgrade();
final FindIterable<Document> views = collection.find(dbQuery1);
final Document view1 = views.first();
@SuppressWarnings("unchecked") final List<Document> widgets1 = (List) view1.get("state", Document.class).get("a2a804b7-27cf-4cac-8015-58d9a9640d33", Document.class).get("widgets");
assertThat(widgets1.size()).isEqualTo(2);
assertThat(widgets1.stream().filter(widget -> widget.getString("type").equals("messages")).count()).isEqualTo(1);
assertThat(widgets1.stream().filter(widget -> widget.getString("type").equals("messages")).allMatch((widget) -> {
final Document config = widget.get("config", Document.class);
@SuppressWarnings("unchecked") final List<String> fields = (List) config.get("fields");
final boolean startWithTimestamp = fields.get(0).contains("timestamp");
final boolean showMessageRow = config.getBoolean("show_message_row");
return startWithTimestamp && showMessageRow;
})).isTrue();
final BasicDBObject dbQuery2 = new BasicDBObject();
dbQuery2.put("_id", new ObjectId("58458e442f857c314491344f"));
final FindIterable<Document> views2 = collection.find(dbQuery2);
final Document view2 = views2.first();
final Document states = view2.get("state", Document.class);
assertThat(states.values().size()).isEqualTo(13);
assertThat(states.keySet()).containsExactly("7c042319-530a-41b9-9dbb-9676fb1da1a4", "9e5144be-a445-4289-a4cc-0f55142524bc", "c13b2482-60e7-4b1e-98c9-0df8d6da8230", "5adc9297-dfc8-4fd9-b422-cbb097715a62", "ade8c853-503c-407f-b125-efbe2d368973", "cc2bf983-b398-4295-bf01-1c10ed1a97e1", "64feccae-9447-40ef-a401-79a7972078a2", "7c7e04c6-f9f0-495c-91cc-865f60687f8c", "eeaa8838-616f-40c0-88c0-1059ac64f37e", "91c6f8c9-024c-48ec-a869-90548fad218a", "955a71f2-673a-4e1c-a99f-ef97b1b4ae71", "343ff7b6-4554-49d4-bc0b-1339fdc5dac0", "7a84d053-e40a-48c1-a433-97521f7ce7ef");
states.values().forEach(state -> {
@SuppressWarnings("unchecked") final List<Document> widgets2 = (List) ((Document) state).get("widgets");
assertThat(widgets2.stream().filter(widget -> widget.getString("type").equals("messages")).count()).isGreaterThan(0);
widgets2.stream().filter(widget -> widget.getString("type").equals("messages")).forEach((widget) -> {
final Document config = widget.get("config", Document.class);
@SuppressWarnings("unchecked") final List<String> fields = (List) config.get("fields");
final boolean startWithTimestamp = fields.get(0).contains("timestamp");
final boolean showMessageRow = config.getBoolean("show_message_row");
assertThat(startWithTimestamp).isTrue();
assertThat(showMessageRow).isTrue();
});
});
}
use of com.mongodb.client.MongoCollection in project spring-data-mongodb by spring-projects.
the class DefaultDbRefResolver method bulkFetch.
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.convert.DbRefResolver#bulkFetch(java.util.List)
*/
@Override
public List<Document> bulkFetch(List<DBRef> refs) {
Assert.notNull(mongoDbFactory, "Factory must not be null!");
Assert.notNull(refs, "DBRef to fetch must not be null!");
if (refs.isEmpty()) {
return Collections.emptyList();
}
String collection = refs.iterator().next().getCollectionName();
List<Object> ids = new ArrayList<>(refs.size());
for (DBRef ref : refs) {
if (!collection.equals(ref.getCollectionName())) {
throw new InvalidDataAccessApiUsageException("DBRefs must all target the same collection for bulk fetch operation.");
}
ids.add(ref.getId());
}
DBRef databaseSource = refs.iterator().next();
MongoCollection<Document> mongoCollection = getCollection(databaseSource);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(String.format("Bulk fetching DBRefs %s from %s.%s.", ids, StringUtils.hasText(databaseSource.getDatabaseName()) ? databaseSource.getDatabaseName() : mongoCollection.getNamespace().getDatabaseName(), databaseSource.getCollectionName()));
}
List<Document> result = //
mongoCollection.find(//
new Document(BasicMongoPersistentProperty.ID_FIELD_NAME, new Document("$in", ids))).into(new ArrayList<>());
return //
ids.stream().flatMap(//
id -> documentWithId(id, result)).collect(Collectors.toList());
}
use of com.mongodb.client.MongoCollection in project spring-data-mongodb by spring-projects.
the class SessionAwareMethodInterceptorUnitTests method proxiesNewCollectionInstanceReturnedByMethod.
// DATAMONGO-1880
@Test
public void proxiesNewCollectionInstanceReturnedByMethod() {
MongoCollection otherCollection = mock(MongoCollection.class);
when(targetCollection.withCodecRegistry(any())).thenReturn(otherCollection);
MongoCollection target = collection.withCodecRegistry(MongoClientSettings.getDefaultCodecRegistry());
assertThat(target).isInstanceOf(Proxy.class).isNotSameAs(collection).isNotSameAs(targetCollection);
target.drop();
verify(otherCollection).drop(eq(session));
}
use of com.mongodb.client.MongoCollection in project MyPet by xXKeyleXx.
the class MongoDbRepository method updateToV2.
private void updateToV2() {
MongoCollection petCollection = db.getCollection(Configuration.Repository.MongoDB.PREFIX + "pets");
petCollection.createIndex(new BasicDBObject("uuid", 1));
petCollection.createIndex(new BasicDBObject("owner_uuid", 1));
MongoCollection playerCollection = db.getCollection(Configuration.Repository.MongoDB.PREFIX + "players");
playerCollection.createIndex(new BasicDBObject("internal_uuid", 1));
playerCollection.createIndex(new BasicDBObject("offline_uuid", 1));
playerCollection.createIndex(new BasicDBObject("mojang_uuid", 1));
}
Aggregations