diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/FilterHelper.java b/src/main/java/pl/com/it_crowd/youtrack/api/FilterHelper.java index 6765278..051d035 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/FilterHelper.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/FilterHelper.java @@ -1,5 +1,7 @@ package pl.com.it_crowd.youtrack.api; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; @@ -35,6 +37,8 @@ public final class FilterHelper { private List conditions = new ArrayList(); + private long maxResults; + // --------------------------- CONSTRUCTORS --------------------------- private Filter() @@ -48,15 +52,28 @@ public final class FilterHelper { public String toString() { StringBuilder builder = new StringBuilder(); + String space; + try { + space = URLEncoder.encode(" ", "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } for (Condition condition : conditions) { + builder.append(space); if (condition.key != null) { - builder.append(" "); builder.append(condition.key); builder.append(":"); } - builder.append(condition.value); + try { + builder.append(URLEncoder.encode(condition.value, "UTF-8")); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + if (maxResults > 0) { + builder.append("&max=").append(maxResults); } - return builder.toString(); + return builder.toString().trim(); } // -------------------------- OTHER METHODS -------------------------- @@ -67,6 +84,12 @@ public final class FilterHelper { return this; } + public Filter maxResults(long maxResults) + { + this.maxResults = maxResults; + return this; + } + public Filter summary(String summary) { conditions.add(new Condition(null, summary)); @@ -75,14 +98,15 @@ public final class FilterHelper { public Filter unresolved() { - conditions.add(new Condition(null, "#Unresolved")); + conditions.add(new Condition(Key.STATE, "Unresolved")); return this; } // -------------------------- ENUMERATIONS -------------------------- private enum Key { - ISSUE_ID("issue id"); + ISSUE_ID("issue id"), + STATE("state"); // ------------------------------ FIELDS ------------------------------