1
0
Fork 0

fixed tabbing

master
Bob Carroll 2016-05-30 13:11:12 -07:00
parent d23935a267
commit c8802583aa
2 changed files with 204 additions and 204 deletions

View File

@ -528,131 +528,131 @@ public class Issue extends Resource {
} }
/** /**
* Iterates over all issues in the query by getting the next page of * Iterates over all issues in the query by getting the next page of
* issues when the iterator reaches the last of the current page. * issues when the iterator reaches the last of the current page.
*/ */
private static class IssueIterator implements Iterator<Issue> { private static class IssueIterator implements Iterator<Issue> {
private Iterator<Issue> currentPage; private Iterator<Issue> currentPage;
private RestClient restclient; private RestClient restclient;
private Issue nextIssue; private Issue nextIssue;
private Integer maxResults = -1; private Integer maxResults = -1;
private String jql; private String jql;
private String includedFields; private String includedFields;
private String expandFields; private String expandFields;
private Integer startAt; private Integer startAt;
private List<Issue> issues; private List<Issue> issues;
private int total; private int total;
public IssueIterator(RestClient restclient, String jql, public IssueIterator(RestClient restclient, String jql,
String includedFields, String expandFields, Integer maxResults, Integer startAt) String includedFields, String expandFields, Integer maxResults, Integer startAt)
throws JiraException { throws JiraException {
this.restclient = restclient; this.restclient = restclient;
this.jql = jql; this.jql = jql;
this.includedFields = includedFields; this.includedFields = includedFields;
this.expandFields = expandFields; this.expandFields = expandFields;
this.maxResults = maxResults; this.maxResults = maxResults;
this.startAt = startAt; this.startAt = startAt;
}
@Override
public boolean hasNext() {
if (nextIssue != null) {
return true;
}
try {
nextIssue = getNextIssue();
} catch (JiraException e) {
throw new RuntimeException(e);
}
return nextIssue != null;
} }
@Override
public boolean hasNext() {
if (nextIssue != null) {
return true;
}
try {
nextIssue = getNextIssue();
} catch (JiraException e) {
throw new RuntimeException(e);
}
return nextIssue != null;
}
@Override @Override
public Issue next() { public Issue next() {
if (! hasNext()) { if (! hasNext()) {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
Issue result = nextIssue; Issue result = nextIssue;
nextIssue = null; nextIssue = null;
return result; return result;
} }
@Override @Override
public void remove() { public void remove() {
throw new UnsupportedOperationException("Method remove() not support for class " + this.getClass().getName()); throw new UnsupportedOperationException("Method remove() not support for class " + this.getClass().getName());
} }
/** /**
* Gets the next issue, returning null if none more available * Gets the next issue, returning null if none more available
* Will ask the next set of issues from the server if the end of the current list of issues is reached. * Will ask the next set of issues from the server if the end of the current list of issues is reached.
* *
* @return the next issue, null if none more available * @return the next issue, null if none more available
* @throws JiraException * @throws JiraException
*/ */
private Issue getNextIssue() throws JiraException { private Issue getNextIssue() throws JiraException {
// first call // first call
if (currentPage == null) { if (currentPage == null) {
currentPage = getNextIssues().iterator(); currentPage = getNextIssues().iterator();
if (currentPage == null || !currentPage.hasNext()) { if (currentPage == null || !currentPage.hasNext()) {
return null; return null;
} else { } else {
return currentPage.next(); return currentPage.next();
} }
} }
// check if we need to get the next set of issues // check if we need to get the next set of issues
if (! currentPage.hasNext()) { if (! currentPage.hasNext()) {
currentPage = getNextIssues().iterator(); currentPage = getNextIssues().iterator();
} }
// return the next item if available // return the next item if available
if (currentPage.hasNext()) { if (currentPage.hasNext()) {
return currentPage.next(); return currentPage.next();
} else { } else {
return null; return null;
} }
} }
/** /**
* Execute the query to get the next set of issues. * Execute the query to get the next set of issues.
* Also sets the startAt, maxMresults, total and issues fields, * Also sets the startAt, maxMresults, total and issues fields,
* so that the SearchResult can access them. * so that the SearchResult can access them.
* *
* @return the next set of issues. * @return the next set of issues.
* @throws JiraException * @throws JiraException
*/ */
private List<Issue> getNextIssues() throws JiraException { private List<Issue> getNextIssues() throws JiraException {
if (issues == null) { if (issues == null) {
startAt = Integer.valueOf(0); startAt = Integer.valueOf(0);
} else { } else {
startAt = startAt + issues.size(); startAt = startAt + issues.size();
} }
JSON result = null; JSON result = null;
try { try {
URI searchUri = createSearchURI(restclient, jql, includedFields, URI searchUri = createSearchURI(restclient, jql, includedFields,
expandFields, maxResults, startAt); expandFields, maxResults, startAt);
result = restclient.get(searchUri); result = restclient.get(searchUri);
} catch (Exception ex) { } catch (Exception ex) {
throw new JiraException("Failed to search issues", ex); throw new JiraException("Failed to search issues", ex);
} }
if (!(result instanceof JSONObject)) { if (!(result instanceof JSONObject)) {
throw new JiraException("JSON payload is malformed"); throw new JiraException("JSON payload is malformed");
} }
Map map = (Map) result; Map map = (Map) result;
this.startAt = Field.getInteger(map.get("startAt")); this.startAt = Field.getInteger(map.get("startAt"));
this.maxResults = Field.getInteger(map.get("maxResults")); this.maxResults = Field.getInteger(map.get("maxResults"));
this.total = Field.getInteger(map.get("total")); this.total = Field.getInteger(map.get("total"));
this.issues = Field.getResourceArray(Issue.class, map.get("issues"), restclient); this.issues = Field.getResourceArray(Issue.class, map.get("issues"), restclient);
return issues; return issues;
} }
} }
@ -675,38 +675,38 @@ public class Issue extends Resource {
public int max = 0; public int max = 0;
public int total = 0; public int total = 0;
public List<Issue> issues = null; public List<Issue> issues = null;
private RestClient restclient; private RestClient restclient;
private String jql; private String jql;
private String includedFields; private String includedFields;
private String expandFields; private String expandFields;
private Integer startAt; private Integer startAt;
private IssueIterator issueIterator; private IssueIterator issueIterator;
public SearchResult(RestClient restclient, String jql, public SearchResult(RestClient restclient, String jql,
String includedFields, String expandFields, Integer maxResults, Integer startAt) throws JiraException { String includedFields, String expandFields, Integer maxResults, Integer startAt) throws JiraException {
this.restclient = restclient; this.restclient = restclient;
this.jql = jql; this.jql = jql;
this.includedFields = includedFields; this.includedFields = includedFields;
this.expandFields = expandFields; this.expandFields = expandFields;
initSearchResult(maxResults, start); initSearchResult(maxResults, start);
} }
private void initSearchResult(Integer maxResults, Integer start) throws JiraException { private void initSearchResult(Integer maxResults, Integer start) throws JiraException {
this.issueIterator = new IssueIterator(restclient, jql, includedFields, expandFields, maxResults, startAt); this.issueIterator = new IssueIterator(restclient, jql, includedFields, expandFields, maxResults, startAt);
this.issueIterator.hasNext(); this.issueIterator.hasNext();
this.max = issueIterator.maxResults; this.max = issueIterator.maxResults;
this.start = issueIterator.startAt; this.start = issueIterator.startAt;
this.issues = issueIterator.issues; this.issues = issueIterator.issues;
this.total = issueIterator.total; this.total = issueIterator.total;
} }
/** /**
* All issues found. * All issues found.
* *
* @return All issues found. * @return All issues found.
*/ */
public Iterator<Issue> iterator() { public Iterator<Issue> iterator() {
return issueIterator; return issueIterator;
} }
} }
@ -860,10 +860,10 @@ public class Issue extends Resource {
JSON result = null; JSON result = null;
try { try {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("expand", "projects.issuetypes.fields"); params.put("expand", "projects.issuetypes.fields");
params.put("projectKeys", pval); params.put("projectKeys", pval);
params.put("issuetypeNames", itval); params.put("issuetypeNames", itval);
URI createuri = restclient.buildURI( URI createuri = restclient.buildURI(
getBaseUri() + "issue/createmeta", getBaseUri() + "issue/createmeta",
params); params);
@ -918,8 +918,8 @@ public class Issue extends Resource {
JSON result = null; JSON result = null;
try { try {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("expand", "transitions.fields"); params.put("expand", "transitions.fields");
URI transuri = restclient.buildURI( URI transuri = restclient.buildURI(
getRestUri(key) + "/transitions",params); getRestUri(key) + "/transitions",params);
result = restclient.get(transuri); result = restclient.get(transuri);
@ -1009,24 +1009,24 @@ public class Issue extends Resource {
} }
/** /**
* Removes an attachments. * Removes an attachments.
* *
* @param attachmentId attachment id to remove * @param attachmentId attachment id to remove
* *
* @throws JiraException when the attachment removal fails * @throws JiraException when the attachment removal fails
*/ */
public void removeAttachment(String attachmentId) throws JiraException { public void removeAttachment(String attachmentId) throws JiraException {
if (attachmentId == null) { if (attachmentId == null) {
throw new NullPointerException("attachmentId may not be null"); throw new NullPointerException("attachmentId may not be null");
} }
try { try {
restclient.delete(getBaseUri() + "attachment/" + attachmentId); restclient.delete(getBaseUri() + "attachment/" + attachmentId);
} catch (Exception ex) { } catch (Exception ex) {
throw new JiraException("Failed remove attachment " + attachmentId, ex); throw new JiraException("Failed remove attachment " + attachmentId, ex);
} }
} }
/** /**
* Adds a comment to this issue. * Adds a comment to this issue.
@ -1271,9 +1271,9 @@ public class Issue extends Resource {
Map<String, String> queryParams = new HashMap<String, String>(); Map<String, String> queryParams = new HashMap<String, String>();
queryParams.put("fields", includedFields); queryParams.put("fields", includedFields);
if (expand != null) { if (expand != null) {
queryParams.put("expand", expand); queryParams.put("expand", expand);
} }
return new Issue(restclient, realGet(restclient, key, queryParams)); return new Issue(restclient, realGet(restclient, key, queryParams));
} }
@ -1357,19 +1357,19 @@ public class Issue extends Resource {
String includedFields, String expandFields, Integer maxResults, Integer startAt) String includedFields, String expandFields, Integer maxResults, Integer startAt)
throws JiraException { throws JiraException {
SearchResult sr = new SearchResult(restclient, jql, includedFields, expandFields, maxResults, startAt); SearchResult sr = new SearchResult(restclient, jql, includedFields, expandFields, maxResults, startAt);
return sr; return sr;
} }
private static JSON executeSearch(RestClient restclient, String jql, private static JSON executeSearch(RestClient restclient, String jql,
String includedFields, String expandFields, Integer maxResults, String includedFields, String expandFields, Integer maxResults,
Integer startAt) throws JiraException { Integer startAt) throws JiraException {
JSON result = null; JSON result = null;
try { try {
URI searchUri = createSearchURI(restclient, jql, includedFields, URI searchUri = createSearchURI(restclient, jql, includedFields,
expandFields, maxResults, startAt); expandFields, maxResults, startAt);
result = restclient.get(searchUri); result = restclient.get(searchUri);
} catch (Exception ex) { } catch (Exception ex) {
throw new JiraException("Failed to search issues", ex); throw new JiraException("Failed to search issues", ex);
@ -1378,42 +1378,42 @@ public class Issue extends Resource {
if (!(result instanceof JSONObject)) { if (!(result instanceof JSONObject)) {
throw new JiraException("JSON payload is malformed"); throw new JiraException("JSON payload is malformed");
} }
return result; return result;
} }
/** /**
* Creates the URI to execute a jql search. * Creates the URI to execute a jql search.
* *
* @param restclient * @param restclient
* @param jql * @param jql
* @param includedFields * @param includedFields
* @param expandFields * @param expandFields
* @param maxResults * @param maxResults
* @param startAt * @param startAt
* @return the URI to execute a jql search. * @return the URI to execute a jql search.
* @throws URISyntaxException * @throws URISyntaxException
*/ */
private static URI createSearchURI(RestClient restclient, String jql, private static URI createSearchURI(RestClient restclient, String jql,
String includedFields, String expandFields, Integer maxResults, String includedFields, String expandFields, Integer maxResults,
Integer startAt) throws URISyntaxException { Integer startAt) throws URISyntaxException {
Map<String, String> queryParams = new HashMap<String, String>(); Map<String, String> queryParams = new HashMap<String, String>();
queryParams.put("jql", jql); queryParams.put("jql", jql);
if(maxResults != null){ if(maxResults != null){
queryParams.put("maxResults", String.valueOf(maxResults)); queryParams.put("maxResults", String.valueOf(maxResults));
} }
if (includedFields != null) { if (includedFields != null) {
queryParams.put("fields", includedFields); queryParams.put("fields", includedFields);
} }
if (expandFields != null) { if (expandFields != null) {
queryParams.put("expand", expandFields); queryParams.put("expand", expandFields);
} }
if (startAt != null) { if (startAt != null) {
queryParams.put("startAt", String.valueOf(startAt)); queryParams.put("startAt", String.valueOf(startAt));
} }
URI searchUri = restclient.buildURI(getBaseUri() + "search", queryParams); URI searchUri = restclient.buildURI(getBaseUri() + "search", queryParams);
return searchUri; return searchUri;
} }
/** /**
* Reloads issue data from the JIRA server (issue includes all navigable * Reloads issue data from the JIRA server (issue includes all navigable

View File

@ -61,7 +61,7 @@ public class JiraClient {
* @throws JiraException * @throws JiraException
*/ */
public JiraClient(String uri, ICredentials creds) throws JiraException { public JiraClient(String uri, ICredentials creds) throws JiraException {
this(null, uri, creds); this(null, uri, creds);
} }
/** /**
@ -73,19 +73,19 @@ public class JiraClient {
* @throws JiraException * @throws JiraException
*/ */
public JiraClient(HttpClient httpClient, String uri, ICredentials creds) throws JiraException { public JiraClient(HttpClient httpClient, String uri, ICredentials creds) throws JiraException {
if (httpClient == null) { if (httpClient == null) {
PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(); PoolingClientConnectionManager connManager = new PoolingClientConnectionManager();
connManager.setDefaultMaxPerRoute(20); connManager.setDefaultMaxPerRoute(20);
connManager.setMaxTotal(40); connManager.setMaxTotal(40);
httpClient = new DefaultHttpClient(connManager); httpClient = new DefaultHttpClient(connManager);
} }
restclient = new RestClient(httpClient, creds, URI.create(uri)); restclient = new RestClient(httpClient, creds, URI.create(uri));
if (creds != null) { if (creds != null) {
username = creds.getLogonName(); username = creds.getLogonName();
//intialize connection if required //intialize connection if required
creds.initialize(restclient); creds.initialize(restclient);
} }
} }
@ -368,7 +368,7 @@ public class JiraClient {
startAt); startAt);
} }
/** /**
* Retrieve the jira filter with the supplied id. * Retrieve the jira filter with the supplied id.
* @param id id of the filter to retreive. * @param id id of the filter to retreive.
* @return The Jira filter with the supplied id * @return The Jira filter with the supplied id