From edab96f4c841e9267ad3c9e778f0ae677892673b Mon Sep 17 00:00:00 2001 From: Bernard Labno Date: Wed, 31 Oct 2012 14:56:42 +0000 Subject: [PATCH] Add updateIssue method and updated attribute to Comment --- src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- src/main/java/pl/com/it_crowd/youtrack/api/rest/AssignedByType.java | 2 -- src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeList.java | 2 -- src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeType.java | 2 -- src/main/java/pl/com/it_crowd/youtrack/api/rest/Comment.java | 28 ++++++++++++++++++++++++++-- src/main/java/pl/com/it_crowd/youtrack/api/rest/Field.java | 2 -- src/main/java/pl/com/it_crowd/youtrack/api/rest/Issue.java | 2 -- src/main/java/pl/com/it_crowd/youtrack/api/rest/Issues.java | 2 -- src/main/java/pl/com/it_crowd/youtrack/api/rest/ObjectFactory.java | 2 -- src/main/java/pl/com/it_crowd/youtrack/api/rest/User.java | 2 -- src/main/java/pl/com/it_crowd/youtrack/api/rest/UserGroupRefType.java | 2 -- src/main/java/pl/com/it_crowd/youtrack/api/rest/UserRefs.java | 2 -- src/main/xsd/issue.xml | 11 +++++++++++ src/main/xsd/issuesByProject.xml | 2 +- src/main/xsd/types.xsd | 1 + 15 files changed, 83 insertions(+), 32 deletions(-) diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java b/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java index 8db462e..6ffae40 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java @@ -5,11 +5,13 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; +import org.apache.http.NameValuePair; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.HttpResponseException; import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; @@ -24,6 +26,7 @@ import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.impl.conn.SchemeRegistryFactory; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; +import pl.com.it_crowd.youtrack.api.defaults.Fields; import pl.com.it_crowd.youtrack.api.exceptions.NoResultFoundException; import pl.com.it_crowd.youtrack.api.exceptions.YoutrackAPIException; import pl.com.it_crowd.youtrack.api.exceptions.YoutrackErrorException; @@ -50,6 +53,7 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -57,8 +61,6 @@ import java.util.regex.Pattern; public class YoutrackAPI { // ------------------------------ FIELDS ------------------------------ - private final static QName Error_QNAME = new QName("", "error"); - private final static QName Issue_QNAME = new QName("", "issue"); private HttpClient httpClient; @@ -123,18 +125,23 @@ public class YoutrackAPI { public YoutrackAPI(String serviceLocation) { - this(serviceLocation, getDefaultHttpClient()); + this(serviceLocation, null); } public YoutrackAPI(String serviceLocation, HttpClient httpClient) { this.serviceLocation = serviceLocation; - this.httpClient = httpClient; + this.httpClient = httpClient == null ? getDefaultHttpClient() : httpClient; } public YoutrackAPI(String serviceLocation, String username, String password) throws IOException, JAXBException { - this(serviceLocation); + this(serviceLocation, null, username, password); + } + + public YoutrackAPI(String serviceLocation, HttpClient httpClient, String username, String password) throws IOException, JAXBException + { + this(serviceLocation, httpClient); login(username, password); } @@ -306,11 +313,31 @@ public class YoutrackAPI { return wrappedIssues; } - private HttpPut createPutRequest(URI uri, BasicNameValuePair... nameValuePair) throws UnsupportedEncodingException + public void updateIssue(String issueId, String summary, String description) throws IOException { - final HttpPut request = new HttpPut(uri); - request.setEntity(new UrlEncodedFormEntity(Arrays.asList(nameValuePair))); - return request; + final URI uri; + try { + uri = new URIBuilder(serviceLocation + "/rest/issue/" + issueId).build(); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + final HttpPost request = createPostRequest(uri, new BasicNameValuePair(Fields.summary.name(), summary), + new BasicNameValuePair(Fields.description.name(), description)); + final HttpResponse response = httpClient.execute(request); + final StatusLine statusLine = response.getStatusLine(); + final HttpEntity entity = response.getEntity(); + final String responseText = entity == null ? null : EntityUtils.toString(entity); + throwExceptionsIfNeeded(statusLine, responseText); + } + + private HttpPost createPostRequest(URI uri, NameValuePair... nameValuePair) throws UnsupportedEncodingException + { + return setEntity(new HttpPost(uri), nameValuePair); + } + + private HttpPut createPutRequest(URI uri, NameValuePair... nameValuePair) throws UnsupportedEncodingException + { + return setEntity(new HttpPut(uri), nameValuePair); } private String execute(HttpUriRequest request) throws IOException @@ -334,6 +361,14 @@ public class YoutrackAPI { return responseText; } + private T setEntity(T request, NameValuePair[] nameValuePair) throws UnsupportedEncodingException + { + final ArrayList list = new ArrayList(); + Collections.addAll(list, nameValuePair); + request.setEntity(new UrlEncodedFormEntity(list)); + return request; + } + private void throwExceptionsIfNeeded(StatusLine statusLine, String responseText) throws IOException { if (statusLine.getStatusCode() >= 300) { diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssignedByType.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssignedByType.java index 3c75382..d6d35c4 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssignedByType.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssignedByType.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.annotation.XmlAccessType; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeList.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeList.java index 445c5b9..41efc75 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeList.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeList.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.annotation.XmlAccessType; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeType.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeType.java index 189570c..5dc818e 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeType.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/AssigneeType.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.annotation.XmlAccessType; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Comment.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Comment.java index fed7571..0b2b4c2 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Comment.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Comment.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.JAXBElement; @@ -49,6 +47,7 @@ import java.util.List; * <attribute name="text" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="shownForIssueAuthor" type="{http://www.w3.org/2001/XMLSchema}string" /> * <attribute name="created" type="{http://www.w3.org/2001/XMLSchema}long" /> + * <attribute name="updated" type="{http://www.w3.org/2001/XMLSchema}long" /> * <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" /> * </restriction> * </complexContent> @@ -88,6 +87,9 @@ public class Comment { @XmlAttribute protected String text; + @XmlAttribute + protected Long updated; + // --------------------- GETTER / SETTER METHODS --------------------- /** @@ -296,6 +298,28 @@ public class Comment { this.text = value; } + /** + * Gets the value of the updated property. + * + * @return possible object is + * {@link Long } + */ + public Long getUpdated() + { + return updated; + } + + /** + * Sets the value of the updated property. + * + * @param value allowed object is + * {@link Long } + */ + public void setUpdated(Long value) + { + this.updated = value; + } + // -------------------------- INNER CLASSES -------------------------- /** diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Field.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Field.java index 932bac2..bbeeb43 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Field.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Field.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.annotation.XmlAccessType; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issue.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issue.java index d78ac00..3359438 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issue.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issue.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.annotation.XmlAccessType; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issues.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issues.java index 72431b8..f2b4c53 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issues.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/Issues.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.annotation.XmlAccessType; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/ObjectFactory.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/ObjectFactory.java index 4e5d2c6..e7abba1 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/ObjectFactory.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/ObjectFactory.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.JAXBElement; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/User.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/User.java index 3a41570..b90f64b 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/User.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/User.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.annotation.XmlAccessType; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/UserGroupRefType.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/UserGroupRefType.java index 53f095e..abe00d7 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/UserGroupRefType.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/UserGroupRefType.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.annotation.XmlAccessType; diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/rest/UserRefs.java b/src/main/java/pl/com/it_crowd/youtrack/api/rest/UserRefs.java index 43e52a1..c515d04 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/rest/UserRefs.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/UserRefs.java @@ -2,9 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.07.05 at 06:19:38 PM CEST // - package pl.com.it_crowd.youtrack.api.rest; import javax.xml.bind.annotation.XmlAccessType; diff --git a/src/main/xsd/issue.xml b/src/main/xsd/issue.xml index 9615330..f80279a 100644 --- a/src/main/xsd/issue.xml +++ b/src/main/xsd/issue.xml @@ -48,4 +48,15 @@ No subsystem + + + + + + + + + \ No newline at end of file diff --git a/src/main/xsd/issuesByProject.xml b/src/main/xsd/issuesByProject.xml index 8e68bef..aa32ce4 100644 --- a/src/main/xsd/issuesByProject.xml +++ b/src/main/xsd/issuesByProject.xml @@ -189,7 +189,7 @@ + shownForIssueAuthor="false" created="1292932584457" updated="1351673522146"> diff --git a/src/main/xsd/types.xsd b/src/main/xsd/types.xsd index 44158d5..243dc9c 100644 --- a/src/main/xsd/types.xsd +++ b/src/main/xsd/types.xsd @@ -56,6 +56,7 @@ + -- libgit2 0.24.0