package com.tw.go.task.sonarqualitygate;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by MarkusW on 22.10.2015.
 */
public class SonarParser
{
    private JSONObject project;

    public SonarParser(JSONObject projectResult){
        this.project = projectResult;
    }

    public JSONObject GetQualityGateDetails()
    {
        if (project.has("msr")) {
            JSONArray msrList = project.getJSONArray("msr");

            for (int i = 0; i < msrList.length(); i++)
            {
                JSONObject msr = (JSONObject) msrList.get(i);
                String key = msr.getString("key");

                if("quality_gate_details".equals(key))
                {
                    String data = msr.getString("data");
                    //data = data.replace("\\", "");
                    JSONObject resultObj = new JSONObject(data);
                    return resultObj;
                }

            }


        }
        return null;
    }


}

@@ -39,35 +39,8 @@
 e;%0A%0A
-import org.json.JSONArray;%0A
 impo
@@ -279,21 +279,24 @@
 lic 
-JSONObject Ge
+String getProjec
 tQua
@@ -307,14 +307,13 @@
 Gate
-Detail
+Statu
 s()%0A
@@ -343,19 +343,29 @@
 ct.has(%22
-msr
+projectStatus
 %22)) %7B%0A  
@@ -382,541 +382,175 @@
 JSON
-Array msrList = project.getJSONArray(%22msr%22);%0A%0A            for (int i = 0; i %3C msrList.length(); i++)%0A            %7B%0A                JSONObject msr = (JSONObject) msrList.get(i);%0A                String key = msr.getString(%22key%22);%0A%0A                if(%22quality_gate_details%22.equals(key))%0A                %7B%0A                    String data = msr.getString(%22data%22);%0A                    //data = data.replace(%22%5C%5C%22, %22%22);%0A                    JSONObject resultObj = new JSONObject(data);%0A                    return resultObj;%0A                %7D%0A
+Object projectStatus = project.getJSONObject(%22projectStatus%22);%0A            if (projectStatus.has(%22status%22)) %7B%0A                return projectStatus.getString(%22status%22);
 %0A   
@@ -560,18 +560,16 @@
       %7D%0A
-%0A%0A
         
@@ -601,8 +601,5 @@
   %7D%0A
-%0A%0A%7D%0A
+%7D

Change quality status by new json result