快速简单的java程序,用于与JIRA对话并创建史诗、故事和问题

快速简单的java程序,用于与JIRA对话并创建史诗、故事和问题,java,rest,jira,Java,Rest,Jira,我正在寻找一些快速简单的java程序,可以与JIRA接口,创建史诗、故事和问题我相信这个程序可以修改/扩展,并且可以优化。我正在寻找反馈。我计划添加XML文件,其中可以添加所有数据,并可以依次创建任务、史诗、故事等 package com.xxxxxx.mavenify.HelloWorldy; /**/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import j

我正在寻找一些快速简单的java程序,可以与JIRA接口,创建史诗、故事和问题

我相信这个程序可以修改/扩展,并且可以优化。我正在寻找反馈。我计划添加XML文件,其中可以添加所有数据,并可以依次创建任务、史诗、故事等

package com.xxxxxx.mavenify.HelloWorldy;

/**/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.Charsets;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import okhttp3.ResponseBody;


import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;


/**
 * Hello world!a
 *
 */
public class App 
{public static String ticket = "https://wts-jira.xxxxx.com/jira/rest/api/2/issue"; //rest/api/2/issue/

    public static void main( String[] args )
    {
        getHashmap();
    }

    public static String encodedPassword()
    {       return "Basic dT zU3NjI3MjpTdW1tZXIyMDE5";                  
    }

    public static String generateEpic(String summary,String componentIdNumber,String componentIdText,String applicationIDNumber,
            String applicationIDText,String acceptanceCriteria1, String dueDate,String descriptionText,String issueType)
    {
        return new String("{\"fields\": {\"project\": {\"key\": \"WHSAR\"},\"assignee\": {\"name\":\"u576272\"},\"summary\": \""+ applicationIDText + " - Artifactory migration"+ "\",\r\n" + 
                "\"customfield_12703\": \"" + applicationIDText + "\", \"customfield_19545\": {\"Option id\": \"38679\",\"value\": \"Artifactory migration\"\r\n" + 
                "},\"customfield_10183\": 7,\"customfield_15891\": {\"Option id\": \""+ applicationIDNumber+ "\",\"value\": \""+ applicationIDText+"\"},"
                        + "\"customfield_11709\": \"Receive sign-off email or message from the app team manager.\",\"duedate\": \"26-04-19\",\r\n" + 
                "\"description\": \""+descriptionText+"\", \"issuetype\": {\"name\": \"Epic\"}}}\r\n"); 
        }

    public static String generateUserStory(String summary,String componentIdNumber,String componentIdText,String applicationIDNumber,
            String applicationIDText,String acceptanceCriteria1,String dueDate,String descriptionText,String issueType, String epicLink)
    {                                           
        return new String("{\"fields\": {\"project\": {\"key\": \"WHSAR\" }, \"summary\": \"" + summary + "\", \"customfield_19545\": { \"Option id\": \""+componentIdNumber+"\",\"value\": \""+componentIdText+"\"}, \"customfield_15891\": {\r\n" + 
                "\"Option id\": \""+applicationIDNumber+"\",\"value\": \""+applicationIDText+"\"},\"duedate\": \"" + dueDate +"\",\"customfield_12702\":\""+epicLink+"\", \"description\": \""+ applicationIDText + " - "+ "Ensure artifactory migration is complete.\","
                        + "\"customfield_11709\": \""+acceptanceCriteria1+"\",\"issuetype\": {\"name\": \"User Story\" }}}");
    }

    public static String generateTask(String summary,String componentIdNumber,String componentIdText,String applicationIDNumber,
            String applicationIDText,String acceptanceCriteria1,String dueDate,String descriptionText,String issueType, String storyLink)
    {
        return new String("{\"fields\": {\"project\": { \"key\": \"WHSAR\" },\"parent\": {\"key\": \""+ storyLink +"\"},"
                + "\"customfield_15891\": {\"Option id\": \""+applicationIDNumber+"\",\"value\": \""+applicationIDText+"\" },\"summary\": \"" + applicationIDText +" -  "+ summary
                + "\",\"customfield_19545\": {\"Option id\": \""+componentIdNumber+"\",\"value\": \""+componentIdText+"\"},"
                + "\"customfield_11709\": \""+acceptanceCriteria1+ "\",\"duedate\": \"26-04-19\",\"description\": \"" + applicationIDText + " -  "+ descriptionText + "\",\"issuetype\": {\"id\": \"5\"}}}");
    }

