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

feat(search): add route and method to search


Signed-off-by: default avatarIvan Del Pino <idelpino@teclib.com>
parent d39685a6
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="0.1.0"></a>
# 0.1.0 (2018-12-06)
### Bug Fixes
* **config:** changes in config and scripts files ([81c1265](https://github.com/glpi-project/java-library-glpi/commit/81c1265))
* **package:** update conventional-github-releaser to version 3.0.0 ([8e22d54](https://github.com/glpi-project/java-library-glpi/commit/8e22d54))
### Features
* **addItems:** add method ([85360e4](https://github.com/glpi-project/java-library-glpi/commit/85360e4))
* **addItems:** add optional App-Token ([a7a2640](https://github.com/glpi-project/java-library-glpi/commit/a7a2640))
* **api:** add initSessionByCredentials function ([917100a](https://github.com/glpi-project/java-library-glpi/commit/917100a))
* **api:** add view and code in example and refactor glpi instance ([9598006](https://github.com/glpi-project/java-library-glpi/commit/9598006))
* **changeActiveEntities:** add method ([739b617](https://github.com/glpi-project/java-library-glpi/commit/739b617))
* **changeActiveEntities:** add optional App-Token ([4db751e](https://github.com/glpi-project/java-library-glpi/commit/4db751e))
* **changeActiveProfile:** add method ([aeb4678](https://github.com/glpi-project/java-library-glpi/commit/aeb4678))
* **changeActiveProfile:** add optional App-Token ([17b686e](https://github.com/glpi-project/java-library-glpi/commit/17b686e))
* **constructor:** add context on constructor ([ced6105](https://github.com/glpi-project/java-library-glpi/commit/ced6105))
* **constructor:** implement url parameter on constructor ([ed61e3f](https://github.com/glpi-project/java-library-glpi/commit/ed61e3f))
* **deleteItems:** add method ([ed67ac5](https://github.com/glpi-project/java-library-glpi/commit/ed67ac5))
* **deleteItems:** add optional App-Token ([7014066](https://github.com/glpi-project/java-library-glpi/commit/7014066))
* **files:** request download file and save in disk ([c306e8d](https://github.com/glpi-project/java-library-glpi/commit/c306e8d))
* **getActiveEntities:** add endpoint route ([e46025f](https://github.com/glpi-project/java-library-glpi/commit/e46025f))
* **getActiveEntities:** add method ([d10b89b](https://github.com/glpi-project/java-library-glpi/commit/d10b89b))
* **getActiveEntities:** add optional App-Token ([533d065](https://github.com/glpi-project/java-library-glpi/commit/533d065))
* **getActiveProfile:** add endpoint route ([a020f1b](https://github.com/glpi-project/java-library-glpi/commit/a020f1b))
* **getActiveProfile:** add method ([51e93e5](https://github.com/glpi-project/java-library-glpi/commit/51e93e5))
* **getActiveProfile:** add optional App-Token ([4e710b5](https://github.com/glpi-project/java-library-glpi/commit/4e710b5))
* **getAllItem:** add enpoint route ([2c41919](https://github.com/glpi-project/java-library-glpi/commit/2c41919))
* **getAllItemQuery:** add class to manage parameters on get all item ([0a6f2a8](https://github.com/glpi-project/java-library-glpi/commit/0a6f2a8))
* **getAllItems:** add optional App-Token ([b002516](https://github.com/glpi-project/java-library-glpi/commit/b002516))
* **getAnItem:** add method ([f5ff38e](https://github.com/glpi-project/java-library-glpi/commit/f5ff38e))
* **getAnItem:** add optional App-Token ([21154b7](https://github.com/glpi-project/java-library-glpi/commit/21154b7))
* improve interface callback response ([f5be9d3](https://github.com/glpi-project/java-library-glpi/commit/f5be9d3))
* **getAnItem:** add string option for itemtype ([703db67](https://github.com/glpi-project/java-library-glpi/commit/703db67))
* **getAnItemQuery:** add class to manage parameters on get an item ([268d54e](https://github.com/glpi-project/java-library-glpi/commit/268d54e))
* **getFullSession:** add endpoint route ([fb24bde](https://github.com/glpi-project/java-library-glpi/commit/fb24bde))
* **getFullSession:** add method ([227c3d9](https://github.com/glpi-project/java-library-glpi/commit/227c3d9))
* **getFullSession:** add optional App-Token ([f12f876](https://github.com/glpi-project/java-library-glpi/commit/f12f876))
* **getGlpiConfig:** add method ([e1cd382](https://github.com/glpi-project/java-library-glpi/commit/e1cd382))
* **getGlpiConfig:** add optional App-Token ([a9da9a1](https://github.com/glpi-project/java-library-glpi/commit/a9da9a1))
* **getMyEntities:** add endpoint route ([7c47933](https://github.com/glpi-project/java-library-glpi/commit/7c47933))
* **getMyEntities:** add method ([77a1301](https://github.com/glpi-project/java-library-glpi/commit/77a1301))
* **getMyEntities:** add optional App-Token ([b90ec96](https://github.com/glpi-project/java-library-glpi/commit/b90ec96))
* **getMyProfile:** add endpoint route ([42d9971](https://github.com/glpi-project/java-library-glpi/commit/42d9971))
* **getMyProfiles:** add optional App-Token ([6bfe163](https://github.com/glpi-project/java-library-glpi/commit/6bfe163))
* **routes:** include endpoints in interface ([257b8e8](https://github.com/glpi-project/java-library-glpi/commit/257b8e8))
* add download file request ([c175f4e](https://github.com/glpi-project/java-library-glpi/commit/c175f4e))
* **getSubItemQuery:** add class to manage parameters on get sub item ([b91be63](https://github.com/glpi-project/java-library-glpi/commit/b91be63))
* **getSubItems:** add method ([de0b4c7](https://github.com/glpi-project/java-library-glpi/commit/de0b4c7))
* **getSubItems:** add optional App-Token ([b769449](https://github.com/glpi-project/java-library-glpi/commit/b769449))
* **getSubItems:** add string option for itemtype ([91ca0dd](https://github.com/glpi-project/java-library-glpi/commit/91ca0dd))
* **initsession:** add synchronous init session by credentials method ([d98fd03](https://github.com/glpi-project/java-library-glpi/commit/d98fd03))
* **itemtype:** add enum item type ([e9de716](https://github.com/glpi-project/java-library-glpi/commit/e9de716))
* **killsession:** add endpoint route ([caca9b9](https://github.com/glpi-project/java-library-glpi/commit/caca9b9))
* **killSession:** add method ([01c9363](https://github.com/glpi-project/java-library-glpi/commit/01c9363))
* **killSession:** add optional App-Token ([ffe1b86](https://github.com/glpi-project/java-library-glpi/commit/ffe1b86))
* **lostPassword:** add method lost password and recovery password ([f33d498](https://github.com/glpi-project/java-library-glpi/commit/f33d498))
* **routes:** added full session, pluginFlyve and pluginFlyveID ([80242a3](https://github.com/glpi-project/java-library-glpi/commit/80242a3))
* **sessionToken:** manage global session token ([6bbbce0](https://github.com/glpi-project/java-library-glpi/commit/6bbbce0))
* **updateItems:** add optional App-Token ([c799fdd](https://github.com/glpi-project/java-library-glpi/commit/c799fdd))
* **view:** add adapter and list view result request ([a457dcf](https://github.com/glpi-project/java-library-glpi/commit/a457dcf))
* **view:** add spinner to filter request and show result ([8efdffc](https://github.com/glpi-project/java-library-glpi/commit/8efdffc))
<a name="0.1.0"></a>
# 0.1.0 (2018-12-05)
### Bug Fixes
* **package:** update conventional-github-releaser to version 3.0.0 ([8e22d54](https://github.com/glpi-project/java-library-glpi/commit/8e22d54))
### Features
* **addItems:** add method ([85360e4](https://github.com/glpi-project/java-library-glpi/commit/85360e4))
* **addItems:** add optional App-Token ([a7a2640](https://github.com/glpi-project/java-library-glpi/commit/a7a2640))
* **api:** add initSessionByCredentials function ([917100a](https://github.com/glpi-project/java-library-glpi/commit/917100a))
* **api:** add view and code in example and refactor glpi instance ([9598006](https://github.com/glpi-project/java-library-glpi/commit/9598006))
* **changeActiveEntities:** add method ([739b617](https://github.com/glpi-project/java-library-glpi/commit/739b617))
* **changeActiveEntities:** add optional App-Token ([4db751e](https://github.com/glpi-project/java-library-glpi/commit/4db751e))
* **changeActiveProfile:** add method ([aeb4678](https://github.com/glpi-project/java-library-glpi/commit/aeb4678))
* **changeActiveProfile:** add optional App-Token ([17b686e](https://github.com/glpi-project/java-library-glpi/commit/17b686e))
* **constructor:** add context on constructor ([ced6105](https://github.com/glpi-project/java-library-glpi/commit/ced6105))
* **constructor:** implement url parameter on constructor ([ed61e3f](https://github.com/glpi-project/java-library-glpi/commit/ed61e3f))
* **deleteItems:** add method ([ed67ac5](https://github.com/glpi-project/java-library-glpi/commit/ed67ac5))
* **deleteItems:** add optional App-Token ([7014066](https://github.com/glpi-project/java-library-glpi/commit/7014066))
* **files:** request download file and save in disk ([c306e8d](https://github.com/glpi-project/java-library-glpi/commit/c306e8d))
* **getActiveEntities:** add endpoint route ([e46025f](https://github.com/glpi-project/java-library-glpi/commit/e46025f))
* **getActiveEntities:** add method ([d10b89b](https://github.com/glpi-project/java-library-glpi/commit/d10b89b))
* **getActiveEntities:** add optional App-Token ([533d065](https://github.com/glpi-project/java-library-glpi/commit/533d065))
* **getActiveProfile:** add endpoint route ([a020f1b](https://github.com/glpi-project/java-library-glpi/commit/a020f1b))
* **getActiveProfile:** add method ([51e93e5](https://github.com/glpi-project/java-library-glpi/commit/51e93e5))
* **getActiveProfile:** add optional App-Token ([4e710b5](https://github.com/glpi-project/java-library-glpi/commit/4e710b5))
* **getAllItem:** add enpoint route ([2c41919](https://github.com/glpi-project/java-library-glpi/commit/2c41919))
* **getAllItemQuery:** add class to manage parameters on get all item ([0a6f2a8](https://github.com/glpi-project/java-library-glpi/commit/0a6f2a8))
* **getAllItems:** add optional App-Token ([b002516](https://github.com/glpi-project/java-library-glpi/commit/b002516))
* **getAnItem:** add method ([f5ff38e](https://github.com/glpi-project/java-library-glpi/commit/f5ff38e))
* **getAnItem:** add optional App-Token ([21154b7](https://github.com/glpi-project/java-library-glpi/commit/21154b7))
* improve interface callback response ([f5be9d3](https://github.com/glpi-project/java-library-glpi/commit/f5be9d3))
* **getAnItem:** add string option for itemtype ([703db67](https://github.com/glpi-project/java-library-glpi/commit/703db67))
* **getAnItemQuery:** add class to manage parameters on get an item ([268d54e](https://github.com/glpi-project/java-library-glpi/commit/268d54e))
* **getFullSession:** add endpoint route ([fb24bde](https://github.com/glpi-project/java-library-glpi/commit/fb24bde))
* **getFullSession:** add method ([227c3d9](https://github.com/glpi-project/java-library-glpi/commit/227c3d9))
* **getFullSession:** add optional App-Token ([f12f876](https://github.com/glpi-project/java-library-glpi/commit/f12f876))
* **getGlpiConfig:** add method ([e1cd382](https://github.com/glpi-project/java-library-glpi/commit/e1cd382))
* **getGlpiConfig:** add optional App-Token ([a9da9a1](https://github.com/glpi-project/java-library-glpi/commit/a9da9a1))
* **getMyEntities:** add endpoint route ([7c47933](https://github.com/glpi-project/java-library-glpi/commit/7c47933))
* **getMyEntities:** add method ([77a1301](https://github.com/glpi-project/java-library-glpi/commit/77a1301))
* **getMyEntities:** add optional App-Token ([b90ec96](https://github.com/glpi-project/java-library-glpi/commit/b90ec96))
* **getMyProfile:** add endpoint route ([42d9971](https://github.com/glpi-project/java-library-glpi/commit/42d9971))
* **getMyProfiles:** add optional App-Token ([6bfe163](https://github.com/glpi-project/java-library-glpi/commit/6bfe163))
* **routes:** include endpoints in interface ([257b8e8](https://github.com/glpi-project/java-library-glpi/commit/257b8e8))
* add download file request ([c175f4e](https://github.com/glpi-project/java-library-glpi/commit/c175f4e))
* **getSubItemQuery:** add class to manage parameters on get sub item ([b91be63](https://github.com/glpi-project/java-library-glpi/commit/b91be63))
* **getSubItems:** add method ([de0b4c7](https://github.com/glpi-project/java-library-glpi/commit/de0b4c7))
* **getSubItems:** add optional App-Token ([b769449](https://github.com/glpi-project/java-library-glpi/commit/b769449))
* **getSubItems:** add string option for itemtype ([91ca0dd](https://github.com/glpi-project/java-library-glpi/commit/91ca0dd))
* **initsession:** add synchronous init session by credentials method ([d98fd03](https://github.com/glpi-project/java-library-glpi/commit/d98fd03))
* **itemtype:** add enum item type ([e9de716](https://github.com/glpi-project/java-library-glpi/commit/e9de716))
* **killsession:** add endpoint route ([caca9b9](https://github.com/glpi-project/java-library-glpi/commit/caca9b9))
* **killSession:** add method ([01c9363](https://github.com/glpi-project/java-library-glpi/commit/01c9363))
* **killSession:** add optional App-Token ([ffe1b86](https://github.com/glpi-project/java-library-glpi/commit/ffe1b86))
* **lostPassword:** add method lost password and recovery password ([f33d498](https://github.com/glpi-project/java-library-glpi/commit/f33d498))
* **routes:** added full session, pluginFlyve and pluginFlyveID ([80242a3](https://github.com/glpi-project/java-library-glpi/commit/80242a3))
* **sessionToken:** manage global session token ([6bbbce0](https://github.com/glpi-project/java-library-glpi/commit/6bbbce0))
* **updateItems:** add optional App-Token ([c799fdd](https://github.com/glpi-project/java-library-glpi/commit/c799fdd))
* **view:** add adapter and list view result request ([a457dcf](https://github.com/glpi-project/java-library-glpi/commit/a457dcf))
* **view:** add spinner to filter request and show result ([8efdffc](https://github.com/glpi-project/java-library-glpi/commit/8efdffc))
......@@ -111,6 +111,7 @@ public class MainActivity extends AppCompatActivity {
list.add("Call Request");
list.add("List Search Options");
list.add("File Request");
list.add("Search");
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerTest.setAdapter(adapter);
......@@ -142,6 +143,9 @@ public class MainActivity extends AppCompatActivity {
case "File Request":
btnFile();
break;
case "Search":
btnSearch();
break;
}
}
});
......@@ -171,6 +175,28 @@ public class MainActivity extends AppCompatActivity {
}
private void btnSearch() {
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
glpi.searchItems("Users", new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("Search Item: %s", response);
updateAdapter("Success: Search Item");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
@Override
public void onFailure(String errorMessage) {
FlyveLog.e("Search Item: %s", errorMessage);
updateAdapter("Error: Search Item");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
});
}
private void btnKill() {
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
......
......@@ -35,6 +35,7 @@ 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;
......@@ -587,6 +588,39 @@ public class GLPI extends ServiceGenerator {
});
}
/**
* Search items
*
* @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) {
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) {
if (response.isSuccessful()) {
callback.onResponse(response.body());
} else {
String errorMessage;
try {
errorMessage = response.errorBody().string();
} catch (Exception ex) {
errorMessage = context.getResources().getString(R.string.error_generic);
}
callback.onFailure(errorMessage);
}
}
@Override
public void onFailure(Call<JsonObject> call, Throwable t) {
callback.onFailure(t.getMessage());
}
});
}
/**
* Create a valid Array with common headers needs
*
......@@ -628,9 +662,6 @@ public class GLPI extends ServiceGenerator {
});
}
public void searchItems() {
}
public interface ResponseHandle<T, U> {
void onResponse(T response);
......
......@@ -161,4 +161,8 @@ public interface Routes {
@GET("listSearchOptions/{itemType}")
Call<JsonObject> getListSearchOption(@HeaderMap Map<String, String> headers, @Path("itemType") String itemType, @QueryMap Map<String, String> options);
@Headers("Content-Type: application/json")
@GET("search/{itemType}")
Call<JsonObject> searchItem(@HeaderMap Map<String, String> headers, @Path("itemType") String itemType, @QueryMap Map<String, String> options);
}
/* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of the GLPI API Client Library for Java,
* a subproject of GLPI. GLPI is a free IT Asset Management.
*
* GLPI is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* GLPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* --------------------------------------------------------------------
* @author Ivan Del Pino - <idelpino@teclib.com>
* @copyright (C) 2017 Teclib' and contributors.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/glpi-project/java-library-glpi
* @link http://www.glpi-project.org/
* --------------------------------------------------------------------
*/
package org.glpi.api.query;
import java.util.HashMap;
import java.util.Map;
public class GetSearchItem {
private String link;
private String field;
private String meta;
private String itemtype;
private String searchtype;
private String value;
private String criteria;
private String metacriteria;
private String sort;
private String order;
private String range;
private String forcedisplay;
private String rawdata;
private String withindexes;
private String uid_cols;
private String giveItems;
/**
* Get a map with all the parameters available to work with the get search item
* @return Map<String, String> with the parameters selected
*/
public Map<String, String> getQuery() {
Map<String, String> map = new HashMap<>();
if (link != null) {
map.put("link", link.toString());
}
if (field != null) {
map.put("field", field.toString());
}
if (meta != null) {
map.put("meta", meta.toString());
}
if (itemtype != null) {
map.put("itemtype", itemtype.toString());
}
if (searchtype != null) {
map.put("searchtype", searchtype.toString());
}
if (value != null) {
map.put("value", value.toString());
}
if (criteria != null) {
map.put("criteria", criteria.toString());
}
if (metacriteria != null) {
map.put("metacriteria", metacriteria.toString());
}
if (sort != null) {
map.put("with_infocoms", sort.toString());
}
if (order != null) {
map.put("order", order.toString());
}
if (range != null) {
map.put("range", range.toString());
}
if (forcedisplay != null) {
map.put("forcedisplay", forcedisplay.toString());
}
if (rawdata != null) {
map.put("rawdata", rawdata.toString());
}
if (withindexes != null) {
map.put("withindexes", withindexes.toString());
}
if (uid_cols != null) {
map.put("uid_cols", uid_cols.toString());
}
if (giveItems != null) {
map.put("giveItems", giveItems.toString());
}
return map;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public String getMeta() {
return meta;
}
public void setMeta(String meta) {
this.meta = meta;
}
public String getItemtype() {
return itemtype;
}
public void setItemtype(String itemtype) {
this.itemtype = itemtype;
}
public String getSearchtype() {
return searchtype;
}
public void setSearchtype(String searchtype) {
this.searchtype = searchtype;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getCriteria() {
return criteria;
}
public void setCriteria(String criteria) {
this.criteria = criteria;
}
public String getMetacriteria() {
return metacriteria;
}
public void setMetacriteria(String metacriteria) {
this.metacriteria = metacriteria;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
public String getRange() {
return range;
}
public void setRange(String range) {
this.range = range;
}
public String getForcedisplay() {
return forcedisplay;
}
public void setForcedisplay(String forcedisplay) {
this.forcedisplay = forcedisplay;
}
public String getRawdata() {
return rawdata;
}
public void setRawdata(String rawdata) {
this.rawdata = rawdata;
}
public String getWithindexes() {
return withindexes;
}
public void setWithindexes(String withindexes) {
this.withindexes = withindexes;
}
public String getUid_cols() {
return uid_cols;
}
public void setUid_cols(String uid_cols) {
this.uid_cols = uid_cols;
}
public String getGiveItems() {
return giveItems;
}
public void setGiveItems(String giveItems) {
this.giveItems = giveItems;
}
}
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