use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorageTest method testIncrementAttributeValueBy.
@Test
public void testIncrementAttributeValueBy() throws Exception {
mongoDbStorage.createCollection(COLLECTION_INC_ATTR_VALUE_BY);
String incAttribute = "incAttribute";
DataDocument insertedDocument = createDummyDocument();
String id = mongoDbStorage.createDocument(COLLECTION_INC_ATTR_VALUE_BY, insertedDocument);
final DataFilter documentIdFilter = mongoDbStorageDialect.documentIdFilter(id);
mongoDbStorage.incrementAttributeValueBy(COLLECTION_INC_ATTR_VALUE_BY, documentIdFilter, incAttribute, 1);
DataDocument readDocument = mongoDbStorage.readDocument(COLLECTION_INC_ATTR_VALUE_BY, documentIdFilter);
assertThat(readDocument.containsKey(incAttribute)).isTrue();
assertThat(readDocument.getInteger(incAttribute)).isEqualTo(1);
mongoDbStorage.incrementAttributeValueBy(COLLECTION_INC_ATTR_VALUE_BY, documentIdFilter, incAttribute, 10);
readDocument = mongoDbStorage.readDocument(COLLECTION_INC_ATTR_VALUE_BY, documentIdFilter);
assertThat(readDocument.containsKey(incAttribute)).isTrue();
assertThat(readDocument.getInteger(incAttribute)).isEqualTo(11);
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoUtils method convertDocument.
public static DataDocument convertDocument(Document document) {
MongoUtils.replaceId(document);
DataDocument dataDocument = new DataDocument(document);
MongoUtils.convertNestedAndListDocuments(dataDocument);
return dataDocument;
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDataDao method updateData.
@Override
public DataDocument updateData(final String collectionId, final String documentId, final DataDocument data) {
Document document = new Document(data);
FindOneAndReplaceOptions options = new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER);
Document updatedDocument = dataCollection(collectionId).findOneAndReplace(idFilter(documentId), document, options);
if (updatedDocument == null) {
throw new StorageException("Document '" + documentId + "' has not been updated (replaced).");
}
return MongoUtils.convertDocument(updatedDocument);
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDataDao method createData.
@Override
public List<DataDocument> createData(final String collectionId, final List<DataDocument> data) {
List<Document> documents = data.stream().map(dataDocument -> new Document(dataDocument).append(ID, new ObjectId(dataDocument.getId()))).collect(Collectors.toList());
dataCollection(collectionId).insertMany(documents);
for (int i = 0; i < documents.size(); i++) {
Object idObj = documents.get(i).get(ID);
String id = idObj instanceof String ? (String) idObj : ((ObjectId) idObj).toHexString();
data.get(i).setId(id);
}
return data;
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class DocumentServiceIT method testUpdateDocument.
@Test
public void testUpdateDocument() {
String id = createDocument().getId();
DataDocument data = new DataDocument(KEY1, VALUE2);
Entity entity = Entity.json(data);
LocalDateTime beforeUpdateTime = LocalDateTime.now();
Response response = client.target(DOCUMENTS_URL_PREFIX).path(collection.getId()).path("documents").path(id).path("data").request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
assertThat(response).isNotNull();
assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
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).doesNotContainKey(KEY2);
}
Aggregations