Metadata

metadata.ql

An entity to handle metadata on meta-allowable objects. Only one should be created per application context. Objects that allow metadata on them are: songs, albums, artists, collections.

Metadata attributes may be owned by a single object, or inherited from parent objects. The hierarchy of inheritance is: song -> album -> artist Such that songs can get metadata from albums and then artists, and albums can get metadata from artists.

Constructor Overview

Constructor Description
Metadata(_connection)

Create a new metadata object with the given database connection. For depending libraries, use the createMetadata function instead of the constructor.

Function Overview

Function Description
static fun createMetadata(database)
static fun defaultMetadata() Create a new metadata connection with the environment variables. Expected environment variables (with defaults) are: - QL_METADATA_DATABASE_HOST (localhost) - QL_METADATA_DATABASE_PORT (5432) - QL_MET...
fun isConnected() Check if the metadata database connection is connected.
fun _getParent(metaObject) Get the parent object of the given object, if it has one.
fun _getHierarchyIds(metaObject, inherit) Get the hierarchy of IDs for the given object, inheriting from parent objects.
fun _constructPlaceholders(count) Construct a string of ? placeholders for a prepared statement.
fun getTags(metaObject) Get the tags for the given object, inheriting from parent objects. If no tags are found, an empty list is returned.
fun getTags(metaObject, inherit) Get the tags for the given object. If no tags are found, an empty list is returned.
fun getDescription(metaObject) Get the description for the given object, inheriting from parent objects. If no description is found, an empty string is returned.
fun _constructDescriptionPlaceholder(count)
fun getDescription(metaObject, inherit) Get the description for the given object. If no description is found, an empty string is returned.
fun getRating(metaObject) Get the rating for the given object, inheriting from parent objects. If no rating is found, -1 is returned.
fun getRating(metaObject, inherit) Get the rating for the given object. If no rating is found, -1 is returned.
fun getCustomField(metaObject, field) Get the custom field for the given object, returned as an Optional.
fun getCustomField(metaObject, field, inherit) Get the custom field for the given object, returned as an Optional.
fun getAllCustomFields(metaObject) Get all custom fields for the given object, inheriting from parent objects.
fun getAllCustomFields(metaObject, inherit) Get all custom fields for the given object.
fun setTags(metaObject, tags) Set the tags for the given object.
fun addTag(metaObject, tag) Add a tag to the given object.
fun removeTag(metaObject, tag) Remove a tag from the given object. If the tag is found in parent objects, remove it from there too.
fun removeTag(metaObject, tag, inherit) Remove a tag from the given object, inheriting from parent objects.
fun setDescription(metaObject, description) Set the description for the given object.
fun setRating(metaObject, rating) Set the rating for the given object.
fun setCustomField(metaObject, field, value) Set the custom field for the given object. Custom field allowed types: string, int, double, boolean
fun setAllCustomFields(metaObject, fields) Set all custom fields for the given object. Custom field allowed types: string, int, double, boolean, list (of the previous types)

Field Overview

Field Description
Connection _connection

Constructors

Metadata(_connection) link

Create a new metadata object with the given database connection. For depending libraries, use the createMetadata function instead of the constructor.

Params
_connection

An active connection to a database

Functions

static fun createMetadata(database) link
static fun defaultMetadata() link

Create a new metadata connection with the environment variables. Expected environment variables (with defaults) are: - QL_METADATA_DATABASE_HOST (localhost) - QL_METADATA_DATABASE_PORT (5432) - QL_METADATA_DATABASE (metadata) - QL_METADATA_USER (admin) - QL_METADATA_PASS (pass)

Returns Metadata

The created metadata object

fun isConnected() link

Check if the metadata database connection is connected.

Returns boolean

true if connected, false if not

fun _getParent(metaObject) link

Get the parent object of the given object, if it has one.

Params
metaObject

The object to get the parent of

Returns Optional

The parent object, if it has one

fun _getHierarchyIds(metaObject, inherit) link

Get the hierarchy of IDs for the given object, inheriting from parent objects.

Params
metaObject

The object to get the hierarchy for

inherit ( boolean )

Whether to inherit from parent objects. If false, only the given object's ID is returned in the array

Returns list

