Newer
Older
import 'package:flutter/cupertino.dart';
class Collection {
int id;
String description;
String collectionName;
Collection({
required this.id,
required this.description,
required this.collectionName,
});
factory Collection.fromJson(Map<String, dynamic> json) {
return Collection(
id: json['id'],
description: json['description'],
);
}
Map<String, dynamic> toJson() => {
'id': id,
'description': description,
'collectionName' : collectionName
};
@override
String toString(){
return collectionName + ' ' + id.toString() + ' ' + description;
}
}
class Device{
int id;
String urn;
Device(this.id, this.urn);
factory Device.fromJson(Map<String, dynamic> json){
return Device( json['id'] as int,
json['urn'] as String);
Map<String, dynamic> toJson() => {
'id': id,
'urn': urn
};
int id; //This shall be the mysql primary key database id
int urnId;
String type; // Event type name TODO: this should be an EventType variable
int typeId;
String startDate;
String endDate;
String latitude;
String longitude;
String elevation;
required this.urnId,
required this.urn,
required this.label,
required this.type,
required this.typeId,
required this.description,
required this.status,
required this.startDate,
required this.endDate,
required this.latitude,
required this.longitude,
required this.elevation,
});
factory Event.fromJson(Map<String, dynamic> json){
return Event(
id: json['id'],
urnId: json['urnId'],
urn: json['urn'],
label: json['label'],
type: json['type'],
typeId: json['typeId'],
description: json['description'],
status: json['status'],
startDate: json['startDate'],
endDate: json['endDate'],
latitude: json['latitude'],
longitude: json['longitude'],
elevation: json['elevation'],
Map<String, dynamic> toMap() {
return {
'id' : id,
'urnId': urnId,
'urn': urn,
'label': label,
'type' : type,
'typeId' : typeId,
'description' : description,
'status' : status,
'startDate' : startDate,
'endDate' : endDate,
'latitude' : latitude,
'longitude' : longitude,
'elevation' : elevation
};
}
Map<String, dynamic> toMapNoId() {
return {
'urnId': urnId,
'urn': urn,
'label': label,
'type' : type,
'typeId' : typeId,
'description' : description,
'status' : status,
'startDate' : startDate,
'endDate' : endDate,
'latitude' : latitude,
'longitude' : longitude,
'elevation' : elevation
};
}
'id' : id,
'urnId': urnId,
'urn': urn,
'label': label,
'type' : type,
'typeId' : typeId,
'description' : description,
'status' : status,
'startDate' : startDate,
'endDate' : endDate,
'latitude' : latitude,
'longitude' : longitude,
'elevation' : elevation
Map<String, dynamic> toSensorJson() {
return {
"\"itemID\"":"\"$urnId\"",
"\"inheritToAllChildren\"":"\"false\"",
"\"inheritToChildren\"":[],
"\"event\"":{
"\"startDate\"":"\"$startDate\"",
"\"endDate\"":"\"$endDate\"",
"\"label\"":"\"$label\"",
"\"description\"":"\"$description\"",
"\"eventType\"":"\"$typeId\"",
"\"latitude\"":"\"$latitude\"",
"\"longitude\"":"\"$longitude\"",
"\"elevationInMeter\"":"\"$elevation\"",
"\"id\"":"\"0\""
}
@override
String toString(){
return '{ '
'${this.id}, '
'${this.urnId}, '
'${this.urn}, '
'${this.label}, '
'${this.type}, '
'${this.description}, '
'${this.startDate}, '
'${this.endDate}, '
'${this.latitude},'
'${this.longitude},'
'${this.elevation},'
'${this.status} }';
EventType({
required this.id,
required this.name
});
EventType.fromSensorJson(Map<String, dynamic> json)
: id = json['id'],
EventType.fromJson(Map<String, dynamic> json)
: id = json['id'],
name = json['name'];
Map<String, dynamic> toJson() => {
'id': id,
'name': name,
};
@override
String toString(){
return name;
}
class SensorLogin{
String mail;
String password;
SensorLogin(
this.mail,
this.password,
);
Map<String, dynamic> toJson() => {
SensorLogin.fromJson(Map<String, dynamic> json)
: mail = json['mail'],
password = json['password'];
// Storage classes
// ConfigurationStoreBase for Collection, devices, event types, login information
// EventStoreBase for created event information.
abstract class ConfigurationStoreBase {
List<Collection> collections = [];
Collection currentCollection = Collection(id: -1, description: '', collectionName: '');
List<Device> devices = [];
List<EventType> eventTypes = [];
bool initialized = false;
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
Map<String, dynamic> toMap() {
return {
'collections' : jsonEncode(collections),
'currentCollection': currentCollection.toJson(),
'devices': jsonEncode(devices),
'eventTypes': jsonEncode(eventTypes),
'loginInformation' : loginInformation.toJson(),
'initialized' : initialized,
};
}
void fromMap(Map<String, dynamic> map) {
List<dynamic> dynList = jsonDecode(map['collections']);
collections = [];
for (var element in dynList){
collections.add(Collection.fromJson(element));
}
currentCollection = Collection.fromJson(map['currentCollection']);
dynList = jsonDecode(map['devices']);
devices = [];
for (var element in dynList){
devices.add(Device.fromJson(element));
}
dynList = jsonDecode(map['eventTypes']);
eventTypes = [];
for (var element in dynList){
eventTypes.add(EventType.fromJson(element));
}
loginInformation = SensorLogin.fromJson(map['loginInformation']);
initialized = map['initialized'];
}
Collection getCollectionFromName(String name) {
for (var collection in collections) {
if (collection.collectionName == name) {
return collection;
}
}
throw Exception('Event with name :' + name + ' was not found.');
}
if (device.urn == urn) {
return device.id;
}
}
throw Exception('Device with urn:' + urn + ' was not found.');
}
int getEventIdFromName(String name) {
if (eventType.name == name) {
return eventType.id;
}
}
throw Exception('Event with name :' + name + ' was not found.');
}
collections = [];
devices = [];
eventTypes = [];
currentCollection = Collection(id: -1, description: '', collectionName: '');
loginInformation = SensorLogin('admin', 'adminadmin');
initialized = false;
class ConfigurationStoreInstance extends ConfigurationStoreBase {
static final ConfigurationStoreInstance _instance = ConfigurationStoreInstance
._internal();
factory ConfigurationStoreInstance() {
ConfigurationStoreInstance._internal() {
collections = [];
devices = [];
eventTypes = [];
id: 0,
urnId:-1,
urn:'urn0',
label:'',
type:'',
typeId:-1,
description:'',
status:'PENDING',
startDate:'',
endDate: '',
latitude: '',
longitude: '',
elevation: ''
);
Map<String, dynamic> toMap() {
return {
'currentEvent' : currentEvent.toJson()
};
void fromMap(Map<String, dynamic> map) {
currentEvent = Event.fromJson(map['currentEvent']);
}
//String getEventDump(List<Event> events){
// String ev = '[';
// for (var event in events) {
// ev += jsonEncode(event);
// ev += ',';
// }
// ev += ']';
// return ev;
//}
//fromEventDump(dump){
// events = [];
// for (var entry in dump) {
// debugPrint('Added Event from Storage: ' + entry.toString());
// events.add(Event.fromJson(entry));
// }
//}
class EventStoreInstance extends EventStoreBase {
static final EventStoreInstance _instance = EventStoreInstance._internal();
return _instance;
}
id:0,
urnId:-1,
urn:'urn0',
label:'',
type:'',
typeId:-1,
description:'',
status:'PENDING',
startDate:'',
endDate: '',
latitude: '',
longitude: '',
elevation: ''
);;
id:0,
urnId:-1,
urn:'urn0',
label:'',
type:'',
typeId:-1,
description:'',
status:'PENDING',
startDate:'',
endDate: '',
latitude: '',
longitude: '',
elevation: ''
);