Commit edab96f4c841e9267ad3c9e778f0ae677892673b
1 parent
157c4465
Add updateIssue method and updated attribute to Comment
Showing
15 changed files
with
83 additions
and
32 deletions
... | ... | @@ -5,11 +5,13 @@ import org.apache.http.HttpEntity; |
5 | 5 | import org.apache.http.HttpHeaders; |
6 | 6 | import org.apache.http.HttpResponse; |
7 | 7 | import org.apache.http.HttpStatus; |
8 | +import org.apache.http.NameValuePair; | |
8 | 9 | import org.apache.http.StatusLine; |
9 | 10 | import org.apache.http.client.ClientProtocolException; |
10 | 11 | import org.apache.http.client.HttpClient; |
11 | 12 | import org.apache.http.client.HttpResponseException; |
12 | 13 | import org.apache.http.client.entity.UrlEncodedFormEntity; |
14 | +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; | |
13 | 15 | import org.apache.http.client.methods.HttpGet; |
14 | 16 | import org.apache.http.client.methods.HttpPost; |
15 | 17 | import org.apache.http.client.methods.HttpPut; |
... | ... | @@ -24,6 +26,7 @@ import org.apache.http.impl.conn.PoolingClientConnectionManager; |
24 | 26 | import org.apache.http.impl.conn.SchemeRegistryFactory; |
25 | 27 | import org.apache.http.message.BasicNameValuePair; |
26 | 28 | import org.apache.http.util.EntityUtils; |
29 | +import pl.com.it_crowd.youtrack.api.defaults.Fields; | |
27 | 30 | import pl.com.it_crowd.youtrack.api.exceptions.NoResultFoundException; |
28 | 31 | import pl.com.it_crowd.youtrack.api.exceptions.YoutrackAPIException; |
29 | 32 | import pl.com.it_crowd.youtrack.api.exceptions.YoutrackErrorException; |
... | ... | @@ -50,6 +53,7 @@ import java.security.cert.CertificateException; |
50 | 53 | import java.security.cert.X509Certificate; |
51 | 54 | import java.util.ArrayList; |
52 | 55 | import java.util.Arrays; |
56 | +import java.util.Collections; | |
53 | 57 | import java.util.List; |
54 | 58 | import java.util.regex.Matcher; |
55 | 59 | import java.util.regex.Pattern; |
... | ... | @@ -57,8 +61,6 @@ import java.util.regex.Pattern; |
57 | 61 | public class YoutrackAPI { |
58 | 62 | // ------------------------------ FIELDS ------------------------------ |
59 | 63 | |
60 | - private final static QName Error_QNAME = new QName("", "error"); | |
61 | - | |
62 | 64 | private final static QName Issue_QNAME = new QName("", "issue"); |
63 | 65 | |
64 | 66 | private HttpClient httpClient; |
... | ... | @@ -123,18 +125,23 @@ public class YoutrackAPI { |
123 | 125 | |
124 | 126 | public YoutrackAPI(String serviceLocation) |
125 | 127 | { |
126 | - this(serviceLocation, getDefaultHttpClient()); | |
128 | + this(serviceLocation, null); | |
127 | 129 | } |
128 | 130 | |
129 | 131 | public YoutrackAPI(String serviceLocation, HttpClient httpClient) |
130 | 132 | { |
131 | 133 | this.serviceLocation = serviceLocation; |
132 | - this.httpClient = httpClient; | |
134 | + this.httpClient = httpClient == null ? getDefaultHttpClient() : httpClient; | |
133 | 135 | } |
134 | 136 | |
135 | 137 | public YoutrackAPI(String serviceLocation, String username, String password) throws IOException, JAXBException |
136 | 138 | { |
137 | - this(serviceLocation); | |
139 | + this(serviceLocation, null, username, password); | |
140 | + } | |
141 | + | |
142 | + public YoutrackAPI(String serviceLocation, HttpClient httpClient, String username, String password) throws IOException, JAXBException | |
143 | + { | |
144 | + this(serviceLocation, httpClient); | |
138 | 145 | login(username, password); |
139 | 146 | } |
140 | 147 | |
... | ... | @@ -306,11 +313,31 @@ public class YoutrackAPI { |
306 | 313 | return wrappedIssues; |
307 | 314 | } |
308 | 315 | |
309 | - private HttpPut createPutRequest(URI uri, BasicNameValuePair... nameValuePair) throws UnsupportedEncodingException | |
316 | + public void updateIssue(String issueId, String summary, String description) throws IOException | |
310 | 317 | { |
311 | - final HttpPut request = new HttpPut(uri); | |
312 | - request.setEntity(new UrlEncodedFormEntity(Arrays.asList(nameValuePair))); | |
313 | - return request; | |
318 | + final URI uri; | |
319 | + try { | |
320 | + uri = new URIBuilder(serviceLocation + "/rest/issue/" + issueId).build(); | |
321 | + } catch (URISyntaxException e) { | |
322 | + throw new RuntimeException(e); | |
323 | + } | |
324 | + final HttpPost request = createPostRequest(uri, new BasicNameValuePair(Fields.summary.name(), summary), | |
325 | + new BasicNameValuePair(Fields.description.name(), description)); | |
326 | + final HttpResponse response = httpClient.execute(request); | |
327 | + final StatusLine statusLine = response.getStatusLine(); | |
328 | + final HttpEntity entity = response.getEntity(); | |
329 | + final String responseText = entity == null ? null : EntityUtils.toString(entity); | |
330 | + throwExceptionsIfNeeded(statusLine, responseText); | |
331 | + } | |
332 | + | |
333 | + private HttpPost createPostRequest(URI uri, NameValuePair... nameValuePair) throws UnsupportedEncodingException | |
334 | + { | |
335 | + return setEntity(new HttpPost(uri), nameValuePair); | |
336 | + } | |
337 | + | |
338 | + private HttpPut createPutRequest(URI uri, NameValuePair... nameValuePair) throws UnsupportedEncodingException | |
339 | + { | |
340 | + return setEntity(new HttpPut(uri), nameValuePair); | |
314 | 341 | } |
315 | 342 | |
316 | 343 | private String execute(HttpUriRequest request) throws IOException |
... | ... | @@ -334,6 +361,14 @@ public class YoutrackAPI { |
334 | 361 | return responseText; |
335 | 362 | } |
336 | 363 | |
364 | + private <T extends HttpEntityEnclosingRequestBase> T setEntity(T request, NameValuePair[] nameValuePair) throws UnsupportedEncodingException | |
365 | + { | |
366 | + final ArrayList<NameValuePair> list = new ArrayList<NameValuePair>(); | |
367 | + Collections.addAll(list, nameValuePair); | |
368 | + request.setEntity(new UrlEncodedFormEntity(list)); | |
369 | + return request; | |
370 | + } | |
371 | + | |
337 | 372 | private void throwExceptionsIfNeeded(StatusLine statusLine, String responseText) throws IOException |
338 | 373 | { |
339 | 374 | if (statusLine.getStatusCode() >= 300) { | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.annotation.XmlAccessType; | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.annotation.XmlAccessType; | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.annotation.XmlAccessType; | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.JAXBElement; |
... | ... | @@ -49,6 +47,7 @@ import java.util.List; |
49 | 47 | * <attribute name="text" type="{http://www.w3.org/2001/XMLSchema}string" /> |
50 | 48 | * <attribute name="shownForIssueAuthor" type="{http://www.w3.org/2001/XMLSchema}string" /> |
51 | 49 | * <attribute name="created" type="{http://www.w3.org/2001/XMLSchema}long" /> |
50 | + * <attribute name="updated" type="{http://www.w3.org/2001/XMLSchema}long" /> | |
52 | 51 | * <attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" /> |
53 | 52 | * </restriction> |
54 | 53 | * </complexContent> |
... | ... | @@ -88,6 +87,9 @@ public class Comment { |
88 | 87 | @XmlAttribute |
89 | 88 | protected String text; |
90 | 89 | |
90 | + @XmlAttribute | |
91 | + protected Long updated; | |
92 | + | |
91 | 93 | // --------------------- GETTER / SETTER METHODS --------------------- |
92 | 94 | |
93 | 95 | /** |
... | ... | @@ -296,6 +298,28 @@ public class Comment { |
296 | 298 | this.text = value; |
297 | 299 | } |
298 | 300 | |
301 | + /** | |
302 | + * Gets the value of the updated property. | |
303 | + * | |
304 | + * @return possible object is | |
305 | + * {@link Long } | |
306 | + */ | |
307 | + public Long getUpdated() | |
308 | + { | |
309 | + return updated; | |
310 | + } | |
311 | + | |
312 | + /** | |
313 | + * Sets the value of the updated property. | |
314 | + * | |
315 | + * @param value allowed object is | |
316 | + * {@link Long } | |
317 | + */ | |
318 | + public void setUpdated(Long value) | |
319 | + { | |
320 | + this.updated = value; | |
321 | + } | |
322 | + | |
299 | 323 | // -------------------------- INNER CLASSES -------------------------- |
300 | 324 | |
301 | 325 | /** | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.annotation.XmlAccessType; | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.annotation.XmlAccessType; | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.annotation.XmlAccessType; | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.JAXBElement; | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.annotation.XmlAccessType; | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.annotation.XmlAccessType; | ... | ... |
... | ... | @@ -2,9 +2,7 @@ |
2 | 2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-833 |
3 | 3 | // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> |
4 | 4 | // Any modifications to this file will be lost upon recompilation of the source schema. |
5 | -// Generated on: 2012.07.05 at 06:19:38 PM CEST | |
6 | 5 | // |
7 | - | |
8 | 6 | package pl.com.it_crowd.youtrack.api.rest; |
9 | 7 | |
10 | 8 | import javax.xml.bind.annotation.XmlAccessType; | ... | ... |
... | ... | @@ -48,4 +48,15 @@ |
48 | 48 | <field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CustomField" name="Subsystem"> |
49 | 49 | <value>No subsystem</value> |
50 | 50 | </field> |
51 | + <comment id="1-0" author="root" issueId="QA-25" deleted="false" text="Well, this is my first comment.
A bit edited." shownForIssueAuthor="false" | |
52 | + created="1351614073487" updated="1351673040458"> | |
53 | + <replies/> | |
54 | + </comment> | |
55 | + <comment id="1-1" author="root" issueId="QA-25" deleted="false" text="Well this is another comment" shownForIssueAuthor="false" created="1351673293632"> | |
56 | + <replies/> | |
57 | + </comment> | |
58 | + <comment id="1-2" author="bernard" issueId="QA-25" deleted="false" text="Sialala.
Edited by root" shownForIssueAuthor="false" created="1351673503044" | |
59 | + updated="1351673522146"> | |
60 | + <replies/> | |
61 | + </comment> | |
51 | 62 | </issue> |
\ No newline at end of file | ... | ... |
... | ... | @@ -189,7 +189,7 @@ |
189 | 189 | </comment> |
190 | 190 | <comment id="39-86" author="tomek" issueId="SM-4" deleted="false" |
191 | 191 | text="Some use cases are related to "Students" and "Courses and Classes" packages. These weren't finished yet." |
192 | - shownForIssueAuthor="false" created="1292932584457"> | |
192 | + shownForIssueAuthor="false" created="1292932584457" updated="1351673522146"> | |
193 | 193 | <replies/> |
194 | 194 | </comment> |
195 | 195 | <field name="Priority"> | ... | ... |
... | ... | @@ -56,6 +56,7 @@ |
56 | 56 | <xs:attribute type="xs:string" name="text" use="optional"/> |
57 | 57 | <xs:attribute type="xs:string" name="shownForIssueAuthor" use="optional"/> |
58 | 58 | <xs:attribute type="xs:long" name="created" use="optional"/> |
59 | + <xs:attribute type="xs:long" name="updated" use="optional"/> | |
59 | 60 | <xs:attribute type="xs:string" name="name" use="optional"/> |
60 | 61 | </xs:complexType> |
61 | 62 | ... | ... |
Please
register
or
login
to post a comment