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
3726e09e
Commit
3726e09e
authored
3 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
moved event put logic to sensorconnector.dart
parent
07ae2545
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/sensorconnector.dart
+0
-1
0 additions, 1 deletion
lib/sensorconnector.dart
lib/viewevents.dart
+10
-76
10 additions, 76 deletions
lib/viewevents.dart
with
10 additions
and
77 deletions
lib/sensorconnector.dart
+
0
−
1
View file @
3726e09e
...
@@ -114,7 +114,6 @@ class SensorConnector {
...
@@ -114,7 +114,6 @@ class SensorConnector {
encoding:
Encoding
.
getByName
(
"utf-8"
),
encoding:
Encoding
.
getByName
(
"utf-8"
),
);
);
if
(
response
.
statusCode
==
201
)
{
if
(
response
.
statusCode
==
201
)
{
event
.
status
=
'EXPORTED'
;
//Update the event status so that it is only exported once.
return
true
;
return
true
;
}
else
{
}
else
{
throw
Exception
(
'Failed to put event. '
throw
Exception
(
'Failed to put event. '
...
...
This diff is collapsed.
Click to expand it.
lib/viewevents.dart
+
10
−
76
View file @
3726e09e
...
@@ -2,6 +2,7 @@ import 'dart:convert';
...
@@ -2,6 +2,7 @@ import 'dart:convert';
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'datamodel.dart'
;
import
'datamodel.dart'
;
import
'package:http/http.dart'
as
http
;
import
'package:http/http.dart'
as
http
;
import
'sensorconnector.dart'
;
class
ViewEvents
extends
StatefulWidget
{
class
ViewEvents
extends
StatefulWidget
{
const
ViewEvents
({
Key
?
key
})
:
super
(
key:
key
);
const
ViewEvents
({
Key
?
key
})
:
super
(
key:
key
);
...
@@ -13,58 +14,15 @@ class ViewEvents extends StatefulWidget {
...
@@ -13,58 +14,15 @@ class ViewEvents extends StatefulWidget {
class
_ViewEvents
extends
State
<
ViewEvents
>
{
class
_ViewEvents
extends
State
<
ViewEvents
>
{
int
_synccounter
=
0
;
//For displaying progress during event upload
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
{
Future
<
bool
>
syncEvents
()
async
{
final
EventStoreInstance
events
=
EventStoreInstance
();
final
EventStoreInstance
events
=
EventStoreInstance
();
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
S
tring
?
token
=
await
login
();
S
ensorConnector
connection
=
SensorConnector
();
if
(
token
!=
null
)
{
String
?
token
=
await
connection
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
String
baseUrl
=
'https://sandbox.sensor.awi.de/rest/sensors/events/putEvent/'
;
configuration
.
loginInformation
.
password
);
String
url
=
''
;
if
(
token
!=
null
)
{
_synccounter
=
events
.
getPendingEventCount
();
_synccounter
=
events
.
getPendingEventCount
();
debugPrint
(
'Number of Events: '
+
events
.
events
.
length
.
toString
());
debugPrint
(
'Number of Events: '
+
events
.
events
.
length
.
toString
());
debugPrint
(
'Number of Pending Events: '
+
_synccounter
.
toString
());
debugPrint
(
'Number of Pending Events: '
+
_synccounter
.
toString
());
...
@@ -74,37 +32,13 @@ class _ViewEvents extends State<ViewEvents> {
...
@@ -74,37 +32,13 @@ class _ViewEvents extends State<ViewEvents> {
debugPrint
(
'Idx: '
+
index
.
toString
()
+
' '
+
debugPrint
(
'Idx: '
+
index
.
toString
()
+
' '
+
event
.
toSensorJson
()
.
toString
());
event
.
toSensorJson
()
.
toString
());
index
++
;
index
++
;
if
(
await
connection
.
putEvent
(
event
,
token
)
==
true
){
url
=
baseUrl
+
event
.
id
.
toString
()
+
'?createVersion=false'
;
//Event has been posted to Sensor.
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
--
;
_synccounter
--
;
debugPrint
(
debugPrint
(
'put success, remaining events: '
+
_synccounter
.
toString
());
'put success, remaining events: '
+
_synccounter
.
toString
());
event
.
status
=
'EXPORTED'
;
//Update event status so that it is only exported once.
event
.
status
=
'EXPORTED'
;
//Update event status so that it is only exported once.
setState
(()
{});
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.'
);
}
}
setState
(()
{});
}
}
}
}
return
true
;
return
true
;
...
...
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