T
- The type of the value of the custom object.public interface CustomObjectQueryModel<T extends CustomObject<?>> extends ResourceQueryModel<T>
Meta model to explore for which fields can be queried in a CustomObject.
Example:
withCustomObject(client(), co -> { final CustomObjectQuery<Foo> customObjectQuery = CustomObjectQuery.of(Foo.class) .withPredicates(o -> o.id().is(co.getId())); final PagedQueryResult<CustomObject<Foo>> result = client().executeBlocking(customObjectQuery); assertThat(result.head().get()) .isEqualTo(co); });
See the test code.
CustomObject
Modifier and Type | Method and Description |
---|---|
StringQuerySortingModel<T> |
container() |
StringQuerySortingModel<T> |
key() |
static <T extends CustomObject<?>> |
of() |
RootJsonQueryModel<T> |
value()
Query model for
CustomObject.getValue() . |
createdAt, id, is, lastModifiedAt, not
StringQuerySortingModel<T> container()
StringQuerySortingModel<T> key()
static <T extends CustomObject<?>> CustomObjectQueryModel<T> of()
RootJsonQueryModel<T> value()
CustomObject.getValue()
.
Example for custom objects which contain nested objects as value:
/* the custom object will look like: { "container":"CustomObjectQueryIntegrationTest", "key":"demoQueryByNestedValue", "value": { "foo": "bar", "baz": { "x": "y" }, "count": 5 } } */ final ObjectNode valueAsJsonObjectNode = objectMapper.createObjectNode(); valueAsJsonObjectNode.put("foo", "bar"); final ObjectNode bazNode = objectMapper.createObjectNode(); bazNode.put("x", "y"); valueAsJsonObjectNode.set("baz", bazNode); valueAsJsonObjectNode.put("count", 5); final String container = "CustomObjectQueryIntegrationTest"; final String key = "demoQueryByNestedValue"; final CustomObjectUpsertCommand<JsonNode> cmd = CustomObjectUpsertCommand.of(CustomObjectDraft.ofUnversionedUpsert(container, key, valueAsJsonObjectNode)); client().executeBlocking(cmd); final CustomObjectQuery<JsonNode> query = CustomObjectQuery.ofJsonNode() .plusPredicates(m -> m.container().is(container)) .plusPredicates(m -> m.key().is(key)) .plusPredicates(m -> m.value().ofJsonObject().ofString("foo").is("bar")) .plusPredicates(m -> m.value().ofJsonObject().ofJsonObject("baz").ofString("x").is("y")) .plusPredicates(m -> m.value().ofJsonObject().ofInteger("count").isGreaterThan(4)); final PagedQueryResult<CustomObject<JsonNode>> pagedQueryResult = client().executeBlocking(query); final List<CustomObject<JsonNode>> results = pagedQueryResult.getResults(); assertThat(results).hasSize(1); assertThat(results.get(0).getKey()).isEqualTo(key);
See the test code.
Example for custom objects which contain just a scalar value like a String or a an Integer:
/* the custom object will look like: { "container":"CustomObjectQueryIntegrationTest", "key":"demoQueryByFlatValue", "value": 4 } */ final JsonNode value = new IntNode(4); final String container = "CustomObjectQueryIntegrationTest"; final String key = "demoQueryByFlatValue"; final CustomObjectUpsertCommand<JsonNode> cmd = CustomObjectUpsertCommand.of(CustomObjectDraft.ofUnversionedUpsert(container, key, value)); client().executeBlocking(cmd); final CustomObjectQuery<JsonNode> query = CustomObjectQuery.ofJsonNode() .plusPredicates(m -> m.container().is(container)) .plusPredicates(m -> m.key().is(key)) .plusPredicates(m -> m.value().ofJsonValue().ofInteger().isGreaterThan(3)); final PagedQueryResult<CustomObject<JsonNode>> pagedQueryResult = client().executeBlocking(query); final List<CustomObject<JsonNode>> results = pagedQueryResult.getResults(); assertThat(results).hasSize(1); assertThat(results.get(0).getKey()).isEqualTo(key);
See the test code.