Skip to main content
Version: 1.5.x

Conditions

Conditions allow complex decisions based on a given input and context. The Input of a condition can be any number of values that are needed to perform the specific logic. A Condition always returns true of false on a singular Subject and when used on multiples Subjects it can return a result set on which the condition matches.

In the case of Dossier Organizer there are multiple uses of the condition data structure to find or filter collections:

  1. Dossier Organizer provides index querying which uses conditions to search for a result set based on the metadata of a collection. In this use case the context for the Conditions is restricted to the collections metadata to ensure fast response times. The base object to reference is always the metadata object of the collection.

Example collection:

{
"id": "899770d1-08be-472b-acf2-a72f8f75583f",
"metadata": {
"customer": {
"name": "Levigo"
}
},
"elements": [ ],
"typeId": "example"
}

Example condition

{
"equals": {
"customer.name": "Levigo"
}
}
  1. Access Policies also use the conditions structure and allow the integrator to define access rules to restrict or allow a user to perform a specific action on a collection. The context for access policies is split to include both collection and collection element data. The base element to reference in a collection has to be defined in the resources definition of the Access policy. Currently collection and collection-element are supported as a reference.

Example collection:

{
"id": "899770d1-08be-472b-acf2-a72f8f75583f",
"metadata": {
"customer": {
"name": "Levigo"
}
},
"elements": [
{
"id": "2c2d7bd6-2c63-44c1-a35e-5cc88af68d65",
"metadata": {
"title": "Document"
}
}
],
"typeId": "example"
}

Example condition

{ 
"equals": {
"collection.id": "899770d1-08be-472b-acf2-a72f8f75583f"
}
}
{ 
"equals": {
"collection-element.metadata.title": "Document"
}
}

There are many implementations of conditions that can be combined to form complex decisions.
In the following section these different types are explained.

Composite Conditions

To be able to use multiple conditions there are "Composite Conditions". These Composite Conditions take two or more Conditions and evaluate based on their result. This based on simple boolean expressions and provides the following variants:

AndCondition (Boolean AND)

{
"and": {
"conditions": [
{ /* condition 1 */ },
{ /* condition 2 */ },
...
]
}
}

A condition which evaluates to the logical conjunction (and) of its sub-conditions.

OrCondition (Boolean OR)

{
"or": {
"conditions": [
{ /* condition 1 */ },
{ /* condition 2 */ },
...
]
}
}

A condition which evaluates to the logical disjunction (or) of its sub-conditions.

NotCondition (Boolean NAND)

{
"not": {
"conditions": [
{ /* condition 1 */ },
{ /* condition 2 */ },
...
]
}
}

A condition which evaluates to the logical negation (not) of its sub-conditions. Optionally this condition can have more than one sub-condition, in this Case it evaluates to true if there is at least one sub-condition evaluating to false.

Comparison Conditions

For deciding condition we have a multitude of comparative conditions. These comparisons can be executed against any indexed field in a collection. The types of values that can be compared can be textual, numeric, boolean or a date format.

EqualsCondition ("==")

{
"equals": { "foo": true }
}

A condition evaluating equality between predicate value and its given context counterpart. The equals condition does not do any type conversion so the compared type must match the expression. Thus, "1" (the string) is not considered equal to 1 (the integer).

GreaterThanCondition (">")

{
"greaterThan": { "foo": 3 }
}

A condition evaluating if the given context value is greater than the corresponding predicate value. If the value is null or the values cannot be compared in this way false will be returned.

GreaterOrEqualToCondition (">=")

{
"greaterOrEqualTo": { "foo": 1.2 }
}

A condition evaluating if the given context value is greater or equal to the corresponding predicate value. If the value is null or the values cannot be compared in this way false will be returned.

LessThanCondition ("<")

{
"lessThan": { "foo": "bar" }
}

A condition evaluating if the given context value is less than the corresponding predicate value. If the value is null or the values cannot be compared in this way false will be returned.

LessOrEqualToCondition ("<=")

{
"lessOrEqualTo": { "foo": 2 }
}

A condition evaluating if the given context value is less or equal to the corresponding predicate value. If the value is null or the values cannot be compared in this way false will be returned.

Fixed logical conditions

We also have a few other logical conditions that don't take predicate values.

ExistsCondition

{
"exists": { "foo": null }
}

A condition implementation which checks for the existence of all target variables. The target variable is considered existent if it resolves to any non-null value.

TrueCondition

{
"true": { "foo": null }
}

A condition implementation which checks whether the target variables is True. The target variable is considered true if it resolves to a Boolean with the value true or the string representation "true" with ignored casing. Null variables are considered false.

FalseCondition

{
"false": { "foo": null }
}

A condition implementation which checks whether the target variables is False. The target variable is considered false if it resolves to a Boolean with the value false or the string representation "false" with ignored casing. Null variables are considered false.

Other conditions

RangeCondition

{
"range": { "foo": [0, 100] }
}

A condition evaluating if the given context value is in between the corresponding predicate values. If the value is null or the values cannot be compared in this way false will be returned. If the predicate list does not contain exactly two elements the condition will always return false.

Advanced Example

With the conditions above you can create your own intricate conditions with arbitrary complexity:

{
"and": {
"conditions": [
{
"range": { "date": ["2020-01-01", "2021-01-01"] }
},
{
"or": {
"conditions": [
{
"and": {
"conditions": [
{ "greaterThan": { "meta.importance": 3 } },
{ "exists": { "meta.id": null } }
]
}
},
{ "true": { "valid": null } }
]
}
}
]
}
}

This would evaluate to a condition that fetches collections with

  • a date between "2020-01-01" and "2021-01-01"
  • that also eiter
    • has field valid = true
    • or have
      • meta.importance greater than 3
      • and a meta.id field.