    public static void getHashmap() 
    {        
        try {
            String applicationIDNumber = "38782";


/*          38717 = IBOSS               
*/                          
            String applicationIDText = "1SOR";
            String dueDate = "06-05-19";    
            org.json.simple.JSONObject jnew;            
            String issueType;
            JSONParser j1 = new JSONParser();

            org.json.simple.JSONObject jnew2;
            org.json.simple.JSONObject jnew3;

            jnew = genEpic(applicationIDNumber, applicationIDText, dueDate);

            String summaryUS1 = applicationIDText  + " - Ensure project kick off date and resource details from app manager.";
            String summaryUS2 = applicationIDText + " - Ensure migration pre-requisites and Go/no go.";
            String summaryUS3 = applicationIDText + " - Ensure artifactory migration is complete.";

            String componentIdNoUS1 = "38680";
            String componentIdTextUS1 ="Prerequisites";

            String accepatanceCriteriaUS1 = "Acceptance of Project kick off date and the resources details from app manager.";
            String accepatanceCriteriaUS2 = "Migration pre-requisites are complete and team decision of either Go /no go.";
            String accepatanceCriteriaUS3 = "Receive sign-off email or message from the app team manager.";         

            String descriptionUS1 = "Ensure app manager has confirmed project kick off date and resource details for the application being migrated.";
            String descriptionUS2 = "Ensure migration pre-requisites are complete before the application migration has started and team is clear on Go/no go.";
            String descriptionUS3 = "Ensure artifactory migration is complete.";

            String componentIdNoUS2  = "38682"; 
            String componentIdTextUS2 ="Initiation";

            String componentIdNoUS3  = "38681";
            String componentIdTextUS3 ="Verification";          

            issueType ="user story";
            String epicLink =jnew.values().toArray()[2].toString();         

            org.json.simple.JSONObject jnew1 =  (org.json.simple.JSONObject)j1.parse(genIssue(summaryUS1, applicationIDNumber, applicationIDText, componentIdNoUS1, 
                    componentIdTextUS1, accepatanceCriteriaUS1, dueDate, descriptionUS1, issueType, epicLink, ""));

            System.out.println("story 1 done ->" +jnew1.values().toArray()[2].toString());

            j1= new JSONParser();
            jnew2 =  (org.json.simple.JSONObject)j1.parse(genIssue(summaryUS2, applicationIDNumber, applicationIDText, componentIdNoUS2, 
                    componentIdTextUS2, accepatanceCriteriaUS2, dueDate, descriptionUS2, issueType, epicLink, ""));

            System.out.println("story 2 done ->" +jnew2.values().toArray()[2].toString());

            j1= new JSONParser();
            jnew3 =  (org.json.simple.JSONObject)j1.parse(genIssue(summaryUS3, applicationIDNumber, applicationIDText, componentIdNoUS3, 
                    componentIdTextUS3, accepatanceCriteriaUS3, dueDate, descriptionUS3, issueType, epicLink, ""));

            System.out.println("story 3 done ->" + jnew3.values().toArray()[2].toString());

            genTask(applicationIDNumber, applicationIDText, dueDate, jnew2.values().toArray()[2].toString(), jnew3.values().toArray()[2].toString());


        }catch (Exception ex) {

            //handle exception here
            System.out.println(ex.toString() +  " \n "+ ex.getMessage());
            ex.printStackTrace();

        } finally {
            //Deprecated
            //httpClient.getConnectionManager().shutdown(); 
        }       
    }

    static org.json.simple.JSONObject genEpic(String applicationIDNumber, String applicationIDText, String dueDate)
            throws ParseException, IOException {
        org.json.simple.JSONObject jnew;
        String summaryEText = applicationIDText  + " - Artifactory migration"; //1CCP
        String componentIdNumber = "38679";
        String componentIdText = "Artifactory migration";           
        String acceptanceCriteria = "Client Sign-off";

        String descriptionText = applicationIDText  + " - Below instructions are applicable to you or your team ONLY if you use "
                + "old artifactory instance https://wfs-artifactory.xxxxx.com. \\n It is moved to new instance - "
                + "https://artifactory-intg-b.xxxxxx.net ";     

        String issueType ="epic";

        JSONParser j = new JSONParser();
        jnew =  (org.json.simple.JSONObject)j.parse(genIssue(summaryEText, applicationIDNumber, applicationIDText, componentIdNumber, 
                componentIdText, acceptanceCriteria, dueDate, descriptionText, issueType, "", ""));

        //{"customfield_15891":"Option id 'null' is not valid"}
        System.out.println("epic done " + applicationIDText + " -> " + jnew.values().toArray()[2].toString());
        return jnew;
    }

