Showing
1 changed file
with
29 additions
and
5 deletions
1 | package pl.com.it_crowd.youtrack.api; | 1 | package pl.com.it_crowd.youtrack.api; |
2 | 2 | ||
3 | +import java.io.UnsupportedEncodingException; | ||
4 | +import java.net.URLEncoder; | ||
3 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
4 | import java.util.List; | 6 | import java.util.List; |
5 | 7 | ||
@@ -35,6 +37,8 @@ public final class FilterHelper { | @@ -35,6 +37,8 @@ public final class FilterHelper { | ||
35 | 37 | ||
36 | private List<Condition> conditions = new ArrayList<Condition>(); | 38 | private List<Condition> conditions = new ArrayList<Condition>(); |
37 | 39 | ||
40 | + private long maxResults; | ||
41 | + | ||
38 | // --------------------------- CONSTRUCTORS --------------------------- | 42 | // --------------------------- CONSTRUCTORS --------------------------- |
39 | 43 | ||
40 | private Filter() | 44 | private Filter() |
@@ -48,15 +52,28 @@ public final class FilterHelper { | @@ -48,15 +52,28 @@ public final class FilterHelper { | ||
48 | public String toString() | 52 | public String toString() |
49 | { | 53 | { |
50 | StringBuilder builder = new StringBuilder(); | 54 | StringBuilder builder = new StringBuilder(); |
55 | + String space; | ||
56 | + try { | ||
57 | + space = URLEncoder.encode(" ", "UTF-8"); | ||
58 | + } catch (UnsupportedEncodingException e) { | ||
59 | + throw new RuntimeException(e); | ||
60 | + } | ||
51 | for (Condition condition : conditions) { | 61 | for (Condition condition : conditions) { |
62 | + builder.append(space); | ||
52 | if (condition.key != null) { | 63 | if (condition.key != null) { |
53 | - builder.append(" "); | ||
54 | builder.append(condition.key); | 64 | builder.append(condition.key); |
55 | builder.append(":"); | 65 | builder.append(":"); |
56 | } | 66 | } |
57 | - builder.append(condition.value); | 67 | + try { |
68 | + builder.append(URLEncoder.encode(condition.value, "UTF-8")); | ||
69 | + } catch (UnsupportedEncodingException e) { | ||
70 | + throw new RuntimeException(e); | ||
71 | + } | ||
72 | + } | ||
73 | + if (maxResults > 0) { | ||
74 | + builder.append("&max=").append(maxResults); | ||
58 | } | 75 | } |
59 | - return builder.toString(); | 76 | + return builder.toString().trim(); |
60 | } | 77 | } |
61 | 78 | ||
62 | // -------------------------- OTHER METHODS -------------------------- | 79 | // -------------------------- OTHER METHODS -------------------------- |
@@ -67,6 +84,12 @@ public final class FilterHelper { | @@ -67,6 +84,12 @@ public final class FilterHelper { | ||
67 | return this; | 84 | return this; |
68 | } | 85 | } |
69 | 86 | ||
87 | + public Filter maxResults(long maxResults) | ||
88 | + { | ||
89 | + this.maxResults = maxResults; | ||
90 | + return this; | ||
91 | + } | ||
92 | + | ||
70 | public Filter summary(String summary) | 93 | public Filter summary(String summary) |
71 | { | 94 | { |
72 | conditions.add(new Condition(null, summary)); | 95 | conditions.add(new Condition(null, summary)); |
@@ -75,14 +98,15 @@ public final class FilterHelper { | @@ -75,14 +98,15 @@ public final class FilterHelper { | ||
75 | 98 | ||
76 | public Filter unresolved() | 99 | public Filter unresolved() |
77 | { | 100 | { |
78 | - conditions.add(new Condition(null, "#Unresolved")); | 101 | + conditions.add(new Condition(Key.STATE, "Unresolved")); |
79 | return this; | 102 | return this; |
80 | } | 103 | } |
81 | 104 | ||
82 | // -------------------------- ENUMERATIONS -------------------------- | 105 | // -------------------------- ENUMERATIONS -------------------------- |
83 | 106 | ||
84 | private enum Key { | 107 | private enum Key { |
85 | - ISSUE_ID("issue id"); | 108 | + ISSUE_ID("issue id"), |
109 | + STATE("state"); | ||
86 | 110 | ||
87 | // ------------------------------ FIELDS ------------------------------ | 111 | // ------------------------------ FIELDS ------------------------------ |
88 | 112 |
Please
register
or
login
to post a comment