fog-controller
Version:
Fog Controller project @ iotracks.com
213 lines (193 loc) • 9.86 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _routing = require('./../models/routing');
var _routing2 = _interopRequireDefault(_routing);
var _baseManager = require('./../managers/baseManager');
var _baseManager2 = _interopRequireDefault(_baseManager);
var _sequelize = require('./../utils/sequelize');
var _sequelize2 = _interopRequireDefault(_sequelize);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @file routingManager.js
* @author Zishan Iqbal
* @description This file includes the CURD operations for the routing Model.
*/
var RoutingManager = function (_BaseManager) {
_inherits(RoutingManager, _BaseManager);
function RoutingManager() {
_classCallCheck(this, RoutingManager);
return _possibleConstructorReturn(this, (RoutingManager.__proto__ || Object.getPrototypeOf(RoutingManager)).apply(this, arguments));
}
_createClass(RoutingManager, [{
key: 'getEntity',
value: function getEntity() {
return _routing2.default;
}
/**
* @desc - finds the routings based on the publishsingInstanceId or destinationInstanceId
* that match with the instanceId
* @param Integer - instanceId
* @return JSON - returns a Array of JSON objects of routing
*/
}, {
key: 'findByInstanceId',
value: function findByInstanceId(instanceId) {
return _routing2.default.findAll({
where: {
$or: [{
publishing_instance_id: {
$eq: instanceId
}
}, {
destination_instance_id: {
$eq: instanceId
}
}]
}
});
}
}, {
key: 'isDebugging',
value: function isDebugging(uuid, fogInstanceId) {
return _routing2.default.findAll({
where: {
$and: [{
publishing_instance_id: fogInstanceId,
destination_instance_id: fogInstanceId,
publishing_element_id: uuid,
destination_element_id: 'debug'
}]
}
});
}
}, {
key: 'isViewer',
value: function isViewer(uuid, fogInstanceId) {
return _routing2.default.findAll({
where: {
$and: [{
publishing_instance_id: fogInstanceId,
destination_instance_id: fogInstanceId,
publishing_element_id: uuid,
destination_element_id: 'viewer'
}]
}
});
}
}, {
key: 'findByElementInstanceUuids',
value: function findByElementInstanceUuids(uuids) {
var query = 'select r.*, e.track_id from routing r JOIN element_instance e on e.UUID = r.publishing_element_id where r.publishing_element_id in (:uuids)';
return _sequelize2.default.query(query, {
replacements: {
uuids: uuids
},
type: _sequelize2.default.QueryTypes.SELECT
});
}
}, {
key: 'findOutputRoutingByElementInstanceUuids',
value: function findOutputRoutingByElementInstanceUuids(uuids) {
var query = 'select r.*, e.track_id from routing r JOIN element_instance e on e.UUID = r.destination_element_id where r.destination_element_id in (:uuids)';
return _sequelize2.default.query(query, {
replacements: {
uuids: uuids
},
type: _sequelize2.default.QueryTypes.SELECT
});
}
}, {
key: 'findByElementInstanceUuidsAndRoutingDestination',
value: function findByElementInstanceUuidsAndRoutingDestination(uuids) {
var query = 'select r.*, e.track_id from routing r JOIN element_instance e on e.UUID = r.publishing_element_id where r.destination_element_id in (:uuids)';
return _sequelize2.default.query(query, {
replacements: {
uuids: uuids
},
type: _sequelize2.default.QueryTypes.SELECT
});
}
}, {
key: 'findOutputRoutingByElementInstanceUuidsAndRoutingPublishing',
value: function findOutputRoutingByElementInstanceUuidsAndRoutingPublishing(uuids) {
var query = 'select r.*, e.track_id from routing r JOIN element_instance e on e.UUID = r.destination_element_id where r.publishing_element_id in (:uuids)';
return _sequelize2.default.query(query, {
replacements: {
uuids: uuids
},
type: _sequelize2.default.QueryTypes.SELECT
});
}
}, {
key: 'deleteByPublishingElementId',
value: function deleteByPublishingElementId(elementId) {
return _routing2.default.destroy({
where: {
publishing_element_id: elementId
}
});
}
}, {
key: 'deleteByPublishingOrDestinationElementId',
value: function deleteByPublishingOrDestinationElementId(elementId) {
return _routing2.default.destroy({
where: {
$or: [{
publishing_element_id: elementId
}, {
destination_element_id: elementId
}]
}
});
}
}, {
key: 'deleteByFogAndElement',
value: function deleteByFogAndElement(instanceId1, instanceId2, elementId1, elementId2, isNetwork) {
return _routing2.default.destroy({
where: {
publishing_instance_id: instanceId1,
destination_instance_id: instanceId2,
publishing_element_id: elementId1,
destination_element_id: elementId2,
is_network_connection: isNetwork
}
});
}
}, {
key: 'deleteByNetworkElementInstanceId',
value: function deleteByNetworkElementInstanceId(elementId) {
var deleteQuery = " \
DELETE FROM routing \
WHERE publishing_element_id IN( \
SELECT networkElementId1 \
FROM network_pairing \
WHERE elementID1 = ' + elementId + ' \
) \
OR publishing_element_id IN( \
SELECT networkElementId2 \
FROM network_pairing \
WHERE elementID2 = ' + elementId + ' \
) \
OR destination_element_id IN( \
SELECT networkElementId1 \
FROM network_pairing \
WHERE elementID1 = ' + elementId + ' \
) \
OR destination_element_id IN( \
SELECT networkElementId2 \
FROM network_pairing \
WHERE elementID2 = ' + elementId + ' \
) \
";
return _sequelize2.default.query(deleteQuery);
}
}]);
return RoutingManager;
}(_baseManager2.default);
var instance = new RoutingManager();
exports.default = instance;