    static void genTask(String applicationIDNumber, String applicationIDText, String dueDate, 
            String storyLink2, String storyLink3) throws ParseException, IOException {
        String issueType;
        String summaryT1 = "Ensure dev-lead acceptance of migration documentation";
        String componentIdT1 = "38684";
        String componentTextT1 = "Documentation";
        //appID and text
        String acceptanceCriteriaT1 = "Confirmation from the dev-lead that migration document is received.";
        String descriptionT1 ="Ensure dev-lead has received the migration documentation.";

        String summaryT2 = "Identify application dependencies.";
        String componentIdT2 = "38679";
        String componentTextT2 = "Artifactory migration";
        //appID and text
        String acceptanceCriteriaT2 = "Document application dependencies in the sub-task:";
        String descriptionT2 ="Identify application dependencies - set of questionnaire \\n " +
                "1. if job touches AHP, MAVEN, Gradle, nuget, npm, promethus, nexus.\\n " + 
                "2. If other applications are dependent on application in scope - if so how many of them and what are they? \\n ";


        String summaryT3 = "Ensure successful local build";
        String componentIdT3 = "38683";
        String componentTextT3 = "CI (Continuous Integration)";
        //appID and text
        String acceptanceCriteriaT3 = "email or message from SME or app team that local builds are successful";
        String descriptionT3 ="Ensure successful local build.  Here is the documentation:"
                + "https://confluence.xxxxx.net/display/WBT/Gradle+User+Set+Up+for+using+INTG \\n "  
                                + "https://confluence.xxxxxx.net/display/WBT/Maven+User+Set+Up+for+using+INTG \\n"  
                                + "https://confluence.xxxxxxx.net/display/WBT/Nuget+User+Set+Up+for+using+INTG \\n"  
                                + "https://confluence.xxxxxxx.net/display/WBT/NPM+User+Set+Up+for+using+INTG";

        String summaryT4 = "Ensure successful build from jenkin job";
        String componentIdT4 = "38683";
        String componentTextT4 = "CI (Continuous Integration)";
        //appID and text
        String acceptanceCriteriaT4 = "Receive sign-off or message from app team that jenkins builds are good.";
        String descriptionT4 ="Ensure successful build from jenkin job.";

        issueType ="task";

        JSONParser j1 = new JSONParser();
        System.out.println("sub task 1 done ->" + ((org.json.simple.JSONObject)j1.parse(genIssue(summaryT1, applicationIDNumber, applicationIDText, 
                componentIdT1,componentTextT1, acceptanceCriteriaT1, dueDate, descriptionT1, issueType, "", storyLink2))).values().toArray()[2].toString());

        j1= new JSONParser();

        System.out.println("sub task 2 done ->" + ((org.json.simple.JSONObject)j1.parse(genIssue(summaryT2, applicationIDNumber, applicationIDText, 
                componentIdT2,componentTextT2, acceptanceCriteriaT2, dueDate, descriptionT2, issueType, "", storyLink2))).values().toArray()[2].toString());

        j1= new JSONParser();

        System.out.println("sub task 3 done ->" + ((org.json.simple.JSONObject)j1.parse(genIssue(summaryT3, applicationIDNumber, applicationIDText, 
                componentIdT3,componentTextT3, acceptanceCriteriaT3, dueDate, descriptionT3, issueType, "", storyLink3))).values().toArray()[2].toString());

        j1= new JSONParser();

        System.out.println("sub task 4 done ->" + ((org.json.simple.JSONObject)j1.parse(genIssue(summaryT4, applicationIDNumber, applicationIDText, 
                componentIdT4,componentTextT4, acceptanceCriteriaT4, dueDate, descriptionT4, issueType, "", storyLink3))).values().toArray()[2].toString());
    }

    static String genIssue(String summary, String applicationIDNumber, String applicationIDText, String componentIdNumber,
            String componentIdText, String acceptanceCriteria,String dueDate, String descriptionText, String issueType, String epicLink,String storyLink) 
            throws IOException {

        String jsonString = "";
        if(issueType == "epic")
            jsonString = generateEpic(summary,componentIdNumber,componentIdText,applicationIDNumber,
                    applicationIDText,acceptanceCriteria,dueDate,descriptionText, issueType);
        else if(issueType =="user story")
            jsonString = generateUserStory(summary, componentIdNumber, componentIdText, applicationIDNumber, 
                    applicationIDText,acceptanceCriteria, dueDate, descriptionText, issueType, epicLink);
        else if(issueType == "task")
            jsonString = generateTask(summary, componentIdNumber, componentIdText, applicationIDNumber, 
                    applicationIDText,acceptanceCriteria, dueDate, descriptionText, issueType, storyLink);


        OkHttpClient client1 = new OkHttpClient();

        MediaType mediaType1 = MediaType.parse("application/json");
        RequestBody body1 = RequestBody.create(mediaType1,jsonString);
        Request request1 = new Request.Builder()
          .url("https://wts-jira.xxxxxx.com/rest/api/2/issue")
          .post(body1)
          .addHeader("Authorization", "Basic dTU3NjI3MjpTdW1tZXIyMDE5")
          .addHeader("Content-Type", "application/json")
          .addHeader("cache-control", "no-cache")             
          .build();

        Response response1 = client1.newCall(request1).execute();
        return response1.body().string();
    }   
}
这是POM.XML文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.xxxxxx.mavenify</groupId>
<artifactId>HelloWorldy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>HelloWorldy</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>            
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.7</version>
    </dependency>

    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
        <version>3.9.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>       
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20180813</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>


</dependencies>

4.0.0
com.xxxxxx.mavenify
地狱世界
0.0.1-快照
罐子
地狱世界
http://maven.apache.org
UTF-8
朱尼特
朱尼特
3.8.1
测验
org.apache.httpcomponents
httpcore
4.4.9
org.apache.httpcomponents
httpclient
4.5.7
com.squareup.okhttp3
okhttp
3.9.1
org.apache.commons
公地io
1.3.2
公地io
公地io
2.5
org.json
json
20180813
com.googlecode.json-simple
简单json
1.1

此问题被认为不适合此网站,因为它要求我们找到外部资源或将整个程序编码为答案。在前一种情况下,这些答案是基于意见的。在后者中,它们是不可靠的。