This article has been written to help users participating to the Dalet Flex Challenge 2023 - Challenge number 3 Publish. The configurations described here are not intended to be reproduced in a production environment.
Begin the script by defining the execute()
function. Use the following line of code:
def execute() {
Retrieve the asset using flexSdkClient.assetService.getAsset()
method. You can use the following line of code:
def asset = flexSdkClient.assetService.getAsset(context.getAsset().id)
Retrieve the metadata of the asset using flexSdkClient.assetService.getAssetMetadata()
. Pass the asset
variable obtained in the previous step. Use the following line of code:
def metadata = flexSdkClient.assetService.getAssetMetadata(asset)
Log the metadata
using context.logInfo()
to display it. Convert metadata
to a string using as String
. Add the following line of code:
context.logInfo(metadata as String)
Parse the metadata
as JSON using new JsonSlurper().parseText()
. Assign the result to the status
variable. Use the following line of code:
def status = new JsonSlurper().parseText(metadata as String)
Log the value of status."acalder-review"[0]."name"
using context.logInfo()
. This accesses the desired value from the JSON object. Add the following line of code:
context.logInfo(status."acalder-review"[0]."name" as String)
Assign the value of status."acalder-review"[0]."name"
to the cleanStatus
variable. Use the following line of code:
def cleanStatus = status."acalder-review"[0]."name" as String
Log the message 'My clean status is ' followed by the value of cleanStatus
using context.logInfo()
. Add the following line of code:
context.logInfo('My clean status is ' + cleanStatus)
Implement conditional statements to check the value of cleanStatus
. Use an if-else if
structure. Add the following lines of code:
if (cleanStatus == 'Approved') {
return 'ok'
} else if (cleanStatus == 'Refused') {
return 'fail'
}
Finally, close the execute()
function by adding the following line of code:
}
In summary, the script retrieves an asset and its metadata, parses the metadata as JSON, extracts a specific value (status."acalder-review"[0]."name"
), and checks if it is 'Approved' or 'Refused'. The script returns 'ok' if the clean status is 'Approved' and 'fail' if it is 'Refused'.
def execute(){
def asset = flexSdkClient.assetService.getAsset(context.getAsset().id)
def metadata = flexSdkClient.assetService.getAssetMetadata(asset)
context.logInfo(metadata as String)
def status = new JsonSlurper().parseText(metadata as String)
context.logInfo(status."acalder-review"[0]."name" as String)
def cleanStatus = status."acalder-review"[0]."name" as String
context.logInfo('My clean status is ', cleanStatus)
if(cleanStatus == 'Approved'){
return 'ok'
}else if (cleanStatus == 'Refused'){
return 'fail'
}
Comments
0 comments
Please sign in to leave a comment.