JIRA 작업을 MS Project MPP 파일로 내 보냅니다
이 기사에서는 REST API를 사용하여 JIRA에서 [MPP]로 작업을 내보내는 방법을 보여 드리겠습니다.
Jira 작업을 MPP로 내보내십시오
다음은 JIRA 작업을 MPP 또는 Aspose.Tasks에서 지원하는 모든 내보내기 형식으로 내보내기위한 고유 한 솔루션을 구축 할 수있는 주요 아이디어를 보여주는 단순화 된 코드입니다.
JIRA에서 MPP 형식으로 작업을 내보내려면 다음 단계를 수행해야합니다.
- Jira API에 요청하여 내보내기 작업을 선택하십시오.
- 프로젝트 클래스 인스턴스를 만듭니다.
- 결과 JSON을 통과하고 결과 JSON의 각 “문제"엔티티에 대한 작업 객체를 만듭니다.
- 작업 설정을위한 논리를 구현하십시오.
- 프로젝트 클래스 인스턴스를 필요한 형식의 파일에 저장하십시오 (이 예제의 MPP).
1using System;
2using System.Collections.Generic;
3using System.Net.Http;
4using Aspose.Tasks;
5using Newtonsoft.Json.Linq;
6using Task = Aspose.Tasks.Task;
7
8namespace JiraToMpp
9{
10 class Program
11 {
12 private static readonly string OutputFileName = @"c:\output.mpp";
13 private static readonly string LicenseFileName = @"c:\Aspose.Tasks.NET.SHA256.lic";
14 private static readonly string JiraHost = @"https://issue.test.local";
15 private static readonly string UserName = "user_name";
16 private static readonly string UserApiKey = "user_api_key";
17
18 static async System.Threading.Tasks.Task Main()
19 {
20 System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
21 SetLicense();
22
23 HttpClient client = new HttpClient();
24
25 AddBasicAuthorizationHeader(client);
26
27 string endPointAddress = JiraHost + "/rest/api/2/search?jql=ORDER%20BY%20Created&maxResults=100&startAt=0";
28 var result = await client.GetStringAsync(endPointAddress);
29 dynamic deserialized = JObject.Parse(result);
30 var issues = deserialized.issues;
31
32 Project project = new Project();
33 Dictionary<string, dynamic> rawTasks = new Dictionary<string, dynamic>();
34 HashSet<string> subTasksSet = new HashSet<string>();
35
36 foreach (var issue in issues)
37 {
38 rawTasks.Add((string)issue.key, issue);
39
40 if (issue.fields.subtasks != null && issue.fields.subtasks.Count > 0)
41 {
42 foreach (var subTask in issue.fields.subtasks)
43 {
44 subTasksSet.Add((string)subTask.key);
45 }
46 }
47
48 }
49
50 var builder = new TasksBuilder(project, rawTasks, subTasksSet);
51 builder.Build();
52
53 project.Save(OutputFileName, SaveFileFormat.Mpp);
54 }
55
56 private static void SetLicense()
57 {
58 License l = new License();
59 using (var fs2 = System.IO.File.OpenRead(LicenseFileName))
60 {
61 l.SetLicense(fs2);
62 }
63 }
64
65 private static void AddBasicAuthorizationHeader(HttpClient client)
66 {
67 string headerValue = string.Format("{0}:{1}", UserName, UserApiKey);
68 var bytes = System.Text.Encoding.UTF8.GetBytes(headerValue);
69 var encodedText = Convert.ToBase64String(bytes);
70 client.DefaultRequestHeaders.Add("Authorization", "Basic " + encodedText);
71 }
72 }
73
74 internal sealed class TasksBuilder
75 {
76 private readonly Project project;
77 private readonly Dictionary<string, dynamic> jsonTasks;
78 private readonly HashSet<string> subTasks;
79 private readonly HashSet<string> processedIssues = new HashSet<string>();
80
81 private ExtendedAttributeDefinition linkExtendedAttribute;
82 private ExtendedAttributeDefinition jiraKeyExtendedAttribute;
83
84 public TasksBuilder(Project project, Dictionary<string, dynamic> jsonTasks, HashSet<string> subTasks)
85 {
86 this.project = project;
87 this.jsonTasks = jsonTasks;
88 this.subTasks = subTasks;
89 this.SetUpExtendedAttributes();
90 }
91
92 public void Build()
93 {
94 foreach (var kv in this.jsonTasks)
95 {
96 if (this.processedIssues.Contains(kv.Key))
97 {
98 continue;
99 }
100
101 if (this.subTasks.Contains(kv.Key))
102 {
103 continue;
104 }
105
106 this.ProcessIssue(kv.Value, this.project.RootTask.Children);
107 this.processedIssues.Add(kv.Key);
108 }
109 }
110
111 private void ProcessIssue(dynamic issue, TaskCollection parentCollection)
112 {
113 var taskName = (string)issue.fields["summary"];
114
115 Task task = parentCollection.Add(taskName);
116
117 Console.WriteLine("Added task " + taskName);
118
119 // TODO : implement logic for setting task's start, finish and duration.
120
121 this.MapExtendedAttributes(issue, task);
122
123 if (issue.fields.subtasks == null)
124 {
125 return;
126 }
127
128 foreach (var subTask in issue.fields.subtasks)
129 {
130 var subTaskKey = (string)subTask.key;
131 var rawSubTask = this.jsonTasks[subTaskKey];
132 this.ProcessIssue(rawSubTask, task.Children);
133 }
134 }
135
136 private void MapExtendedAttributes(dynamic rawIssue, Task task)
137 {
138 var key = (string)rawIssue.key;
139 var link = (string)rawIssue.self;
140
141 task.ExtendedAttributes.Add(this.jiraKeyExtendedAttribute.CreateExtendedAttribute(key));
142 task.ExtendedAttributes.Add(this.linkExtendedAttribute.CreateExtendedAttribute(link));
143 }
144
145 private void SetUpExtendedAttributes()
146 {
147 this.linkExtendedAttribute = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, "Link to the issue");
148 this.jiraKeyExtendedAttribute = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text2, "Issue Key");
149 }
150 }
151}
This example demonstrates how to retrieve tasks from Jira using the REST API, convert them into Task
objects with Aspose.Tasks, and export them to the MPP format. The process begins with an HTTP request to the Jira API using basic authentication. The received JSON data is parsed and stored in a dictionary for further processing. The TasksBuilder
class is responsible for constructing the task hierarchy by iterating through issues and creating corresponding tasks and subtasks. Each task is assigned extended attributes that include the issue key and a link to the original Jira issue. The implementation includes a placeholder for setting task start and finish dates, as well as duration, which should be defined according to the project’s requirements. Finally, the constructed project is saved to a file in the MPP format.