Skip to content
Snippets Groups Projects
datamodel.dart 5.13 KiB
Newer Older
import 'package:shared_preferences/shared_preferences.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'],
      collectionName: json['collectionName'],
      description: json['description'],
    );
  }

  @override
  String toString(){
    return collectionName;
  }
}

class Device{
  int id;
  String urn;

  Device(this.id, this.urn);

  factory Device.fromJson(Map<String, dynamic> parsedJson){
    return Device( parsedJson['id'] as int,
        parsedJson['urn'] as String);
  }

  @override
  String toString(){
    return '{ ${this.id}, ${this.urn} }';
  }
}

  int id;
  String urn;
  String label;
  String type;
  String description;
  String status;
Maximilian Betz's avatar
Maximilian Betz committed
  String latitude;
  String longitude;
  String elevation;
Maximilian Betz's avatar
Maximilian Betz committed
      this.id,
      this.urn,
      this.label,
      this.type,
      this.description,
      this.status,
      [this.latitude = "",
      this.longitude = "",
      this.elevation = ""]
      );

  factory Event.fromJson(Map<String, dynamic> parsedJson){
    return Event( parsedJson['id'] as int,
Maximilian Betz's avatar
Maximilian Betz committed
      parsedJson['urn'] as String,
      parsedJson['label'] as String,
      parsedJson['type'] as String,
      parsedJson['description'] as String,
      parsedJson['status'] as String,
      "",
      "",
      "",
    );
Maximilian Betz's avatar
Maximilian Betz committed
    return '{ ${this.id}, '
        '${this.urn}, '
        '${this.label}, '
        '${this.type}, '
        '${this.description}, '
        '${this.latitude},'
        '${this.longitude},'
        '${this.elevation},'
        '${this.status} }';

  factory EventType.fromJson(Map<String, dynamic> parsedJson){
    return EventType(parsedJson['id'] as int, parsedJson['name'] as String);
  }
}

abstract class CollectionStoreBase {
  List<Collection> store = [];

  Collection getCollectionFromName(String name) {
    for (var collection in store) {
      if (collection.collectionName == name) {
        return collection;
      }
    }
    throw Exception('Event with name :' + name + ' was not found.');
  }

}

class CollectionStoreInstance extends CollectionStoreBase {
  static final CollectionStoreInstance _instance = CollectionStoreInstance
      ._internal();

  factory CollectionStoreInstance() {
    return _instance;
  }

  CollectionStoreInstance._internal() {
    store = [];
  }

  void reset() {
    store = [];
  }
}


abstract class DeviceStoreBase {
  List<Device> store = [];

  int getDeviceIdFromUrn(String urn) {
    for (var device in store) {
      if (device.urn == urn) {
        return device.id;
      }
    }
    throw Exception('Device with urn:' + urn + ' was not found.');
  }

  void reset(){
    store = [];
  }
}

abstract class EventStoreBase{
  List<Event> store = [];
}

abstract class EventCurrentBase{
  Event store = Event(0, 'urn0', '', '', '', 'PENDING');
}

abstract class CollectionCurrentBase{
  Collection store = Collection(id: -1, description: '', collectionName: '');
abstract class EventTypeStoreBase{
  List<EventType> store = [];

  int getEventIdFromName(String name) {
    for (var eventType in store) {
      if (eventType.name == name) {
        return eventType.id;
      }
    }
    throw Exception('Event with name :' + name + ' was not found.');
  }
}

class EventStoreInstance extends EventStoreBase {
  static final EventStoreInstance _instance = EventStoreInstance._internal();

  factory EventStoreInstance() {
    return _instance;
  }
  EventStoreInstance._internal() {
    store = [];
  }

  void reset(){
    store = [];
  }
class EventCurrentInstance extends EventCurrentBase {
  static final EventCurrentInstance _instance = EventCurrentInstance._internal();

  factory EventCurrentInstance(){
    return _instance;
  }

  EventCurrentInstance._internal(){
    store = Event(-1, 'urn0', '', '', '', 'PENDING');
  }

  void reset(){
    store = Event(-1, 'urn0', '', '', '', 'PENDING');
class CollectionCurrentInstance extends CollectionCurrentBase {
  static final CollectionCurrentInstance _instance = CollectionCurrentInstance._internal();

  factory CollectionCurrentInstance(){
    return _instance;
  }

  CollectionCurrentInstance._internal(){
    store = Collection(collectionName: 'name', description: 'description', id: -1);
  }

  void reset(){
    store = Collection(collectionName: 'name', description: 'description', id: -1);
  }
}

class EventTypeStoreInstance extends EventTypeStoreBase{
  static final EventTypeStoreInstance _instance = EventTypeStoreInstance._internal();
  factory EventTypeStoreInstance(){
    return _instance;
  }

  EventTypeStoreInstance._internal(){
    store = [];
  }


  void reset(){
    store = [];
  }
}


class DeviceStoreInstance extends DeviceStoreBase{
  static final DeviceStoreInstance _instance = DeviceStoreInstance._internal();

  factory DeviceStoreInstance(){
    return _instance;
  }

  DeviceStoreInstance._internal(){
    store = [];
  }