Search in sources :

Example 31 with DataDocument

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

the class ImportFacadeIT method testImportCommaSeparatedCSV.

@Test
public void testImportCommaSeparatedCSV() {
    final String commaSeparatedCsv = "h1,h2,h3\n" + "a,,c,d\n" + ",,,\n" + "a,b,c,d\n";
    ImportedCollection importedCollection = createImportObject(commaSeparatedCsv);
    Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
    assertThat(collection).isNotNull();
    List<DataDocument> data = dataDao.getData(collection.getId(), query());
    assertThat(data).hasSize(3);
    int h1Num = 0;
    int h2Num = 0;
    int h3Num = 0;
    for (DataDocument dataDocument : data) {
        String h1 = dataDocument.getString("h1");
        String h2 = dataDocument.getString("h2");
        String h3 = dataDocument.getString("h3");
        h1Num += h1 != null && h1.equals("a") ? 1 : 0;
        h2Num += h2 != null && h2.equals("b") ? 1 : 0;
        h3Num += h3 != null && h3.equals("c") ? 1 : 0;
    }
    assertThat(h1Num).isEqualTo(2);
    assertThat(h2Num).isEqualTo(1);
    assertThat(h3Num).isEqualTo(2);
}
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)

Example 32 with DataDocument

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

the class ImportFacadeIT method testImportCorrectCSV.

@Test
public void testImportCorrectCSV() {
    final String correctCsv = "h1;h2;h3;h4\n" + ";b;c;d\n" + ";;c;d\n" + "a;b;;d\n" + "a;b;;\n";
    ImportedCollection importedCollection = createImportObject(correctCsv);
    Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
    assertThat(collection).isNotNull();
    List<DataDocument> data = dataDao.getData(collection.getId(), query());
    assertThat(data).hasSize(4);
    int h1Num = 0;
    int h2Num = 0;
    int h3Num = 0;
    int h4Num = 0;
    for (DataDocument dataDocument : data) {
        String h1 = dataDocument.getString("h1");
        String h2 = dataDocument.getString("h2");
        String h3 = dataDocument.getString("h3");
        String h4 = dataDocument.getString("h4");
        h1Num += h1 != null && h1.equals("a") ? 1 : 0;
        h2Num += h2 != null && h2.equals("b") ? 1 : 0;
        h3Num += h3 != null && h3.equals("c") ? 1 : 0;
        h4Num += h4 != null && h4.equals("d") ? 1 : 0;
    }
    assertThat(h1Num).isEqualTo(2);
    assertThat(h2Num).isEqualTo(3);
    assertThat(h3Num).isEqualTo(2);
    assertThat(h4Num).isEqualTo(3);
}
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)

Example 33 with DataDocument

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

the class ImportFacadeIT method testImportNoLinesCSV.

@Test
public void testImportNoLinesCSV() {
    final String noLinesCsv = "h1;h2;h3;h4\n";
    ImportedCollection importedCollection = createImportObject(noLinesCsv);
    Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
    assertThat(collection).isNotNull();
    List<DataDocument> data = dataDao.getData(collection.getId(), query());
    assertThat(data).isEmpty();
}
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)

Example 34 with DataDocument

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

the class ImportFacadeIT method testImportDiffRowsLengthCSV.

@Test
public void testImportDiffRowsLengthCSV() {
    final String diffRowsLengthCsv = "h1;h2;h3\n" + "a;b;c;d\n" + "a;b;c;d;e;f;g;h\n" + "\n\n\n\n\n" + "a;b;c\n";
    ImportedCollection importedCollection = createImportObject(diffRowsLengthCsv);
    Collection collection = importFacade.importDocuments(ImportFacade.FORMAT_CSV, importedCollection);
    assertThat(collection).isNotNull();
    List<DataDocument> data = dataDao.getData(collection.getId(), query());
    assertThat(data).hasSize(3);
    int h1Num = 0;
    int h2Num = 0;
    int h3Num = 0;
    for (DataDocument dataDocument : data) {
        String h1 = dataDocument.getString("h1");
        String h2 = dataDocument.getString("h2");
        String h3 = dataDocument.getString("h3");
        h1Num += h1 != null && h1.equals("a") ? 1 : 0;
        h2Num += h2 != null && h2.equals("b") ? 1 : 0;
        h3Num += h3 != null && h3.equals("c") ? 1 : 0;
    }
    assertThat(h1Num).isEqualTo(3);
    assertThat(h2Num).isEqualTo(3);
    assertThat(h3Num).isEqualTo(3);
}
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)

Example 35 with DataDocument

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

the class LinkInstanceFacadeIT method createDocument.

private Document createDocument(String collectionId) {
    Document document = prepareDocument();
    document.setCollectionId(collectionId);
    document.setCreatedBy(USER);
    document.setCreationDate(LocalDateTime.now());
    document.setDataVersion(DocumentFacade.INITIAL_VERSION);
    Document storedDocument = documentDao.createDocument(document);
    DataDocument storedData = dataDao.createData(collectionId, storedDocument.getId(), document.getData());
    storedDocument.setData(storedData);
    return storedDocument;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document)

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