Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MobileEventLog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Data-Logistics-Support
MobileEventLog
Commits
546cec09
Commit
546cec09
authored
3 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
updated gathering token on each sync
parent
3fa6b83c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-0
1 addition, 0 deletions
README.md
lib/configuration.dart
+1
-0
1 addition, 0 deletions
lib/configuration.dart
lib/viewevents.dart
+84
-41
84 additions, 41 deletions
lib/viewevents.dart
with
86 additions
and
41 deletions
README.md
+
1
−
0
View file @
546cec09
...
...
@@ -57,4 +57,5 @@ a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :
## TODOs
-
FlutterSecureStorage for user password?
This diff is collapsed.
Click to expand it.
lib/configuration.dart
+
1
−
0
View file @
546cec09
...
...
@@ -29,6 +29,7 @@ Future<int> login() async {
debugPrint
(
'Login success'
);
//TODO: display feedback to user that credentials are correct
debugPrint
(
response
.
headers
[
'set-cookie'
]
?.
split
(
';'
)[
0
]
.
toString
());
debugPrint
(
response
.
body
.
toString
());
debugPrint
(
response
.
headers
.
toString
());
debugPrint
(
response
.
headers
[
'set-cookie'
]);
...
...
This diff is collapsed.
Click to expand it.
lib/viewevents.dart
+
84
−
41
View file @
546cec09
...
...
@@ -15,60 +15,103 @@ class ViewEvents extends StatefulWidget {
class
_ViewEvents
extends
State
<
ViewEvents
>
{
int
_synccounter
=
0
;
//For displaying progress during event upload
Future
<
String
?
>
login
()
async
{
String
?
token
;
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
String
url
=
'https://sandbox.sensor.awi.de/rest/sensors/contacts/login'
;
debugPrint
(
"Start login to : "
+
url
);
Map
<
String
,
dynamic
>
body
=
{
'username'
:
configuration
.
loginInformation
.
mail
,
'authPassword'
:
configuration
.
loginInformation
.
password
};
String
encodedBody
=
body
.
keys
.
map
((
key
)
=
>
"
$key
=
${body[key]}
"
)
.
join
(
"&"
);
debugPrint
(
encodedBody
);
final
response
=
await
http
.
post
(
Uri
.
parse
(
url
),
body:
encodedBody
,
headers:
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/x-www-form-urlencoded'
},
encoding:
Encoding
.
getByName
(
"utf-8"
)
);
if
(
response
.
statusCode
==
200
)
{
debugPrint
(
'Login success'
);
//TODO: display feedback to user that credentials are correct
token
=
response
.
headers
[
'set-cookie'
]
?.
split
(
';'
)[
0
];
debugPrint
(
"Token:"
+
token
!
);
debugPrint
(
response
.
body
.
toString
());
debugPrint
(
response
.
headers
.
toString
());
debugPrint
(
response
.
headers
[
'set-cookie'
]);
}
else
{
debugPrint
(
'Header: '
+
response
.
headers
.
toString
());
debugPrint
(
'Body: '
+
response
.
body
.
toString
());
debugPrint
(
'StatusCode: '
+
response
.
statusCode
.
toString
());
throw
Exception
(
'Failed to login'
);
}
return
token
;
}
Future
<
bool
>
syncEvents
()
async
{
final
EventStoreInstance
events
=
EventStoreInstance
();
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
String
?
token
=
await
login
();
String
baseUrl
=
'https://sandbox.sensor.awi.de/rest/sensors/events/putEvent/'
;
String
url
=
''
;
_synccounter
=
events
.
getPendingEventCount
();
debugPrint
(
'Number of Events: '
+
events
.
events
.
length
.
toString
());
debugPrint
(
'Number of Pending Events: '
+
_synccounter
.
toString
());
var
index
=
0
;
for
(
var
event
in
events
.
events
){
if
(
event
.
status
==
'PENDING'
)
{
debugPrint
(
'Idx: '
+
index
.
toString
()
+
' '
+
event
.
toSensorJson
()
.
toString
());
index
++
;
url
=
baseUrl
+
event
.
id
.
toString
()
+
'?createVersion=false'
;
debugPrint
(
'XXX '
+
Uri
.
parse
(
url
)
.
toString
());
final
response
=
await
http
.
put
(
Uri
.
parse
(
url
),
headers:
{
"Content-Type"
:
"application/json"
,
"Cookie"
:
"x-auth-token=72d9d4d20a33f87edca7e1ba01ce8db8"
},
body:
event
.
toSensorJson
()
.
toString
(),
encoding:
Encoding
.
getByName
(
"utf-8"
),
);
if
(
response
.
statusCode
==
201
)
{
_synccounter
--
;
debugPrint
(
'put success, remaining events: '
+
_synccounter
.
toString
());
event
.
status
=
'EXPORTED'
;
//Update event status so that it is only exported once.
if
(
token
!=
null
)
{
String
baseUrl
=
'https://sandbox.sensor.awi.de/rest/sensors/events/putEvent/'
;
String
url
=
''
;
//if(mounted){
// setState(() { //refresh the UI
// });}
_synccounter
=
events
.
getPendingEventCount
();
debugPrint
(
'Number of Events: '
+
events
.
events
.
length
.
toString
());
debugPrint
(
'Number of Pending Events: '
+
_synccounter
.
toString
());
var
index
=
0
;
for
(
var
event
in
events
.
events
)
{
if
(
event
.
status
==
'PENDING'
)
{
debugPrint
(
'Idx: '
+
index
.
toString
()
+
' '
+
event
.
toSensorJson
()
.
toString
());
index
++
;
setState
(()
{
url
=
baseUrl
+
event
.
id
.
toString
()
+
'?createVersion=false'
;
debugPrint
(
'XXX '
+
Uri
.
parse
(
url
)
.
toString
());
final
response
=
await
http
.
put
(
Uri
.
parse
(
url
),
headers:
{
"Content-Type"
:
"application/json"
,
"Cookie"
:
token
},
body:
event
.
toSensorJson
()
.
toString
(),
encoding:
Encoding
.
getByName
(
"utf-8"
),
);
if
(
response
.
statusCode
==
201
)
{
_synccounter
--
;
debugPrint
(
'put success, remaining events: '
+
_synccounter
.
toString
());
event
.
status
=
'EXPORTED'
;
//Update event status so that it is only exported once.
});
debugPrint
(
response
.
body
.
toString
());
debugPrint
(
response
.
headers
.
toString
());
debugPrint
(
response
.
headers
[
'set-cookie'
]);
setState
(()
{});
}
else
{
debugPrint
(
'Header: '
+
response
.
headers
.
toString
());
debugPrint
(
'Body: '
+
response
.
body
.
toString
());
debugPrint
(
'StatusCode: '
+
response
.
statusCode
.
toString
());
throw
Exception
(
'Failed to put.'
);
debugPrint
(
response
.
body
.
toString
());
debugPrint
(
response
.
headers
.
toString
());
debugPrint
(
response
.
headers
[
'set-cookie'
]);
}
else
{
debugPrint
(
'Header: '
+
response
.
headers
.
toString
());
debugPrint
(
'Body: '
+
response
.
body
.
toString
());
debugPrint
(
'StatusCode: '
+
response
.
statusCode
.
toString
());
throw
Exception
(
'Failed to put.'
);
}
}
}
return
true
;
}
return
tru
e
;
return
fals
e
;
}
@override
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment