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 new file mode 100644 index 0000000..6765278 --- /dev/null +++ b/src/main/java/pl/com/it_crowd/youtrack/api/FilterHelper.java @@ -0,0 +1,125 @@ +package pl.com.it_crowd.youtrack.api; + +import java.util.ArrayList; +import java.util.List; + +public final class FilterHelper { +// -------------------------- STATIC METHODS -------------------------- + + public static Filter issueId(String issueId) + { + return new Filter().issueId(issueId); + } + + public static Filter summary(String summary) + { + return new Filter().summary(summary); + } + + public static Filter unresolved() + { + return new Filter().unresolved(); + } + +// --------------------------- CONSTRUCTORS --------------------------- + + private FilterHelper() + { + + } + +// -------------------------- INNER CLASSES -------------------------- + + public static class Filter { +// ------------------------------ FIELDS ------------------------------ + + private List conditions = new ArrayList(); + +// --------------------------- CONSTRUCTORS --------------------------- + + private Filter() + { + + } + +// ------------------------ CANONICAL METHODS ------------------------ + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + for (Condition condition : conditions) { + if (condition.key != null) { + builder.append(" "); + builder.append(condition.key); + builder.append(":"); + } + builder.append(condition.value); + } + return builder.toString(); + } + +// -------------------------- OTHER METHODS -------------------------- + + public Filter issueId(String issueId) + { + conditions.add(new Condition(Key.ISSUE_ID, issueId)); + return this; + } + + public Filter summary(String summary) + { + conditions.add(new Condition(null, summary)); + return this; + } + + public Filter unresolved() + { + conditions.add(new Condition(null, "#Unresolved")); + return this; + } + +// -------------------------- ENUMERATIONS -------------------------- + + private enum Key { + ISSUE_ID("issue id"); + +// ------------------------------ FIELDS ------------------------------ + + private String key; + +// --------------------------- CONSTRUCTORS --------------------------- + + Key(String key) + { + this.key = key; + } + +// ------------------------ CANONICAL METHODS ------------------------ + + @Override + public String toString() + { + return key; + } + } + +// -------------------------- INNER CLASSES -------------------------- + + private class Condition { +// ------------------------------ FIELDS ------------------------------ + + private Key key; + + private String value; + +// --------------------------- CONSTRUCTORS --------------------------- + + private Condition(Key key, String value) + { + this.key = key; + this.value = value; + } + } + } +} 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 81fd878..ef80051 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 @@ -16,16 +16,13 @@ import pl.com.it_crowd.youtrack.api.rest.Issues; import javax.xml.bind.JAXBException; import java.io.IOException; import java.net.URL; +import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.List; -import java.security.GeneralSecurityException; - public class YoutrackAPI { // ------------------------------ FIELDS ------------------------------ - private Integer MAX_RESULTS = 1000; - private String serviceLocation; private WebClient webClient; @@ -41,7 +38,7 @@ public class YoutrackAPI { try { this.webClient.setUseInsecureSSL(true); } catch (GeneralSecurityException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + throw new RuntimeException("Cannot turn on 'Use insecure SSL'", e); } } @@ -80,9 +77,9 @@ public class YoutrackAPI { } } - public List searchIssuesByProject(String project) throws JAXBException, IOException + public List searchIssuesByProject(String project, Object filter) throws JAXBException, IOException { - String url = serviceLocation + "/rest/issue/byproject/" + project + "?max=" + MAX_RESULTS; + String url = serviceLocation + "/rest/issue/byproject/" + project + "?filter=" + filter; WebResponse webResponse = webClient.getPage(url).getWebResponse(); List issues = IssuesUnmarshaller.unmarshal(webResponse.getContentAsStream()).getIssue();