Commit 6ee60a39 authored by Ivan Del Pino's avatar Ivan Del Pino Committed by Rafael Jesus Hernández Vasquez
Browse files

feat(search): add models to query in search


Signed-off-by: default avatarIvan Del Pino <idelpino@teclib.com>
parent d0a16a2b
......@@ -46,6 +46,9 @@ import com.orhanobut.logger.PrettyFormatStrategy;
import org.glpi.api.GLPI;
import org.glpi.api.itemType;
import org.glpi.api.query.GetListSearchOptionsQuery;
import org.glpi.api.query.GetSearchItem;
import org.glpi.api.request.search.CriteriaItem;
import org.glpi.api.request.search.CriteriaRequest;
import org.glpi.api.response.FullSessionModel;
import org.glpi.api.response.InitSession;
import org.glpi.api.utils.Helpers;
......@@ -178,7 +181,20 @@ public class MainActivity extends AppCompatActivity {
private void btnSearch() {
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
glpi.searchItems("Users", new GLPI.ResponseHandle<JsonObject, String>() {
GetSearchItem getSearchItem = new GetSearchItem();
CriteriaRequest criteria = new CriteriaRequest();
ArrayList<CriteriaItem> listCriteriaItem = new ArrayList<>();
CriteriaItem criteriaItem = new CriteriaItem();
criteriaItem.setField(1);
criteriaItem.setItemtype("User");
criteriaItem.setSearchtype("equals");
listCriteriaItem.add(criteriaItem);
criteria.setCriteria(listCriteriaItem);
getSearchItem.setCriteria(criteria);
Map<String, String> query = getSearchItem.getQuery();
glpi.searchItems("Users", query, new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("Search Item: %s", response);
......
......@@ -35,7 +35,6 @@ import com.google.gson.JsonObject;
import org.glpi.api.query.GetAllItemQuery;
import org.glpi.api.query.GetAnItemQuery;
import org.glpi.api.query.GetSearchItem;
import org.glpi.api.query.GetSubItemQuery;
import org.glpi.api.request.ChangeActiveEntitiesRequest;
import org.glpi.api.request.ChangeActiveProfileRequest;
......@@ -591,13 +590,13 @@ public class GLPI extends ServiceGenerator {
/**
* Search items
*
* @param itemType : search item
* @param query
* @param callback here you are going to get the asynchronous response
* @param itemType: search item
*/
public void searchItems(String itemType, final ResponseHandle<JsonObject, String> callback) {
public void searchItems(String itemType, Map<String, String> query, final ResponseHandle<JsonObject, String> callback) {
HashMap<String, String> header = new HashMap<>();
header.put("Session-Token", sessionToken);
Map<String, String> query = new GetSearchItem().getQuery();
interfaces.searchItem(header, itemType, query).enqueue(new Callback<JsonObject>() {
@Override
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
......
......@@ -25,6 +25,9 @@
package org.glpi.api.query;
import org.glpi.api.request.search.CriteriaRequest;
import org.glpi.api.request.search.MetaCriteriaRequest;
import java.util.HashMap;
import java.util.Map;
......@@ -36,8 +39,8 @@ public class GetSearchItem {
private String itemtype;
private String searchtype;
private String value;
private String criteria;
private String metacriteria;
private CriteriaRequest criteria;
private MetaCriteriaRequest metacriteria;
private String sort;
private String order;
private String range;
......@@ -170,19 +173,19 @@ public class GetSearchItem {
this.value = value;
}
public String getCriteria() {
public CriteriaRequest getCriteria() {
return criteria;
}
public void setCriteria(String criteria) {
public void setCriteria(CriteriaRequest criteria) {
this.criteria = criteria;
}
public String getMetacriteria() {
public MetaCriteriaRequest getMetacriteria() {
return metacriteria;
}
public void setMetacriteria(String metacriteria) {
public void setMetacriteria(MetaCriteriaRequest metacriteria) {
this.metacriteria = metacriteria;
}
......
package org.glpi.api.request.search;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class CriteriaItem {
@SerializedName("criteria")
private List<CriteriaItem> criteria;
@SerializedName("link")
private String link;
@SerializedName("field")
private int field;
@SerializedName("searchtype")
private String searchtype;
@SerializedName("value")
private int value;
@SerializedName("meta")
private boolean meta;
@SerializedName("itemtype")
private String itemtype;
public void setCriteria(List<CriteriaItem> criteria) {
this.criteria = criteria;
}
public List<CriteriaItem> getCriteria() {
return criteria;
}
public void setLink(String link) {
this.link = link;
}
public String getLink() {
return link;
}
public void setField(int field) {
this.field = field;
}
public int getField() {
return field;
}
public void setSearchtype(String searchtype) {
this.searchtype = searchtype;
}
public String getSearchtype() {
return searchtype;
}
public void setValue(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public boolean getMeta() {
return meta;
}
public void setMeta(boolean meta) {
this.meta = meta;
}
public String getItemtype() {
return itemtype;
}
public void setItemtype(String itemtype) {
this.itemtype = itemtype;
}
}
\ No newline at end of file
package org.glpi.api.request.search;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class CriteriaRequest {
@SerializedName("criteria")
private List<CriteriaItem> criteria;
public void setCriteria(List<CriteriaItem> criteria) {
this.criteria = criteria;
}
public List<CriteriaItem> getCriteria() {
return criteria;
}
}
\ No newline at end of file
package org.glpi.api.request.search;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class MetaCriteriaRequest {
@SerializedName("metacriteria")
private List<MetacriteriaItem> metacriteria;
public void setMetacriteria(List<MetacriteriaItem> metacriteria) {
this.metacriteria = metacriteria;
}
public List<MetacriteriaItem> getMetacriteria() {
return metacriteria;
}
}
\ No newline at end of file
package org.glpi.api.request.search;
import com.google.gson.annotations.SerializedName;
public class MetacriteriaItem {
@SerializedName("itemtype")
private String itemtype;
@SerializedName("field")
private int field;
@SerializedName("searchtype")
private String searchtype;
@SerializedName("link")
private String link;
@SerializedName("value")
private String value;
public void setItemtype(String itemtype) {
this.itemtype = itemtype;
}
public String getItemtype() {
return itemtype;
}
public void setField(int field) {
this.field = field;
}
public int getField() {
return field;
}
public void setSearchtype(String searchtype) {
this.searchtype = searchtype;
}
public String getSearchtype() {
return searchtype;
}
public void setLink(String link) {
this.link = link;
}
public String getLink() {
return link;
}
public void setValue(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment