use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoUtils method convertNestedAndListDocuments.
public static void convertNestedAndListDocuments(DataDocument dataDocument) {
for (String key : dataDocument.keySet()) {
Object value = dataDocument.get(key);
if (isDocument(value)) {
DataDocument converted = new DataDocument((Document) value);
dataDocument.replace(key, converted);
convertNestedAndListDocuments(converted);
} else if (isList(value)) {
List l = (List) value;
if (!l.isEmpty() && isDocument(l.get(0))) {
ArrayList<DataDocument> docs = new ArrayList<>(l.size());
dataDocument.replace(key, docs);
for (Object o : l) {
if (!isDocument(o)) {
continue;
}
DataDocument d = new DataDocument((Document) o);
docs.add(d);
convertNestedAndListDocuments(d);
}
}
}
}
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorageTest method testRenameAttribute.
@Test
public void testRenameAttribute() throws Exception {
mongoDbStorage.createCollection(COLLECTION_RENAME_ATTRIBUTE);
DataDocument insertedDocument = createDummyDocument();
String id = mongoDbStorage.createDocument(COLLECTION_RENAME_ATTRIBUTE, insertedDocument);
String changedAttr = "changed_" + DUMMY_KEY1;
mongoDbStorage.renameAttribute(COLLECTION_RENAME_ATTRIBUTE, DUMMY_KEY1, changedAttr);
DataDocument document = mongoDbStorage.readDocument(COLLECTION_RENAME_ATTRIBUTE, mongoDbStorageDialect.documentIdFilter(id));
assertThat(document.containsKey(DUMMY_KEY1)).isFalse();
assertThat(document.containsKey(changedAttr)).isTrue();
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorageTest method testNestedDocuments.
@Test
public void testNestedDocuments() throws Exception {
mongoDbStorage.createCollection(COLLECTION_NESTED_DOCUMENTS);
DataDocument d = createDummyDocument();
d.put("a", createDummyDocument());
d.put("b", createDummyDocument());
d.put("l", Arrays.asList(1, 2, 3, 4));
d.put("ld", Arrays.asList(createDummyDocument(), createDummyDocument(), createDummyDocument()));
DataDocument doubleNested = createDummyDocument();
doubleNested.put("dn", createDummyDocument());
d.put("c", doubleNested);
DataDocument trippleNested = createDummyDocument();
DataDocument tn = createDummyDocument();
tn.put("tnn", createDummyDocument());
trippleNested.put("tn", tn);
trippleNested.put("ld", Arrays.asList(createDummyDocument(), createDummyDocument(), createDummyDocument()));
d.put("d_d", trippleNested);
String id = mongoDbStorage.createDocument(COLLECTION_NESTED_DOCUMENTS, d);
final DataFilter documentIdFilter = mongoDbStorageDialect.documentIdFilter(id);
mongoDbStorage.dropAttribute(COLLECTION_NESTED_DOCUMENTS, documentIdFilter, "d_d.tn.tnn." + DUMMY_KEY1);
// use debug to see nested hierarchy works
DataDocument nested = mongoDbStorage.readDocument(COLLECTION_NESTED_DOCUMENTS, documentIdFilter);
assertThat(nested).isNotNull();
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorageTest method testCreateAndReadDocument.
@Test
public void testCreateAndReadDocument() throws Exception {
mongoDbStorage.createCollection(COLLECTION_CREATE_AND_READ_DOCUMENT);
DataDocument insertedDocument = createDummyDocument();
String documentId = mongoDbStorage.createDocument(COLLECTION_CREATE_AND_READ_DOCUMENT, insertedDocument);
DataDocument readedDocument = mongoDbStorage.readDocument(COLLECTION_CREATE_AND_READ_DOCUMENT, mongoDbStorageDialect.documentIdFilter(documentId));
assertThat(insertedDocument.getString(DUMMY_KEY1)).isEqualTo(readedDocument.getString(DUMMY_KEY1));
assertThat(insertedDocument.getString(DUMMY_KEY2)).isEqualTo(readedDocument.getString(DUMMY_KEY2));
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorageTest method testIndexes.
@Test
public void testIndexes() throws Exception {
mongoDbStorage.createCollection(COLLECTION_INDEXES);
List<DataDocument> dataDocuments = mongoDbStorage.listIndexes(COLLECTION_INDEXES);
// default _id index
assertThat(dataDocuments).hasSize(1);
mongoDbStorage.createIndex(COLLECTION_INDEXES, new DataDocument("ixs1", 1), false);
mongoDbStorage.createIndex(COLLECTION_INDEXES, new DataDocument("ixs1", 2), true);
dataDocuments = mongoDbStorage.listIndexes(COLLECTION_INDEXES);
assertThat(dataDocuments).hasSize(3);
}
Aggregations