Search in sources :

Example 26 with DataDocument

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

the class MongoDataDao method createData.

@Override
public DataDocument createData(final String collectionId, final String documentId, final DataDocument data) {
    Document document = new Document(data).append(ID, new ObjectId(documentId));
    dataCollection(collectionId).insertOne(document);
    return data;
}
Also used : ObjectId(org.bson.types.ObjectId) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument)

Example 27 with DataDocument

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

the class MongoDataDao method patchData.

@Override
public DataDocument patchData(final String collectionId, final String documentId, final DataDocument data) {
    data.remove(ID);
    Document updateDocument = new Document("$set", new Document(data));
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
    Document patchedDocument = dataCollection(collectionId).findOneAndUpdate(idFilter(documentId), updateDocument, options);
    if (patchedDocument == null) {
        throw new StorageException("Document '" + documentId + "' has not been patched (partially updated).");
    }
    return MongoUtils.convertDocument(patchedDocument);
}
Also used : FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument) StorageException(io.lumeer.storage.api.exception.StorageException)

Example 28 with DataDocument

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

the class DocumentFacadeIT method testGetDocument.

@Test
public void testGetDocument() {
    String id = createDocument().getId();
    Document document = documentFacade.getDocument(collection.getId(), id);
    assertThat(document).isNotNull();
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(document.getId()).isEqualTo(id);
    assertions.assertThat(document.getCollectionId()).isEqualTo(collection.getId());
    assertions.assertThat(document.getCreatedBy()).isEqualTo(USER);
    assertions.assertThat(document.getCreationDate()).isBeforeOrEqualTo(LocalDateTime.now());
    assertions.assertThat(document.getUpdatedBy()).isNull();
    assertions.assertThat(document.getUpdateDate()).isNull();
    assertions.assertThat(document.getDataVersion()).isEqualTo(1);
    assertions.assertAll();
    DataDocument data = document.getData();
    assertThat(data).isNotNull();
    assertThat(data).containsEntry(KEY1, VALUE1);
    assertThat(data).containsEntry(KEY2, VALUE2);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) SoftAssertions(org.assertj.core.api.SoftAssertions) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 29 with DataDocument

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

the class DocumentFacadeIT method testPatchDocumentData.

@Test
public void testPatchDocumentData() {
    Document document = createDocument();
    String id = document.getId();
    Collection storedCollection = collectionDao.getCollectionById(collection.getId());
    assertThat(storedCollection.getDocumentsCount()).isEqualTo(1);
    assertThat(storedCollection.getAttributes()).extracting(Attribute::getFullName).containsOnly(KEY1, KEY2);
    assertThat(findCollectionAttribute(storedCollection, KEY1).getUsageCount()).isEqualTo(1);
    assertThat(findCollectionAttribute(storedCollection, KEY2).getUsageCount()).isEqualTo(1);
    DataDocument data = new DataDocument(KEY1, VALUE2);
    LocalDateTime beforeUpdateTime = LocalDateTime.now();
    Document updatedDocument = documentFacade.patchDocumentData(collection.getId(), id, data);
    assertThat(updatedDocument).isNotNull();
    Document storedDocument = documentDao.getDocumentById(id);
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(storedDocument.getId()).isEqualTo(id);
    assertions.assertThat(storedDocument.getCollectionId()).isEqualTo(collection.getId());
    assertions.assertThat(storedDocument.getCreatedBy()).isEqualTo(USER);
    assertions.assertThat(storedDocument.getCreationDate()).isBeforeOrEqualTo(beforeUpdateTime);
    assertions.assertThat(storedDocument.getUpdatedBy()).isEqualTo(USER);
    assertions.assertThat(storedDocument.getUpdateDate()).isAfterOrEqualTo(beforeUpdateTime).isBeforeOrEqualTo(LocalDateTime.now());
    assertions.assertThat(storedDocument.getDataVersion()).isEqualTo(2);
    assertions.assertThat(storedDocument.getData()).isNull();
    assertions.assertAll();
    DataDocument storedData = dataDao.getData(collection.getId(), id);
    assertThat(storedData).isNotNull();
    assertThat(storedData).containsEntry(KEY1, VALUE2);
    assertThat(storedData).containsEntry(KEY2, VALUE2);
    storedCollection = collectionDao.getCollectionById(collection.getId());
    assertThat(storedCollection.getDocumentsCount()).isEqualTo(1);
    assertThat(storedCollection.getAttributes()).extracting(Attribute::getFullName).containsOnly(KEY1, KEY2);
    assertThat(findCollectionAttribute(storedCollection, KEY1).getUsageCount()).isEqualTo(1);
    assertThat(findCollectionAttribute(storedCollection, KEY2).getUsageCount()).isEqualTo(1);
}
Also used : LocalDateTime(java.time.LocalDateTime) DataDocument(io.lumeer.engine.api.data.DataDocument) SoftAssertions(org.assertj.core.api.SoftAssertions) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 30 with DataDocument

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

the class ImportFacadeIT method testImportEmptyHeaderCSV.

@Test
public void testImportEmptyHeaderCSV() {
    final String noHeaderCsv = "\n" + "a;b;c;d\n" + "a;b;c;d\n";
    ImportedCollection importedCollection = createImportObject(noHeaderCsv);
    Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
    assertThat(collection).isNotNull();
    List<DataDocument> data = dataDao.getData(collection.getId(), query());
    // it's because library ignores any leading empty lines
    assertThat(data).hasSize(1);
    assertThat(data.get(0).keySet()).containsOnly("_id", "a", "b", "c", "d");
    assertThat(data.get(0).getString("a")).isEqualTo("a");
    assertThat(data.get(0).getString("b")).isEqualTo("b");
    assertThat(data.get(0).getString("c")).isEqualTo("c");
    assertThat(data.get(0).getString("d")).isEqualTo("d");
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) ImportedCollection(io.lumeer.api.model.ImportedCollection) JsonCollection(io.lumeer.api.dto.JsonCollection) ImportedCollection(io.lumeer.api.model.ImportedCollection) Collection(io.lumeer.api.model.Collection) 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