Commit 0c67a985 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 list search options


Signed-off-by: default avatarIvan Del Pino <idelpino@teclib.com>
parent 6fbe6e0e
......@@ -45,6 +45,7 @@ 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.response.FullSessionModel;
import org.glpi.api.response.InitSession;
import org.glpi.api.utils.Helpers;
......@@ -54,6 +55,7 @@ import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import okhttp3.ResponseBody;
......@@ -107,6 +109,7 @@ public class MainActivity extends AppCompatActivity {
list.add("Full Session");
list.add("Kill session");
list.add("Call Request");
list.add("List Search Options");
list.add("File Request");
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
......@@ -133,6 +136,9 @@ public class MainActivity extends AppCompatActivity {
case "Call Request":
btnCall();
break;
case "List Search Options":
btnSearchOptions();
break;
case "File Request":
btnFile();
break;
......@@ -141,6 +147,30 @@ public class MainActivity extends AppCompatActivity {
});
}
private void btnSearchOptions() {
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
Map<String, String> query = new GetListSearchOptionsQuery(this).getQuery();
glpi.listSearchOptions(query, new GLPI.ResponseHandle<JsonObject, String>() {
@Override
public void onResponse(JsonObject response) {
FlyveLog.i("Search Option: %s", response);
updateAdapter("Success: Search Option");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
@Override
public void onFailure(String errorMessage) {
FlyveLog.e("Search Option: %s", errorMessage);
updateAdapter("Error: Search Option");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
});
}
private void btnKill() {
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
......
......@@ -604,7 +604,28 @@ public class GLPI extends ServiceGenerator {
public void getMultipleItems() {
}
public void listSearchOptions() {
public void listSearchOptions(Map<String, String> query, final ResponseHandle<JsonObject, String> callback) {
interfaces.getListSearchOption(getHeader(), "Users", 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());
}
});
}
public void searchItems() {
......
......@@ -28,7 +28,6 @@ package org.glpi.api;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import org.glpi.api.request.ChangeActiveEntitiesRequest;
import org.glpi.api.request.ChangeActiveProfileRequest;
......@@ -158,4 +157,8 @@ public interface Routes {
@GET
Call<ResponseBody> downloadFile(@Url String url, @HeaderMap Map<String, String> headers);
@Headers("Content-Type: application/json")
@GET("listSearchOptions/{itemType}")
Call<JsonObject> getListSearchOption(@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 Rafael Hernandez - <rhernandez@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 android.content.Context;
import java.util.HashMap;
import java.util.Map;
public class GetListSearchOptionsQuery {
private String raw;
private Context context;
/**
* Get all the parameters available to work with the all items endpoint
* @param context
*/
public GetListSearchOptionsQuery(Context context) {
this.context = context;
}
/**
* Get a map with all the parameters available to work with the all items endpoint
* @return Map<String, String> with the parameters selected
*/
public Map<String, String> getQuery() {
Map<String, String> map = new HashMap<>();
if (raw != null) {
map.put("raw", raw.toString());
}
return map;
}
public String getRaw() {
return raw;
}
public void setRaw(String raw) {
this.raw = raw;
}
}
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