Commit 9598006b authored by Ivan Del Pino's avatar Ivan Del Pino Committed by Rafael Jesus Hernández Vasquez

feat(api): add view and code in example and refactor glpi instance

Signed-off-by: default avatarIvan Del Pino <idelpino@teclib.com>
parent e8d4780e
......@@ -38,4 +38,5 @@ dependencies {
testCompile 'junit:junit:4.12'
compile project(':glpi')
compile 'com.orhanobut:logger:2.1.0'
compile 'com.android.support:recyclerview-v7:26.+'
}
package org.glpi.glpiproject;
public class ExampleData {
private String email;
private String invitationToken;
private String name;
private String phone;
private String url;
private String userToken;
private String website;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getInvitationToken() {
return invitationToken;
}
public void setInvitationToken(String invitationToken) {
this.invitationToken = invitationToken;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUserToken() {
return userToken;
}
public void setUserToken(String userToken) {
this.userToken = userToken;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
}
......@@ -50,6 +50,15 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ExampleData data = new ExampleData();
data.setEmail("greatsupport@example.com");
data.setEmail("5e9d551afc181984042a985fd6552ea8400c190c4f1f61d7838cf8a1b88668f3");
data.setName("Great support");
data.setPhone("+33 123456789");
data.setUrl("https://dev.flyve.org/glpi/apirest.php");
data.setUserToken("ufC5Ct9MXVfQdEOdTp0B0Rb05t8PXNRZKcGmVIWV");
data.setWebsite("https://mygreatsupport.com");
FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
.showThreadInfo(false) // (Optional) Whether to show thread info or not. Default true
.methodCount(0) // (Optional) How many method line to show. Default 2
......@@ -61,10 +70,21 @@ public class MainActivity extends AppCompatActivity {
final GLPI glpi = new GLPI(MainActivity.this, BuildConfig.GLPI_URL);
Button btnInit = (Button) findViewById(R.id.btnInit);
Button btnInit = findViewById(R.id.btnInit);
btnInit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
glpi.initSessionByUserToken(data.getUserToken(), new GLPI.InitSessionCallback() {
@Override
public void onResponse(InitSession response) {
}
@Override
public void onFailure(String errorMessage) {
}
});
glpi.initSessionByCredentials(BuildConfig.GLPI_USER, BuildConfig.GLPI_PASSWORD, new GLPI.InitSessionCallback() {
@Override
public void onResponse(InitSession response) {
......@@ -79,7 +99,7 @@ public class MainActivity extends AppCompatActivity {
}
});
Button btn = (Button) findViewById(R.id.btnCall);
Button btn = findViewById(R.id.btnCall);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -311,7 +331,7 @@ public class MainActivity extends AppCompatActivity {
}
});
Button btnKill = (Button) findViewById(R.id.btnKill);
Button btnKill = findViewById(R.id.btnKill);
btnKill.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......
......@@ -4,56 +4,98 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.glpi.glpiproject.org.glpi.glpiproject.MainActivity">
tools:context="org.glpi.glpiproject.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Hello World!"
android:layout_marginTop="20dp"
android:text="@string/test_api"
android:textColor="@color/colorPrimaryDark"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/textView"
android:layout_marginTop="41dp" />
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="Call APIs"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/btnInit" />
<Button
android:id="@+id/btnKill"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="124dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="Kill Session"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/btnCall"
app:layout_constraintVertical_bias="0.0" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/constraintLayout"
app:layout_constraintTop_toBottomOf="@+id/textView">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewTestApi"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
<Button
android:id="@+id/btnInit"
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="Init Session"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintHorizontal_bias="0.503" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
<Button
android:id="@+id/btnInit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/init_session"
app:layout_constraintHorizontal_bias="0.101"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/call_apis"
app:layout_constraintHorizontal_bias="0.13"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnInit" />
<Button
android:id="@+id/btnKill"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/kill_session"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.101"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnCall" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
<resources>
<string name="app_name">GLPIProject</string>
<string name="test_api">Test Api</string>
<string name="call_apis">Call APIs</string>
<string name="kill_session">Kill Session</string>
<string name="init_session">Init Session</string>
</resources>
......@@ -75,8 +75,8 @@ public class GLPI extends ServiceGenerator {
* @param callback here you are going to get the asynchronous response
*/
public void initSessionByUserToken(String userToken, final InitSessionCallback callback) {
this.appToken = null;
responseInitSession(callback, interfaces.initSessionByUserToken("user_token " + userToken.trim()));
Call<InitSession> call = interfaces.initSessionByUserToken(userToken, userToken);
responseInitSession(callback, call);
}
/**
......@@ -218,18 +218,6 @@ public class GLPI extends ServiceGenerator {
responseJsonObject(callback, interfaces.getAnItem(getHeader(), itemType.name(), id, options));
}
/**
* Return the instance fields of itemtype identified by id.
*
* @param itemType These are the item type available on GLPI
* @param id unique identifier of the itemtype
* @param callback here you are going to get the asynchronous response
*/
public void getItem(String itemType, String id, final JsonObjectCallback callback) {
Map<String, String> options = new GetAnItemQuery().getQuery();
responseJsonObject(callback, interfaces.getAnItem(getHeader(), itemType, id, options));
}
/**
* Return a collection of rows of the sub_itemtype for the identified item.
*
......
......@@ -47,13 +47,13 @@ import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
public interface Routes {
@Headers("Content-Type: application/json")
@GET("initSession")
Call<InitSession> initSessionByUserToken(@Header("Authorization") String authorization);
Call<InitSession> initSessionByUserToken(@Header("user_token") String token, @Query("user_token") String userToken);
@Headers("Content-Type: application/json")
@GET("initSession")
......
......@@ -26,6 +26,7 @@
package org.glpi.api;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
......@@ -36,13 +37,14 @@ public class ServiceGenerator {
private static final int READ_TIMEOUT = 60;
private static final int WRITE_TIMEOUT = 60;
protected Retrofit retrofit;
Retrofit retrofit;
/**
* Initial connection configuration
*
* @param url
*/
protected void start(String url) {
void start(String url) {
OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
.connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
......
......@@ -55,67 +55,67 @@ public class GetAnItemQuery {
Map<String, String> map = new HashMap<>();
if(expandDropdowns!=null) {
if (expandDropdowns != null) {
map.put("expand_dropdowns", expandDropdowns.toString());
}
if(getHateoas!=null) {
if (getHateoas != null) {
map.put("get_hateoas", getHateoas.toString());
}
if(getSha1!=null) {
if (getSha1 != null) {
map.put("get_sha1", getSha1.toString());
}
if(withDevices!=null) {
if (withDevices != null) {
map.put("with_devices", withDevices.toString());
}
if(withDisks!=null) {
if (withDisks != null) {
map.put("with_disks", withDisks.toString());
}
if(withSoftwares!=null) {
if (withSoftwares != null) {
map.put("with_softwares", withSoftwares.toString());
}
if(withConnections!=null) {
if (withConnections != null) {
map.put("with_connections", withConnections.toString());
}
if(withNetworkports!=null) {
if (withNetworkports != null) {
map.put("with_networkports", withNetworkports.toString());
}
if(withInfocoms!=null) {
if (withInfocoms != null) {
map.put("with_infocoms", withInfocoms.toString());
}
if(withContracts!=null) {
if (withContracts != null) {
map.put("with_contracts", withContracts.toString());
}
if(withDocuments!=null) {
if (withDocuments != null) {
map.put("with_documents", withDocuments.toString());
}
if(withTickets!=null) {
if (withTickets != null) {
map.put("with_tickets", withTickets.toString());
}
if(withProblems!=null) {
if (withProblems != null) {
map.put("with_problems", withProblems.toString());
}
if(withChanges!=null) {
if (withChanges != null) {
map.put("with_changes", withChanges.toString());
}
if(withNotes!=null) {
if (withNotes != null) {
map.put("with_notes", withNotes.toString());
}
if(withLogs!=null) {
if (withLogs != null) {
map.put("with_logs", withLogs.toString());
}
......@@ -124,6 +124,7 @@ public class GetAnItemQuery {
/**
* (default: false): show dropdown name instead of id.
*
* @param expandDropdowns
*/
public void setExpandDropdowns(Boolean expandDropdowns) {
......@@ -132,6 +133,7 @@ public class GetAnItemQuery {
/**
* (default: true): Show relations of the item in a links attribute.
*
* @param getHateoas
*/
public void setGetHateoas(Boolean getHateoas) {
......@@ -140,6 +142,7 @@ public class GetAnItemQuery {
/**
* (default: false): Get a sha1 signature instead of the full answer.
*
* @param getSha1
*/
public void setGetSha1(Boolean getSha1) {
......@@ -148,6 +151,7 @@ public class GetAnItemQuery {
/**
* Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], retrieve the associated components.
*
* @param withDevices
*/
public void setWithDevices(Boolean withDevices) {
......@@ -156,6 +160,7 @@ public class GetAnItemQuery {
/**
* Only for Computer, retrieve the associated file-systems.
*
* @param withDisks
*/
public void setWithDisks(Boolean withDisks) {
......@@ -164,6 +169,7 @@ public class GetAnItemQuery {
/**
* Only for Computer, retrieve the associated software's installations.
*
* @param withSoftwares
*/
public void setWithSoftwares(Boolean withSoftwares) {
......@@ -172,6 +178,7 @@ public class GetAnItemQuery {
/**
* Only for Computer, retrieve the associated direct connections
*
* @param withConnections
*/
public void setWithConnections(Boolean withConnections) {
......@@ -180,6 +187,7 @@ public class GetAnItemQuery {
/**
* Retrieve all network's connections and advanced network's informations.
*
* @param withNetworkports
*/
public void setWithNetworkports(Boolean withNetworkports) {
......@@ -188,6 +196,7 @@ public class GetAnItemQuery {
/**
* Retrieve financial and administrative informations.
*
* @param withInfocoms
*/
public void setWithInfocoms(Boolean withInfocoms) {
......@@ -196,6 +205,7 @@ public class GetAnItemQuery {
/**
* Retrieve associated contracts.
*
* @param withContracts
*/
public void setWithContracts(Boolean withContracts) {
......@@ -204,6 +214,7 @@ public class GetAnItemQuery {
/**
* Retrieve associated external documents.
*
* @param withDocuments
*/
public void setWithDocuments(Boolean withDocuments) {
......@@ -212,6 +223,7 @@ public class GetAnItemQuery {
/**
* Retrieve associated itil tickets.
*
* @param withTickets
*/
public void setWithTickets(Boolean withTickets) {
......@@ -220,6 +232,7 @@ public class GetAnItemQuery {
/**
* Retrieve associated itil problems.
*
* @param withProblems
*/
public void setWithProblems(Boolean withProblems) {
......@@ -228,6 +241,7 @@ public class GetAnItemQuery {
/**
* Retrieve associated itil changes.
*
* @param withChanges
*/
public void setWithChanges(Boolean withChanges) {
......@@ -236,6 +250,7 @@ public class GetAnItemQuery {
/**
* Retrieve Notes.
*
* @param withNotes
*/
public void setWithNotes(Boolean withNotes) {
......@@ -244,6 +259,7 @@ public class GetAnItemQuery {
/**
* Retrieve historical.
*
* @param withLogs
*/
public void setWithLogs(Boolean withLogs) {
......
......@@ -45,7 +45,7 @@ public class InitSession {
/**
* set Session Token
* @param string session token
* @param sessionToken session token
*/
public void setSessionToken(String sessionToken) {
this.sessionToken = sessionToken;
......
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