use of io.lumeer.engine.api.data.DataFilter in project engine by Lumeer.
the class MongoDbStorageTest method testSearchAttrs.
@Test
public void testSearchAttrs() throws Exception {
mongoDbStorage.createCollection(COLLECTION_SEARCH_ATTRS);
for (int i = 0; i < 200; i++) {
DataDocument insertedDocument = new DataDocument("a", i).append("b", i * 2).append("c", i * 3).append("d", i + 4).append("e", i + 5).append("f", new DataDocument("a", i).append("b", i - 2).append("c", i * i));
mongoDbStorage.createDocument(COLLECTION_SEARCH_ATTRS, insertedDocument);
}
// test whether we get all documents
List<DataDocument> docs = mongoDbStorage.search(COLLECTION_SEARCH_ATTRS, null, null);
assertThat(docs).hasSize(200);
final DataFilter filter = new MongoDbDataFilter(Filters.gte("a", 100));
docs = mongoDbStorage.search(COLLECTION_SEARCH_ATTRS, filter, Arrays.asList("a", "c", "f.b"));
assertThat(docs).hasSize(100);
DataDocument anyDoc = docs.get(0);
assertThat(anyDoc).containsKeys("_id", "a", "c", "f");
assertThat(anyDoc).doesNotContainKeys("b", "d", "e");
DataDocument nestedDoc = anyDoc.getDataDocument("f");
assertThat(nestedDoc).containsKey("b");
assertThat(nestedDoc).doesNotContainKeys("a", "c");
// test if it's necceserry to include attribute which is used in filter
docs = mongoDbStorage.search(COLLECTION_SEARCH_ATTRS, filter, Arrays.asList("b", "c", "d"));
assertThat(docs).hasSize(100);
anyDoc = docs.get(0);
assertThat(anyDoc).containsKeys("_id", "b", "c", "d");
assertThat(anyDoc).doesNotContainKeys("a", "e", "f");
}
use of io.lumeer.engine.api.data.DataFilter in project engine by Lumeer.
the class MongoDbStorageTest method testComplexArrayManipulation.
@Test
public void testComplexArrayManipulation() throws Exception {
mongoDbStorage.createCollection(COLLECTION_COMPLEX_ARRAY_MANIPULATION);
DataDocument d = createDummyDocument();
DataDocument n = createDummyDocument();
DataDocument d1 = new DataDocument();
d1.put("gt", 10);
DataDocument d2 = new DataDocument();
d2.put("lt", 20);
n.put("a", Arrays.asList(d1, d2));
d.put("n", n);
String id = mongoDbStorage.createDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, d);
final DataFilter documentIdFilter = mongoDbStorageDialect.documentIdFilter(id);
DataDocument fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(2);
DataDocument d3 = new DataDocument();
d3.put("equals", "true");
mongoDbStorage.addItemToArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", d3);
fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(3);
DataDocument d4 = new DataDocument();
d4.put("i", true);
DataDocument d5 = new DataDocument();
d4.put("p", 12.3);
mongoDbStorage.addItemsToArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", Arrays.asList(d4, d5));
fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(5);
mongoDbStorage.removeItemsFromArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", Arrays.asList(d2, d3));
fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(3);
mongoDbStorage.removeItemFromArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", d2);
fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(3);
mongoDbStorage.removeItemFromArray(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter, "n.a", d4);
fromDb = mongoDbStorage.readDocument(COLLECTION_COMPLEX_ARRAY_MANIPULATION, documentIdFilter);
assertThat(fromDb.getArrayList("n.a", DataDocument.class)).hasSize(2);
}
use of io.lumeer.engine.api.data.DataFilter 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);
}
Aggregations