From 16d07deaa5c8fa1519bc7a871f34330132e7c919 Mon Sep 17 00:00:00 2001 From: Bernard Labno Date: Tue, 3 Jul 2012 10:50:59 +0000 Subject: [PATCH] Get project assignees. --- src/main/java/pl/com/it_crowd/youtrack/api/YoutrackAPI.java | 33 +++++++++++++++++++++++++++------ src/main/java/pl/com/it_crowd/youtrack/api/rest/Comment.java | 4 ++-- 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 | 6 +++--- 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 | 26 +++++++++++++++++++++----- src/main/java/pl/com/it_crowd/youtrack/api/rest/User.java | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/pl/com/it_crowd/youtrack/api/rest/UserRefs.java | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/xjb/bindings.xjb | 10 ++++++++++ src/main/xsd/error.xsd | 2 +- src/main/xsd/individualAssignees.xml | 4 ++++ src/main/xsd/individualAssignees.xsd | 13 +++++++++++++ src/main/xsd/types.xsd | 7 +++++++ src/test/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPITest.java | 26 +++++++++++++++++++------- 14 files changed, 271 insertions(+), 26 deletions(-) create mode 100644 src/main/java/pl/com/it_crowd/youtrack/api/rest/User.java create mode 100644 src/main/java/pl/com/it_crowd/youtrack/api/rest/UserRefs.java create mode 100644 src/main/xsd/individualAssignees.xml create mode 100644 src/main/xsd/individualAssignees.xsd 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 4285735..3596c03 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 @@ -29,13 +29,15 @@ import pl.com.it_crowd.youtrack.api.exceptions.YoutrackAPIException; import pl.com.it_crowd.youtrack.api.exceptions.YoutrackErrorException; import pl.com.it_crowd.youtrack.api.rest.Issue; import pl.com.it_crowd.youtrack.api.rest.Issues; -import pl.com.it_crowd.youtrack.api.rest.ObjectFactory; +import pl.com.it_crowd.youtrack.api.rest.User; +import pl.com.it_crowd.youtrack.api.rest.UserRefs; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -53,6 +55,10 @@ 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; private String serviceLocation; @@ -201,6 +207,23 @@ public class YoutrackAPI { return matcher.group(1); } + public List getIndividualAssignees(String project) throws IOException, JAXBException + { + final URI uri; + try { + uri = new URIBuilder(serviceLocation + "/rest/admin/project/" + project + "/assignee/individual").build(); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + final String responseString = execute(new HttpGet(uri)); + final Object result = YoutrackUnmarshaller.unmarshall(responseString); + if (result instanceof UserRefs) { + return ((UserRefs) result).getUsers(); + } else { + throw new YoutrackAPIException("Unexpected type: " + result); + } + } + public IssueWrapper getIssue(String issueId) throws IOException, JAXBException { final URI uri; @@ -224,15 +247,13 @@ public class YoutrackAPI { return new IssueWrapper((Issue) result); } else if (result instanceof JAXBElement) { final JAXBElement jaxbElement = (JAXBElement) result; - if (ObjectFactory._Error_QNAME.equals(jaxbElement.getName())) { - throw new RuntimeException("Unexpected type: " + jaxbElement.getValue()); - } else if (ObjectFactory._Issue_QNAME.equals(jaxbElement.getName())) { + if (Issue_QNAME.equals(jaxbElement.getName())) { return new IssueWrapper((Issue) jaxbElement.getValue()); } else { - throw new RuntimeException(jaxbElement.getValue() + ""); + throw new YoutrackAPIException("Unexpected type: " + jaxbElement.getValue()); } } else { - throw new RuntimeException("Unexpected type " + result); + throw new YoutrackAPIException("Unexpected type " + result); } } 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 887b1f9..90bffa8 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,7 +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.02 at 11:11:34 PM CEST +// Generated on: 2012.07.03 at 12:32:28 PM CEST // package pl.com.it_crowd.youtrack.api.rest; @@ -63,7 +63,7 @@ public class Comment { @XmlAttribute protected String author; - @XmlElementRefs({@XmlElementRef(name = "value", type = JAXBElement.class), @XmlElementRef(name = "replies", type = JAXBElement.class)}) + @XmlElementRefs({@XmlElementRef(name = "replies", type = JAXBElement.class), @XmlElementRef(name = "value", type = JAXBElement.class)}) @XmlMixed protected List content; 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 d890361..4abbc19 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,7 +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.02 at 11:11:34 PM CEST +// Generated on: 2012.07.03 at 12:32:28 PM CEST // package pl.com.it_crowd.youtrack.api.rest; 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 597fc85..263919b 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,7 +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.02 at 11:11:34 PM CEST +// Generated on: 2012.07.03 at 12:32:28 PM CEST // package pl.com.it_crowd.youtrack.api.rest; @@ -40,7 +40,7 @@ import java.util.List; public class Issue { // ------------------------------ FIELDS ------------------------------ - @XmlElements({@XmlElement(name = "comment", type = Comment.class), @XmlElement(name = "field", type = Field.class)}) + @XmlElements({@XmlElement(name = "field", type = Field.class), @XmlElement(name = "comment", type = Comment.class)}) protected List fieldOrComment; @XmlAttribute @@ -66,8 +66,8 @@ public class Issue { *

*

* Objects of the following type(s) are allowed in the list - * {@link Comment } * {@link Field } + * {@link Comment } */ public List getFieldOrComment() { 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 0e98feb..02a6a98 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,7 +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.02 at 11:11:34 PM CEST +// Generated on: 2012.07.03 at 12:32:28 PM CEST // package pl.com.it_crowd.youtrack.api.rest; 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 7a3f515..a2c9e8e 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,7 +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.02 at 11:11:34 PM CEST +// Generated on: 2012.07.03 at 12:32:28 PM CEST // package pl.com.it_crowd.youtrack.api.rest; @@ -29,14 +29,14 @@ import javax.xml.namespace.QName; public class ObjectFactory { // ------------------------------ FIELDS ------------------------------ - public final static QName _Error_QNAME = new QName("", "error"); - - public final static QName _Issue_QNAME = new QName("", "issue"); - private final static QName _CommentReplies_QNAME = new QName("", "replies"); private final static QName _CommentValue_QNAME = new QName("", "value"); + private final static QName _Error_QNAME = new QName("", "error"); + + private final static QName _Issue_QNAME = new QName("", "issue"); + // --------------------------- CONSTRUCTORS --------------------------- /** @@ -131,4 +131,20 @@ public class ObjectFactory { { return new Issues(); } + + /** + * Create an instance of {@link User } + */ + public User createUser() + { + return new User(); + } + + /** + * Create an instance of {@link UserRefs } + */ + public UserRefs createUserRefs() + { + return new UserRefs(); + } } 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 new file mode 100644 index 0000000..24b3e33 --- /dev/null +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/User.java @@ -0,0 +1,89 @@ +// +// 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.03 at 12:32:28 PM CEST +// + +package pl.com.it_crowd.youtrack.api.rest; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; + +/** + *

Java class for userType complex type. + *

+ *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <complexType name="userType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <attribute name="login" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="url" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "userType") +public class User { +// ------------------------------ FIELDS ------------------------------ + + @XmlAttribute(required = true) + protected String login; + + @XmlAttribute + @XmlSchemaType(name = "anyURI") + protected String url; + +// --------------------- GETTER / SETTER METHODS --------------------- + + /** + * Gets the value of the login property. + * + * @return possible object is + * {@link String } + */ + public String getLogin() + { + return login; + } + + /** + * Sets the value of the login property. + * + * @param value allowed object is + * {@link String } + */ + public void setLogin(String value) + { + this.login = value; + } + + /** + * Gets the value of the url property. + * + * @return possible object is + * {@link String } + */ + public String getUrl() + { + return url; + } + + /** + * Sets the value of the url property. + * + * @param value allowed object is + * {@link String } + */ + public void setUrl(String value) + { + this.url = value; + } +} 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 new file mode 100644 index 0000000..f1f5212 --- /dev/null +++ b/src/main/java/pl/com/it_crowd/youtrack/api/rest/UserRefs.java @@ -0,0 +1,73 @@ +// +// 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.03 at 12:32:28 PM CEST +// + +package pl.com.it_crowd.youtrack.api.rest; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import java.util.ArrayList; +import java.util.List; + +/** + *

Java class for anonymous complex type. + *

+ *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="user" type="{}userType" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = {"users"}) +@XmlRootElement(name = "userRefs") +public class UserRefs { +// ------------------------------ FIELDS ------------------------------ + + @XmlElement(name = "user") + protected List users; + +// --------------------- GETTER / SETTER METHODS --------------------- + + /** + * Gets the value of the users property. + *

+ *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the users property. + *

+ *

+ * For example, to add a new item, do as follows: + *

+     *    getUsers().add(newItem);
+     * 
+ *

+ *

+ *

+ * Objects of the following type(s) are allowed in the list + * {@link User } + */ + public List getUsers() + { + if (users == null) { + users = new ArrayList(); + } + return this.users; + } +} diff --git a/src/main/xjb/bindings.xjb b/src/main/xjb/bindings.xjb index 85db285..54fb3c5 100644 --- a/src/main/xjb/bindings.xjb +++ b/src/main/xjb/bindings.xjb @@ -9,6 +9,12 @@ + + + + + + @@ -28,6 +34,10 @@ + + + + \ No newline at end of file diff --git a/src/main/xsd/error.xsd b/src/main/xsd/error.xsd index 285fb42..60ba6f2 100644 --- a/src/main/xsd/error.xsd +++ b/src/main/xsd/error.xsd @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/src/main/xsd/individualAssignees.xml b/src/main/xsd/individualAssignees.xml new file mode 100644 index 0000000..32e176f --- /dev/null +++ b/src/main/xsd/individualAssignees.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/main/xsd/individualAssignees.xsd b/src/main/xsd/individualAssignees.xsd new file mode 100644 index 0000000..511b1e4 --- /dev/null +++ b/src/main/xsd/individualAssignees.xsd @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/xsd/types.xsd b/src/main/xsd/types.xsd index b101132..97186b8 100644 --- a/src/main/xsd/types.xsd +++ b/src/main/xsd/types.xsd @@ -21,6 +21,7 @@ + @@ -44,4 +45,10 @@ + + + + + + \ No newline at end of file diff --git a/src/test/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPITest.java b/src/test/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPITest.java index 085face..1544978 100644 --- a/src/test/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPITest.java +++ b/src/test/java/pl/com/it_crowd/youtrack/api/rest/YoutrackAPITest.java @@ -27,7 +27,7 @@ public class YoutrackAPITest { // -------------------------- OTHER METHODS -------------------------- @Test - public void commandAllStatesTest() throws IOException, JAXBException + public void commandAllStates() throws IOException, JAXBException { final YoutrackAPI api = new YoutrackAPI(getServiceLocation(), getUsername(), getPassword()); final String issueId = "TST-1"; @@ -44,7 +44,19 @@ public class YoutrackAPITest { } @Test - public void commandTest() throws IOException, JAXBException + public void getIndividualAssignees() throws IOException, JAXBException + { + final YoutrackAPI api = new YoutrackAPI(getServiceLocation(), getUsername(), getPassword()); + final List assignees = api.getIndividualAssignees("TST"); + Assert.assertNotNull(assignees); + Assert.assertEquals(2, assignees.size()); + for (User user : assignees) { + Assert.assertTrue("bernard".equals(user.getLogin()) || "root".equals(user.getLogin())); + } + } + + @Test + public void command() throws IOException, JAXBException { final YoutrackAPI api = new YoutrackAPI(getServiceLocation(), getUsername(), getPassword()); final String issueId = "TST-1"; @@ -85,7 +97,7 @@ public class YoutrackAPITest { } @Test - public void createIssueTest() throws IOException, AuthenticationException, JAXBException + public void createIssue() throws IOException, AuthenticationException, JAXBException { YoutrackAPI api = new YoutrackAPI(getServiceLocation(), getUsername(), getPassword()); final String issueId = api.createIssue("TST", "Test summary", "Test description"); @@ -94,7 +106,7 @@ public class YoutrackAPITest { } @Test - public void getIssueTest() throws IOException, AuthenticationException, JAXBException + public void getIssue() throws IOException, AuthenticationException, JAXBException { YoutrackAPI api = new YoutrackAPI(getServiceLocation(), getUsername(), getPassword()); final IssueWrapper issue = api.getIssue("TST-1"); @@ -116,7 +128,7 @@ public class YoutrackAPITest { } @Test(expected = YoutrackErrorException.class) - public void loginFailureTest() throws IOException, JAXBException + public void loginFailure() throws IOException, JAXBException { final String username = "someFakeLogin"; final String password = "someFakePassword"; @@ -130,7 +142,7 @@ public class YoutrackAPITest { } @Test - public void loginTest() throws IOException, AuthenticationException, JAXBException + public void loginSuccess() throws IOException, AuthenticationException, JAXBException { final String username = getUsername(); final String password = getPassword(); @@ -140,7 +152,7 @@ public class YoutrackAPITest { } @Test - public void searchIssuesByProjectTest() throws IOException, AuthenticationException, JAXBException + public void searchIssuesByProject() throws IOException, AuthenticationException, JAXBException { YoutrackAPI api = new YoutrackAPI(getServiceLocation(), getUsername(), getPassword()); List issues = api.searchIssuesByProject("TST", null); -- libgit2 0.24.0