Literal projection

Projection – Abstract

Purpose: Returns a simple fixed value in the context of a search.

images/download/attachments/78251658/image-2023-10-24_11-29-30-version-1-modificationdate-1698139782480-api-v2.png

A Literal projection returns a fixed value in the context of a search, determined solely by the value configuration for the Literal parameter.

The Literal projection is frequently (and often repeatedly) used in the context of a Concatenated projection to contribute static components to a concatenated text.

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 string image of the value resolver from the value configuration for the Literal that generates the return value is used as the column name (if relevant). 'Static resolvers' usually return their value or a string image of it (e.g. 'true').
    NOTE◄ The automatically generated column name is only suitable in exceptional cases. If the Literal projection is at all relevant for the name of an output column, it is therefore recommended to explicitly specify an (alias) name for the column.

Literal

undefined

The value configuration determines a return value, which is determined once and enters as a constant in the execution of the query on the database.

  • A Literal projection is therefore not 'resolved' individually for each row returned from the database.

By default, a text value resolver (see Static values) is suggested, since returning a string is the most common use for a static value.

Technically, any value resolvers (individually or in combination, see Chained resolver) can be used to define a Literal. However, not all data types are suitable as return values for a Literal.

  • In general, complex values (data objects with multiple fields, e.g. a 'Date with time', a 'Number with unit' or a dynamic enumeration value) cannot be processed.

  • Only in special cases certain data types are automatically translated into a data type suitable for the Literal projection (e.g. 'Static enumeration value' → Long for the 'Ordinal').

Examples

Typical example: Text concatenation with static components

The Literal projection is used particularly often to combine field contents with static text characters in a Concatenated projection of a CSV or tuple search.

In the following example, in a search on the City entity, a reference to the 'State' (state) is enclosed in brackets and then attached to the place name (placeName).

The screenshot shows a Concatenated projection with four text components:

  • At positions 1 and 3, one Property projection each accesses a field of the entity.

  • At positions 2 and 4, a Literal projection adds a static string to structure the concatenated string:

    • The first Literal ' (' contains a space and the opening brackets.

    • The second Literal ')' contains only one closing bracket.

NOTE◄ All projections used here do without a specification for the Name parameter. Effectively, the column name for the Concatenated projection is therefore systematically composed from the default names for the concatenated projections. The literals contribute the complete Literal.


Runtime example:

placeName (state)
Neukirchen (Oberösterreich)
Neukirchen (Schleswig-Holstein)
Neukirchen (Hessen)
Neukirchen (Bayern)

images/download/attachments/78251658/image-2023-10-24_11-34-4-version-1-modificationdate-1698140056338-api-v2.png

Simple example: Write a number range value into the query result

Each time a search is called, a unique string is generated via a Number range value resolver, which on one hand identifies the executing user (User of session) via his ID (id) and on the other contains a 'sequence number' for the query.

Configuration:

NOTE◄ In order for a Literal projection to appear in the search result, a tuple or CSV search must be performed. In the example, we assume a CSV search for an unspecified entity.

The screenshot shows three Projections for the (CSV) search, the first of which – a Literal projection – is shown expanded:

  • The Name parameter with the value 'Search_ID' labels the column in the output (see below).

  • The value configuration for the Literal uses the Number range value resolver for the Number range type 'XF_SEARCH_CONTROL' set up for this purpose, in order to obtain a value once via this, which is assigned as a constant for the projection.

The other projections with the (alias) names 'Booking' and 'Status' contain the actual payload of our request.

images/download/attachments/78251658/image-2023-10-24_11-37-33-version-1-modificationdate-1698140265362-api-v2.png

Runtime example:

First CSV search request

Subsequent CSV search request

Search_ID,Booking,Status
USR:1901#QRY:1000007,RE01230858,NEW
USR:1901#QRY:1000007,RE01230857,NEW
USR:1901#QRY:1000007,RE01230856,NEW
USR:1901#QRY:1000007,RE01230849,NEW
USR:1901#QRY:1000007,RE01230846,NEW
USR:1901#QRY:1000007,RE01230845,NEW
USR:1901#QRY:1000007,RE01230841,NEW
USR:1901#QRY:1000007,RE01000000,NEW
Search_ID,Booking,Status
USR:1901#QRY:1000009,RE01230859,NEW
USR:1901#QRY:1000009,RE01230858,NEW
USR:1901#QRY:1000009,RE01230857,NEW
USR:1901#QRY:1000009,RE01230856,REJECTED
USR:1901#QRY:1000009,RE01230849,NEW
USR:1901#QRY:1000009,RE01230846,NEW
USR:1901#QRY:1000009,RE01230845,CONFIRMED
USR:1901#QRY:1000009,RE01230841,NEW
USR:1901#QRY:1000009,RE01000000,CONFIRMED
  • The second run results in changed status values for some bookings and an additional new booking compared to the first one.

