Search in sources :

Example 51 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MongoDbStorage method run.

private List<DataDocument> run(final Bson command) {
    final List<DataDocument> result = new ArrayList<>();
    Document cursor = (Document) database.runCommand(command).get(CURSOR_KEY);
    if (cursor != null) {
        ((ArrayList<Document>) cursor.get(FIRST_BATCH_KEY)).forEach(d -> {
            result.add(MongoUtils.convertDocument(d));
        });
    }
    return result;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) ArrayList(java.util.ArrayList) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument) BsonDocument(org.bson.BsonDocument)

Example 52 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MongoDataDaoTest method testGetDataByDocumenstIds.

@Test
public void testGetDataByDocumenstIds() {
    String id1 = createDocument(KEY1, VALUE1);
    String id2 = createDocument(KEY1, VALUE2);
    String id3 = createDocument(KEY1, VALUE1);
    String id4 = createDocument(KEY1, VALUE2);
    SearchQuery searchQuery = SearchQuery.createBuilder(USER).documentIds(Collections.singleton(id2)).build();
    List<DataDocument> data = dataDao.getData(COLLECTION_ID, searchQuery);
    assertThat(data).extracting(DataDocument::getId).containsOnly(id2);
    searchQuery = SearchQuery.createBuilder(USER).documentIds(new HashSet<>(Arrays.asList(id1, id3, id4))).build();
    data = dataDao.getData(COLLECTION_ID, searchQuery);
    assertThat(data).extracting(DataDocument::getId).containsOnly(id1, id3, id4);
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 53 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MongoDataDaoTest method testGetDataByFulltextAttributeValueAndDocumentsIds.

@Test
public void testGetDataByFulltextAttributeValueAndDocumentsIds() {
    String id1 = createDocument(KEY1, VALUE1);
    String id2 = createDocument(KEY1, "fulltext");
    String id3 = createDocument(KEY1, "something fulltext");
    String id4 = createDocument(KEY1, VALUE1);
    SearchQuery searchQuery = SearchQuery.createBuilder(USER).fulltext("fulltext").documentIds(new HashSet<>(Arrays.asList(id1, id2))).build();
    List<DataDocument> data = dataDao.getData(COLLECTION_ID, searchQuery);
    assertThat(data).extracting(DataDocument::getId).containsOnly(id2);
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) DataDocument(io.lumeer.engine.api.data.DataDocument) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 54 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MongoDataDaoTest method testCreateData.

@Test
public void testCreateData() {
    DataDocument data = new DataDocument().append(KEY1, VALUE1).append(KEY2, VALUE2);
    DataDocument storedData = dataDao.createData(COLLECTION_ID, DOCUMENT_ID, data);
    assertThat(storedData).isNotNull();
    assertThat(storedData.getId()).isNull();
    MongoCursor<Document> mongoCursor = dataCollection().find().iterator();
    assertThat(mongoCursor.hasNext()).isTrue();
    Document document = mongoCursor.next();
    assertThat(document.get("_id").toString()).isNotNull().isEqualTo(DOCUMENT_ID);
    assertThat(document).containsEntry(KEY1, VALUE1);
    assertThat(document).containsEntry(KEY2, VALUE2);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) Test(org.junit.Test)

Example 55 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class MorphiaDocumentDaoTest method prepareDocument.

private MorphiaDocument prepareDocument() {
    MorphiaDocument document = new MorphiaDocument();
    document.setCollectionId(COLLECTION_ID);
    document.setCreationDate(CREATION_DATE);
    document.setCreatedBy(CREATED_BY);
    document.setDataVersion(DATA_VERSION);
    document.setData(new DataDocument("something", "that should not be stored"));
    return document;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument)

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