Search in sources :

Example 6 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class ImportFacade method addDocumentsToDb.

private void addDocumentsToDb(String collectionId, List<Document> documents) {
    List<Document> storedDocuments = documentDao.createDocuments(documents);
    List<DataDocument> dataDocuments = new LinkedList<>();
    for (int i = 0; i < documents.size(); i++) {
        DataDocument dataDocument = documents.get(i).getData();
        dataDocument.setId(storedDocuments.get(i).getId());
        dataDocuments.add(dataDocument);
    }
    dataDao.createData(collectionId, dataDocuments);
}
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) LinkedList(java.util.LinkedList)

Example 7 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class MorphiaDocumentDaoTest method testCreateDocumentMultiple.

@Test
public void testCreateDocumentMultiple() {
    Document document = prepareDocument();
    String id = documentDao.createDocument(document).getId();
    assertThat(id).isNotNull().isNotEmpty();
    assertThat(ObjectId.isValid(id)).isTrue();
    Document document2 = new MorphiaDocument();
    String id2 = documentDao.createDocument(document2).getId();
    assertThat(id2).isNotNull().isNotEmpty();
    assertThat(ObjectId.isValid(id2)).isTrue();
    assertThat(id).isNotEqualTo(id2);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) Test(org.junit.Test)

Example 8 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class MorphiaDocumentDaoTest method testGetDocumentById.

@Test
public void testGetDocumentById() {
    String id = createDocument().getId();
    Document document = documentDao.getDocumentById(id);
    assertThat(document).isNotNull();
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(document.getId()).isEqualTo(id);
    assertions.assertThat(document.getCollectionId()).isEqualTo(COLLECTION_ID);
    assertions.assertThat(document.getCreatedBy()).isEqualTo(CREATED_BY);
    assertions.assertThat(document.getCreationDate()).isEqualTo(CREATION_DATE);
    assertions.assertThat(document.getUpdatedBy()).isNull();
    assertions.assertThat(document.getUpdateDate()).isNull();
    assertions.assertThat(document.getDataVersion()).isEqualTo(DATA_VERSION);
    assertions.assertAll();
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) Test(org.junit.Test)

Example 9 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class MorphiaDocumentDao method createDocuments.

@Override
public List<Document> createDocuments(final List<Document> documents) {
    List<org.bson.Document> bsonDocuments = documents.stream().map(doc -> new MorphiaDocument(doc).toBsonDocument()).collect(Collectors.toList());
    database.getCollection(databaseCollection()).insertMany(bsonDocuments);
    for (int i = 0; i < documents.size(); i++) {
        documents.get(i).setId(bsonDocuments.get(i).getObjectId(ID).toHexString());
    }
    return documents;
}
Also used : ID(io.lumeer.storage.mongodb.model.common.MorphiaEntity.ID) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) Arrays(java.util.Arrays) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Document(io.lumeer.api.model.Document) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Query(org.mongodb.morphia.query.Query) Project(io.lumeer.api.model.Project) WriteResult(com.mongodb.WriteResult) List(java.util.List) ResourceType(io.lumeer.api.model.ResourceType) RequestScoped(javax.enterprise.context.RequestScoped) WriteFailedException(io.lumeer.storage.mongodb.exception.WriteFailedException) ObjectId(org.bson.types.ObjectId) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) Document(io.lumeer.api.model.Document) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument)

Example 10 with Document

use of io.lumeer.api.model.Document 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)

Aggregations

Document (io.lumeer.api.model.Document)32 DataDocument (io.lumeer.engine.api.data.DataDocument)31 JsonDocument (io.lumeer.api.dto.JsonDocument)21 Test (org.junit.Test)18 SoftAssertions (org.assertj.core.api.SoftAssertions)10 Collection (io.lumeer.api.model.Collection)7 LocalDateTime (java.time.LocalDateTime)7 MorphiaDocument (io.lumeer.storage.mongodb.model.MorphiaDocument)6 JsonQuery (io.lumeer.api.dto.JsonQuery)5 HashSet (java.util.HashSet)4 ObjectId (org.bson.types.ObjectId)4 JsonCollection (io.lumeer.api.dto.JsonCollection)3 Entity (javax.ws.rs.client.Entity)3 Response (javax.ws.rs.core.Response)3 Pagination (io.lumeer.api.model.Pagination)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 WriteResult (com.mongodb.WriteResult)1 CsvParser (com.univocity.parsers.csv.CsvParser)1 CsvParserSettings (com.univocity.parsers.csv.CsvParserSettings)1