Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getAllFilter #238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions src/main/java/net/rcarz/jiraclient/Filter.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package net.rcarz.jiraclient;

import net.sf.json.JSON;
import net.sf.json.JSONObject;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
* Represens a Jira filter.
*/
Expand All @@ -18,8 +21,9 @@ public class Filter extends Resource {
public Filter(RestClient restclient, JSONObject json) {
super(restclient);

if (json != null)
deserialise(json);
if (json != null) {
deserialise(json);
}
}

private void deserialise(JSONObject json) {
Expand All @@ -44,6 +48,29 @@ public String getName() {
return name;
}

public static List<Filter> getAll(final RestClient restclient) throws JiraException {
JSON result = null;

try {
URI uri = restclient.buildURI(getBaseUri() + "filter/");
result = restclient.get(uri);
} catch (Exception ex) {
throw new JiraException("Failed to retrieve filters", ex);
}

if (!(result instanceof JSONArray)) {
throw new JiraException("JSON payload is malformed");
}
List<Filter> filters = new ArrayList<Filter>();
for (int i = 0; i < ((JSONArray)result).size(); i++) {
if (!(((JSONArray)result).get(i) instanceof JSONObject)) {
throw new JiraException("JSON payload is malformed");
}
filters.add(new Filter(restclient, (JSONObject) ((JSONArray)result).get(i)));
}
return filters;
}

public static Filter get(final RestClient restclient, final String id) throws JiraException {
JSON result = null;

Expand Down
Loading