Skip to the content

How to integrate JIRA into Aras Innovator

We receive a lot of questions on data federation when we are evaluated for PLM projects. Mainly because of the legacy systems in place, but also because some dedicated software may be very well suited for some specific people in the company.

In this tutorial, I will show you how to integrate data from JIRA into Aras Innovator.

The step-by-step video tutorial will guide you through the process. Scroll down to find additional information and scripts.

 

Additional tutorial notes

This implementation is based on an ArasLab project:
https://community.aras.com/b/english/posts/calling-a-rest-web-service-from-an-aras-method

Prereq:

Install the latest version of Innovator from: Aras.

Add the 2 below references to method-config.xml. Look at this Aras community Article for instructions on how to do that.

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Data model

Create the ItemType: Jira_ISSUE

Properties:

Property Label Datatype Special req.
jiraid ID String (50)  
jiraurl URL String (150) Hidden: True
jirakey Key String (50) Keyes Name Order: 10
title Title Federated  
description Description Federated  
issuetype IssueType Federated  
status Status Federated  

Server events:

Method Event
ARAS_JIRA_REST_onAfterGet onAfterGet
ARAS_JIRA_REST_onBeforeAdd onBeforeAdd

Settings:
All settings are contained inside this method:
ARAS_JIRA_Settings - If you don't want settings to be hardcoded inside the method-code - you can use the builtin "Variables" itemtype.

ARAS_JIRA_REST_onBeforeAdd

Item JIRA_settings = this.getInnovator().applyMethod("ARAS_JIRA_Settings", "");
string JIRA_user  = JIRA_settings.getProperty("JIRA_user",""); 
string JIRA_token = JIRA_settings.getProperty("JIRA_token",""); 
string JIRA_projectkey = JIRA_settings.getProperty("JIRA_projectkey","");
string JIRA_baseURL = JIRA_settings.getProperty("JIRA_baseURL","");
string encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(JIRA_user+":"+JIRA_token));

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(JIRA_baseURL + "/issue/");
request.ContentType="application/json";
request.Method="POST";
request.Headers.Add("Authorization","Basic "+encoded);
string json = "{\"fields\": {\"project\":{\"key\":\"" + JIRA_projectkey + "\"},"+
            "\"summary\":\""+this.getProperty("title","")+"\","+
            "\"description\":\""+this.getProperty("description","")+"\","+
            "\"issuetype\": {\"name\":\""+this.getProperty("issueType","Task")+"\"}}}";
    
using(var streamWriter = new StreamWriter(request.GetRequestStream())){
    streamWriter.Write(json);
    streamWriter.Flush();
    streamWriter.Close();
}  

var httpResponse=(HttpWebResponse) request.GetResponse();
using(var streamReader = new StreamReader(httpResponse.GetResponseStream())){
    var result = streamReader.ReadToEnd();
    JObject Result = JObject.Parse(result);
    this.setProperty("jiraid",Result["id"].ToString());
    this.setProperty("jiraurl",Result["self"].ToString());
    this.setProperty("jirakey",Result["key"].ToString());
}

return this;

ARAS_JIRA_REST_onAfterGet:

Item JIRA_settings = this.getInnovator().applyMethod("ARAS_JIRA_Settings", "");
string JIRA_user  = JIRA_settings.getProperty("JIRA_user",""); 
string JIRA_token = JIRA_settings.getProperty("JIRA_token",""); 
string JIRA_projectkey = JIRA_settings.getProperty("JIRA_projectkey","");
string JIRA_baseURL = JIRA_settings.getProperty("JIRA_baseURL","");
string html = string.Empty;
string encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(JIRA_user+":"+JIRA_token));

int attempts = 0;
bool completedSuccessfully = false;

while(attempts <= 1 && !completedSuccessfully){
    string ids="(";
    for (int i=0;i<this.getItemCount();i++){
        string id = this.getItemByIndex(i).getProperty("jiraid","");
        if (id!=""){
            if (ids.Length>1){
                ids=ids+",";
            }
            ids=ids+id;
        }
    }
    ids=ids+")";

    // execute the REST Call
    string URL = JIRA_baseURL + "/search?jql=project=\"" + JIRA_projectkey + "\"+AND+id+in+"+ids;
    HttpWebRequest request = (HttpWebRequest) WebRequest.Create(URL);
    request.Headers.Add("Authorization","Basic "+encoded);
    
    JObject Result;
    try
    {
        using(HttpWebResponse response = (HttpWebResponse)request.GetResponse()){
            using(Stream stream = response.GetResponseStream()) {
                using(StreamReader reader= new StreamReader(stream))
                {
                    html = reader.ReadToEnd();
                    Result = JObject.Parse(html);
                }
     
                IList<JToken> issueResults = Result["issues"].Children().ToList();
                
                // merge data
                foreach (JToken issue in issueResults){
                    for (int j =0;j<this.getItemCount();j++){
                        if (this.getItemByIndex(j).getProperty("jiraid","")==issue["id"].ToString()){
                            this.getItemByIndex(j).setProperty("status",issue["fields"]["status"]["name"].ToString());
                            this.getItemByIndex(j).setProperty("title",issue["fields"]["summary"].ToString());
                            this.getItemByIndex(j).setProperty("description",issue["fields"]["description"].ToString());
                            this.getItemByIndex(j).setProperty("jirakey",issue["key"].ToString());
                            this.getItemByIndex(j).setProperty("jiraurl",issue["self"].ToString());
                            this.getItemByIndex(j).setProperty("issuetype",issue["fields"]["issuetype"]["name"].ToString());
                        }
                    }
                }
            }
        }
        completedSuccessfully = true;
    }
    catch
    {
        attempts++;
        for (int i=0;i<this.getItemCount();i++){
                URL = JIRA_baseURL + "/search?jql=project=\"" + JIRA_projectkey + "\"+AND+id="+this.getItemByIndex(i).getProperty("jiraid","");
                request = (HttpWebRequest) WebRequest.Create(URL);
                request.Headers.Add("Authorization","Basic "+encoded);
                
                try
                {
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                } catch{
                    Item deleteOrphanIssue = this.getInnovator().newItem("Jira_ISSUE", "delete");
                    deleteOrphanIssue.setAttribute("where", "[Jira_ISSUE].jiraid='" + this.getItemByIndex(i).getProperty("jiraid","") + "'");
                    deleteOrphanIssue.apply();
                    if (this.isCollection()) this.removeItem(this.getItemByIndex(i));
                }
        }
    }
}
return this;

ARAS_JIRA_Settings:

Innovator inn = this.getInnovator();
Item JIRA_settings = inn.newItem("JIRA_settings","");
JIRA_settings.setProperty("JIRA_projectkey", "-proj_key-");
JIRA_settings.setProperty("JIRA_token", "-paste-token-here-");
JIRA_settings.setProperty("JIRA_user", "your@email.com");
JIRA_settings.setProperty("JIRA_baseURL", "https://[your-jira-instance]/rest/api/2");
return JIRA_settings;

About the author

Stephan Thierry

Stephan Thierry has 20 years of experience in software development and all surrounding processes. which are daily being put to the test as head of IT in Minerva. Among his specialties are .NET-Core, JavaScript, Aras Innovator, Security policies, Infrastructure, Documentation, SourceControl, Bug tracking systems, Support Organisation, GitLab CE, DevOps, Training and Machine Learning.

comments powered by Disqus

Request Demo

Ready to see Medical Device PLM in action? Send an email for a Free Demo and get a one-on-one preview on how your Business can benefit!