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
2ec0e10f
Commit
2ec0e10f
authored
3 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
improved exception handling
parent
6596ab64
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
lib/datamodel.dart
+6
-0
6 additions, 0 deletions
lib/datamodel.dart
lib/sensorconnector.dart
+4
-2
4 additions, 2 deletions
lib/sensorconnector.dart
lib/viewevents.dart
+174
-160
174 additions, 160 deletions
lib/viewevents.dart
with
184 additions
and
162 deletions
lib/datamodel.dart
+
6
−
0
View file @
2ec0e10f
class
Collection
{
class
Collection
{
int
id
;
int
id
;
String
description
;
String
description
;
...
@@ -41,6 +42,7 @@ class Device{
...
@@ -41,6 +42,7 @@ class Device{
}
}
}
}
class
Event
{
class
Event
{
int
id
;
// Device URN id
int
id
;
// Device URN id
String
urn
;
String
urn
;
...
@@ -138,6 +140,7 @@ class Event{
...
@@ -138,6 +140,7 @@ class Event{
}
}
}
}
class
EventType
{
class
EventType
{
int
id
;
int
id
;
String
name
;
String
name
;
...
@@ -152,6 +155,7 @@ class EventType{
...
@@ -152,6 +155,7 @@ class EventType{
}
}
}
}
class
SensorLogin
{
class
SensorLogin
{
String
mail
;
String
mail
;
String
password
;
String
password
;
...
@@ -220,6 +224,7 @@ abstract class ConfigurationStoreBase {
...
@@ -220,6 +224,7 @@ abstract class ConfigurationStoreBase {
}
}
}
}
class
ConfigurationStoreInstance
extends
ConfigurationStoreBase
{
class
ConfigurationStoreInstance
extends
ConfigurationStoreBase
{
static
final
ConfigurationStoreInstance
_instance
=
ConfigurationStoreInstance
static
final
ConfigurationStoreInstance
_instance
=
ConfigurationStoreInstance
.
_internal
();
.
_internal
();
...
@@ -251,6 +256,7 @@ abstract class EventStoreBase{
...
@@ -251,6 +256,7 @@ abstract class EventStoreBase{
}
}
}
}
class
EventStoreInstance
extends
EventStoreBase
{
class
EventStoreInstance
extends
EventStoreBase
{
static
final
EventStoreInstance
_instance
=
EventStoreInstance
.
_internal
();
static
final
EventStoreInstance
_instance
=
EventStoreInstance
.
_internal
();
...
...
This diff is collapsed.
Click to expand it.
lib/sensorconnector.dart
+
4
−
2
View file @
2ec0e10f
...
@@ -34,10 +34,12 @@ class SensorConnector {
...
@@ -34,10 +34,12 @@ class SensorConnector {
debugPrint
(
'Login success. Token: '
+
token
!.
toString
());
debugPrint
(
'Login success. Token: '
+
token
!.
toString
());
}
else
{
}
else
{
throw
Exception
(
'Failed to login
.
'
debugPrint
(
'Failed to login'
'Header: '
+
response
.
headers
.
toString
()
+
'Header: '
+
response
.
headers
.
toString
()
+
' StatusCode: '
+
response
.
statusCode
.
toString
()
+
' StatusCode: '
+
response
.
statusCode
.
toString
()
+
' Body: '
+
response
.
body
.
toString
());
' Body: '
+
response
.
body
.
toString
());
throw
Exception
(
'Failed to login'
);
}
}
return
token
;
return
token
;
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/viewevents.dart
+
174
−
160
View file @
2ec0e10f
...
@@ -23,40 +23,48 @@ class _ViewEvents extends State<ViewEvents> {
...
@@ -23,40 +23,48 @@ class _ViewEvents extends State<ViewEvents> {
super
.
initState
();
super
.
initState
();
}
}
Future
<
bool
>
syncEvents
()
async
{
Future
<
void
>
syncEvents
()
async
{
//final EventStoreInstance events = EventStoreInstance();
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
SensorConnector
connection
=
SensorConnector
();
SensorConnector
connection
=
SensorConnector
();
int
_
sync
c
ounter
=
0
;
//For displaying progress during event upload
int
sync
C
ounter
=
_events
.
getPendingEventCount
();;
//For displaying progress during event upload
String
?
token
=
await
connection
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
if
(
syncCounter
>
0
)
{
configuration
.
loginInformation
.
password
);
try
{
String
?
token
=
await
connection
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
configuration
.
loginInformation
.
password
);
if
(
token
!=
null
)
{
if
(
token
!=
null
)
{
_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
());
var
index
=
0
;
var
index
=
0
;
for
(
var
event
in
_events
.
events
)
{
for
(
var
event
in
_events
.
events
)
{
if
(
event
.
status
==
'PENDING'
)
{
if
(
event
.
status
==
'PENDING'
)
{
debugPrint
(
'Idx: '
+
index
.
toString
()
+
' '
+
debugPrint
(
'Idx: '
+
index
.
toString
()
+
' '
+
event
.
toSensorJson
()
.
toString
());
event
.
toSensorJson
()
.
toString
());
index
++
;
index
++
;
if
(
await
connection
.
putEvent
(
event
,
token
)
==
true
)
{
if
(
await
connection
.
putEvent
(
event
,
token
)
==
true
){
//Event has been posted to Sensor.
//Event has been posted to Sensor.
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 export only once
setState
(()
{});
setState
(()
{});
}
else
{
}
else
{
_sync_status
=
'export failed: '
+
event
.
urn
;
throw
Exception
(
'Sync for '
+
event
.
urn
+
'failed'
);
}
}
}
}
_sync_status
=
'export success'
;
}
}
}
catch
(
e
)
{
debugPrint
(
'Exception:
$e
'
);
_sync_status
=
'
$e
'
;
setState
(()
{});
}
}
_sync_status
=
'export success'
;
}
else
{
return
true
;
debugPrint
(
'Nothing to export'
)
;
}
}
return
false
;
}
}
@override
@override
...
@@ -67,168 +75,174 @@ class _ViewEvents extends State<ViewEvents> {
...
@@ -67,168 +75,174 @@ class _ViewEvents extends State<ViewEvents> {
title:
const
Text
(
"View Added Events"
),
title:
const
Text
(
"View Added Events"
),
),
),
body:
Container
(
body:
Container
(
margin:
const
EdgeInsets
.
symmetric
(
horizontal:
5.0
),
margin:
const
EdgeInsets
.
symmetric
(
horizontal:
5.0
),
child:
child:
SingleChildScrollView
(
SingleChildScrollView
(
scrollDirection:
Axis
.
horizontal
,
scrollDirection:
Axis
.
horizontal
,
child:
SingleChildScrollView
(
child:
SingleChildScrollView
(
scrollDirection:
Axis
.
vertical
,
scrollDirection:
Axis
.
vertical
,
child:
DataTable
(
child:
DataTable
(
columns:
const
<
DataColumn
>[
columns:
const
<
DataColumn
>[
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'Id'
,
'Id'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'URN'
,
'URN'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'Label'
,
'Label'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'Type'
,
'Type'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'Description'
,
'Description'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'StartDate'
,
'StartDate'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'EndDate'
,
'EndDate'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'Latitude'
,
'Latitude'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'Longitude'
,
'Longitude'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'Elevation'
,
'Elevation'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
),
DataColumn
(
DataColumn
(
label:
Text
(
label:
Text
(
'Status'
,
'Status'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
)
,
]
,
],
rows:
<
DataRow
>[
rows:
<
DataRow
>[
for
(
var
event
in
_events
.
events
)
for
(
var
event
in
_events
.
events
)
DataRow
(
DataRow
(
cells:
<
DataCell
>[
cells:
<
DataCell
>[
DataCell
(
Text
(
event
.
id
.
toString
())),
DataCell
(
Text
(
event
.
id
.
toString
()
)),
DataCell
(
Text
(
event
.
urn
)),
DataCell
(
Text
(
event
.
urn
)),
DataCell
(
DataC
el
l
(
TextFormFi
el
d
(
TextFormField
(
readOnly:
true
,
readOnly:
true
,
initialValue:
event
.
label
,
initialValue:
event
.
label
,
onFieldSubmitted:
(
val
)
{
onFieldSubmitted:
(
val
)
{
event
.
label
=
val
;
//Update Database
event
.
label
=
val
;
//Update Database
},
}
,
)
,
),
),
),
DataCell
(
Text
(
event
.
type
)
),
DataCell
(
Text
(
event
.
type
)),
DataCell
(
DataC
el
l
(
TextFormFi
el
d
(
TextFormField
(
readOnly:
true
,
readOnly:
true
,
initialValue:
event
.
description
,
initialValue:
event
.
description
,
onFieldSubmitted:
(
val
)
{
onFieldSubmitted:
(
val
)
{
event
.
description
=
val
;
//Update Database
event
.
description
=
val
;
//Update Database
},
}
,
)
,
),
),
),
DataCell
(
Text
(
event
.
startDate
)
),
DataCell
(
Text
(
event
.
start
Date
)),
DataCell
(
Text
(
event
.
end
Date
)),
DataCell
(
Text
(
event
.
endDate
)),
DataCell
(
DataC
el
l
(
TextFormFi
el
d
(
TextFormField
(
readOnly:
true
,
readOnly:
tru
e
,
initialValue:
event
.
latitud
e
,
initialValue:
event
.
latitude
,
onFieldSubmitted:
(
val
)
{
onFieldSubmitted:
(
val
)
{
event
.
latitude
=
val
;
//Update Database
event
.
latitude
=
val
;
//Update Database
},
}
,
)
,
),
),
),
DataCell
(
DataC
el
l
(
TextFormFi
el
d
(
TextFormField
(
readOnly:
true
,
readOnly:
tru
e
,
initialValue:
event
.
longitud
e
,
initialValue:
event
.
longitude
,
onFieldSubmitted:
(
val
)
{
onFieldSubmitted:
(
val
)
{
event
.
longitude
=
val
;
//Update Database
event
.
longitude
=
val
;
//Update Database
},
}
,
)
,
),
),
),
DataCell
(
DataC
el
l
(
TextFormFi
el
d
(
TextFormField
(
readOnly:
true
,
readOnly:
true
,
initialValue:
event
.
elevation
,
initialValue:
event
.
elevation
,
onFieldSubmitted:
(
val
)
{
onFieldSubmitted:
(
val
)
{
event
.
elevation
=
val
;
//Update Database
event
.
elevation
=
val
;
//Update Database
},
}
,
)
,
),
),
),
DataCell
(
DataCell
(
TextFormField
(
TextFormField
(
readOnly:
true
,
readOnly:
true
,
controller:
TextEditingController
(
//Required to update field here
controller:
TextEditingController
(
//Required to update field here
text:
event
.
status
,
text:
event
.
status
,
),
onFieldSubmitted:
(
val
)
{
event
.
status
=
val
;
//Update Database
},
),
),
onFieldSubmitted:
(
val
)
{
event
.
status
=
val
;
//Update Database
},
),
),
)
,
]
,
]
,
)
,
)
,
]
,
]
,
)
,
),
),
),
),
),
),
),
bottomNavigationBar:
Row
(
bottomNavigationBar:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetwe
en
,
mainAxisAlignment:
MainAxisAlignment
.
en
d
,
children:
[
children:
[
const
SizedBox
(
width:
10
),
const
SizedBox
(
width:
10
),
Text
(
_sync_status
),
Text
(
_sync_status
),
FloatingActionButton
.
extended
(
const
SizedBox
(
width:
50
),
heroTag:
null
,
Container
(
tooltip:
'Upload Events'
,
margin:
const
EdgeInsets
.
symmetric
(
vertical:
10.0
),
icon:
null
,
child:
label:
const
Text
(
'Sync'
),
FloatingActionButton
.
extended
(
onPressed:
()
{
heroTag:
null
,
syncEvents
();
tooltip:
'Upload Events'
,
},
icon:
null
,
label:
const
Text
(
'Sync'
),
onPressed:
()
{
syncEvents
();
},
),
),
),
const
SizedBox
(
width:
10.0
),
],
],
),
),
);
);
...
...
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