Case projection

Projection – Abstract

Purpose: Returns a conditional return value via case differentiation with a variable number of branches.

images/download/attachments/106963020/image-2023-11-6_10-53-17-version-1-modificationdate-1699264400572-api-v2.png


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.

  • If no Name is specified, the text null may appear as the column name. As an exception, the column names of configured Projections (in the branches) are not accessed.

Branches

images/download/attachments/106963020/image-2023-11-6_10-53-46-version-1-modificationdate-1699264429504-api-v2.png

Initially, the Case projection already contains a branch for which a condition or a projection can be configured immediately.

  • The menu icon (top left in the screenshot) is repeated for each branch. Among other things, it contains functions for copying and pasting (for entire branches).

  • An additional branch can be created or inserted from the clipboard using the images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/add.svg icon (on the right in the screenshot).




images/download/attachments/106963020/image-2023-11-6_11-4-45-version-1-modificationdate-1699265088500-api-v2.png

The sequence (and therefore priority) of the branches can be adjusted via the tree view (far left in the editor) using drag & drop.

  • The screenshot (left) shows an example with two branches displayed by the tree in the caseWhens node.

  • Drag & drop actions for the elements in the caseWhens node immediately change the order of the branches.

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


images/download/attachments/106963020/image-2023-11-3_14-54-0-version-1-modificationdate-1699019639795-api-v2.png


The hash symbol indicates the placeholder for the configuration of a condition within a branch.

  • The first of several Restrictions can be added to the configuration via the images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/add.svg icon.

  • If no condition is defined, the branch is treated as if a condition had been fulfilled.

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


images/download/attachments/106963020/image-2023-11-6_10-54-13-version-1-modificationdate-1699264456177-api-v2.png


The menu icon (far left within the projection configuration) offers Projections for selection via the context menu.

  • If no projection is defined, the branch returns 'No value' ($null) if its return value is required.

Examples

Typical example: Conditional editing of address data

images/download/attachments/106963020/image-2023-11-6_10-56-44-version-1-modificationdate-1699264607101-api-v2.png

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:

  • The first line (ADDRESS_LINE_1) should directly display the text in the 'Name' property (name1).

  • The second line (ADDRESS_LINE_2) should be filled according to the following case distinction:

    • If the 'Postbox' (postboxNumber) property is filled, the English localized property name should be concatenated with the value via a space character.

    • Otherwise, the 'Street' (street1) property should be linked to the 'Street number' (streetNo) property using a space.

  • The third line (ADDRESS_LINE_3) should output a static text concatenation according to the following scheme:

    • 'Country' (countryCode) followed by a minus sign as separator

    • 'Postal code' (zipcode) followed by a space as separator

    • 'City' (city)

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.

images/download/attachments/106963020/image-2023-11-6_11-0-38-version-1-modificationdate-1699264841485-api-v2.png

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 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:

  • We reference the Bundle via the Class for which the 'Address' (Address) class is selected.

  • The internal property name postboxNumber is specified as the Resource.

  • If the Static option is selected, the desired Locale can be selected statically in the Locale parameter using the Combobox. Here we select 'English' so that the prefix 'Postbox no.' always appears with the default localization.

images/download/attachments/106963020/image-2023-11-6_11-1-35-version-1-modificationdate-1699264898401-api-v2.png

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:

images/download/attachments/106963020/image-2023-11-6_10-52-24-version-1-modificationdate-1699264346709-api-v2.png

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.

Special case: Evaluating a rule in the condition of a Case projection

In addition to the internal 'ID' (id), a CSV search for Users should output the 'username' (username) property as a readable projection if at least one of the following conditions is met:

  • In the execution context, refers to a specific role ('Administrator') as the Role of session.

  • The 'Owner' (ownerId) of a listed user account is the Company of session.

If neither of the two conditions applies, the static text ************ should appear instead of the username.

Configuration:

images/download/attachments/106963020/image-2023-11-6_11-19-34-version-1-modificationdate-1699265977160-api-v2.png

The conditional output for the 'username' (username) property is achieved by a Case projection as follows:

  • We assign the internal property name (username) as the Name for the output column to avoid null appearing as the column title.

  • The Case projection uses two branches:

    • The first branch contains the condition to be evaluated with two instances of the Field restriction in an OR conjunction:

    • Via the second branch of the case differentiation, a Literal projection without an explicit condition returns the static text ************, which is output if the condition in the first branch is not fulfilled.

Runtime example:

In the context of a login without the 'Administrator' role and with a Company of session whose 'ID' (id) is 1902, the search returns the following values, for example:

id,ownerId,username
51,501,************
151,502,************
4201,1902,jdsmith0815
4202,1902,jmmustermann
4203,1902,jmustermann
4204,1902,mjmartinez123
...