private static List <JiraNamedEntity> getLinks(XPathNavigator nav) { XPathExpression expr = nav.Compile("issuelink/issuekey"); XPathNodeIterator it = nav.Select(expr); List <JiraNamedEntity> result = new List <JiraNamedEntity>(); if (nav.MoveToFirstChild()) { while (it.MoveNext()) { int id = XPathUtils.getAttributeSafely(it.Current, "id", 0); string key = it.Current.Value; result.Add(new JiraNamedEntity(id, key, null)); } nav.MoveToParent(); } return(result); }
private void getComments(XPathNavigator nav) { XPathExpression expr = nav.Compile("comment"); XPathNodeIterator it = nav.Select(expr); if (!nav.MoveToFirstChild()) { return; } while (it.MoveNext()) { Comment c = new Comment { Body = it.Current.Value, Author = XPathUtils.getAttributeSafely(it.Current, "author", "Unknown"), Created = XPathUtils.getAttributeSafely(it.Current, "created", "Unknown") }; comments.Add(c); } nav.MoveToParent(); }
private void getAttachments(XPathNavigator nav) { XPathExpression expr = nav.Compile("attachment"); XPathNodeIterator it = nav.Select(expr); if (!nav.MoveToFirstChild()) { return; } while (it.MoveNext()) { JiraAttachment a = new JiraAttachment( int.Parse(XPathUtils.getAttributeSafely(it.Current, "id", "0")), XPathUtils.getAttributeSafely(it.Current, "name", "none"), JiraIssueUtils.getDateTimeFromJiraTimeString(XPathUtils.getAttributeSafely(it.Current, "created", "none")), XPathUtils.getAttributeSafely(it.Current, "author", "none"), int.Parse(XPathUtils.getAttributeSafely(it.Current, "size", "0"))); attachments.Add(a); } nav.MoveToParent(); }
public JiraIssue(JiraServer server, XPathNavigator nav) { Server = server; nav.MoveToFirstChild(); do { switch (nav.Name) { case "key": Key = nav.Value; Id = XPathUtils.getAttributeSafely(nav, "id", UNKNOWN); ProjectKey = Key.Substring(0, Key.LastIndexOf('-')); break; case "parent": ParentKey = nav.Value; break; case "subtasks": getSubtasks(nav); break; case "summary": Summary = nav.Value; break; case "attachments": getAttachments(nav); break; case "status": Status = nav.Value; StatusIconUrl = XPathUtils.getAttributeSafely(nav, "iconUrl", null); StatusId = XPathUtils.getAttributeSafely(nav, "id", UNKNOWN); break; case "priority": Priority = nav.Value; PriorityIconUrl = XPathUtils.getAttributeSafely(nav, "iconUrl", null); PriorityId = XPathUtils.getAttributeSafely(nav, "id", UNKNOWN); break; case "description": Description = nav.Value; break; case "type": IssueType = nav.Value; IssueTypeIconUrl = XPathUtils.getAttributeSafely(nav, "iconUrl", null); IssueTypeId = XPathUtils.getAttributeSafely(nav, "id", UNKNOWN); break; case "assignee": Assignee = XPathUtils.getAttributeSafely(nav, "username", "Unknown"); string assigneName = nav.Value; break; case "reporter": Reporter = XPathUtils.getAttributeSafely(nav, "username", "Unknown"); string reporterName = nav.Value; break; case "created": CreationDate = JiraIssueUtils.getDateTimeFromJiraTimeString(nav.Value); break; case "updated": UpdateDate = JiraIssueUtils.getDateTimeFromJiraTimeString(nav.Value); break; case "resolution": Resolution = nav.Value; ResolutionId = XPathUtils.getAttributeSafely(nav, "id", UNKNOWN); break; case "timeestimate": RemainingEstimate = nav.Value; RemainingEstimateInSeconds = XPathUtils.getAttributeSafely(nav, "seconds", UNKNOWN); break; case "timeoriginalestimate": OriginalEstimate = nav.Value; OriginalEstimateInSeconds = XPathUtils.getAttributeSafely(nav, "seconds", UNKNOWN); break; case "timespent": TimeSpent = nav.Value; TimeSpentInSeconds = XPathUtils.getAttributeSafely(nav, "seconds", UNKNOWN); break; case "version": versions.Add(nav.Value); break; case "fixVersion": fixVersions.Add(nav.Value); break; case "component": components.Add(nav.Value); break; case "comments": getComments(nav); break; case "environment": Environment = nav.Value; break; case "issuelinks": getIssueLinks(nav); break; default: break; } } while (nav.MoveToNext()); if (Key == null || Summary == null) { throw new InvalidDataException(); } }
private void getIssueLinks(XPathNavigator nav) { XPathExpression expr = nav.Compile("issuelinktype"); XPathNodeIterator it = nav.Select(expr); if (!nav.MoveToFirstChild()) { return; } while (it.MoveNext()) { int id = XPathUtils.getAttributeSafely(it.Current, "id", 0); string linkTypeName = null; string outwardLinksName = null; string inwardLinksName = null; List <JiraNamedEntity> outwardIdsAndKeys = null; List <JiraNamedEntity> inwardIdsAndKeys = null; if (it.Current.MoveToFirstChild()) { do { switch (it.Current.Name) { case "name": linkTypeName = it.Current.Value; break; case "outwardlinks": outwardLinksName = XPathUtils.getAttributeSafely(it.Current, "description", null); outwardIdsAndKeys = getLinks(it.Current); break; case "inwardlinks": inwardLinksName = XPathUtils.getAttributeSafely(it.Current, "description", null); inwardIdsAndKeys = getLinks(it.Current); break; } } while (it.Current.MoveToNext()); if (id == 0 || linkTypeName == null) { continue; } IssueLinkType ilt = new IssueLinkType(id, linkTypeName, outwardLinksName, inwardLinksName); if (outwardIdsAndKeys != null) { foreach (JiraNamedEntity entity in outwardIdsAndKeys) { ilt.OutwardLinks.Add(entity.Name); } } if (inwardIdsAndKeys != null) { foreach (JiraNamedEntity entity in inwardIdsAndKeys) { ilt.InwardLinks.Add(entity.Name); } } issueLinks.Add(ilt); } it.Current.MoveToParent(); } nav.MoveToParent(); }