Case projection
Projection – Abstract
Purpose: Returns a conditional return value via case differentiation with a variable number of branches.
The Case projection provides a conditional return value via case differentiation with a variable number of branches for which different Projections can be configured.
A condition can be defined for each branch (via Restrictions). The conditions are 'checked' from left to right according to the following scheme:
If the existing condition is fulfilled or no condition exists, the projection in the associated branch determines the return value for the Case projection. Other branches are then irrelevant.
If a condition exists but is not fulfilled, the next branch is checked. If no further branch exists, 'No value' ($null) is returned.
►IMPORTANT◄ If an Case projection uses more than one branch, all configured Projections must provide the same data type, otherwise errors will occur on the database side. Only 'No value' ($null) is compatible with all other data types.
Configuration
Parameter |
Type |
Description |
Name |
String |
The optional Name parameter can be used to assign an (alias) name to the projection.
|
Branches |
||
|
Initially, the Case projection already contains a branch for which a condition or a projection can be configured immediately.
|
|
|
The sequence (and therefore priority) of the branches can be adjusted via the tree view (far left in the editor) using drag & drop.
►NOTE◄ A case distinction often contains an 'Else' branch without a condition. If this is moved to an earlier position, subsequent branches become ineffective. |
|
Condition |
|
The hash symbol indicates the placeholder for the configuration of a condition within a branch.
►NOTE◄ The symbolism for rules (see Rules and values) looks similar for good reason. However, rules cannot be used for the condition within a search. It must be possible to evaluate the condition on the database side. However, Rules and values can only be evaluated directly in Lobster Data Platform / Orchestration. In special use cases, it can still be useful to integrate the results of rules or values into the logic of the condition via Restrictions. However, such results can only be included as constants in the database query generated by the search. |
Projection |
|
The menu icon (far left within the projection configuration) offers Projections for selection via the context menu.
|
Examples
Typical example: Conditional editing of address data
|
A tuple search prepares the data from Addresses in such a way that three projections prepare the 'text lines' for the address when it is sent by post:
|
Runtime example:
<core:TupleSearchResult maxResults="100" count="84">
<columns>
<name>ADDRESS_LINE_1</name>
<name>ADDRESS_LINE_2</name>
<name>ADDRESS_LINE_3</name>
</columns>
<result>
<row>
<item xsi:type="xsd:string">fixIT Ltd.</item>
<item xsi:type="xsd:string">Uphill 247</item>
<item xsi:type="xsd:string">IE-X64GB Array on Byte</item>
</row>
<row>
<item xsi:type="xsd:string">MEGATRUST Inc.</item>
<item xsi:type="xsd:string">Postbox no. XYZ0815</item>
<item xsi:type="xsd:string">MT-SCM Smart City</item>
</row>
...
</result>
</core:TupleSearchResult>
Configuration:
As an application example for Case projection, the definition for the second address line (ADDRESS_LINE_2) is particularly relevant, as the content is to be formatted depending on a condition.
The Case projection is configured as shown in the screenshot:
The text ADDRESS_LINE_2 is entered directly as the Name for the output column.
We set up two branches for the two cases to be distinguished:
The first branch (left) is intended for the case where a 'P.O. Box' is specified:
The Field restriction in the condition checks whether the 'Postbox' (postboxNumber) property is 'filled' (!=null).
In this case, the Concatenated projection below links the property name as a Literal projection (see following note for details) with the value from the 'Mailbox' property via a space (Literal projection) as desired.
The second branch (right) regulates the default case (no 'mailbox' specified) via another Concatenated projection.
No condition is configured, so this branch always takes effect if the condition for the first branch is not fulfilled.
►NOTE◄ Further branches could be added to the case differentiation, e.g. to differentiate between the preparation with and without 'house number' or to include the optional second property for the street (street2). Of course, it is also possible to use another instance of the Case projection within a projection in order to display a hierarchical 'decision tree'.
►NOTE◄ The prefix (property name) for the 'mailbox' within the Concatenated projection configured in the first branch provides a Literal projection whose Literal uses a Value from localization resolver with the following configuration:
|
|
More complex example: Conditional evaluation for a company and address attribute
A search should check whether the consignee address of a shipment (see Shipments) refers to a Country that is on a 'blacklist' for deliveries.
The 'blacklist' is given in the context by a blacklist variable, which contains a list of dynamic enumeration values of the Country type.
The consignee address of the shipment is defined via the 'Company and address attribute' with the (sub)type 'Consignee' (CNE):
If an explicit 'address' (address) is specified for the CNE attribute, this should be decisive.
If no explicit 'address' (address) is specified, the attribute should by convention reference a 'company' (company) instead, whose address (company.address) should then be included in the check.
Configuration:
We limit ourselves here to the Field restriction, which is considered 'passed' if the 'recipient country' is not included in the 'blacklist'.
A Chained projection is used in the check value (left), which enables us to use a case distinction when 'resolving' the company and address attribute at the address level:
The Typed attribute projection initially only accesses the complete attribute value:
The Attribute parameter specifies that the attribute type should be 'Company and address attribute'.
The Type parameter specifies the desired (sub)type 'Consignee' (CNE) from the dynamic enumeration Company type for the attribute type 'Company and address attribute'.
No entry is made for the Property parameter so that the decision on the decisive property can be made in the next stage of the concatenation.
Two branches are configured within the Case projection:
The first branch uses Field restriction as a condition to determine whether the address property of the attribute is filled (not $null) and, if this is the case, passes the specified address (address) on to the next level of the concatenation.
The second branch does not use a condition. It is used if the address property is not filled and then forwards the company address (company.address) to the next level of the concatenation.
The final Property projection refers to the 'Country' property (countryCode) to be evaluated, which should not be found in the list value of the blacklist variable.
The compare value (right) is provided by the blacklist variable, in the form of a list of Country values not specified here.
►NOTE◄ The Chained projection and the Case projection could be 'avoided' by testing the following logic instead:
(<CNE>.address.countryCode not in blacklist) OR ((<CNE>.address.countryCode == $null) AND (<CNE>.company.address,countryCode not in blacklist))
This logical aggregate can be implemented by linking several instances of the Field restriction. In contrast, the solution approach shown above avoids repeated access to the typed attribute (symbolically referred to as <CNE> in the aggregate) via the Chained projection and the redundant reference to the list variable (blacklist) as a compare value via the Case projection used within.
►NOTE◄ Special cases ('Attribute does not exist', 'No company referenced', 'Company does not reference an address', 'Address does not specify a Country') are not discussed here. We assume that the Field restriction is executed in a context in which these cases are already excluded.