Search in sources :

Example 1 with MorphiaDocument

use of io.lumeer.storage.mongodb.model.MorphiaDocument 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 2 with MorphiaDocument

use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.

the class MorphiaDocumentDaoTest method createDocument.

private MorphiaDocument createDocument() {
    MorphiaDocument document = prepareDocument();
    datastore.save(documentDao.databaseCollection(), document);
    return document;
}
Also used : MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument)

Example 3 with MorphiaDocument

use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.

the class MorphiaDocumentDaoTest method testUpdateDocumentNotExisting.

@Test
@Ignore("Stored anyway with the current implementation")
public void testUpdateDocumentNotExisting() {
    MorphiaDocument document = prepareDocument();
    assertThatThrownBy(() -> documentDao.updateDocument(DOCUMENT_ID, document)).isInstanceOf(WriteFailedException.class);
}
Also used : MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with MorphiaDocument

use of io.lumeer.storage.mongodb.model.MorphiaDocument 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 5 with MorphiaDocument

use of io.lumeer.storage.mongodb.model.MorphiaDocument in project engine by Lumeer.

the class MorphiaDocumentDao method updateDocument.

@Override
public Document updateDocument(final String id, final Document document) {
    MorphiaDocument morphiaDocument = new MorphiaDocument(document);
    morphiaDocument.setId(id);
    datastore.save(databaseCollection(), morphiaDocument);
    return morphiaDocument;
}
Also used : MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument)

Aggregations

MorphiaDocument (io.lumeer.storage.mongodb.model.MorphiaDocument)10 Test (org.junit.Test)5 Document (io.lumeer.api.model.Document)4 DataDocument (io.lumeer.engine.api.data.DataDocument)4 ObjectId (org.bson.types.ObjectId)3 SoftAssertions (org.assertj.core.api.SoftAssertions)2 WriteResult (com.mongodb.WriteResult)1 Project (io.lumeer.api.model.Project)1 ResourceType (io.lumeer.api.model.ResourceType)1 DocumentDao (io.lumeer.storage.api.dao.DocumentDao)1 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)1 WriteFailedException (io.lumeer.storage.mongodb.exception.WriteFailedException)1 ID (io.lumeer.storage.mongodb.model.common.MorphiaEntity.ID)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RequestScoped (javax.enterprise.context.RequestScoped)1 Ignore (org.junit.Ignore)1