Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

CONNECT data services developer documentation

Asset Rules

  • Last UpdatedSep 08, 2023
  • 4 minute read

Asset rules create assets based on stream properties (such as ID, Name, Description, and stream metadata). Asset rules are executed on streams in the following ways:

  • On-demand execution – an asset rule is defined and created and it is applied to all existing applicable streams
  • Unattended execution – all asset rules are run whenever a stream is created, updated, or deleted.

The asset rules API allows you to programmatically create, read, update, and delete asset rules.

Example Asset Rule

{
   "Id":"sampleID",
   "Name":"sampleName",
   "Description":"sampleDescription",
   "AutomationId":"sampleAutomationID",
   "Expressions":[
      {
         "Field":"Id",
         "Specifications":[
            {
               "Type":"Group",
               "Name":"streamId"
            }
         ]
      },
      {
         "Field":"Name",
         "Specifications":[
            {
               "Type":"Group",
               "Name":"location",
               "StrictValueMappings":true,
               "ValueMappings":{
                  "SL":"San leandro",
                  "AUS":"Austin"
               }
            },
            {
               "Type":"Delimiter",
               "Value":"."
            },
            {
               "Type":"Literal",
               "Value":"test"
            }
         ]
      }
   ],
   "Outputs":[
      {
         "Field":"Asset",
         "Value":{
            "Id":"{location} asset",
            "Name":"{location} asset",
            "Description":"this is an asset generated by an asset rule",
            "Metadata":[
               {
                  "Id":"Location",
                  "Name":"Location",
                  "Description":"the location of the asset",
                  "SdsTypeCode":"18",
                  "Value":"{location}"
               }
            ],
            "StreamReferences":[
               {
                  "Id":"Rule Stream",
                  "Description":"a stream reference to the input stream that caused the rule to generate this asset",
                  "StreamId":"{streamId}"
               }
            ]
         }
      }
   ]
}

Rule Properties

Property Name Type Required? Description
ID String Required An identifier for the asset rule.
Name String Optional Name of the rule. If left empty, the name defaults to the ID.
Description String Optional Description of the asset rule.
Automation Id String Required Reference to the automation ID object whose permissions are used during rule execution.
Expressions Rule Expression List Optional List of expressions that captures values from stream properties.
Outputs Rule Output List Required List of potential outputs of rules. For asset rules, this is a list of assets.

Expressions

Rule expressions define which streams a rule applies to and what information is extracted from the stream. For a rule to apply to a stream, all of the rule's expressions must match. Expressions have the following properties:

  • Fields – strings that determine which stream property to look at for specifications
  • Specifications – objects that define specifications of a segment in a pattern. Refer to [Specification Types][xref:AssetRules#specification-types] and [Specification Objects][xref:AssetRules#specification-objects] for a description.

Fields

The following fields are supported:

Property Name Syntax Description
Id "Id" The stream Id.
Name "Name" The stream name
Description "Description" The stream description
Metadata "Metadata['key']" The stream metadata. The example extracts the value of the metadata with key 'key'.
Type "Type.Properties[?(@.Id == 'Value')].Uom" The stream type. The example extracts the unit of measure from the 'Value' property of the stream type.

The Metadata and Type fields are objects rather than values, so [Json Path Syntax][xref:AssetRules#JSON Paths] is required. The extracted value must be a single value, rather than an object or array. For Metadata, the syntax should always extract the value of a single key in the Metadata collection. For more information on available properties for a stream type, see [Types][xref:sdsTypes].

Specification Types

Specification Description
Wildcard Any remaining characters or strings in a stream property. There can be only one wildcard type in a specification.
Group Collection of characters that include only specified delimiters.
Literal A hard-coded string. Only stream properties with a specified literal are captured by a rule.
Delimiter A specific string that interacts with groups. A group must specify a delimiter to use.

Specification Objects

Property Name Type Required? Description
Type String Required A specification type.
Value String Optional Required only for the iteral and delimiter specification types.
Specifies the text and delimiter values.
Name String Optional Required only for the group and wildcard specification types.
Specifies the name of the extracted group used in the asset output. Must not begin with a digit and all characters must be a letter, digit or underscore.
CharacterType String Optional Required only for the group specification type.
Specifies whether the specification allows Any, Letters, Digits or Alphanumeric characters. If not specified, the default is Any.
CharacterLength Integer Optional Required only for the group specification type.
Specifies the length of characters expected to be extracted by the group. If not specified, it defaults to the longest string length of the group.
RequiredDelimiters Array Optional Required only for the group specification type.
Sequence of required delimiters within a group. If specified, each delimiter within the array must appear in the exact order and number within the group. If not specified, the default value is an empty array.
ValueMappings Dictionary Optional Required only for the group and wildcard specification types.
A collection of mapped values for each group. If not specified, the default is null.
StrictValueMappings Boolean Optional If set to true, for a stream to match a rule, you must set a value / mapping pair within ValueMappings. If false, and a matching value mapping is not present, the value itself is passed through. For example, if you set a value mapping of "PDX":"Portland" within ValueMappings and StrictValueMappings is 'false', a value of PDX is passed through because the ValueMappings object is ignored. If not specified, the default value of true is used.

JSON Paths

JSON paths can be used in the Expression Field to retrieve stream metadata and stream type properties. The following are examples of JSON paths. Note: RegEx in JSON path is not supported in the Field specification.

Retrieve the value of the metadata key 'location' for the stream:

{
   "Field": "Metadata['location']",
   "Specifications": [
      {
         "Type": "Group",
         "Name": "value"
      }
   ]
}

Retrieve the unit of measure of the 'Value' property from the stream type:

{
   "Field": "Type.Properties[?(@.Id == 'Value')].Uom",
   "Specifications": [
      {
         "Type": "Group",
         "Name": "valueUom"
      }
   ]
}

Outputs

Only asset outputs are supported.

Asset output objects

Property Name Type Required? Description
Field String Required The only supported value is Asset.
Value Asset Object Required The definition of the asset that is generated or updated with additional fields when a stream matches the rule criteria. The asset Id is required. All other properties supported in an asset (Name, Description, Metadata, Stream References, Status) are optional. All fields can be specified as a combination of literal values and captured values (for example, Pump{pumpNumber} where {pumpNumber} is defined in a specification). Multiple rules or streams can modify a single asset, with each contributing one or more properties to the rule. During execution, assets are created if they do not exist, and, otherwise, properties are appended to existing assets.
In This Topic
TitleResults for “How to create a CRG?”Also Available in