diff --git a/src/tech/avroid/api/Eva.groovy b/src/tech/avroid/api/Eva.groovy deleted file mode 100644 index 3f9acb1..0000000 --- a/src/tech/avroid/api/Eva.groovy +++ /dev/null @@ -1,97 +0,0 @@ -package tech.avroid.api - -import groovy.json.JsonOutput -import groovy.json.JsonSlurper - -/** - * Class for work with API Eva - */ -@Deprecated -class Eva implements Serializable { - private Script script - private String host - private String creds - - /** - * Constructor - * @param script Script - script context - * @param host String - url of Eva service - * @param creds String - jenkins credentials with eva token for API work - */ - Eva(Script script, String host, String creds) { - this.script = script - this.host = host - this.creds = creds - } - - /** - * Create new link for Eva Object. For example, tasks - * !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 - */ - public void createLink(String parentId, String linkName, String url) { - Map body = [ - jsonrpc: "1.2", - method: "CmfLink.create", - kwargs: [ - parent: parentId, - name: linkName, - url: url - ]] - - 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) - ) - } - } - - /** - * Getting Eva task id - * @param filterValue String - value for search task - * @param filterParam String - type of filter for search task. Default value - "code" - * @return String - id of task - */ - public String getTaskId(String filterValue, String filterParam = "code") { - String response = getTask(filterValue, filterParam) - Object result = new JsonSlurper().parseText(response).result - - if (result) { - return result.id - } - return null - } - - /** - * Getting Eva task information - * @param filterValue String - value for search task - * @param filterParam String - type of filter for search task. Default value - "code" - * @return String - id of task - */ - private String getTask(String filterValue, String filterParam = "code") { - Map body = [ - jsonrpc: "1.2", - method: "CmfTask.get", - kwargs: [ - filter: [filterParam, "==", filterValue], - ]] - - script.withCredentials([script.string(credentialsId: creds, variable: 'token')]) { - return script.httpRequest( - url: "$host/api/", - contentType: 'APPLICATION_JSON', - httpMode: 'POST', - customHeaders: [[name: 'Authorization', value: "Bearer $script.token"]], - validResponseCodes: '200', - requestBody: JsonOutput.toJson(body) - ).content.toString() - } - } -} diff --git a/src/tech/avroid/eva/Eva.groovy b/src/tech/avroid/eva/Eva.groovy index 06b2f93..38d7aff 100644 --- a/src/tech/avroid/eva/Eva.groovy +++ b/src/tech/avroid/eva/Eva.groovy @@ -1,7 +1,7 @@ package tech.avroid.eva import groovy.json.JsonOutput -import groovy.json.JsonSlurper +import groovy.json.JsonSlurperClassic /** * Class for work with API Eva @@ -26,16 +26,16 @@ class Eva implements Serializable { /** * Create new link for Eva Object. For example, tasks * !WARNING: can to create multiple similar links - * @param parentId String - id of Object for which created link + * @param taskId String - id of Object for which created link * @param linkName String - name of link * @param url String - full url of link */ - public void createLink(String parentId, String linkName, String url) { + public void createLink(String taskId, String linkName, String url) { Map body = [ jsonrpc: "1.2", method: "CmfLink.create", kwargs: [ - parent: parentId, + parent: taskId, name: linkName, url: url ]] @@ -51,49 +51,6 @@ class Eva implements Serializable { ) } } - - /** - * Getting Eva task id - * @param filterValue String - value for search task - * @param filterParam String - type of filter for search task. Default value - "code" - * @return String - id of task - */ - public String getTaskId(String filterValue, String filterParam = "code") { - String response = getTask(filterValue, filterParam) - Object result = new JsonSlurper().parseText(response).result - - if (result) { - return result.id - } - return null - } - - /** - * Getting Eva task information @Deprecated use getTaskInfo - * @param filterValue String - value for search task - * @param filterParam String - type of filter for search task. Default value - "code" - * @return String - id of task - */ - @Deprecated - private String getTask(String filterValue, String filterParam = "code") { - Map body = [ - jsonrpc: "1.2", - method: "CmfTask.get", - kwargs: [ - filter: [filterParam, "==", filterValue], - ]] - - script.withCredentials([script.string(credentialsId: creds, variable: 'token')]) { - return script.httpRequest( - url: "$host/api/", - contentType: 'APPLICATION_JSON', - httpMode: 'POST', - customHeaders: [[name: 'Authorization', value: "Bearer $script.token"]], - validResponseCodes: '200', - requestBody: JsonOutput.toJson(body) - ).content.toString() - } - } /** * Getting Eva task information @@ -110,14 +67,18 @@ class Eva implements Serializable { ]] script.withCredentials([script.string(credentialsId: creds, variable: 'token')]) { - return script.readJSON( text: script.httpRequest( - url: "$host/api/", - contentType: 'APPLICATION_JSON', - httpMode: 'POST', - customHeaders: [[name: 'Authorization', value: "Bearer $script.token"]], - validResponseCodes: '200', - requestBody: JsonOutput.toJson(body) - ).content.toString())['result'] + String response = script.httpRequest( + url: "$host/api/", + contentType: 'APPLICATION_JSON', + httpMode: 'POST', + customHeaders: [[name: 'Authorization', value: "Bearer $script.token"]], + validResponseCodes: '200', + requestBody: JsonOutput.toJson(body) + ).content + + Map result = new JsonSlurperClassic().parseText(response).result + + return result } } }