Commit cfcd880c074023a9aff7732725e58074c719521e
1 parent
5b6367a5
Restored searchIssuesByProject. Added FilterHelper.
Showing
2 changed files
with
129 additions
and
7 deletions
1 | +package pl.com.it_crowd.youtrack.api; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | + | ||
6 | +public final class FilterHelper { | ||
7 | +// -------------------------- STATIC METHODS -------------------------- | ||
8 | + | ||
9 | + public static Filter issueId(String issueId) | ||
10 | + { | ||
11 | + return new Filter().issueId(issueId); | ||
12 | + } | ||
13 | + | ||
14 | + public static Filter summary(String summary) | ||
15 | + { | ||
16 | + return new Filter().summary(summary); | ||
17 | + } | ||
18 | + | ||
19 | + public static Filter unresolved() | ||
20 | + { | ||
21 | + return new Filter().unresolved(); | ||
22 | + } | ||
23 | + | ||
24 | +// --------------------------- CONSTRUCTORS --------------------------- | ||
25 | + | ||
26 | + private FilterHelper() | ||
27 | + { | ||
28 | + | ||
29 | + } | ||
30 | + | ||
31 | +// -------------------------- INNER CLASSES -------------------------- | ||
32 | + | ||
33 | + public static class Filter { | ||
34 | +// ------------------------------ FIELDS ------------------------------ | ||
35 | + | ||
36 | + private List<Condition> conditions = new ArrayList<Condition>(); | ||
37 | + | ||
38 | +// --------------------------- CONSTRUCTORS --------------------------- | ||
39 | + | ||
40 | + private Filter() | ||
41 | + { | ||
42 | + | ||
43 | + } | ||
44 | + | ||
45 | +// ------------------------ CANONICAL METHODS ------------------------ | ||
46 | + | ||
47 | + @Override | ||
48 | + public String toString() | ||
49 | + { | ||
50 | + StringBuilder builder = new StringBuilder(); | ||
51 | + for (Condition condition : conditions) { | ||
52 | + if (condition.key != null) { | ||
53 | + builder.append(" "); | ||
54 | + builder.append(condition.key); | ||
55 | + builder.append(":"); | ||
56 | + } | ||
57 | + builder.append(condition.value); | ||
58 | + } | ||
59 | + return builder.toString(); | ||
60 | + } | ||
61 | + | ||
62 | +// -------------------------- OTHER METHODS -------------------------- | ||
63 | + | ||
64 | + public Filter issueId(String issueId) | ||
65 | + { | ||
66 | + conditions.add(new Condition(Key.ISSUE_ID, issueId)); | ||
67 | + return this; | ||
68 | + } | ||
69 | + | ||
70 | + public Filter summary(String summary) | ||
71 | + { | ||
72 | + conditions.add(new Condition(null, summary)); | ||
73 | + return this; | ||
74 | + } | ||
75 | + | ||
76 | + public Filter unresolved() | ||
77 | + { | ||
78 | + conditions.add(new Condition(null, "#Unresolved")); | ||
79 | + return this; | ||
80 | + } | ||
81 | + | ||
82 | +// -------------------------- ENUMERATIONS -------------------------- | ||
83 | + | ||
84 | + private enum Key { | ||
85 | + ISSUE_ID("issue id"); | ||
86 | + | ||
87 | +// ------------------------------ FIELDS ------------------------------ | ||
88 | + | ||
89 | + private String key; | ||
90 | + | ||
91 | +// --------------------------- CONSTRUCTORS --------------------------- | ||
92 | + | ||
93 | + Key(String key) | ||
94 | + { | ||
95 | + this.key = key; | ||
96 | + } | ||
97 | + | ||
98 | +// ------------------------ CANONICAL METHODS ------------------------ | ||
99 | + | ||
100 | + @Override | ||
101 | + public String toString() | ||
102 | + { | ||
103 | + return key; | ||
104 | + } | ||
105 | + } | ||
106 | + | ||
107 | +// -------------------------- INNER CLASSES -------------------------- | ||
108 | + | ||
109 | + private class Condition { | ||
110 | +// ------------------------------ FIELDS ------------------------------ | ||
111 | + | ||
112 | + private Key key; | ||
113 | + | ||
114 | + private String value; | ||
115 | + | ||
116 | +// --------------------------- CONSTRUCTORS --------------------------- | ||
117 | + | ||
118 | + private Condition(Key key, String value) | ||
119 | + { | ||
120 | + this.key = key; | ||
121 | + this.value = value; | ||
122 | + } | ||
123 | + } | ||
124 | + } | ||
125 | +} |
@@ -16,16 +16,13 @@ import pl.com.it_crowd.youtrack.api.rest.Issues; | @@ -16,16 +16,13 @@ import pl.com.it_crowd.youtrack.api.rest.Issues; | ||
16 | import javax.xml.bind.JAXBException; | 16 | import javax.xml.bind.JAXBException; |
17 | import java.io.IOException; | 17 | import java.io.IOException; |
18 | import java.net.URL; | 18 | import java.net.URL; |
19 | +import java.security.GeneralSecurityException; | ||
19 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
20 | import java.util.List; | 21 | import java.util.List; |
21 | 22 | ||
22 | -import java.security.GeneralSecurityException; | ||
23 | - | ||
24 | public class YoutrackAPI { | 23 | public class YoutrackAPI { |
25 | // ------------------------------ FIELDS ------------------------------ | 24 | // ------------------------------ FIELDS ------------------------------ |
26 | 25 | ||
27 | - private Integer MAX_RESULTS = 1000; | ||
28 | - | ||
29 | private String serviceLocation; | 26 | private String serviceLocation; |
30 | 27 | ||
31 | private WebClient webClient; | 28 | private WebClient webClient; |
@@ -41,7 +38,7 @@ public class YoutrackAPI { | @@ -41,7 +38,7 @@ public class YoutrackAPI { | ||
41 | try { | 38 | try { |
42 | this.webClient.setUseInsecureSSL(true); | 39 | this.webClient.setUseInsecureSSL(true); |
43 | } catch (GeneralSecurityException e) { | 40 | } catch (GeneralSecurityException e) { |
44 | - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. | 41 | + throw new RuntimeException("Cannot turn on 'Use insecure SSL'", e); |
45 | } | 42 | } |
46 | } | 43 | } |
47 | 44 | ||
@@ -80,9 +77,9 @@ public class YoutrackAPI { | @@ -80,9 +77,9 @@ public class YoutrackAPI { | ||
80 | } | 77 | } |
81 | } | 78 | } |
82 | 79 | ||
83 | - public List<Issue> searchIssuesByProject(String project) throws JAXBException, IOException | 80 | + public List<Issue> searchIssuesByProject(String project, Object filter) throws JAXBException, IOException |
84 | { | 81 | { |
85 | - String url = serviceLocation + "/rest/issue/byproject/" + project + "?max=" + MAX_RESULTS; | 82 | + String url = serviceLocation + "/rest/issue/byproject/" + project + "?filter=" + filter; |
86 | WebResponse webResponse = webClient.<Page>getPage(url).getWebResponse(); | 83 | WebResponse webResponse = webClient.<Page>getPage(url).getWebResponse(); |
87 | 84 | ||
88 | List<Issues.Issue> issues = IssuesUnmarshaller.unmarshal(webResponse.getContentAsStream()).getIssue(); | 85 | List<Issues.Issue> issues = IssuesUnmarshaller.unmarshal(webResponse.getContentAsStream()).getIssue(); |
Please
register
or
login
to post a comment