This repository has been archived by the owner on Feb 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from daniel-sc/new_filter
adding support for filter operation
- Loading branch information
Showing
8 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
package com.podio.item.filter; | ||
|
||
public class Filter { | ||
import org.codehaus.jackson.annotate.JsonProperty; | ||
|
||
public abstract class Filter<VALUES> { | ||
|
||
private final String key; | ||
|
||
Filter(String key) { | ||
this.key = key; | ||
} | ||
|
||
@JsonProperty("values") | ||
public abstract VALUES getValues(); | ||
|
||
@JsonProperty("key") | ||
public String getKey() { | ||
return key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.podio.item.filter; | ||
|
||
import org.codehaus.jackson.annotate.JsonProperty; | ||
|
||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class FilterCreatedOn extends Filter<FilterInterval> { | ||
|
||
/** non-static to allow for multi threading */ | ||
private final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); | ||
|
||
private final FilterInterval values; | ||
|
||
public FilterCreatedOn(Date from, Date to) { | ||
super("created_on"); | ||
values = new FilterInterval(); | ||
values.setFrom(from != null ? DATE_FORMAT.format(from) : null); | ||
values.setTo(to != null ? DATE_FORMAT.format(to) : null); | ||
} | ||
|
||
@Override | ||
@JsonProperty("values") | ||
public FilterInterval getValues() { | ||
return values; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.podio.item.filter; | ||
|
||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class FilterDateField extends FilterFieldValue<FilterInterval> { | ||
|
||
/** non-static to allow for multi threading */ | ||
private final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); | ||
|
||
private final FilterInterval values; | ||
|
||
public FilterDateField(int fieldId, Date from, Date to) { | ||
super(fieldId); | ||
values = new FilterInterval(); | ||
values.setFrom(from != null ? DATE_FORMAT.format(from) : null); | ||
values.setTo(to != null ? DATE_FORMAT.format(to) : null); | ||
} | ||
|
||
@Override | ||
public FilterInterval getValues() { | ||
return values; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.podio.item.filter; | ||
|
||
public abstract class FilterFieldValue<VALUES> extends Filter<VALUES> { | ||
|
||
public FilterFieldValue(int fieldId) { | ||
super(String.valueOf(fieldId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.podio.item.filter; | ||
|
||
import org.codehaus.jackson.annotate.JsonProperty; | ||
|
||
public class FilterInterval { | ||
|
||
private String from; | ||
private String to; | ||
|
||
@JsonProperty("from") | ||
public String getFrom() { | ||
return from; | ||
} | ||
|
||
public void setFrom(String from) { | ||
this.from = from; | ||
} | ||
@JsonProperty("to") | ||
public String getTo() { | ||
return to; | ||
} | ||
|
||
public void setTo(String to) { | ||
this.to = to; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.podio.item.filter; | ||
|
||
import org.codehaus.jackson.annotate.JsonProperty; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ItemFilter { | ||
|
||
private String sortBy; | ||
private Boolean sortDesc; | ||
private Integer limit; | ||
private Integer offset; | ||
private List<Filter> filters; | ||
|
||
public ItemFilter() { | ||
filters = new ArrayList<Filter>(); | ||
} | ||
|
||
/** | ||
* Creates a copy (actual filters are only shallow copy!) | ||
* @param filter | ||
*/ | ||
public ItemFilter(ItemFilter filter) { | ||
this(); | ||
sortBy = filter.getSortBy(); | ||
sortDesc = filter.getSortDesc(); | ||
limit = filter.getLimit(); | ||
offset = filter.getOffset(); | ||
filters = filter.getFilters(); | ||
} | ||
|
||
|
||
@JsonProperty("sort_by") | ||
public String getSortBy() { | ||
return sortBy; | ||
} | ||
|
||
public void setSortBy(String sortBy) { | ||
this.sortBy = sortBy; | ||
} | ||
|
||
@JsonProperty("sort_desc") | ||
public Boolean getSortDesc() { | ||
return sortDesc; | ||
} | ||
|
||
public void setSortDesc(Boolean sortDesc) { | ||
this.sortDesc = sortDesc; | ||
} | ||
|
||
@JsonProperty("limit") | ||
public Integer getLimit() { | ||
return limit; | ||
} | ||
|
||
public void setLimit(Integer limit) { | ||
this.limit = limit; | ||
} | ||
|
||
@JsonProperty("offset") | ||
public Integer getOffset() { | ||
return offset; | ||
} | ||
|
||
public void setOffset(Integer offset) { | ||
this.offset = offset; | ||
} | ||
|
||
@JsonProperty("filters") | ||
public List<Filter> getFilters() { | ||
return filters; | ||
} | ||
|
||
public void setFilters(List<Filter> filters) { | ||
this.filters = filters; | ||
} | ||
} |