From 0ee189e8e07b8c74b6565b077ae702edba45c75f Mon Sep 17 00:00:00 2001 From: dcore94 Date: Mon, 18 Oct 2021 12:08:50 +0200 Subject: [PATCH] introduced termination when folder exists meaning order already processed --- templates/da_cache_to_shub.json.j2 | 86 +++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/templates/da_cache_to_shub.json.j2 b/templates/da_cache_to_shub.json.j2 index 571a52a..79ea031 100644 --- a/templates/da_cache_to_shub.json.j2 +++ b/templates/da_cache_to_shub.json.j2 @@ -59,7 +59,7 @@ }, { "name": "decision", - "taskReferenceName": "check_user_existance", + "taskReferenceName": "check_folder_existance", "inputParameters": { "folders": "${check_folder.output.response.body.itemlist}" }, @@ -108,31 +108,69 @@ } }, { - "name" : "pyrest", - "taskReferenceName" : "create_destination_folder", - "type" : "SIMPLE", - "inputParameters" : { - "url" : "${init.input.storagehub}/workspace/items/${workflow.variables.parent_folder_id}/create/FOLDER", - "method" : "POST", - "headers" : { - "Content-type": "application/x-www-form-urlencoded", - "Accept" : "text/plain", - "Authorization" : "${init.input.auth}" - }, - "body" : { - "name" : "${init.input.folder}", - "description" : "Target folder of Bluecloud data downloads", - "hidden" : "false" - } - } + "name" : "http", + "taskReferenceName" : "check_destination_folder", + "type" : "HTTP", + "inputParameters" : { + "http_request": { + "uri" : "${init.input.storagehub}/workspace/items/${workflow.variables.parent_folder_id}/items/${init.input.folder}", + "method" : "GET", + "headers" : { "Authorization" : "${init.input.auth}" } + } + } }, { - "type": "SET_VARIABLE", - "name": "store_target_folderid", - "taskReferenceName": "store_target_folderid", - "inputParameters": { - "target_folder_id": "${create_destination_folder.output.body}" - } + "name": "decision", + "taskReferenceName": "check_destination_folder_existance", + "inputParameters": { + "folders": "${check_destination_folder.output.response.body.itemlist}" + }, + "type": "DECISION", + "caseExpression": "($.folders.length === 0 ? 'create' : 'exists')", + "decisionCases": { + "create": [ + { + "name" : "pyrest", + "taskReferenceName" : "create_destination_folder", + "type" : "SIMPLE", + "inputParameters" : { + "url" : "${init.input.storagehub}/workspace/items/${workflow.variables.parent_folder_id}/create/FOLDER", + "method" : "POST", + "headers" : { + "Content-type": "application/x-www-form-urlencoded", + "Accept" : "text/plain", + "Authorization" : "${init.input.auth}" + }, + "body" : { + "name" : "${init.input.folder}", + "description" : "Target folder of Bluecloud data downloads", + "hidden" : "false" + } + } + }, + { + "type": "SET_VARIABLE", + "name": "store_target_folderid", + "taskReferenceName": "store_target_folderid", + "inputParameters": { + "target_folder_id": "${create_destination_folder.output.body}" + } + } + ], + "exists" : [ + { + "name": "terminate", + "taskReferenceName": "duplicate_folder", + "inputParameters": { + "terminationStatus": "FAILED", + "workflowOutput": "Order already processed." + }, + "type": "TERMINATE", + "startDelay": 0, + "optional": false + } + ] + } }, { "name": "LAMBDA_TASK",