Skip to end of banner
Go to start of banner

Batch Metadata Expressions

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Introduced in version 23.1

Introduction

From version 23.1 you can create a batch offering rich metadata expressions where the new metadata of the item can be determined by

  • The (previous) metadata of the item

  • Combinations of fields

  • Conditions

  • Textual operations

Batch with metadata expressions

The new batch task is available and named BatchExpressionTemplatesTask. It takes as an argument a list of metadata sidecar-like arguments. An example of such metadata sidecar is

{
    "Descriptive": {
       "Title": "#{R('Descriptive.Title').toUpperCase()}",
       "Description": "#{R('Descriptive.Title') + ': ' + R('Dynamic.Description')}",
       "Keywords": {"Keyword": "#{{R('Dynamic.CustomTag')}}"}
    },
    "Dynamic": {
        "Orientation": "#{R('Technical.Width') > R('Technical.Height') ? 'Horizontal' : 'Vertical'}",
        "AdditionalInformation": "My custom field"
    }
}

When putting a string in metadata sidecar that has the pattern #{...} it will be evaluated using the Spring Expression Language. Inside an expression, you can reference the metadata using R(<Dotted key>) or record(<Dotted key>) for example R('Descriptive.Title') or record('Descriptive.Title').

The R takes an optional second argument, which is the default value when the metadata field is not present.

Merging

When the templated sidecar is evaluated against a record it will result for example in the following metadata sidecar

{
    "Descriptive": {
       "Title": "MY TEST FILE",
       "Description": "My test file: this is a test file",
       "Keywords": {"Keyword": ["My custom tag"]}
    },
   "Dynamic": {
        "Orientation": "Horizontal",
        "AdditionalInformation": "My custom field"
    }
}

This metadata sidecar will then be merged against the record using the same rules as when MediaHaven Rest API - Updating a record.

The output of the metadata accessor

The output of the metadata accessor R or record is the following depending on which field type the dotted key refers to:

Level

Case

Effect

Example Expression

Example Output

Top

SimpleField

String

R('Descriptive.Title')

My title

Top

ListField

List of Strings

R('Descriptive.Keywords')

["A", "B", "C"]

Top

MapField

Map of Strings

R('Structural.Versioning')

{"Status": "HEAD", "Version": "2"}

Top

MultiItemField

Map of List of Strings

R('Descriptive.Authors')

{"Authors": ["Cedric"], "Director": ["Alice", "Bob"]}

Top

Others

Not allowed

Sub

Child of ListField

List of Strings

R('Descriptive.Keywords.Keyword')

["A", "B", "C"]

Sub

Child of MultiItemField

List of Strings

R('Descriptive.Authors.Director')

["Alice", "Bob"]

Sub

Child of MapField

String

R('Structural.Versioning.Status')

HEAD

Sub

Other

Not allowed

Output after evaluating the expression

After evaluating all expressions in the input metadata sidecar, the result is a new metadata sidecar in JSON. The conversion follows the following rules

Output after evaluating the expression

Conversion into JSON

String

JSON string

Boolean

JSON boolean

Long

JSON number

List<String>

JSON array

Map<String>

JSON object

Map<String,List<String>>

JSON object containing JSON arrays

Notice how the string "#{{R('Dynamic.CustomTag')}}" is evaluated into an array ["My custom tag"]. The end result is a valid metadata sidecar for “Keywords” namely "Keywords": {"Keyword": ["My custom tag"]} whereas before evaluating the expression "Keywords": {"Keyword": "#{...}"} is not a strictly valid metadata sidecar because the value of "Keyword" must be an array and not a string.

Restrictions

The available features of SPel are for security reasons restricted to the following patterns

  • Literal expressions

  • Boolean and relational operators

  • Inline lists, maps, etc

  • Ternary operator

  • The method named “R” or “record”

  • No labels