Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.

Commit 3f8eba2

Browse files
authored
Merge pull request #35 from daniel-sc/new_filter
adding support for filter operation
2 parents 60da00d + 1291f89 commit 3f8eba2

File tree

8 files changed

+188
-1
lines changed

8 files changed

+188
-1
lines changed

src/main/java/com/podio/item/ItemAPI.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.podio.filter.ExternalIdFilterBy;
1212
import com.podio.filter.FilterByValue;
1313
import com.podio.filter.SortBy;
14+
import com.podio.item.filter.ItemFilter;
1415
import com.sun.jersey.api.client.GenericType;
1516
import com.sun.jersey.api.client.WebResource;
1617

@@ -266,6 +267,11 @@ public List<ItemRevision> getItemRevisions(int itemId) {
266267
});
267268
}
268269

270+
public ItemsResponse filterItems(int appId, ItemFilter filter) {
271+
return getResourceFactory().getApiResource("/item/app/" + appId + "/filter/")
272+
.entity(filter, MediaType.APPLICATION_JSON_TYPE).post(ItemsResponse.class);
273+
}
274+
269275
/**
270276
* Returns the items on app matching the given filters.
271277
*

src/main/java/com/podio/item/ItemBadge.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public int getFiles() {
153153
return files;
154154
}
155155

156+
@JsonProperty("file_count")
156157
public void setFiles(int files) {
157158
this.files = files;
158159
}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package com.podio.item.filter;
22

3-
public class Filter {
3+
import org.codehaus.jackson.annotate.JsonProperty;
44

5+
public abstract class Filter<VALUES> {
6+
7+
private final String key;
8+
9+
Filter(String key) {
10+
this.key = key;
11+
}
12+
13+
@JsonProperty("values")
14+
public abstract VALUES getValues();
15+
16+
@JsonProperty("key")
17+
public String getKey() {
18+
return key;
19+
}
520
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.podio.item.filter;
2+
3+
import org.codehaus.jackson.annotate.JsonProperty;
4+
5+
import java.text.DateFormat;
6+
import java.text.SimpleDateFormat;
7+
import java.util.Date;
8+
9+
public class FilterCreatedOn extends Filter<FilterInterval> {
10+
11+
/** non-static to allow for multi threading */
12+
private final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
13+
14+
private final FilterInterval values;
15+
16+
public FilterCreatedOn(Date from, Date to) {
17+
super("created_on");
18+
values = new FilterInterval();
19+
values.setFrom(from != null ? DATE_FORMAT.format(from) : null);
20+
values.setTo(to != null ? DATE_FORMAT.format(to) : null);
21+
}
22+
23+
@Override
24+
@JsonProperty("values")
25+
public FilterInterval getValues() {
26+
return values;
27+
}
28+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.podio.item.filter;
2+
3+
import java.text.DateFormat;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Date;
6+
7+
public class FilterDateField extends FilterFieldValue<FilterInterval> {
8+
9+
/** non-static to allow for multi threading */
10+
private final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
11+
12+
private final FilterInterval values;
13+
14+
public FilterDateField(int fieldId, Date from, Date to) {
15+
super(fieldId);
16+
values = new FilterInterval();
17+
values.setFrom(from != null ? DATE_FORMAT.format(from) : null);
18+
values.setTo(to != null ? DATE_FORMAT.format(to) : null);
19+
}
20+
21+
@Override
22+
public FilterInterval getValues() {
23+
return values;
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.podio.item.filter;
2+
3+
public abstract class FilterFieldValue<VALUES> extends Filter<VALUES> {
4+
5+
public FilterFieldValue(int fieldId) {
6+
super(String.valueOf(fieldId));
7+
}
8+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.podio.item.filter;
2+
3+
import org.codehaus.jackson.annotate.JsonProperty;
4+
5+
public class FilterInterval {
6+
7+
private String from;
8+
private String to;
9+
10+
@JsonProperty("from")
11+
public String getFrom() {
12+
return from;
13+
}
14+
15+
public void setFrom(String from) {
16+
this.from = from;
17+
}
18+
@JsonProperty("to")
19+
public String getTo() {
20+
return to;
21+
}
22+
23+
public void setTo(String to) {
24+
this.to = to;
25+
}
26+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.podio.item.filter;
2+
3+
import org.codehaus.jackson.annotate.JsonProperty;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class ItemFilter {
9+
10+
private String sortBy;
11+
private Boolean sortDesc;
12+
private Integer limit;
13+
private Integer offset;
14+
private List<Filter> filters;
15+
16+
public ItemFilter() {
17+
filters = new ArrayList<Filter>();
18+
}
19+
20+
/**
21+
* Creates a copy (actual filters are only shallow copy!)
22+
* @param filter
23+
*/
24+
public ItemFilter(ItemFilter filter) {
25+
this();
26+
sortBy = filter.getSortBy();
27+
sortDesc = filter.getSortDesc();
28+
limit = filter.getLimit();
29+
offset = filter.getOffset();
30+
filters = filter.getFilters();
31+
}
32+
33+
34+
@JsonProperty("sort_by")
35+
public String getSortBy() {
36+
return sortBy;
37+
}
38+
39+
public void setSortBy(String sortBy) {
40+
this.sortBy = sortBy;
41+
}
42+
43+
@JsonProperty("sort_desc")
44+
public Boolean getSortDesc() {
45+
return sortDesc;
46+
}
47+
48+
public void setSortDesc(Boolean sortDesc) {
49+
this.sortDesc = sortDesc;
50+
}
51+
52+
@JsonProperty("limit")
53+
public Integer getLimit() {
54+
return limit;
55+
}
56+
57+
public void setLimit(Integer limit) {
58+
this.limit = limit;
59+
}
60+
61+
@JsonProperty("offset")
62+
public Integer getOffset() {
63+
return offset;
64+
}
65+
66+
public void setOffset(Integer offset) {
67+
this.offset = offset;
68+
}
69+
70+
@JsonProperty("filters")
71+
public List<Filter> getFilters() {
72+
return filters;
73+
}
74+
75+
public void setFilters(List<Filter> filters) {
76+
this.filters = filters;
77+
}
78+
}

0 commit comments

Comments
 (0)