var uuid = require('uuid'); // required for generating timebased guids
var moment = require('moment'); // require
/**
* Core Object for operations
* @namespace core/operation
* @class
*/
class Operation {
/**
* Returns an empty operation object
* @constructor
*/
constructor() {
this._createdAt = {
value: null,
label: 'Empfang Server'
}
this._alarmdate = {
value: null,
label: 'Datum'
}
this._alarmtime = {
value: null,
label: 'Uhrzeit'
};
this._alarmtimeCalc = {
value: null,
label: 'Alarmzeit'
};
this._community = {
value: null,
label: 'Gemeinde'
};
this._district = {
value: null,
label: 'Ortsteil'
};
this._gear = {
value: null,
label: 'Einsatzmittel'
};
this._gearCalc = {
value: null,
label: 'Liste Einsatzmittel'
};
this._gkx = {
value: null,
label: 'GK-Koordinate X'
};
this._gky = {
value: null,
label: 'GK-Koordinate Y'
};
this._keywordCategory = {
value: null,
label: 'Stichwort Kategorie'
};
this._keywordId = {
value: null,
label: 'Stichwort ID'
};
this._keywordName = {
value: null,
label: 'Stichwort Name'
};
this._keywordRaw = {
value: null,
label: 'Stichwort ABEK'
};
this._lat = {
value: null,
label: 'WGS84 Latitude'
};
this._location = {
value: null,
label: 'Ort'
};
this._locationCalc = {
value: null,
label: 'Ortsangabe'
}
this._lon = {
value: null,
label: 'WGS84 Longitude'
};
this._message = {
value: null,
label: 'Mitteilung'
};
this._object = {
value: null,
label: 'Objekt'
};
this._operationSourceConnector = {
value: null,
label: 'Quelle'
};
this._operationState = {
value: null,
label: 'Zustand'
};
this._operationnumber = {
value: null,
label: 'Einsatznummer'
};
this._rawdata = {
value: null,
label: 'Alarmierung Rohdaten'
};
this._section = {
value: null,
label: 'Abschnitt'
};
this._street = {
value: null,
label: 'Straße'
};
this._subject = {
value: null,
label: 'Stichwort'
};
this._zveis = {
value: null,
label: 'Schleifen'
};
this._zveisCalc = {
value: null,
label: 'Schleife Liste'
};
this._floor = {
value: null,
label: 'Etage'
}
this._ils = {
value: null,
label: 'Leitstelle'
}
this._uuid = {
value: null,
label: 'UUID'
};
this.setCreatedAtTimestamp();
}
/**
* Automatic timestamp of creation of this object instance
* @type {string}
*/
set createdAt(createdAt) {
this._createdAt.value = createdAt;
}
get createdAt() {
return this._createdAt;
}
/**
* Section information (Kreuzung)
* @type {string}
*/
set section(section) {
this._section.value = section;
// Calculate locationCalc if location and object not set
if ((this.isDefined(this._location) === false) && (this.isDefined(this._object) === false) && (this.isDefined(this._section) === true)) {
this._locationCalc.value = section;
}
}
get section() {
return this._section;
}
/**
* Date the alarm has been raised
* @type {string}
*/
set alarmdate(alarmdate) {
this._alarmdate.value = alarmdate;
if (this._alarmtime.value !== null) {
this._alarmtimeCalc.value = this._alarmdate.value + ' ' + this._alarmtime.value;
}
}
get alarmdate() {
return this._alarmdate;
}
/**
* Time the alarm has been raised
* @type {string}
*/
set alarmtime(alarmtime) {
this._alarmtime.value = alarmtime;
if (this._alarmdate.value !== null) {
this._alarmtimeCalc.value = this._alarmdate.value + ' ' + this._alarmtime.value;
}
}
get alarmtime() {
return this._alarmtime;
}
/**
* Alarm time calculated (will be calculated as soon alarmdate and alarmtime have been set)
* @type {string}
*/
set alarmtimeCalc(alarmtimeCalc) {
this._alarmtimeCalc.value = alarmtimeCalc;
}
get alarmtimeCalc() {
return this._alarmtimeCalc;
}
/**
* Gear as string
* @type {string}
*/
set gear(gear) {
this._gear.value = gear;
this._gearCalc.value = this._gear.value.split(/\r?\n/);
}
get gear() {
return this._gear;
}
/**
* List of gear from gear split by separator character "\n"
* @type {Array}
*/
set gearCalc(gear) {
this._gearCalc.value = gear;
}
get gearCalc() {
return this._gearCalc;
}
/**
* Number of operation as reported by source ('Einsatznummer')
* @type {string}
*/
set operationnumber(operationnumber) {
this._operationnumber.value = operationnumber;
}
get operationnumber() {
return this._operationnumber;
}
/**
* Location ('Einsatznummer')
* @type {string}
*/
set location(location) {
this._location.value = location;
if (this.isDefined(this._location) === true){
this._locationCalc.value = location;
}
}
get location() {
return this._location;
}
/**
* Message for alarm ('Bemerkung')
* @type {string}
*/
set message(message) {
this._message.value = message;
}
get message() {
return this._message;
}
/**
* community ('Gemeinde')
* @type {string}
*/
set community(community) {
this._community.value = community;
}
get community() {
return this._community;
}
/**
* stores the whole alarm as a raw text field ('sds_komplett')
* @type {string}
*/
set rawdata(rawdata) {
this._rawdata.value = rawdata;
}
get rawdata() {
return this._rawdata;
}
/**
* Object named in alarm ('Objekt'), e.g. "Schlosshotel DORMERO Reichenschwand"
* @type {string}
*/
set object(object) {
this._object.value = object;
if (this.isDefined(this._location) === false && this.isDefined(this._object) === true) {
this._locationCalc.value = object;
}
}
get object() {
return this._object;
}
/**
* district
* @type {string}
*/
set district(district) {
this._district.value = district;
}
get district() {
return this._district;
}
/**
* keywordId
* @type {string}
*/
set keywordId(keywordId) {
this._keywordId.value = keywordId;
}
get keywordId() {
return this._keywordId;
}
/**
* keywordCategory
* @type {string}
*/
set keywordCategory(keywordCategory) {
this._keywordCategory.value = keywordCategory;
}
get keywordCategory() {
return this._keywordCategory;
}
/**
* keywordRaw
* @type {string}
*/
set keywordRaw(keywordRaw) {
this._keywordRaw.value = keywordRaw;
}
get keywordRaw() {
return this._keywordRaw;
}
/**
* keywordName
* @type {string}
*/
set keywordName(keywordName) {
this._keywordName.value = keywordName;
}
get keywordName() {
return this._keywordName;
}
/**
* zveis listed in alarm as string. Will calculate zveiCalc after setting
* @type {string}
*/
set zveis(zveis) {
this._zveis.value = zveis;
this._zveisCalc.value = this._zveis.value.split(',');
}
get zveis() {
return this._zveis;
}
/**
* List of ZVEIs as an Array
* @type {Array}
*/
set zveisCalc(zveisCalc) {
this._zveisCalc.value = zveisCalc;
}
get zveisCalc() {
return this._zveisCalc;
}
/**
* Subject of Alarm ('Stichwort')
* @type {string}
*/
set subject(subject) {
this._subject.value = subject;
}
get subject() {
return this._subject;
}
/**
* street
* @type {string}
*/
set street(street) {
this._street.value = street;
if (
(this.isDefined(this._location) === false) &&
(this.isDefined(this._object) === false) &&
(this.isDefined(this._section) === false) &&
(this.isDefined(this._street) === true)
) {
this.locationCalc = street;
}
}
get street() {
return this._street;
}
/**
* gkx - Gauss Krueger X-Coordinate
* @type {string}
*/
set gkx(gkx) {
this._gkx.value = gkx;
}
get gkx() {
return this._gkx;
}
/**
* gky- Gauss Krueger Y-Coordinate
* @type {string}
*/
set gky(gky) {
this._gky.value = gky;
}
get gky() {
return this._gky;
}
/**
* latitude
* @type {string}
*/
set lat(lat) {
this._lat.value = lat;
}
get lat() {
return this._lat;
}
/**
* longitude
* @type {string}
*/
set lon(lon) {
this._lon.value = lon;
}
get lon() {
return this._lon;
}
/**
* Etage
* @type {string}
*/
set floor(floor) {
this._floor.value = floor;
}
get floor() {
return this._floor;
}
/**
* Leitstelle
* @type {string}
*/
set ils(ils) {
this._ils.value = ils;
}
get ils() {
return this._ils;
}
/**
* operationState (0 if new, 1 if archived)
* @type {integer}
*/
set operationState(operationState) {
this._operationState.value = operationState;
}
get operationState() {
return this._operationState;
}
/**
* namespace of source for this alarm (core or <<namespace>>)
* @type {string}
*/
set operationSourceConnector(operationSourceConnector) {
this._operationSourceConnector.value = operationSourceConnector;
}
get operationSourceConnector() {
return this._operationSourceConnector;
}
/**
* GUID of this operation object
* @type {string}
*/
set uuid(uuid) {
this._uuid.value = uuid;
}
get uuid() {
return this._uuid;
}
/**
* Calculated Location
* @type {string}
*/
set locationCalc(locationCalc) {
this._locationCalc.value = locationCalc;
}
get locationCalc() {
return this._locationCalc;
}
/**
* Sets a new guuid for this operation
*/
setUUID() {
this._uuid.value = uuid.v1();
}
/**
* sets a timestamp in _createdAt.value while instanziiating this class
*/
setCreatedAtTimestamp() {
var timestamp = moment().format();
this._createdAt.value = timestamp;
}
/**
* Returns false if property is null or length = 0
* @param {object} value property to be checked
*/
isDefined(value) {
var retVal = true;
if (value.value === null) {
retVal = false;
} else {
if (value.value.length > 0) {
retVal = true;
} else {
retVal = false;
}
}
return retVal;
}
/**
* Returns minified object which can be used as payload for alarming via FCM or other push services
*/
getReduced() {
var reduced = {};
if (this.isDefined(this._createdAt)) {
reduced._createdAt = this.createdAt;
reduced._createdAt = this.createdAt;
}
if (this.isDefined(this._alarmdate)) {
reduced._alarmdate = this.alarmdate;
}
if (this.isDefined(this._alarmtime)) {
reduced._alarmtime = this.alarmtime;
};
if (this.isDefined(this._community)) {
reduced._community = this.community;
};
if (this.isDefined(this._district)) {
reduced._district = this.district;
};
if (this.isDefined(this._gear)) {
reduced._gear = this.gear;
};
if (this.isDefined(this._keywordCategory)) {
reduced._keywordCategory = this.keywordCategory;
};
if (this.isDefined(this._keywordId)) {
reduced._keywordId = this.keywordId;
};
if (this.isDefined(this._keywordName)) {
reduced._keywordName = this.keywordName;
};
// LATITUDE HAS TO BE SENT ALWAY, NO CHECK NEEDED
reduced._lat = this.lat;
if (this.isDefined(this._location)) {
reduced._location = this.location;
};
if (this.isDefined(this.locationCalc)) {
reduced._locationCalc = this.locationCalc;
}
// LONGITUDE HAS TO BE SENT ALWAYS, NO CHECK NEEDED
reduced._lon = this.lon;
if (this.isDefined(this._message)) {
reduced._message = this.message;
};
if (this.isDefined(this._object)) {
reduced._object = this.object;
};
if (this.isDefined(this._operationnumber)) {
reduced._operationnumber = this.operationnumber;
};
if (this.isDefined(this._section)) {
reduced._section = this.section;
};
if (this.isDefined(this._street)) {
reduced._street = this.street;
};
if (this.isDefined(this._subject)) {
reduced._subject = this.subject;
};
if (this.isDefined(this._zveis)) {
reduced._zveis = this.zveis;
};
if (this.isDefined(this._uuid)) {
reduced._uuid = this.uuid;
};
if (this.isDefined(this._floor)) {
reduced._floor = this.floor;
};
if (this.isDefined(this._ils)) {
reduced._ils = this.ils;
};
return reduced;
}
}
module.exports = Operation;