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'], collectionName: json['collectionName'], ); } Map<String, dynamic> toJson() => { 'id': id, 'description': description, 'collectionName' : collectionName }; @override String toString(){ return collectionName; } } 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 }; @override String toString(){ return '{ ${this.id}, ${this.urn} }'; } } class Event{ int id; // Device URN id String urn; String label; String type; // Event type name TODO: this should be an EventType variable int typeId; String description; String status; String startDate; String endDate; String latitude; String longitude; String elevation; Event({ required this.id, 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'], 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> toJson() => { 'id': id, '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\"":"\"$id\"", "\"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.urn}, ' '${this.label}, ' '${this.type}, ' '${this.description}, ' '${this.startDate}, ' '${this.endDate}, ' '${this.latitude},' '${this.longitude},' '${this.elevation},' '${this.status} }'; } } class EventType{ int id; String name; EventType( this.id, this.name ); factory EventType.fromSensorJson(Map<String, dynamic> parsedJson){ return EventType(parsedJson['id'] as int, parsedJson['generalName'] as String); } EventType.fromJson(Map<String, dynamic> json) : id = json['id'], name = json['name']; Map<String, dynamic> toJson() => { 'id': id, 'name': name, }; } class SensorLogin{ String mail; String password; SensorLogin( this.mail, this.password, ); String toJsonString() { return '{ "username": $mail, "authPassword": $password }'; } Map<String, dynamic> toJson() => { "username": mail, "authPassword": 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 = []; SensorLogin loginInformation = SensorLogin('', ''); bool initialized = false; Collection getCollectionFromName(String name) { for (var collection in collections) { if (collection.collectionName == name) { return collection; } } throw Exception('Event with name :' + name + ' was not found.'); } int getDeviceIdFromUrn(String urn) { for (var device in devices) { if (device.urn == urn) { return device.id; } } throw Exception('Device with urn:' + urn + ' was not found.'); } int getEventIdFromName(String name) { for (var eventType in eventTypes) { if (eventType.name == name) { return eventType.id; } } throw Exception('Event with name :' + name + ' was not found.'); } void reset(){ 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() { return _instance; } ConfigurationStoreInstance._internal() { collections = []; devices = []; eventTypes = []; } } abstract class EventStoreBase{ List<Event> events = []; Event currentEvent = Event( id:-1, urn:'urn0', label:'', type:'', typeId:-1, description:'', status:'PENDING', startDate:'', endDate: '', latitude: '', longitude: '', elevation: '' ); int getPendingEventCount(){ int count = 0; for (var event in events) { if (event.status == 'PENDING') { count++; } } return count; } } class EventStoreInstance extends EventStoreBase { static final EventStoreInstance _instance = EventStoreInstance._internal(); factory EventStoreInstance() { return _instance; } EventStoreInstance._internal() { events = []; currentEvent = Event( id:-1, urn:'urn0', label:'', type:'', typeId:-1, description:'', status:'PENDING', startDate:'', endDate: '', latitude: '', longitude: '', elevation: '' );; } void reset(){ events = []; currentEvent = Event( id:-1, urn:'urn0', label:'', type:'', typeId:-1, description:'', status:'PENDING', startDate:'', endDate: '', latitude: '', longitude: '', elevation: '' ); } }