From 2c65da730e72f81550e6c8519d7e8fa7a7aebb06 Mon Sep 17 00:00:00 2001 From: "aleksandr.vodyanov" Date: Wed, 10 Jan 2024 14:57:45 +0300 Subject: [PATCH] DO-103_eva_api_class (#10) Reviewed-on: https://git.avroid.tech/DevOps/jenkins-shared-lib/pulls/10 Co-authored-by: aleksandr.vodyanov Co-committed-by: aleksandr.vodyanov --- src/tech/avroid/api/Eva.groovy | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/tech/avroid/api/Eva.groovy b/src/tech/avroid/api/Eva.groovy index 7654b47..6008a1d 100644 --- a/src/tech/avroid/api/Eva.groovy +++ b/src/tech/avroid/api/Eva.groovy @@ -23,13 +23,12 @@ class Eva implements Serializable { /** * Create new link for Eva Object. For example, tasks - * !WARNING: can to create multiple similar links + * !WARNING: can to create multiple similar links * @param parentId String - id of Object for which created link * @param linkName String - name of link * @param url String - full url of link - * @return Boolean - success or failure create */ - public createLink(String parentId, String linkName, String url) { + public void createLink(String parentId, String linkName, String url) { Map body = [ jsonrpc: "1.2", method: "CmfLink.create", @@ -41,13 +40,13 @@ class Eva implements Serializable { script.withCredentials([script.string(credentialsId: creds, variable: 'token')]) { script.httpRequest( - url: "$host/api/", - contentType: 'APPLICATION_JSON', - httpMode: 'POST', - customHeaders: [[name: 'Authorization', value: "Bearer $script.token"]], - validResponseCodes: '200', - requestBody: JsonOutput.toJson(body) - ) + url: "$host/api/", + contentType: 'APPLICATION_JSON', + httpMode: 'POST', + customHeaders: [[name: 'Authorization', value: "Bearer $script.token"]], + validResponseCodes: '200', + requestBody: JsonOutput.toJson(body) + ) } } @@ -59,8 +58,12 @@ class Eva implements Serializable { */ public String getTaskId(String filterValue, String filterParam = "code") { String response = getTask(filterValue, filterParam) + Object result = new JsonSlurper().parseText(response).result - return new JsonSlurper().parseText(response).result.id + if (result) { + return result.id + } + return null } /** @@ -83,7 +86,7 @@ class Eva implements Serializable { contentType: 'APPLICATION_JSON', httpMode: 'POST', customHeaders: [[name: 'Authorization', value: "Bearer $script.token"]], - validResponseCodes: '200', + validResponseCodes: '200', requestBody: JsonOutput.toJson(body) ).content.toString() }