Search in sources :

Example 11 with DataDocument

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);
                }
            }
        }
    }
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) BsonDocument(org.bson.BsonDocument)

Example 12 with DataDocument

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();
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 13 with DataDocument

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();
}
Also used : DataFilter(io.lumeer.engine.api.data.DataFilter) DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 14 with DataDocument

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));
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 15 with DataDocument

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Aggregations

DataDocument (io.lumeer.engine.api.data.DataDocument)75 Test (org.junit.Test)42 Collection (io.lumeer.api.model.Collection)16 Document (io.lumeer.api.model.Document)16 JsonDocument (io.lumeer.api.dto.JsonDocument)14 Document (org.bson.Document)13 SoftAssertions (org.assertj.core.api.SoftAssertions)10 ReturnDocument (com.mongodb.client.model.ReturnDocument)9 JsonCollection (io.lumeer.api.dto.JsonCollection)9 DataFilter (io.lumeer.engine.api.data.DataFilter)9 ImportedCollection (io.lumeer.api.model.ImportedCollection)6 SearchQuery (io.lumeer.storage.api.query.SearchQuery)6 LocalDateTime (java.time.LocalDateTime)6 BsonDocument (org.bson.BsonDocument)6 LinkedList (java.util.LinkedList)5 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Response (javax.ws.rs.core.Response)4 DataStorageStats (io.lumeer.engine.api.data.DataStorageStats)3