From f977502120ae0ac0221ca1217258b88ab4f089e1 Mon Sep 17 00:00:00 2001 From: PetrFOX Date: Fri, 27 Nov 2015 22:42:18 +0100 Subject: [PATCH] added searchAPI with searchInApp method --- src/main/java/com/podio/search/Counts.java | 82 ++++++++++ .../search/ReferenceTypeSearchInApp.java | 20 +++ src/main/java/com/podio/search/SearchAPI.java | 64 ++++++++ .../com/podio/search/SearchInAppResponse.java | 38 +++++ .../java/com/podio/search/SearchResult.java | 143 ++++++++++++++++++ 5 files changed, 347 insertions(+) create mode 100644 src/main/java/com/podio/search/Counts.java create mode 100644 src/main/java/com/podio/search/ReferenceTypeSearchInApp.java create mode 100644 src/main/java/com/podio/search/SearchAPI.java create mode 100644 src/main/java/com/podio/search/SearchInAppResponse.java create mode 100644 src/main/java/com/podio/search/SearchResult.java diff --git a/src/main/java/com/podio/search/Counts.java b/src/main/java/com/podio/search/Counts.java new file mode 100644 index 0000000..b180e52 --- /dev/null +++ b/src/main/java/com/podio/search/Counts.java @@ -0,0 +1,82 @@ +package com.podio.search; + +public class Counts { + + private Integer item; + + private Integer task; + + private Integer conversation; + + private Integer app; + + private Integer status; + + private Integer file; + + private Integer profile; + + public Integer getItem() { + return item; + } + + public void setItem(Integer item) { + this.item = item; + } + + public Integer getTask() { + return task; + } + + public void setTask(Integer task) { + this.task = task; + } + + public Integer getConversation() { + return conversation; + } + + public void setConversation(Integer conversation) { + this.conversation = conversation; + } + + public Integer getApp() { + return app; + } + + public void setApp(Integer app) { + this.app = app; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public Integer getFile() { + return file; + } + + public void setFile(Integer file) { + this.file = file; + } + + public Integer getProfile() { + return profile; + } + + public void setProfile(Integer profile) { + this.profile = profile; + } + + @Override + public String toString() { + return "Counts[item=" + item + ", task=" + task + ", conversation=" + + conversation + ", app=" + app + ", status=" + status + ", file=" + + file + ", profile=" + profile + ']'; + } + +} diff --git a/src/main/java/com/podio/search/ReferenceTypeSearchInApp.java b/src/main/java/com/podio/search/ReferenceTypeSearchInApp.java new file mode 100644 index 0000000..8f1dd6b --- /dev/null +++ b/src/main/java/com/podio/search/ReferenceTypeSearchInApp.java @@ -0,0 +1,20 @@ +package com.podio.search; + +import org.codehaus.jackson.annotate.JsonCreator; +import org.codehaus.jackson.annotate.JsonValue; + +public enum ReferenceTypeSearchInApp { + + APP, CONVERSATION, FILE, ITEM, PROFILE, STATUS, TASK; + + @Override + @JsonValue + public String toString() { + return name().toLowerCase(); + } + + @JsonCreator + public static ReferenceTypeSearchInApp getByName(String value) { + return valueOf(value.toUpperCase()); + } +} diff --git a/src/main/java/com/podio/search/SearchAPI.java b/src/main/java/com/podio/search/SearchAPI.java new file mode 100644 index 0000000..8be0449 --- /dev/null +++ b/src/main/java/com/podio/search/SearchAPI.java @@ -0,0 +1,64 @@ +package com.podio.search; + +import com.podio.BaseAPI; +import com.podio.ResourceFactory; +import com.sun.jersey.api.client.WebResource; + +/** + * This API makes it possible to search across Podio. + */ +public class SearchAPI extends BaseAPI { + + public SearchAPI(ResourceFactory resourceFactory) { + super(resourceFactory); + } + + /** + * Searches in all items, files, and tasks in the application. The objects + * will be returned sorted descending by the time the object had any update. + * + * @param appId + * The id of the app to be searched in + * @param query + * The text to search for + * @param limit + * The number of results to return; up to 20 results are returned in one call. + * @param offset + * The rank of the first search result to return (default=0) + * @param refType + * The type of objects to search for + * @param counts + * True if the total counts should be returned + * @param highlights + * True if the highlights for each result should be returned, false otherwise. + * @param searchFields + * The list of fields to search in. Can f.ex. be used to limit the search to the "title" field. + * @return All items + */ + public SearchInAppResponse searchInApp(int appId, String query, Boolean counts, + Boolean highlights, Integer limit, Integer offset, ReferenceTypeSearchInApp refType, + String searchFields) { + WebResource resource = getResourceFactory().getApiResource("/search/app/" + appId + "/v2"); + resource = resource.queryParam("query", query); + if (counts != null) { + resource = resource.queryParam("counts", counts ? "1" : "0"); + } + if (highlights != null) { + resource = resource.queryParam("highlights", highlights ? "1" : "0"); + } + if (limit != null) { + resource = resource.queryParam("limit", limit.toString()); + } + if (offset != null) { + resource = resource.queryParam("offset", offset.toString()); + } + if (refType != null) { + resource = resource.queryParam("ref_type", refType.toString()); + } + if (searchFields != null && !searchFields.equals("")) { + resource = resource.queryParam("search_fields", searchFields); + } + return resource.get(SearchInAppResponse.class); + } + +} diff --git a/src/main/java/com/podio/search/SearchInAppResponse.java b/src/main/java/com/podio/search/SearchInAppResponse.java new file mode 100644 index 0000000..2000d63 --- /dev/null +++ b/src/main/java/com/podio/search/SearchInAppResponse.java @@ -0,0 +1,38 @@ +package com.podio.search; + +import java.util.List; + +public class SearchInAppResponse { + + /** + * Counts for each type of object + */ + private Counts counts; + + /** + * The items returned + */ + private List results; + + @Override + public String toString() { + return "SearchInAppResponse [counts=" + counts.toString() + ", results=" + results.toString() + "]"; + } + + public Counts getCounts() { + return counts; + } + + public void setCounts(Counts counts) { + this.counts = counts; + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } + +} diff --git a/src/main/java/com/podio/search/SearchResult.java b/src/main/java/com/podio/search/SearchResult.java new file mode 100644 index 0000000..32cdcf1 --- /dev/null +++ b/src/main/java/com/podio/search/SearchResult.java @@ -0,0 +1,143 @@ +package com.podio.search; + +import com.podio.app.Application; +import com.podio.common.AuthorizationEntity; +import com.podio.org.Organization; + +import org.codehaus.jackson.annotate.JsonProperty; +import com.podio.space.Space; +import org.joda.time.DateTime; + +public class SearchResult { + + private Integer id; + + private ReferenceTypeSearchInApp type; + + private Integer rank; + + /** + * The app where the item belongs + */ + private Application app; + + private Organization org; + + private Space space; + + private String highlight; + + /** + * The entity who created the item + */ + private AuthorizationEntity createdBy; + + /** + * The date and time the item was created + */ + private DateTime createdOn; + + /** + * The title of the item. This is made of up one of the fields below, or by + * the item name and id + */ + private String title; + + /** + * The direct link to the item + */ + private String link; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getLink() { + return link; + } + + public void setLink(String link) { + this.link = link; + } + + @JsonProperty("created_on") + public DateTime getCreatedOn() { + return createdOn; + } + + @JsonProperty("created_on") + public void setCreatedOn(DateTime createdOn) { + this.createdOn = createdOn; + } + + public ReferenceTypeSearchInApp getType() { + return type; + } + + public void setType(ReferenceTypeSearchInApp type) { + this.type = type; + } + + public Integer getRank() { + return rank; + } + + public void setRank(Integer rank) { + this.rank = rank; + } + + public Application getApp() { + return app; + } + + public void setApp(Application app) { + this.app = app; + } + + public Organization getOrg() { + return org; + } + + public void setOrg(Organization org) { + this.org = org; + } + + public Space getSpace() { + return space; + } + + public void setSpace(Space space) { + this.space = space; + } + + public String getHighlight() { + return highlight; + } + + public void setHighlight(String highlight) { + this.highlight = highlight; + } + + @JsonProperty("created_by") + public AuthorizationEntity getCreatedBy() { + return createdBy; + } + + @JsonProperty("created_by") + public void setCreatedBy(AuthorizationEntity createdBy) { + this.createdBy = createdBy; + } + +}