Simple example: 'Recoding' a Boolean value (e.g. to plain text)

Fields with Boolean values can be used to binarily assign or deny qualitative characteristics to an entity. In a direct projection for such a field, a Boolean value (true/false) then appears in each case, without it being apparent when looking at an output line what this should actually mean.

The 'readability' of the data in a search result can then be increased by assigning a text identifier describing the presence or absence of the flagged feature instead of the Boolean value in each output line.

In the following very simple case, the status of a user account (see Users) is 'recoded' as plain text using the 'Active' (active) Boolean field in a projection, so that the text 'ACTIVE' or 'INACTIVE' appears.

Configuration:

NOTE◄ In order for a Literal projection to appear in the search result, a tuple or CSV search must be performed. In the example, we assume a CSV search for the 'User' (User) entity.

The screenshot shows two Projections for the output of a list of user accounts with a clear indication whether the respective account is active ('ACTIVE') or not ('INACTIVE'):

  • The first projection named 'ACCOUNT_STATUS' uses a Case projection to evaluate the 'Active' (active) Boolean field of the user account by a Field restriction, which is satisfied if the active field contains the value true.

  • The second projection identifies the user account by name – by Property projection on the 'username' (username) property.

images/download/attachments/78251658/image-2023-10-24_11-39-50-version-1-modificationdate-1698140402397-api-v2.png

Runtime example:

In the result of the CSV search, the ACCOUNT_STATUS column shows in an immediately understandable way whether the respective account is active or not.

The output of true/false would only be understandable in connection with the column name.

ACCOUNT_STATUS,ACCOUNT_NAME
ACTIVE,mjmartinez123
ACTIVE,jmustermann
INACTIVE,jmmustermann
INACTIVE,jdsmith0815
....

Special use: Literale Projektion as a check value in a Field restriction

Configuration:

The screenshot shows the configuration for the Restriction of a custom overview for Company accounts accounts based on an OR operation of two instances of the Field restriction:

  • The first Field restriction (left; collapsed) checks if the company metatype 'Company' (COMPANY) is selected in the 'Metatype' (metaType) field of the company. This criterion defines the restriction that should take effect for all roles other than the 'Administrator' role.

  • The second Field restriction (right; expanded) determines whether the Role of session is the 'Administrator' role. If this is the case, then the Field restriction has a 'easing' effect on the other criterion because of the OR conjunction, i.e.: if an 'administrator' is logged in, then the constraint for the 'metatype' is effectively ignored.

    • As a compare value (right) within the Field restriction, a Role value resolver can be used directly to define the 'Administrator' role as a fixed value.

    • As a check value (left) within the Field restriction, on the other hand, only a projection can be considered for formal reasons. Here we use the Literal projection, in which the Role of session resolver can be used. Since this returns an entity of the 'Role' (Role) type, i.e. a complex data object, we still have to concatenate an Object property resolver to get a simple fixed value (here: Long) from the 'ID' (id) field which is suitable as a Literal.

      NOTE◄ As can be seen in the screenshot, we also explicitly resolve the 'ID' field relevant for the comparison in the compare value (right) via an Object property resolver, although the constraint would work without this thanks to an automatic type conversion (Entity → Long/id).

images/download/attachments/78251658/image-2023-10-24_11-42-52-version-1-modificationdate-1698140584585-api-v2.png

ALTERNATIVE configuration:

The configuration shown on the right solves the task equally but a bit more elegantly:

  • The first Field restriction (left; collapsed) has been kept unchanged.

  • The second Field restriction (right; expanded) again acts as an 'exception rule', i.e. to neutralize the restriction for the 'metatype' when an 'administrator' is logged in:

    • We define the check value (left) again via a Literal projection. However, this time we obtain the Boolean return value of a Role rule via a Rule value resolver as the Literal. This is a considerable advantage at the latest when the 'exception' applies to more than one role.

    • As a compare value (right) we need here only a value resolver for a static Boolean value true (see Static values).

NOTE◄ Using the Rule value resolver, any rules can be included in the Restriction according to this scheme, which enables, among other things, access to Association criteria as a Sub criterion rule. However, it must be taken into account that the return values of rules come into play this way only as constants, they cannot be applied to fields of the entity searched for or evaluated in its context.

If, on the other hand, a Property projection returns a check value from a Boolean field of the entity searched for, for example, this can be contrasted with a Boolean compare value from a Rule value without this having to be 'packed' (on the right-hand side in the comparison) into a Literal projection for this purpose.

images/download/attachments/78251658/image-2023-10-24_11-41-13-version-1-modificationdate-1698140485846-api-v2.png