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

Commit f977502

Browse files
committed
added searchAPI with searchInApp method
1 parent 2a0a241 commit f977502

File tree

5 files changed

+347
-0
lines changed

5 files changed

+347
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.podio.search;
2+
3+
public class Counts {
4+
5+
private Integer item;
6+
7+
private Integer task;
8+
9+
private Integer conversation;
10+
11+
private Integer app;
12+
13+
private Integer status;
14+
15+
private Integer file;
16+
17+
private Integer profile;
18+
19+
public Integer getItem() {
20+
return item;
21+
}
22+
23+
public void setItem(Integer item) {
24+
this.item = item;
25+
}
26+
27+
public Integer getTask() {
28+
return task;
29+
}
30+
31+
public void setTask(Integer task) {
32+
this.task = task;
33+
}
34+
35+
public Integer getConversation() {
36+
return conversation;
37+
}
38+
39+
public void setConversation(Integer conversation) {
40+
this.conversation = conversation;
41+
}
42+
43+
public Integer getApp() {
44+
return app;
45+
}
46+
47+
public void setApp(Integer app) {
48+
this.app = app;
49+
}
50+
51+
public Integer getStatus() {
52+
return status;
53+
}
54+
55+
public void setStatus(Integer status) {
56+
this.status = status;
57+
}
58+
59+
public Integer getFile() {
60+
return file;
61+
}
62+
63+
public void setFile(Integer file) {
64+
this.file = file;
65+
}
66+
67+
public Integer getProfile() {
68+
return profile;
69+
}
70+
71+
public void setProfile(Integer profile) {
72+
this.profile = profile;
73+
}
74+
75+
@Override
76+
public String toString() {
77+
return "Counts[item=" + item + ", task=" + task + ", conversation=" +
78+
conversation + ", app=" + app + ", status=" + status + ", file=" +
79+
file + ", profile=" + profile + ']';
80+
}
81+
82+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.podio.search;
2+
3+
import org.codehaus.jackson.annotate.JsonCreator;
4+
import org.codehaus.jackson.annotate.JsonValue;
5+
6+
public enum ReferenceTypeSearchInApp {
7+
8+
APP, CONVERSATION, FILE, ITEM, PROFILE, STATUS, TASK;
9+
10+
@Override
11+
@JsonValue
12+
public String toString() {
13+
return name().toLowerCase();
14+
}
15+
16+
@JsonCreator
17+
public static ReferenceTypeSearchInApp getByName(String value) {
18+
return valueOf(value.toUpperCase());
19+
}
20+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.podio.search;
2+
3+
import com.podio.BaseAPI;
4+
import com.podio.ResourceFactory;
5+
import com.sun.jersey.api.client.WebResource;
6+
7+
/**
8+
* This API makes it possible to search across Podio.
9+
*/
10+
public class SearchAPI extends BaseAPI {
11+
12+
public SearchAPI(ResourceFactory resourceFactory) {
13+
super(resourceFactory);
14+
}
15+
16+
/**
17+
* Searches in all items, files, and tasks in the application. The objects
18+
* will be returned sorted descending by the time the object had any update.
19+
*
20+
* @param appId
21+
* The id of the app to be searched in
22+
* @param query
23+
* The text to search for
24+
* @param limit
25+
* The number of results to return; up to 20 results are returned in one call.
26+
* @param offset
27+
* The rank of the first search result to return (default=0)
28+
* @param refType
29+
* The type of objects to search for
30+
* @param counts
31+
* True if the total counts should be returned
32+
* @param highlights
33+
* True if the highlights for each result should be returned, false otherwise.
34+
* @param searchFields
35+
* The list of fields to search in. Can f.ex. be used to limit the search to the "title" field.
36+
* @return All items
37+
*/
38+
public SearchInAppResponse searchInApp(int appId, String query, Boolean counts,
39+
Boolean highlights, Integer limit, Integer offset, ReferenceTypeSearchInApp refType,
40+
String searchFields) {
41+
WebResource resource = getResourceFactory().getApiResource("/search/app/" + appId + "/v2");
42+
resource = resource.queryParam("query", query);
43+
if (counts != null) {
44+
resource = resource.queryParam("counts", counts ? "1" : "0");
45+
}
46+
if (highlights != null) {
47+
resource = resource.queryParam("highlights", highlights ? "1" : "0");
48+
}
49+
if (limit != null) {
50+
resource = resource.queryParam("limit", limit.toString());
51+
}
52+
if (offset != null) {
53+
resource = resource.queryParam("offset", offset.toString());
54+
}
55+
if (refType != null) {
56+
resource = resource.queryParam("ref_type", refType.toString());
57+
}
58+
if (searchFields != null && !searchFields.equals("")) {
59+
resource = resource.queryParam("search_fields", searchFields);
60+
}
61+
return resource.get(SearchInAppResponse.class);
62+
}
63+
64+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.podio.search;
2+
3+
import java.util.List;
4+
5+
public class SearchInAppResponse {
6+
7+
/**
8+
* Counts for each type of object
9+
*/
10+
private Counts counts;
11+
12+
/**
13+
* The items returned
14+
*/
15+
private List<SearchResult> results;
16+
17+
@Override
18+
public String toString() {
19+
return "SearchInAppResponse [counts=" + counts.toString() + ", results=" + results.toString() + "]";
20+
}
21+
22+
public Counts getCounts() {
23+
return counts;
24+
}
25+
26+
public void setCounts(Counts counts) {
27+
this.counts = counts;
28+
}
29+
30+
public List<SearchResult> getResults() {
31+
return results;
32+
}
33+
34+
public void setResults(List<SearchResult> results) {
35+
this.results = results;
36+
}
37+
38+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package com.podio.search;
2+
3+
import com.podio.app.Application;
4+
import com.podio.common.AuthorizationEntity;
5+
import com.podio.org.Organization;
6+
7+
import org.codehaus.jackson.annotate.JsonProperty;
8+
import com.podio.space.Space;
9+
import org.joda.time.DateTime;
10+
11+
public class SearchResult {
12+
13+
private Integer id;
14+
15+
private ReferenceTypeSearchInApp type;
16+
17+
private Integer rank;
18+
19+
/**
20+
* The app where the item belongs
21+
*/
22+
private Application app;
23+
24+
private Organization org;
25+
26+
private Space space;
27+
28+
private String highlight;
29+
30+
/**
31+
* The entity who created the item
32+
*/
33+
private AuthorizationEntity createdBy;
34+
35+
/**
36+
* The date and time the item was created
37+
*/
38+
private DateTime createdOn;
39+
40+
/**
41+
* The title of the item. This is made of up one of the fields below, or by
42+
* the item name and id
43+
*/
44+
private String title;
45+
46+
/**
47+
* The direct link to the item
48+
*/
49+
private String link;
50+
51+
public int getId() {
52+
return id;
53+
}
54+
55+
public void setId(int id) {
56+
this.id = id;
57+
}
58+
59+
public String getTitle() {
60+
return title;
61+
}
62+
63+
public void setTitle(String title) {
64+
this.title = title;
65+
}
66+
67+
public String getLink() {
68+
return link;
69+
}
70+
71+
public void setLink(String link) {
72+
this.link = link;
73+
}
74+
75+
@JsonProperty("created_on")
76+
public DateTime getCreatedOn() {
77+
return createdOn;
78+
}
79+
80+
@JsonProperty("created_on")
81+
public void setCreatedOn(DateTime createdOn) {
82+
this.createdOn = createdOn;
83+
}
84+
85+
public ReferenceTypeSearchInApp getType() {
86+
return type;
87+
}
88+
89+
public void setType(ReferenceTypeSearchInApp type) {
90+
this.type = type;
91+
}
92+
93+
public Integer getRank() {
94+
return rank;
95+
}
96+
97+
public void setRank(Integer rank) {
98+
this.rank = rank;
99+
}
100+
101+
public Application getApp() {
102+
return app;
103+
}
104+
105+
public void setApp(Application app) {
106+
this.app = app;
107+
}
108+
109+
public Organization getOrg() {
110+
return org;
111+
}
112+
113+
public void setOrg(Organization org) {
114+
this.org = org;
115+
}
116+
117+
public Space getSpace() {
118+
return space;
119+
}
120+
121+
public void setSpace(Space space) {
122+
this.space = space;
123+
}
124+
125+
public String getHighlight() {
126+
return highlight;
127+
}
128+
129+
public void setHighlight(String highlight) {
130+
this.highlight = highlight;
131+
}
132+
133+
@JsonProperty("created_by")
134+
public AuthorizationEntity getCreatedBy() {
135+
return createdBy;
136+
}
137+
138+
@JsonProperty("created_by")
139+
public void setCreatedBy(AuthorizationEntity createdBy) {
140+
this.createdBy = createdBy;
141+
}
142+
143+
}

0 commit comments

Comments
 (0)