The hierarchy of IDs for the object

fun _constructPlaceholders(count) link

Construct a string of ? placeholders for a prepared statement.

Params
count ( int )

The number of placeholders to construct

Returns string

The constructed placeholder string

fun getTags(metaObject) link

Get the tags for the given object, inheriting from parent objects. If no tags are found, an empty list is returned.

Params
metaObject

The object to get tags for

Returns list

The tags for the object, as a list of strings

fun getTags(metaObject, inherit) link

Get the tags for the given object. If no tags are found, an empty list is returned.

Params
metaObject

The object to get tags for

inherit ( boolean )

Whether to inherit from parent objects

Returns list

The tags for the object, as a list of strings

fun getDescription(metaObject) link

Get the description for the given object, inheriting from parent objects. If no description is found, an empty string is returned.

Params
metaObject

The object to get the description for

Returns string

The description for the object

fun _constructDescriptionPlaceholder(count) link
fun getDescription(metaObject, inherit) link

Get the description for the given object. If no description is found, an empty string is returned.

Params
metaObject

The object to get the description for

inherit ( boolean )

Whether to inherit from parent objects

Returns string

The description for the object. If no description is found, an empty string is returned

fun getRating(metaObject) link

Get the rating for the given object, inheriting from parent objects. If no rating is found, -1 is returned.

Params
metaObject

The object to get the rating for

Returns double

The rating for the object

fun getRating(metaObject, inherit) link

Get the rating for the given object. If no rating is found, -1 is returned.

Params
metaObject

The object to get the rating for

inherit ( boolean )

Whether to inherit from parent objects

Returns double

The rating for the object

fun getCustomField(metaObject, field) link

Get the custom field for the given object, returned as an Optional.

Params
metaObject

The object to get the custom field for

field

The field to get

Returns Optional

The custom field for the object, if present. Actual value is whatever type it was set to (e.g. string, int, etc.)

fun getCustomField(metaObject, field, inherit) link

Get the custom field for the given object, returned as an Optional.

Params
metaObject

The object to get the custom field for

field

The field to get

Returns Optional

The custom field for the object, if present. Actual value is whatever type it was set to (e.g. string, int, etc.)

fun getAllCustomFields(metaObject) link

Get all custom fields for the given object, inheriting from parent objects.

Params
metaObject

The object to get the custom fields for

Returns Map

A map of all custom fields for the object, with the field name as the key and the value as the value

fun getAllCustomFields(metaObject, inherit) link

Get all custom fields for the given object.

Params
metaObject

The object to get the custom fields for

inherit ( boolean )

Whether to inherit from parent objects

Returns Map

A map of all custom fields for the object, with the field name as the key and the value as the value

fun setTags(metaObject, tags) link

Set the tags for the given object.

Params
metaObject

The object to set tags for

tags ( list )

The tags to set, as a list of strings

fun addTag(metaObject, tag) link

Add a tag to the given object.

Params
metaObject

The object to add the tag to

tag ( string )

The tag to add

fun removeTag(metaObject, tag) link

Remove a tag from the given object. If the tag is found in parent objects, remove it from there too.

Params
metaObject

The object to remove the tag from

tag ( string )

The tag to remove

fun removeTag(metaObject, tag, inherit) link

Remove a tag from the given object, inheriting from parent objects.

Params
metaObject

The object to remove the tag from

tag ( string )

The tag to remove

inherit ( boolean )

Whether to inherit from parent objects

fun setDescription(metaObject, description) link

Set the description for the given object.

Params
metaObject

The object to set the description for

description ( string )

The description to set

fun setRating(metaObject, rating) link

Set the rating for the given object.

Params
metaObject

The object to set the rating for

rating ( double )

The rating to set

fun setCustomField(metaObject, field, value) link

Set the custom field for the given object. Custom field allowed types: string, int, double, boolean

Params
metaObject

The object to set the custom field for

field

The field to set

value

The value to set

fun setAllCustomFields(metaObject, fields) link

Set all custom fields for the given object. Custom field allowed types: string, int, double, boolean, list (of the previous types)

Params
metaObject

The object to set the custom fields for

fields ( Map )

A map of all custom fields for the object, with the field name as the key and the value as the value