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
hds
flexin
android-app
Commits
e08db2bd
Commit
e08db2bd
authored
Oct 29, 2017
by
Nastuzzi Samy
Browse files
Optimization
Autohandle HTTP errors and send exceptions Change idBadge to badgeId
parent
fb5a2313
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/payutc/FoundationListActivity.java
View file @
e08db2bd
...
...
@@ -47,7 +47,7 @@ public class FoundationListActivity extends BaseActivity {
}
@Override
protected
void
onIdentification
(
String
idB
adge
)
{}
protected
void
onIdentification
(
final
String
b
adge
Id
)
{}
@Override
protected
void
onDestroy
()
{
...
...
app/src/main/java/fr/utc/simde/payutc/MainActivity.java
View file @
e08db2bd
...
...
@@ -78,9 +78,9 @@ public class MainActivity extends BaseActivity {
}
@Override
protected
void
onIdentification
(
final
String
idB
adge
)
{
protected
void
onIdentification
(
final
String
b
adge
Id
)
{
if
(!
dialog
.
isShowing
())
badgeDialog
(
idB
adge
);
badgeDialog
(
b
adge
Id
);
}
@Override
...
...
@@ -142,13 +142,9 @@ public class MainActivity extends BaseActivity {
public
void
run
()
{
if
(
casConnexion
.
getUrl
().
equals
(
""
))
{
try
{
if
(
nemopaySession
.
getCASUrl
()
==
200
)
{
Log
.
d
(
LOG_TAG
,
nemopaySession
.
getRequest
().
getResponse
());
String
url
=
nemopaySession
.
getRequest
().
getResponse
();
casConnexion
.
setUrl
(
url
.
substring
(
1
,
url
.
length
()
-
1
));
}
else
throw
new
Exception
(
"Impossible to get CAS url"
);
nemopaySession
.
getCASUrl
();
String
url
=
nemopaySession
.
getRequest
().
getResponse
();
casConnexion
.
setUrl
(
url
.
substring
(
1
,
url
.
length
()
-
1
));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
}
...
...
@@ -237,7 +233,7 @@ public class MainActivity extends BaseActivity {
}.
start
();
}
protected
void
connectWithBadge
(
final
String
idB
adge
,
final
String
pin
)
{
protected
void
connectWithBadge
(
final
String
b
adge
Id
,
final
String
pin
)
{
if
(!
nemopaySession
.
isRegistered
()
||
nemopaySession
.
isConnected
())
return
;
...
...
@@ -246,24 +242,32 @@ public class MainActivity extends BaseActivity {
@Override
public
void
run
()
{
try
{
nemopaySession
.
loginBadge
(
idB
adge
,
pin
);
nemopaySession
.
loginBadge
(
b
adge
Id
,
pin
);
Thread
.
sleep
(
100
);
}
catch
(
Exception
e
)
{
}
catch
(
final
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
nemopaySession
.
getRequest
().
getResponseCode
()
==
400
)
dialog
.
errorDialog
(
MainActivity
.
this
,
getString
(
R
.
string
.
badge_dialog
),
getString
(
R
.
string
.
badge_pin_error_not_recognized
));
else
dialog
.
errorDialog
(
MainActivity
.
this
,
getString
(
R
.
string
.
badge_dialog
),
e
.
getMessage
());
}
});
}
if
(!
nemopaySession
.
isConnected
())
return
;
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
stopLoading
();
try
{
if
(
nemopaySession
.
isConnected
())
startFoundationListActivity
(
MainActivity
.
this
);
else
if
(
nemopaySession
.
getRequest
().
getResponseCode
()
==
400
)
dialog
.
errorDialog
(
MainActivity
.
this
,
getString
(
R
.
string
.
badge_dialog
),
getString
(
R
.
string
.
badge_pin_error_not_recognized
));
else
dialog
.
errorDialog
(
MainActivity
.
this
,
getString
(
R
.
string
.
badge_dialog
),
getString
(
R
.
string
.
badge_error_no_rights
)
+
".\n"
+
nemopaySession
.
needRights
(
MainActivity
.
this
));
startFoundationListActivity
(
MainActivity
.
this
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
}
...
...
@@ -273,7 +277,7 @@ public class MainActivity extends BaseActivity {
}).
start
();
}
protected
void
badgeDialog
(
final
String
idB
adge
)
{
protected
void
badgeDialog
(
final
String
b
adge
Id
)
{
if
(!
nemopaySession
.
isRegistered
())
{
dialog
.
errorDialog
(
MainActivity
.
this
,
getString
(
R
.
string
.
badge_connection
),
getString
(
R
.
string
.
badge_app_not_registered
));
return
;
...
...
@@ -298,10 +302,10 @@ public class MainActivity extends BaseActivity {
if
(
pinInput
.
getText
().
toString
().
equals
(
""
))
{
Toast
.
makeText
(
MainActivity
.
this
,
R
.
string
.
pin_required
,
Toast
.
LENGTH_SHORT
).
show
();
dialogInterface
.
cancel
();
badgeDialog
(
idB
adge
);
badgeDialog
(
b
adge
Id
);
}
else
{
connectWithBadge
(
idB
adge
,
pinInput
.
getText
().
toString
());
connectWithBadge
(
b
adge
Id
,
pinInput
.
getText
().
toString
());
dialogInterface
.
cancel
();
}
}
...
...
app/src/main/java/fr/utc/simde/payutc/NFCActivity.java
View file @
e08db2bd
...
...
@@ -53,7 +53,7 @@ public abstract class NFCActivity extends Activity {
this
.
registerReceiver
(
NFCReceiver
,
filter
);
}
protected
abstract
void
onIdentification
(
final
String
idB
adge
);
protected
abstract
void
onIdentification
(
final
String
b
adge
Id
);
protected
Boolean
identifierIsAvailable
()
{
return
NFCAdapter
!=
null
;
}
...
...
@@ -71,9 +71,9 @@ public abstract class NFCActivity extends Activity {
protected
void
onNewIntent
(
Intent
intent
)
{
if
(
intent
.
getAction
()
!=
null
&&
intent
.
getAction
().
equals
(
NFCAdapter
.
ACTION_TAG_DISCOVERED
))
{
String
idB
adge
=
ByteArrayToHexString
(((
Tag
)
intent
.
getParcelableExtra
(
NfcAdapter
.
EXTRA_TAG
)).
getId
());
Log
.
d
(
LOG_TAG
,
"ID: "
+
idB
adge
);
onIdentification
(
idB
adge
);
String
b
adge
Id
=
ByteArrayToHexString
(((
Tag
)
intent
.
getParcelableExtra
(
NfcAdapter
.
EXTRA_TAG
)).
getId
());
Log
.
d
(
LOG_TAG
,
"ID: "
+
b
adge
Id
);
onIdentification
(
b
adge
Id
);
}
}
...
...
app/src/main/java/fr/utc/simde/payutc/tools/NemopaySession.java
View file @
e08db2bd
...
...
@@ -29,14 +29,20 @@ public class NemopaySession {
private
String
foundationName
;
private
HTTPRequest
request
;
private
String
[]
rightsNeeded
;
private
String
noRight
;
private
String
noRights
;
private
String
noRightsNeeded
;
private
String
serviceText
;
private
String
notFound
;
private
String
badRequest
;
private
Map
<
String
,
String
>
cookies
=
new
HashMap
<
String
,
String
>();
private
final
Map
<
String
,
String
>
getArgs
=
new
HashMap
<
String
,
String
>()
{{
put
(
"system_id"
,
"payutc"
);
}};
public
NemopaySession
(
Activity
activity
)
{
public
NemopaySession
(
final
Activity
activity
)
{
this
.
name
=
""
;
this
.
key
=
""
;
this
.
session
=
""
;
...
...
@@ -48,6 +54,13 @@ public class NemopaySession {
String
[]
values
=
activity
.
getResources
().
getStringArray
(
R
.
array
.
rights_values
);
for
(
int
i
=
0
;
i
<
Math
.
min
(
keys
.
length
,
values
.
length
);
++
i
)
this
.
allRights
.
put
(
keys
[
i
],
values
[
i
]);
this
.
noRightsNeeded
=
activity
.
getString
(
R
.
string
.
no_need_rights
);
this
.
noRight
=
activity
.
getString
(
R
.
string
.
no_right
);
this
.
noRights
=
activity
.
getString
(
R
.
string
.
no_rights
);
this
.
serviceText
=
activity
.
getString
(
R
.
string
.
service
);
this
.
notFound
=
activity
.
getString
(
R
.
string
.
not_found
);
this
.
badRequest
=
activity
.
getString
(
R
.
string
.
bad_request
);
}
public
Boolean
isConnected
()
{
return
!
this
.
session
.
isEmpty
()
&&
!
this
.
username
.
isEmpty
();
}
...
...
@@ -79,6 +92,24 @@ public class NemopaySession {
public
int
getFoundationId
()
{
return
foundationId
;
}
public
String
getFoundationName
()
{
return
foundationName
;
}
public
int
getBuyerInfo
(
final
String
badgeId
)
throws
Exception
{
if
(!
isConnected
())
throw
new
Exception
(
"Not connected"
);
return
request
(
"POSS3"
,
"getBuyerInfo"
,
new
HashMap
<
String
,
String
>()
{{
put
(
"badge_id"
,
badgeId
);
if
(
foundationId
!=
-
1
)
put
(
"fun_id"
,
Integer
.
toString
(
foundationId
));
}},
new
String
[]{
"sale"
}
);
}
public
int
getArticles
()
throws
Exception
{
if
(!
isConnected
())
throw
new
Exception
(
"Not connected"
);
...
...
@@ -130,7 +161,7 @@ public class NemopaySession {
);
}
public
int
getCASUrl
()
throws
IO
Exception
{
public
int
getCASUrl
()
throws
Exception
{
return
request
(
"POSS3"
,
"getCasUrl"
...
...
@@ -200,7 +231,7 @@ public class NemopaySession {
return
reponseCode
;
}
public
int
loginBadge
(
final
String
idB
adge
,
final
String
pin
)
throws
Exception
{
public
int
loginBadge
(
final
String
b
adge
Id
,
final
String
pin
)
throws
Exception
{
if
(!
isRegistered
())
throw
new
Exception
(
"Not registered"
);
...
...
@@ -208,7 +239,7 @@ public class NemopaySession {
"POSS3"
,
"loginBadge2"
,
new
HashMap
<
String
,
String
>()
{{
put
(
"badge_id"
,
idB
adge
);
put
(
"badge_id"
,
b
adge
Id
);
put
(
"pin"
,
pin
);
}},
new
String
[]{
...
...
@@ -258,16 +289,16 @@ public class NemopaySession {
return
reponseCode
;
}
public
String
needRights
(
Activity
activity
)
{
public
String
forbidden
(
final
String
[]
rightsNeeded
)
{
String
result
;
if
(
this
.
rightsNeeded
.
length
==
0
)
re
turn
activity
.
getString
(
R
.
string
.
no_need_rights
)
;
else
if
(
this
.
rightsNeeded
.
length
==
1
)
result
=
activity
.
getString
(
R
.
string
.
no
_r
ight
)
;
if
(
rightsNeeded
.
length
==
0
)
re
sult
=
this
.
noRightsNeeded
;
else
if
(
rightsNeeded
.
length
==
1
)
result
=
this
.
no
R
ight
;
else
result
=
activity
.
getString
(
R
.
string
.
no
_r
ights
)
;
result
=
this
.
no
R
ights
;
for
(
String
right
:
this
.
rightsNeeded
)
{
for
(
String
right
:
rightsNeeded
)
{
if
(
allRights
.
containsKey
(
right
))
result
+=
" "
+
allRights
.
get
(
right
)
+
","
;
else
{
...
...
@@ -279,20 +310,26 @@ public class NemopaySession {
return
result
.
substring
(
0
,
result
.
length
()
-
1
)
+
"."
;
}
protected
int
request
(
final
String
method
,
final
String
service
)
throws
IO
Exception
{
return
request
(
method
,
service
,
new
HashMap
<
String
,
String
>(),
new
String
[]{});
}
protected
int
request
(
final
String
method
,
final
String
service
,
final
String
[]
rightsNeeded
)
throws
IO
Exception
{
return
request
(
method
,
service
,
new
HashMap
<
String
,
String
>(),
rightsNeeded
);
}
protected
int
request
(
final
String
method
,
final
String
service
,
final
Map
<
String
,
String
>
postArgs
)
throws
IO
Exception
{
return
request
(
method
,
service
,
postArgs
,
new
String
[]{});
}
protected
int
request
(
final
String
method
,
final
String
service
,
final
Map
<
String
,
String
>
postArgs
,
final
String
[]
rightsNeeded
)
throws
IO
Exception
{
protected
int
request
(
final
String
method
,
final
String
service
)
throws
Exception
{
return
request
(
method
,
service
,
new
HashMap
<
String
,
String
>(),
new
String
[]{});
}
protected
int
request
(
final
String
method
,
final
String
service
,
final
String
[]
rightsNeeded
)
throws
Exception
{
return
request
(
method
,
service
,
new
HashMap
<
String
,
String
>(),
rightsNeeded
);
}
protected
int
request
(
final
String
method
,
final
String
service
,
final
Map
<
String
,
String
>
postArgs
)
throws
Exception
{
return
request
(
method
,
service
,
postArgs
,
new
String
[]{});
}
protected
int
request
(
final
String
method
,
final
String
service
,
final
Map
<
String
,
String
>
postArgs
,
final
String
[]
rightsNeeded
)
throws
Exception
{
Log
.
d
(
LOG_TAG
,
"url: "
+
url
+
method
+
"/"
+
service
);
this
.
request
=
new
HTTPRequest
(
url
+
method
+
"/"
+
service
);
this
.
request
.
setGet
(
getArgs
);
this
.
request
.
setPost
(
postArgs
);
this
.
request
.
setCookies
(
this
.
cookies
);
int
reponseCode
=
this
.
request
.
post
();
int
re
s
ponseCode
=
this
.
request
.
post
();
this
.
cookies
=
request
.
getCookies
();
this
.
rightsNeeded
=
rightsNeeded
;
return
reponseCode
;
if
(
responseCode
==
500
)
throw
new
Exception
(
forbidden
(
rightsNeeded
));
else
if
(
responseCode
==
404
)
throw
new
Exception
(
this
.
serviceText
+
" "
+
service
+
" "
+
this
.
notFound
);
else
if
(
responseCode
==
400
)
throw
new
Exception
(
this
.
serviceText
+
" "
+
service
+
" "
+
this
.
badRequest
);
return
responseCode
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment