Skip to the content

So integrieren Sie Jira-Daten in Aras Innovator

 

Wir erhalten viele Fragen zur Integration von Daten aus verschiedenen IT-Systemen, gerade wenn Unternehmen verschiedene PLM-Systeme miteinander benchmarken. Zum einen gilt den Nachweis zu erbringen, wie Daten aus bereits vorhandenen Systemen im PLM sichtbar gemacht werden können. Oder aber eine IT Lösung liefert Daten aus einem dediziertem Bereich in das PLM und lädt Daten aus dem PLM zurück. 

In diesem Tutorial zeige ich Ihnen am Beispiel von JIRA und Aras Innovator, wie eine solche Integration aufgebaut werden kann. 

Das Schritt-für-Schritt-Video führt Sie durch dieses Tutorial. Nachfolgend finden Sie zusätzliche Informationen und Skripte.

 

Zusätzliche Tutorial-Hinweise

Diese Implementierung basiert auf einem ArasLab-Projekt: https://community.aras.com/b/english/posts/calling-a-rest-web-service-from-an-aras-method

Installieren Sie die neueste Version von Innovator

Fügen Sie die 2 unten stehenden Verweise auf hinzu method-config.xml. In diesem Aras-Community-Artikel finden Sie Anweisungen dazu.

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

 

Datenmodell

Erstellen Sie die 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:
Alle Einstellungen sind in dieser Methode enthalten:
ARAS_JIRA_Settings - Wenn Sie nicht möchten, dass die Einstellungen im Methodencode fest programmiert werden, können Sie das integrierte Programm verwenden "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;
comments powered by Disqus