Commits

Jacek Jaroczynski committed 5ad41ff

rest (issue security level, due date, issue links correctly read and displayed)

  • Participants
  • Parent commits 463b342

Comments (0)

Files changed (2)

com.atlassian.connector.eclipse.jira.core/META-INF/MANIFEST.MF

  com.atlassian.connector.eclipse.commons.core;visibility:=reexport,
  com.atlassian.connector.eclipse.jira.restclient;bundle-version="3.0.7",
  org.joda.time;bundle-version="1.6.0",
- org.eclipse.mylyn.tasks.ui;bundle-version="[3.0.0,4.0.0)"
+ org.eclipse.mylyn.tasks.ui;bundle-version="[3.0.0,4.0.0)",
+ org.codehaus.jettison;bundle-version="1.0.0"
 Import-Package: org.eclipse.mylyn.internal.monitor.ui
 Bundle-ActivationPolicy: lazy
 Export-Package: com.atlassian.connector.eclipse.internal.jira.core;x-friends:="com.atlassian.connector.eclipse.jira.ui",

com.atlassian.connector.eclipse.jira.core/src/com/atlassian/connector/eclipse/internal/jira/core/service/rest/JiraRestConverter.java

 import java.util.ArrayList;
 import java.util.List;
 
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.joda.time.DateTime;
 
 import com.atlassian.connector.eclipse.internal.jira.core.model.Component;
+import com.atlassian.connector.eclipse.internal.jira.core.model.IssueLink;
 import com.atlassian.connector.eclipse.internal.jira.core.model.IssueType;
 import com.atlassian.connector.eclipse.internal.jira.core.model.JiraIssue;
 import com.atlassian.connector.eclipse.internal.jira.core.model.Priority;
 import com.atlassian.connector.eclipse.internal.jira.core.model.Project;
 import com.atlassian.connector.eclipse.internal.jira.core.model.Resolution;
+import com.atlassian.connector.eclipse.internal.jira.core.model.SecurityLevel;
 import com.atlassian.connector.eclipse.internal.jira.core.model.Subtask;
 import com.atlassian.connector.eclipse.internal.jira.core.model.Version;
 import com.atlassian.connector.eclipse.internal.jira.core.service.JiraClientCache;
 		JiraIssue jiraIssue = new JiraIssue();
 
 		// TODO rest: set real id if avaialble
-		jiraIssue.setId(issue.getSelf().toString() + "_" + issue.getKey().replace('-', '*'));
+		jiraIssue.setId(generateIssueId(issue.getSelf().toString(), issue.getKey()));
 		jiraIssue.setSelf(issue.getSelf());
 		jiraIssue.setKey(issue.getKey());
 		jiraIssue.setSummary(issue.getSummary());
 			jiraIssue.setActual(issue.getTimeTracking().getTimeSpentMinutes() * 60);
 		}
 
-//		jiraIssue.setSecurityLevel(issue.get)
+		Object security = issue.getField("security").getValue();
+		if (security != null && security instanceof JSONObject) {
+			JSONObject json = (JSONObject) security;
+
+			try {
+				String id = json.getString("id");
+				String name = json.getString("name");
+
+				SecurityLevel securityLevel = new SecurityLevel(id);
+				securityLevel.setName(name);
+
+				jiraIssue.setSecurityLevel(securityLevel);
+			} catch (JSONException e) {
+				// TODO rest handle exception (log)
+				e.printStackTrace();
+			}
+		}
 
 		Project project = cache.getProjectByKey(issue.getProject().getKey());
 		jiraIssue.setProject(project);
 		jiraIssue.setReportedVersions(convertVersions(issue.getAffectedVersions()));
 		jiraIssue.setFixVersions(convertVersions(issue.getFixVersions()));
 
+		DateTime dueDate = issue.getDueDate();
+		if (dueDate != null) {
+			jiraIssue.setDue(dueDate.toDate());
+		}
+
+		jiraIssue.setIssueLinks(convertIssueLinks(issue.getIssueLinks()));
+
 		return jiraIssue;
 	}
 
+	private static IssueLink[] convertIssueLinks(Iterable<com.atlassian.jira.rest.client.domain.IssueLink> issueLinks) {
+
+		List<IssueLink> outIssueLinks = new ArrayList<IssueLink>();
+
+		for (com.atlassian.jira.rest.client.domain.IssueLink issueLink : issueLinks) {
+			outIssueLinks.add(convert(issueLink));
+		}
+
+		return outIssueLinks.toArray(new IssueLink[outIssueLinks.size()]);
+	}
+
+	private static IssueLink convert(com.atlassian.jira.rest.client.domain.IssueLink issueLink) {
+		IssueLink outIssueLink = new IssueLink(generateIssueId(issueLink.getTargetIssueUri().toString(),
+				issueLink.getTargetIssueKey()), issueLink.getTargetIssueKey(), issueLink.getIssueLinkType().getName(),
+				issueLink.getIssueLinkType().getName(), issueLink.getIssueLinkType().getDescription(), "");
+
+		return outIssueLink;
+
+	}
+
 	private static Version[] convertVersions(Iterable<com.atlassian.jira.rest.client.domain.Version> versions) {
 		List<Version> outVersions = new ArrayList<Version>();
 
 
 	private static Subtask convert(com.atlassian.jira.rest.client.domain.Subtask subtask) {
 		// TODO rest use real id once available 
-		return new Subtask(subtask.getIssueUri().toString() + "_" + subtask.getIssueKey().replace('-', '*'),
+		return new Subtask(generateIssueId(subtask.getIssueUri().toString(), subtask.getIssueKey()),
 				subtask.getIssueKey());
 	}
 
+	private static String generateIssueId(String uri, String issueKey) {
+		return uri + "_" + issueKey.replace('-', '*');
+	}
+
 	public static IssueType[] convertIssueTypes(Iterable<com.atlassian.jira.rest.client.domain.IssueType> allIssueTypes) {
 		List<IssueType> issueTypes = new ArrayList<IssueType>();
 
 		JiraIssue outIssue = new JiraIssue();
 
 		// TODO rest set real id
-		outIssue.setId(issue.getSelf().toString() + "_" + issue.getKey().replace('-', '*'));
+		outIssue.setId(generateIssueId(issue.getSelf().toString(), issue.getKey()));
 		outIssue.setKey(issue.getKey());
 		outIssue.setSelf(issue.getSelf());