Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GLPI
java-library-glpi
Commits
303ba855
Unverified
Commit
303ba855
authored
Oct 24, 2017
by
Rafa Hernandez
Browse files
build(example): add app folder with the example
parent
684e7ece
Changes
23
Hide whitespace changes
Inline
Side-by-side
app/.gitignore
0 → 100644
View file @
303ba855
/build
app/build.gradle
0 → 100644
View file @
303ba855
apply
plugin:
'com.android.application'
android
{
compileSdkVersion
26
buildToolsVersion
"26.0.2"
defaultConfig
{
applicationId
"org.flyve.glpiproject"
minSdkVersion
16
targetSdkVersion
26
versionCode
1
versionName
"1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes
{
buildTypes
.
each
{
it
.
buildConfigField
'String'
,
'GLPI_USER'
,
glpi_user
it
.
buildConfigField
'String'
,
'GLPI_PASSWORD'
,
glpi_password
it
.
buildConfigField
'String'
,
'GLPI_URL'
,
glpi_url
}
release
{
minifyEnabled
false
proguardFiles
getDefaultProguardFile
(
'proguard-android.txt'
),
'proguard-rules.pro'
}
}
}
dependencies
{
compile
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
androidTestCompile
(
'com.android.support.test.espresso:espresso-core:2.2.2'
,
{
exclude
group:
'com.android.support'
,
module:
'support-annotations'
})
compile
'com.android.support:appcompat-v7:26.+'
compile
'com.android.support.constraint:constraint-layout:1.0.2'
testCompile
'junit:junit:4.12'
compile
project
(
':glpi'
)
}
app/proguard-rules.pro
0 → 100644
View file @
303ba855
# Add project specific ProGuard rules here.
#
By
default
,
the
flags
in
this
file
are
appended
to
flags
specified
#
in
/
Users
/
rafaelhernandez
/
adt
-
android
/
sdk
/
tools
/
proguard
/
proguard
-
android
.
txt
#
You
can
edit
the
include
path
and
order
by
changing
the
proguardFiles
#
directive
in
build
.
gradle
.
#
#
For
more
details
,
see
#
http
://
developer
.
android
.
com
/
guide
/
developing
/
tools
/
proguard
.
html
#
Add
any
project
specific
keep
options
here
:
#
If
your
project
uses
WebView
with
JS
,
uncomment
the
following
#
and
specify
the
fully
qualified
class
name
to
the
JavaScript
interface
#
class
:
#-
keepclassmembers
class
fqcn
.
of
.
javascript
.
interface
.
for
.
webview
{
#
public
*
;
#
}
#
Uncomment
this
to
preserve
the
line
number
information
for
#
debugging
stack
traces
.
#-
keepattributes
SourceFile
,
LineNumberTable
#
If
you
keep
the
line
number
information
,
uncomment
this
to
#
hide
the
original
source
file
name
.
#-
renamesourcefileattribute
SourceFile
app/src/androidTest/java/org/flyve/glpiproject/ExampleInstrumentedTest.java
0 → 100644
View file @
303ba855
package
org.flyve.glpiproject
;
import
android.content.Context
;
import
android.support.test.InstrumentationRegistry
;
import
android.support.test.runner.AndroidJUnit4
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
static
org
.
junit
.
Assert
.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith
(
AndroidJUnit4
.
class
)
public
class
ExampleInstrumentedTest
{
@Test
public
void
useAppContext
()
throws
Exception
{
// Context of the app under test.
Context
appContext
=
InstrumentationRegistry
.
getTargetContext
();
assertEquals
(
"org.flyve.glpiproject"
,
appContext
.
getPackageName
());
}
}
app/src/main/AndroidManifest.xml
0 → 100644
View file @
303ba855
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"org.flyve.glpiproject"
>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<application
android:allowBackup=
"true"
android:icon=
"@mipmap/ic_launcher"
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
>
<activity
android:name=
".MainActivity"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
app/src/main/java/org/flyve/glpiproject/MainActivity.java
0 → 100644
View file @
303ba855
/* ---------------------------------------------------------------------
*
* 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.flyve.glpiproject
;
import
android.os.Bundle
;
import
android.support.v7.app.AppCompatActivity
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.Button
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonObject
;
import
org.flyve.glpi.GLPI
;
import
org.flyve.glpi.itemType
;
import
org.flyve.glpi.response.InitSession
;
import
java.util.ArrayList
;
public
class
MainActivity
extends
AppCompatActivity
{
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
final
GLPI
glpi
=
new
GLPI
(
MainActivity
.
this
,
BuildConfig
.
GLPI_URL
);
Button
btnInit
=
(
Button
)
findViewById
(
R
.
id
.
btnInit
);
btnInit
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
glpi
.
initSessionByCredentials
(
BuildConfig
.
GLPI_USER
,
BuildConfig
.
GLPI_PASSWORD
,
new
GLPI
.
InitSessionCallback
()
{
@Override
public
void
onResponse
(
InitSession
response
)
{
Log
.
d
(
"initSession"
,
response
.
getSessionToken
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"initSession"
,
errorMessage
);
}
});
}
});
Button
btn
=
(
Button
)
findViewById
(
R
.
id
.
btnCall
);
btn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
glpi
.
getMyProfiles
(
new
GLPI
.
JsonObjectCallback
()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
Log
.
d
(
"getMyProfiles"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"getMyProfiles"
,
errorMessage
);
}
});
glpi
.
getActiveProfile
(
new
GLPI
.
JsonObjectCallback
()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
Log
.
d
(
"getActiveProfile"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"getActiveProfile"
,
errorMessage
);
}
});
glpi
.
getMyEntities
(
new
GLPI
.
JsonObjectCallback
()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
Log
.
d
(
"getMyEntities"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"getMyEntities"
,
errorMessage
);
}
});
glpi
.
getActiveEntities
(
new
GLPI
.
JsonObjectCallback
()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
Log
.
d
(
"getActiveEntities"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"getActiveEntities"
,
errorMessage
);
}
});
glpi
.
getFullSession
(
new
GLPI
.
JsonObjectCallback
()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
Log
.
d
(
"getFullSession"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"getFullSession"
,
errorMessage
);
}
});
glpi
.
getGlpiConfig
(
new
GLPI
.
JsonObjectCallback
()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
Log
.
d
(
"getGlpiConfig"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"getGlpiConfig"
,
errorMessage
);
}
});
glpi
.
getAllItems
(
itemType
.
Computer
,
new
GLPI
.
JsonArrayCallback
()
{
@Override
public
void
onResponse
(
JsonArray
response
)
{
Log
.
d
(
"getAllItems"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"getAllItems"
,
errorMessage
);
}
});
glpi
.
getAnItem
(
itemType
.
Computer
,
"110"
,
new
GLPI
.
JsonObjectCallback
()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
Log
.
d
(
"getAnItem"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"getAnItem"
,
errorMessage
);
}
});
glpi
.
getSubItems
(
itemType
.
Computer
,
"2"
,
itemType
.
ComputerType
,
new
GLPI
.
JsonObjectCallback
()
{
@Override
public
void
onResponse
(
JsonObject
response
)
{
Log
.
d
(
"getSubItems"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"getSubItems"
,
errorMessage
);
}
});
glpi
.
changeActiveProfile
(
"9"
,
new
GLPI
.
VoidCallback
()
{
@Override
public
void
onResponse
(
String
response
)
{
Log
.
d
(
"changeActiveProfile"
,
response
);
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"changeActiveProfile"
,
errorMessage
);
}
});
glpi
.
changeActiveEntities
(
"1"
,
false
,
new
GLPI
.
VoidCallback
()
{
@Override
public
void
onResponse
(
String
response
)
{
Log
.
d
(
"changeActiveEntities"
,
response
);
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"changeActiveEntities"
,
errorMessage
);
}
});
addItemExamplePayload
.
data
item1
=
new
addItemExamplePayload
.
data
(
"My first computer"
,
"12345"
);
addItemExamplePayload
.
data
item2
=
new
addItemExamplePayload
.
data
(
"My second computer"
,
"12345678"
);
addItemExamplePayload
.
data
item3
=
new
addItemExamplePayload
.
data
(
"My computer"
,
"54321"
);
ArrayList
<
addItemExamplePayload
.
data
>
list
=
new
ArrayList
<>();
list
.
add
(
item1
);
list
.
add
(
item2
);
list
.
add
(
item3
);
addItemExamplePayload
obj
=
new
addItemExamplePayload
(
list
);
glpi
.
addItems
(
itemType
.
Computer
,
obj
,
new
GLPI
.
JsonArrayCallback
()
{
@Override
public
void
onResponse
(
JsonArray
response
)
{
Log
.
d
(
"addItems"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"addItems"
,
errorMessage
);
}
});
glpi
.
updateItems
(
itemType
.
Computer
,
"10"
,
obj
,
new
GLPI
.
JsonArrayCallback
()
{
@Override
public
void
onResponse
(
JsonArray
response
)
{
Log
.
d
(
"updateItems"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"updateItems"
,
errorMessage
);
}
});
glpi
.
deleteItems
(
itemType
.
Computer
,
"10"
,
new
GLPI
.
JsonArrayCallback
()
{
@Override
public
void
onResponse
(
JsonArray
response
)
{
Log
.
d
(
"deleteItems"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"deleteItems"
,
errorMessage
);
}
});
deleteItemExamplePayload
.
data
deleteItem1
=
new
deleteItemExamplePayload
.
data
(
"16"
);
deleteItemExamplePayload
.
data
deleteItem2
=
new
deleteItemExamplePayload
.
data
(
"17"
);
deleteItemExamplePayload
.
data
deleteItem3
=
new
deleteItemExamplePayload
.
data
(
"18"
);
ArrayList
<
deleteItemExamplePayload
.
data
>
deleteList
=
new
ArrayList
<>();
deleteList
.
add
(
deleteItem1
);
deleteList
.
add
(
deleteItem2
);
deleteList
.
add
(
deleteItem3
);
deleteItemExamplePayload
deleteObj
=
new
deleteItemExamplePayload
(
deleteList
);
glpi
.
deleteItems
(
itemType
.
Computer
,
deleteObj
,
new
GLPI
.
JsonArrayCallback
()
{
@Override
public
void
onResponse
(
JsonArray
response
)
{
Log
.
d
(
"deleteItems"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"deleteItems"
,
errorMessage
);
}
});
glpi
.
lostPassword
(
"youremail@yourdomain.com"
,
new
GLPI
.
VoidCallback
()
{
@Override
public
void
onResponse
(
String
response
)
{
Log
.
d
(
"lostPassword"
,
response
);
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"lostPassword"
,
errorMessage
);
}
});
glpi
.
recoveryPassword
(
"youremail@yourdomain.com"
,
"asdfasdfafsASDFd333A"
,
"1234"
,
new
GLPI
.
VoidCallback
()
{
@Override
public
void
onResponse
(
String
response
)
{
Log
.
d
(
"recoveryPassword"
,
response
);
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"recoveryPassword"
,
errorMessage
);
}
});
}
});
Button
btnKill
=
(
Button
)
findViewById
(
R
.
id
.
btnKill
);
btnKill
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
glpi
.
killSession
(
new
GLPI
.
VoidCallback
()
{
@Override
public
void
onResponse
(
String
response
)
{
Log
.
d
(
"killSession"
,
response
.
toString
());
}
@Override
public
void
onFailure
(
String
errorMessage
)
{
Log
.
e
(
"killSession"
,
errorMessage
);
}
});
}
});
}
}
app/src/main/java/org/flyve/glpiproject/addItemExamplePayload.java
0 → 100644
View file @
303ba855
/* ---------------------------------------------------------------------
*
* 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.flyve.glpiproject
;
import
java.util.List
;
public
class
addItemExamplePayload
{
public
List
<
data
>
input
;
public
addItemExamplePayload
(
List
<
data
>
input
)
{
this
.
input
=
input
;
}
public
static
class
data
{
public
String
name
;
public
String
serial
;
public
data
(
String
name
,
String
serial
)
{
this
.
name
=
name
;
this
.
serial
=
serial
;
}
}
}
app/src/main/java/org/flyve/glpiproject/deleteItemExamplePayload.java
0 → 100644
View file @
303ba855
/* ---------------------------------------------------------------------
*
* 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.flyve.glpiproject
;
import
java.util.List
;
public
class
deleteItemExamplePayload
{
public
List
<
data
>
input
;
public
deleteItemExamplePayload
(
List
<
data
>
input
)
{
this
.
input
=
input
;
}
public
static
class
data
{
public
String
id
;
public
data
(
String
id
)
{
this
.
id
=
id
;
}
}
}
app/src/main/res/layout/activity_main.xml
0 → 100644
View file @
303ba855
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
"org.flyve.glpiproject.MainActivity"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"0dp"
android:text=
"Hello World!"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
android:id=
"@+id/textView"
android:layout_marginTop=
"41dp"
/>
<Button
android:id=
"@+id/btnCall"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"8dp"
android:layout_marginRight=
"8dp"
android:text=
"Call APIs"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
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"
/>
<Button
android:id=
"@+id/btnInit"
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_marginTop=
"8dp"
app:layout_constraintTop_toBottomOf=
"@+id/textView"
app:layout_constraintHorizontal_bias=
"0.503"
/>