Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/main/java/com/podio/search/Counts.java
Original file line number Diff line number Diff line change
@@ -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 + ']';
}

}
20 changes: 20 additions & 0 deletions src/main/java/com/podio/search/ReferenceTypeSearchInApp.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
64 changes: 64 additions & 0 deletions src/main/java/com/podio/search/SearchAPI.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
38 changes: 38 additions & 0 deletions src/main/java/com/podio/search/SearchInAppResponse.java
Original file line number Diff line number Diff line change
@@ -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<SearchResult> 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<SearchResult> getResults() {
return results;
}

public void setResults(List<SearchResult> results) {
this.results = results;
}

}
143 changes: 143 additions & 0 deletions src/main/java/com/podio/search/SearchResult.java
Original file line number Diff line number Diff line change
@@ -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;
}

}