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);
}
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);
}
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();
}
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;
}
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);
}
Aggregations