cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Find an existing Expression Rule and apply it to an asset

Highlighted
Marble

Find an existing Expression Rule and apply it to an asset

This script finds an existing Expression Rule and applies it to an asset (via asset includes).

Parameters:

  1. model - model name
  2. serial - serial number
  3. exprRuleName - name of the Expression Rule

import static com.axeda.sdk.v2.dsl.Bridges.*

import net.sf.json.JSONObject

import com.axeda.drm.sdk.scripto.Request

import com.axeda.services.v2.Asset

import com.axeda.services.v2.AssetReference

import com.axeda.services.v2.AssetCollection

import com.axeda.services.v2.AssetCriteria

import com.axeda.services.v2.ExpressionRule

import com.axeda.services.v2.ExpressionRuleCriteria

/*

* ApplyExpRuleToAsset.groovy

*

* Finds an existing Expression Rule and includes an asset into it.

*

* @param model        -   (REQ):Str model of the asset.

* @param serial        -   (REQ):Str serial number of the asset.

* @param exprRuleName        -   (REQ):Str name of the Expression Rule.

*

* @author Sara Streeter <sstreeter@axeda.com>

*/

def response = [:]

def root = [:]

try {

   AssetCriteria assetCriteria = new AssetCriteria()

   assetCriteria.modelNumber = Request.parameters.model

   assetCriteria.serialNumber = Request.parameters.serial

   def findAssetResult = assetBridge.find(assetCriteria)

   def asset = findAssetResult.assets[0]

   ExpressionRuleCriteria expressionRuleCriteria = new ExpressionRuleCriteria()

   expressionRuleCriteria.name = Request.parameters.exprRuleName

   def expressionRuleFindResult = expressionRuleBridge.find(expressionRuleCriteria)

   def expressionRule = expressionRuleFindResult.expressionRules[0]

  def expAssets =  expressionRule.includedAssets.add(asset)

  expressionRuleBridge.update(expressionRule)

  response = [ 

      "expressionRule":expressionRule.name,

      "includedAsset": asset.serialNumber 

      ]

} catch (Exception e) {

     response = [

            faultcode: 'Groovy Exception',

            faultstring: e.message

    ];

}

return ["Content-Type": "application/json","Content":JSONObject.fromObject(response).toString(2)]

Tags (2)