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
{
int
id
;
String
description
;
...
...
@@ -41,6 +42,7 @@ class Device{
}
}
class
Event
{
int
id
;
// Device URN id
String
urn
;
...
...
@@ -138,6 +140,7 @@ class Event{
}
}
class
EventType
{
int
id
;
String
name
;
...
...
@@ -152,6 +155,7 @@ class EventType{
}
}
class
SensorLogin
{
String
mail
;
String
password
;
...
...
@@ -220,6 +224,7 @@ abstract class ConfigurationStoreBase {
}
}
class
ConfigurationStoreInstance
extends
ConfigurationStoreBase
{
static
final
ConfigurationStoreInstance
_instance
=
ConfigurationStoreInstance
.
_internal
();
...
...
@@ -251,6 +256,7 @@ abstract class EventStoreBase{
}
}
class
EventStoreInstance
extends
EventStoreBase
{
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 {
debugPrint
(
'Login success. Token: '
+
token
!.
toString
());
}
else
{
throw
Exception
(
'Failed to login
.
'
'Header: '
+
response
.
headers
.
toString
()
+
debugPrint
(
'Failed to login'
'Header: '
+
response
.
headers
.
toString
()
+
' StatusCode: '
+
response
.
statusCode
.
toString
()
+
' Body: '
+
response
.
body
.
toString
());
throw
Exception
(
'Failed to login'
);
}
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> {
super
.
initState
();
}
Future
<
bool
>
syncEvents
()
async
{
//final EventStoreInstance events = EventStoreInstance();
Future
<
void
>
syncEvents
()
async
{
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
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
,
configuration
.
loginInformation
.
password
);
if
(
syncCounter
>
0
)
{
try
{
String
?
token
=
await
connection
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
configuration
.
loginInformation
.
password
);
if
(
token
!=
null
)
{
_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
++
;
if
(
await
connection
.
putEvent
(
event
,
token
)
==
true
){
//Event has been posted to Sensor.
_synccounter
--
;
debugPrint
(
'put success, remaining events: '
+
_synccounter
.
toString
());
event
.
status
=
'EXPORTED'
;
//Update event status so that it is only exported once.
setState
(()
{});
}
else
{
_sync_status
=
'export failed: '
+
event
.
urn
;
if
(
token
!=
null
)
{
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
++
;
if
(
await
connection
.
putEvent
(
event
,
token
)
==
true
)
{
//Event has been posted to Sensor.
syncCounter
--
;
debugPrint
(
'put success, remaining events: '
+
syncCounter
.
toString
());
event
.
status
=
'EXPORTED'
;
//Update event export only once
setState
(()
{});
}
else
{
throw
Exception
(
'Sync for '
+
event
.
urn
+
'failed'
);
}
}
}
_sync_status
=
'export success'
;
}
}
catch
(
e
)
{
debugPrint
(
'Exception:
$e
'
);
_sync_status
=
'
$e
'
;
setState
(()
{});
}
_sync_status
=
'export success'
;
return
true
;
}
else
{
debugPrint
(
'Nothing to export'
)
;
}
return
false
;
}
@override
...
...
@@ -67,168 +75,174 @@ class _ViewEvents extends State<ViewEvents> {
title:
const
Text
(
"View Added Events"
),
),
body:
Container
(
margin:
const
EdgeInsets
.
symmetric
(
horizontal:
5.0
),
child:
SingleChildScrollView
(
scrollDirection:
Axis
.
horizontal
,
child:
SingleChildScrollView
(
scrollDirection:
Axis
.
vertical
,
child:
DataTable
(
margin:
const
EdgeInsets
.
symmetric
(
horizontal:
5.0
),
child:
SingleChildScrollView
(
scrollDirection:
Axis
.
horizontal
,
child:
SingleChildScrollView
(
scrollDirection:
Axis
.
vertical
,
child:
DataTable
(
columns:
const
<
DataColumn
>[
DataColumn
(
label:
Text
(
'Id'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
columns:
const
<
DataColumn
>[
DataColumn
(
label:
Text
(
'Id'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
),
),
),
DataColumn
(
label:
Text
(
'URN'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'URN'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
),
DataColumn
(
label:
Text
(
'Label'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'Label'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
),
DataColumn
(
label:
Text
(
'Type'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'Type'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
),
DataColumn
(
label:
Text
(
'Description'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'Description'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
),
DataColumn
(
label:
Text
(
'StartDate'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'StartDate'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
),
DataColumn
(
label:
Text
(
'EndDate'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'EndDate'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
),
DataColumn
(
label:
Text
(
'Latitude'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'Latitude'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
),
DataColumn
(
label:
Text
(
'Longitude'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'Longitude'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
),
DataColumn
(
label:
Text
(
'Elevation'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'Elevation'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
),
DataColumn
(
label:
Text
(
'Status'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
),
DataColumn
(
label:
Text
(
'Status'
,
style:
TextStyle
(
fontStyle:
FontStyle
.
italic
)
,
),
),
)
,
],
rows:
<
DataRow
>[
for
(
var
event
in
_events
.
events
)
DataRow
(
cells:
<
DataCell
>[
DataCell
(
Text
(
event
.
id
.
toString
()
)),
DataCell
(
Text
(
event
.
urn
)),
DataC
el
l
(
TextFormField
(
readOnly:
true
,
initialValue:
event
.
label
,
onFieldSubmitted:
(
val
)
{
event
.
label
=
val
;
//Update Database
}
,
]
,
rows:
<
DataRow
>[
for
(
var
event
in
_events
.
events
)
DataRow
(
cells:
<
DataCell
>[
DataCell
(
Text
(
event
.
id
.
toString
())),
DataCell
(
Text
(
event
.
urn
)),
DataCell
(
TextFormFi
el
d
(
readOnly:
true
,
initialValue:
event
.
label
,
onFieldSubmitted:
(
val
)
{
event
.
label
=
val
;
//Update Database
},
)
,
),
),
DataCell
(
Text
(
event
.
type
)),
DataC
el
l
(
TextFormField
(
readOnly:
true
,
initialValue:
event
.
description
,
onFieldSubmitted:
(
val
)
{
event
.
description
=
val
;
//Update Database
}
,
DataCell
(
Text
(
event
.
type
)
),
DataCell
(
TextFormFi
el
d
(
readOnly:
true
,
initialValue:
event
.
description
,
onFieldSubmitted:
(
val
)
{
event
.
description
=
val
;
//Update Database
},
)
,
),
),
DataCell
(
Text
(
event
.
start
Date
)),
DataCell
(
Text
(
event
.
endDate
)),
DataC
el
l
(
TextFormField
(
readOnly:
tru
e
,
initialValue:
event
.
latitude
,
onFieldSubmitted:
(
val
)
{
event
.
latitude
=
val
;
//Update Database
}
,
DataCell
(
Text
(
event
.
startDate
)
),
DataCell
(
Text
(
event
.
end
Date
)),
DataCell
(
TextFormFi
el
d
(
readOnly:
true
,
initialValue:
event
.
latitud
e
,
onFieldSubmitted:
(
val
)
{
event
.
latitude
=
val
;
//Update Database
},
)
,
),
),
DataC
el
l
(
TextFormField
(
readOnly:
tru
e
,
initialValue:
event
.
longitude
,
onFieldSubmitted:
(
val
)
{
event
.
longitude
=
val
;
//Update Database
}
,
DataCell
(
TextFormFi
el
d
(
readOnly:
true
,
initialValue:
event
.
longitud
e
,
onFieldSubmitted:
(
val
)
{
event
.
longitude
=
val
;
//Update Database
},
)
,
),
),
DataC
el
l
(
TextFormField
(
readOnly:
true
,
initialValue:
event
.
elevation
,
onFieldSubmitted:
(
val
)
{
event
.
elevation
=
val
;
//Update Database
}
,
DataCell
(
TextFormFi
el
d
(
readOnly:
true
,
initialValue:
event
.
elevation
,
onFieldSubmitted:
(
val
)
{
event
.
elevation
=
val
;
//Update Database
},
)
,
),
),
DataCell
(
TextFormField
(
readOnly:
true
,
controller:
TextEditingController
(
//Required to update field here
DataCell
(
TextFormField
(
readOnly:
true
,
controller:
TextEditingController
(
//Required to update field here
text:
event
.
status
,
),
onFieldSubmitted:
(
val
)
{
event
.
status
=
val
;
//Update Database
},
),
onFieldSubmitted:
(
val
)
{
event
.
status
=
val
;
//Update Database
},
),
)
,
]
,
)
,
]
,
]
,
)
,
]
,
)
,
),
),
),
),
bottomNavigationBar:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetwe
en
,
mainAxisAlignment:
MainAxisAlignment
.
en
d
,
children:
[
const
SizedBox
(
width:
10
),
Text
(
_sync_status
),
FloatingActionButton
.
extended
(
heroTag:
null
,
tooltip:
'Upload Events'
,
icon:
null
,
label:
const
Text
(
'Sync'
),
onPressed:
()
{
syncEvents
();
},
const
SizedBox
(
width:
50
),
Container
(
margin:
const
EdgeInsets
.
symmetric
(
vertical:
10.0
),
child:
FloatingActionButton
.
extended
(
heroTag:
null
,
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