Commit 24c422ae authored by José Gato Luis's avatar José Gato Luis

Merge branch '51-all-messages-logged-into-mongo' into development

parents 345a1b5c 4d563b8e
Pipeline #2639 passed with stages
in 1 minute and 40 seconds
......@@ -26,140 +26,140 @@ var channel = require("../controllers/channels/channel");
var errorsManagment = require('../controllers/errors.js');
var backendChannels = require('../core/backend/mongomodels/channeldb');
var topicWorkers = require('../core/pubsub/topic/dumpTopic');
var logWorkers = require('../core/pubsub/log/mongoLog');
var logWorkers = require('../core/pubsub/log/dumpLog');
var cooperationAgreementWorker = require('../core/pubsub/cooperation-agreement/dumpCA');
var logger = require('../logger.js');
var pubsub = require('../controllers/pubSub/pubsub');
module.exports = function(app, dbConnection, broker) {
module.exports = function (app, dbConnection, broker) {
function dumpWorker(req, res, next) {
//logger.info("dumpWorker()");
function dumpWorker(req, res, next) {
//logger.info("dumpWorker()");
next();
}
next();
}
function passDBConnection(req, res, next) {
req.dbConnection = dbConnection;
next();
}
function passDBConnection(req, res, next) {
req.dbConnection = dbConnection;
next();
}
function passBroker(req, res, next) {
function passBroker(req, res, next) {
req.brokerConnection = broker;
req.brokerConnection = broker;
next();
}
next();
}
function getChannel(req, res, next){
if (!req.body)
errorsManagment.sendError(errorsManagment.NOT_MESSAGE_PUBLISH, res);
if(req.url.indexOf("publish")!=-1)
pubSub = "pub";
else if(req.url.indexOf("subscribe")!=-1)
pubSub = "sub";
else
errorsManagment.sendError(errorsManagment.SUB_URL_NOT_EXISTS, res);
if(pubSub == 'pub')
backendChannels.findChannelByPubID(req.params.pubID, req.dbConnection, function(err, doc) {
if (err)
errorsManagment.sendError(err, res);
else {
req.entityID = doc._id;
req.channelID = doc.channels[0]._id;
req.AEONChannel = doc.channels[0];
next();
}
});
else
backendChannels.findChannelBySubID(req.params.subID, req.dbConnection, function(err, doc) {
if (err)
errorsManagment.sendError(err, res);
else {
req.entityID = doc._id;
req.channelID = doc.channels[0]._id;
req.AEONChannel = doc.channels[0];
next();
}
});
function getChannel(req, res, next) {
}
if (!req.body)
errorsManagment.sendError(errorsManagment.NOT_MESSAGE_PUBLISH, res);
if (req.url.indexOf("publish") != -1)
pubSub = "pub";
else if (req.url.indexOf("subscribe") != -1)
pubSub = "sub";
else
errorsManagment.sendError(errorsManagment.SUB_URL_NOT_EXISTS, res);
/*
* Pub/Sub chain.
* To publish the right chain will be formed by three steps:
* step1: check the message correctness regarding the type of channel
* step2: publish the message
* step3: log the operation into the DDBB
*/
if (pubSub == 'pub')
backendChannels.findChannelByPubID(req.params.pubID, req.dbConnection, function (err, doc) {
var pubChain = {
"workerstep1": topicWorkers.workerTopicDump,
"workerstep2": channel.publish,
"workerstep3": logWorkers.workerLogMessageMongo
}
if (err)
errorsManagment.sendError(err, res);
else {
req.entityID = doc._id;
req.channelID = doc.channels[0]._id;
req.AEONChannel = doc.channels[0];
next();
}
});
else
backendChannels.findChannelBySubID(req.params.subID, req.dbConnection, function (err, doc) {
if (err)
errorsManagment.sendError(err, res);
else {
req.entityID = doc._id;
req.channelID = doc.channels[0]._id;
req.AEONChannel = doc.channels[0];
next();
}
});
}
/*
* Pub/Sub chain.
* To publish the right chain will be formed by three steps:
* step1: check the message correctness regarding the type of channel
* step2: publish the message
* step3: log the operation into the DDBB
*/
var pubChain = {
"workerstep1": topicWorkers.workerTopicDump,
"workerstep2": channel.publish,
"workerstep3": logWorkers.workerLogDump
}
app.post('/publish/:pubID', passDBConnection, passBroker, getChannel,
pubChain.workerstep1,
pubChain.workerstep2,
pubChain.workerstep3,
function (req, res){
//logger.info("end of pub chain");
}
);
/*
* Pub/Sub chain.
* To be subscribed the right chain will be formed by steps:
*
*/
var subscriptionsChain = {
"workerstep1": cooperationAgreementWorker.workerCADump,
"workerstep2": channel.getSubscription,
"workerstep3": dumpWorker
app.post('/publish/:pubID', passDBConnection, passBroker, getChannel,
pubChain.workerstep1,
pubChain.workerstep2,
pubChain.workerstep3,
function (req, res) {
//logger.info("end of pub chain");
}
);
/*
* Pub/Sub chain.
* To be subscribed the right chain will be formed by steps:
*
*/
app.get('/subscribe/config',passDBConnection, passBroker, pubsub.getConfig);
var subscriptionsChain = {
"workerstep1": cooperationAgreementWorker.workerCADump,
"workerstep2": channel.getSubscription,
"workerstep3": dumpWorker
}
app.get('/subscribe/:subID', passDBConnection, passBroker, getChannel,
subscriptionsChain.workerstep1,
subscriptionsChain.workerstep2,
subscriptionsChain.workerstep3,
function (req, res){
//console.log("end of pub chain");
}
);
app.get('/subscribe/config', passDBConnection, passBroker, pubsub.getConfig);
/*
* Delete subscription.
* Delete a subscription and its related queue
*
*/
app.get('/subscribe/:subID', passDBConnection, passBroker, getChannel,
subscriptionsChain.workerstep1,
subscriptionsChain.workerstep2,
subscriptionsChain.workerstep3,
function (req, res) {
//console.log("end of pub chain");
}
);
/*
* Delete subscription.
* Delete a subscription and its related queue
*
*/
app.delete('/subscribe/:subID', passDBConnection, passBroker, getChannel, pubsub.remove);
app.delete('/subscribe/:subID', passDBConnection, passBroker, getChannel, pubsub.remove);
/*
/*
* Some REST cilents dont allow to delete with a body.
* So the next one will allow this operation with other semantic passing
* the body as a query
* We dont like too much but...
*
*/
app.post('/subscribe/:subID/delete', passDBConnection, passBroker, getChannel, function (req, res, next){
req.body= {}
req.body.id = req.query.id;
req.body.desc = req.query.desc;
next();
},pubsub.remove);
app.post('/subscribe/:subID/delete', passDBConnection, passBroker, getChannel, function (req, res, next) {
req.body = {}
req.body.id = req.query.id;
req.body.desc = req.query.desc;
next();
}, pubsub.remove);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment