From a07249829d05fc949e6eb130dbc1f7f000bceae5 Mon Sep 17 00:00:00 2001 From: PetrFOX Date: Mon, 14 Mar 2016 12:32:13 +0100 Subject: [PATCH 1/6] added method getCount on app items and a possibility to exlude self in getContacts methods --- .../java/com/podio/contact/ContactAPI.java | 26 ++++++++++++++----- src/main/java/com/podio/item/ItemAPI.java | 13 ++++++++++ src/main/java/com/podio/item/ItemCount.java | 14 ++++++++++ .../com/podio/contact/ContactAPITest.java | 2 +- 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/podio/item/ItemCount.java diff --git a/src/main/java/com/podio/contact/ContactAPI.java b/src/main/java/com/podio/contact/ContactAPI.java index 0dfa289..8dddf73 100644 --- a/src/main/java/com/podio/contact/ContactAPI.java +++ b/src/main/java/com/podio/contact/ContactAPI.java @@ -142,15 +142,17 @@ public ContactTotal getContactTotal() { * How the contacts should be ordered * @param contactType * The type of contacts to be returned + * @param excludeSelf + * True to exclude self, False to include self. Default value: true * @return The list of contacts */ public List getContacts(ProfileField key, F value, Integer limit, Integer offset, ProfileType type, - ContactOrder order, ContactType contactType) { + ContactOrder order, ContactType contactType, Boolean excludeSelf) { WebResource resource = getResourceFactory().getApiResource("/contact/"); return getContactsCommon(resource, key, value, limit, offset, type, - order, contactType); + order, contactType, excludeSelf); } /** @@ -173,16 +175,19 @@ public List getContacts(ProfileField key, F value, * How the contacts should be ordered * @param contactType * The type of contacts to be returned + * @param excludeSelf + * True to exclude self, False to include self. Default value: true * @return The list of contacts */ public List getOrganizationContacts(int organizationId, ProfileField key, F value, Integer limit, Integer offset, - ProfileType type, ContactOrder order, ContactType contactType) { + ProfileType type, ContactOrder order, ContactType contactType, + Boolean excludeSelf) { WebResource resource = getResourceFactory().getApiResource( "/contact/org/" + organizationId); return getContactsCommon(resource, key, value, limit, offset, type, - order, contactType); + order, contactType, excludeSelf); } /** @@ -204,16 +209,19 @@ public List getOrganizationContacts(int organizationId, * How the contacts should be ordered * @param contactType * The type of contacts to be returned + * @param excludeSelf + * True to exclude self, False to include self. Default value: true * @return The list of contacts */ public List getSpaceContacts(int spaceId, ProfileField key, F value, Integer limit, Integer offset, - ProfileType type, ContactOrder order, ContactType contactType) { + ProfileType type, ContactOrder order, ContactType contactType, + Boolean excludeSelf) { WebResource resource = getResourceFactory().getApiResource( "/contact/space/" + spaceId); return getContactsCommon(resource, key, value, limit, offset, type, - order, contactType); + order, contactType, excludeSelf); } /** @@ -232,7 +240,8 @@ public SpaceContactTotals getSpaceContactTotals(int spaceId) { private List getContactsCommon(WebResource resource, ProfileField key, F value, Integer limit, Integer offset, - final ProfileType type, ContactOrder order, ContactType contactType) { + final ProfileType type, ContactOrder order, ContactType contactType, + Boolean excludeSelf) { if (key != null && value != null) { resource = resource.queryParam("key", key.getName().toLowerCase()) .queryParam("value", key.format(value).toString()); @@ -250,6 +259,9 @@ private List getContactsCommon(WebResource resource, if (contactType != null) { resource = resource.queryParam("contact_type", contactType.name().toLowerCase()); } + if (excludeSelf != null) { + resource = resource.queryParam("exclude_self", excludeSelf ? "1" : "0"); + } return resource.get(getGenericType(type)); } diff --git a/src/main/java/com/podio/item/ItemAPI.java b/src/main/java/com/podio/item/ItemAPI.java index 6cc3b3c..9c3d4df 100644 --- a/src/main/java/com/podio/item/ItemAPI.java +++ b/src/main/java/com/podio/item/ItemAPI.java @@ -322,4 +322,17 @@ public ItemsResponse getItemsByExternalId(int appId, String externalId) { return getItems(appId, null, null, null, null, new FilterByValue(new ExternalIdFilterBy(), externalId)); } + + /** + * Returns the number of items on app + * + * @param appId + * The id of the app + * @return The number of items on app + */ + public int getItemCount(int appId) { + WebResource resource = getResourceFactory().getApiResource( + "/item/app/" + appId + "/count"); + return resource.get(ItemCount.class).getCount(); + } } diff --git a/src/main/java/com/podio/item/ItemCount.java b/src/main/java/com/podio/item/ItemCount.java new file mode 100644 index 0000000..9f2ff22 --- /dev/null +++ b/src/main/java/com/podio/item/ItemCount.java @@ -0,0 +1,14 @@ +package com.podio.item; + +public class ItemCount { + + private int count; + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } +} diff --git a/src/test/java/com/podio/contact/ContactAPITest.java b/src/test/java/com/podio/contact/ContactAPITest.java index 0d3056d..4f2ac3c 100644 --- a/src/test/java/com/podio/contact/ContactAPITest.java +++ b/src/test/java/com/podio/contact/ContactAPITest.java @@ -82,7 +82,7 @@ public void getContactTotals() { public void getSpaceContactsByMail() { List contacts = getAPI().getSpaceContacts(1, ProfileField.MAIL, "haugstrup@hoisthq.com", null, null, - ProfileType.FULL, null, ContactType.SPACE); + ProfileType.FULL, null, ContactType.SPACE, false); Assert.assertEquals(contacts.size(), 1); Assert.assertEquals(contacts.get(0).getUserId().intValue(), 2); From cdf44ef36cd3e1ee871f46f1087e8b2141767e41 Mon Sep 17 00:00:00 2001 From: PetrFOX Date: Wed, 16 Mar 2016 20:55:43 +0100 Subject: [PATCH 2/6] IDE changes + own version --- git | 0 nbactions.xml | 15 +++++++++++++++ pom.xml | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 git create mode 100644 nbactions.xml diff --git a/git b/git new file mode 100644 index 0000000..e69de29 diff --git a/nbactions.xml b/nbactions.xml new file mode 100644 index 0000000..a9b81c7 --- /dev/null +++ b/nbactions.xml @@ -0,0 +1,15 @@ + + + + build + + * + + + install + + + true + + + diff --git a/pom.xml b/pom.xml index 8cbef39..800fae6 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ jar api - 0.7.10-SNAPSHOT + 0.7.10.1 The official Java wrapper for the Podio API http://podio.com From ff09a5f8d520aabc4952dc38057b18cf22eced9e Mon Sep 17 00:00:00 2001 From: PetrFOX Date: Wed, 16 Mar 2016 20:56:37 +0100 Subject: [PATCH 3/6] filtering by number changed float to Float so null can be passed --- src/main/java/com/podio/filter/NumberInterval.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/podio/filter/NumberInterval.java b/src/main/java/com/podio/filter/NumberInterval.java index 34b4628..de09f9d 100644 --- a/src/main/java/com/podio/filter/NumberInterval.java +++ b/src/main/java/com/podio/filter/NumberInterval.java @@ -2,21 +2,21 @@ public final class NumberInterval { - private final float from; + private final Float from; - private final float to; + private final Float to; - public NumberInterval(float from, float to) { + public NumberInterval(Float from, Float to) { super(); this.from = from; this.to = to; } - public float getFrom() { + public Float getFrom() { return from; } - public float getTo() { + public Float getTo() { return to; } } From 139091103f8cf30bb9bc7b303994356373a272f2 Mon Sep 17 00:00:00 2001 From: PetrFOX Date: Wed, 16 Mar 2016 20:57:57 +0100 Subject: [PATCH 4/6] filtering by date updated so that null can be passed --- src/main/java/com/podio/filter/PodioDateInterval.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/podio/filter/PodioDateInterval.java b/src/main/java/com/podio/filter/PodioDateInterval.java index 9f2769c..0568c43 100644 --- a/src/main/java/com/podio/filter/PodioDateInterval.java +++ b/src/main/java/com/podio/filter/PodioDateInterval.java @@ -27,7 +27,8 @@ public String serialize() { } public static final PodioDateInterval absolute(LocalDate fromDate, LocalDate toDate) { - return new PodioDateInterval(new AbsolutePodioDate(fromDate), new AbsolutePodioDate(toDate)); + return new PodioDateInterval(fromDate == null ? null : new AbsolutePodioDate(fromDate), + toDate == null ? null : new AbsolutePodioDate(toDate)); } } From 6be30be898ba1077e7ef00cdfb1ad72d2bbc3d0a Mon Sep 17 00:00:00 2001 From: PetrFOX Date: Wed, 16 Mar 2016 21:01:19 +0100 Subject: [PATCH 5/6] nbactions added --- nbactions.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 nbactions.xml diff --git a/nbactions.xml b/nbactions.xml new file mode 100644 index 0000000..a9b81c7 --- /dev/null +++ b/nbactions.xml @@ -0,0 +1,15 @@ + + + + build + + * + + + install + + + true + + + From abceffcebdc5be9e2f0863fda1760118ec47e8f0 Mon Sep 17 00:00:00 2001 From: PetrFOX Date: Sat, 19 Mar 2016 12:16:53 +0100 Subject: [PATCH 6/6] uprava filtrovani, funguje AbosluteDate, Number, App a Category --- .../com/podio/filter/AbsolutePodioDate.java | 4 +++ .../com/podio/filter/AppFieldFilterBy.java | 6 ++-- .../com/podio/filter/BaseDateFilterBy.java | 2 +- src/main/java/com/podio/filter/FilterBy.java | 2 +- .../java/com/podio/filter/FilterByValue.java | 2 +- .../com/podio/filter/NumberFieldFilterBy.java | 4 +-- .../java/com/podio/filter/NumberInterval.java | 5 ++- .../com/podio/filter/PodioDateInterval.java | 31 ++++++++++++++++++- src/main/java/com/podio/item/ItemAPI.java | 23 ++++++++------ 9 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/podio/filter/AbsolutePodioDate.java b/src/main/java/com/podio/filter/AbsolutePodioDate.java index 4ac3489..a73958d 100644 --- a/src/main/java/com/podio/filter/AbsolutePodioDate.java +++ b/src/main/java/com/podio/filter/AbsolutePodioDate.java @@ -16,4 +16,8 @@ public String serialize() { return this.date.toString("yyyy-MM-dd"); } + public LocalDate getDate() { + return date; + } + } diff --git a/src/main/java/com/podio/filter/AppFieldFilterBy.java b/src/main/java/com/podio/filter/AppFieldFilterBy.java index 5bca167..ae57c49 100644 --- a/src/main/java/com/podio/filter/AppFieldFilterBy.java +++ b/src/main/java/com/podio/filter/AppFieldFilterBy.java @@ -2,8 +2,6 @@ import java.util.List; -import com.podio.common.CSVUtil; - public class AppFieldFilterBy extends FieldFilterBy> { public AppFieldFilterBy(int fieldId) { @@ -11,7 +9,7 @@ public AppFieldFilterBy(int fieldId) { } @Override - public final String format(List values) { - return CSVUtil.toCSV(values); + public final Object format(List values) { + return values; } } diff --git a/src/main/java/com/podio/filter/BaseDateFilterBy.java b/src/main/java/com/podio/filter/BaseDateFilterBy.java index 5bbdc4a..0873490 100644 --- a/src/main/java/com/podio/filter/BaseDateFilterBy.java +++ b/src/main/java/com/podio/filter/BaseDateFilterBy.java @@ -3,7 +3,7 @@ public abstract class BaseDateFilterBy implements FilterBy { @Override - public final String format(PodioDateInterval value) { + public final Object format(PodioDateInterval value) { return value.serialize(); } diff --git a/src/main/java/com/podio/filter/FilterBy.java b/src/main/java/com/podio/filter/FilterBy.java index 728cf5f..d88a609 100644 --- a/src/main/java/com/podio/filter/FilterBy.java +++ b/src/main/java/com/podio/filter/FilterBy.java @@ -4,5 +4,5 @@ public interface FilterBy { String getKey(); - String format(T value); + Object format(T value); } diff --git a/src/main/java/com/podio/filter/FilterByValue.java b/src/main/java/com/podio/filter/FilterByValue.java index b20af78..ab255e1 100644 --- a/src/main/java/com/podio/filter/FilterByValue.java +++ b/src/main/java/com/podio/filter/FilterByValue.java @@ -20,7 +20,7 @@ public T getValue() { return value; } - public String getFormattedValue() { + public Object getFormattedValue() { return by.format(value); } } diff --git a/src/main/java/com/podio/filter/NumberFieldFilterBy.java b/src/main/java/com/podio/filter/NumberFieldFilterBy.java index 9b0d7d1..05d170e 100644 --- a/src/main/java/com/podio/filter/NumberFieldFilterBy.java +++ b/src/main/java/com/podio/filter/NumberFieldFilterBy.java @@ -7,7 +7,7 @@ public NumberFieldFilterBy(int fieldId) { } @Override - public String format(NumberInterval value) { - return value.getFrom() + "-" + value.getTo(); + public Object format(NumberInterval value) { + return value; } } diff --git a/src/main/java/com/podio/filter/NumberInterval.java b/src/main/java/com/podio/filter/NumberInterval.java index de09f9d..ebeb123 100644 --- a/src/main/java/com/podio/filter/NumberInterval.java +++ b/src/main/java/com/podio/filter/NumberInterval.java @@ -1,9 +1,12 @@ package com.podio.filter; -public final class NumberInterval { +import org.codehaus.jackson.map.annotate.JsonSerialize; +public final class NumberInterval { + @JsonSerialize(include = JsonSerialize.Inclusion.ALWAYS) private final Float from; + @JsonSerialize(include = JsonSerialize.Inclusion.ALWAYS) private final Float to; public NumberInterval(Float from, Float to) { diff --git a/src/main/java/com/podio/filter/PodioDateInterval.java b/src/main/java/com/podio/filter/PodioDateInterval.java index 0568c43..53c93e0 100644 --- a/src/main/java/com/podio/filter/PodioDateInterval.java +++ b/src/main/java/com/podio/filter/PodioDateInterval.java @@ -14,7 +14,15 @@ public PodioDateInterval(PodioDate fromDate, PodioDate toDate) { this.toDate = toDate; } - public String serialize() { + public Object serialize() { + + if (fromDate instanceof AbsolutePodioDate || toDate instanceof AbsolutePodioDate) { + PodioDateIntervalFilter values = new PodioDateIntervalFilter( + fromDate == null ? null : ((AbsolutePodioDate) fromDate).getDate(), + toDate == null ? null : ((AbsolutePodioDate) toDate).getDate()); + return values; + } + String result = ""; if (fromDate != null) { result += fromDate.serialize(); @@ -30,5 +38,26 @@ public static final PodioDateInterval absolute(LocalDate fromDate, LocalDate toD return new PodioDateInterval(fromDate == null ? null : new AbsolutePodioDate(fromDate), toDate == null ? null : new AbsolutePodioDate(toDate)); } + + public class PodioDateIntervalFilter { + private final LocalDate from; + private final LocalDate to; + + public PodioDateIntervalFilter(LocalDate from, LocalDate to) { + this.from = from; + this.to = to; + } + + public LocalDate getFrom() { + return from; + } + + public LocalDate getTo() { + return to; + } + + + + } } diff --git a/src/main/java/com/podio/item/ItemAPI.java b/src/main/java/com/podio/item/ItemAPI.java index 9c3d4df..634ddf3 100644 --- a/src/main/java/com/podio/item/ItemAPI.java +++ b/src/main/java/com/podio/item/ItemAPI.java @@ -13,6 +13,7 @@ import com.podio.filter.SortBy; import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.WebResource; +import java.util.HashMap; /** * Items are entries in an app. If you think of app as a table, items will be @@ -288,25 +289,29 @@ public List getItemRevisions(int itemId) { public ItemsResponse getItems(int appId, Integer limit, Integer offset, SortBy sortBy, Boolean sortDesc, FilterByValue... filters) { WebResource resource = getResourceFactory().getApiResource( - "/item/app/" + appId + "/v2/"); + "/item/app/" + appId + "/filter/"); + Map params = new HashMap(); if (limit != null) { - resource = resource.queryParam("limit", limit.toString()); + params.put("limit", limit); } if (offset != null) { - resource = resource.queryParam("offset", offset.toString()); + params.put("offset", offset); } if (sortBy != null) { - resource = resource.queryParam("sort_by", sortBy.getKey()); + params.put("sort_by", sortBy); } if (sortDesc != null) { - resource = resource.queryParam("sort_desc", sortDesc ? "1" : "0"); + params.put("sort_desc", sortDesc); } + Map filterMap = new HashMap(); for (FilterByValue filter : filters) { - resource = resource.queryParam(filter.getBy().getKey(), - filter.getFormattedValue()); + filterMap.put(filter.getBy().getKey(), filter.getFormattedValue()); } - - return resource.get(ItemsResponse.class); + if (filterMap.size() > 0) { + params.put("filters", filterMap); + } + return resource.entity(params, MediaType.APPLICATION_JSON_TYPE) + .post(ItemsResponse.class); } /**