Skip to content

Commit 3fa1a5a

Browse files
committed
C50-592 Create a new post-api to store the bot output context in mongo db
1 parent 1934a01 commit 3fa1a5a

4 files changed

Lines changed: 131 additions & 1 deletion

File tree

server/app/engine/bots/lambdaExecutor.js

Whitespace-only changes.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Copyright [2016] [Relevance Lab]
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
const logger = require('_pr/logger')(module);
18+
const mongoose = require('mongoose');
19+
const Schema = mongoose.Schema;
20+
21+
const botHistoryAuditTrailSchema = new Schema ({
22+
botId: {
23+
type: String
24+
},
25+
actionLogId: {
26+
type: String,
27+
required: true
28+
},
29+
botRunId: {
30+
type: String,
31+
required: true
32+
},
33+
botExecutorName: {
34+
type: String
35+
},
36+
input: {
37+
type : Schema.Types.Mixed,
38+
default : null
39+
},
40+
output: {
41+
type : Schema.Types.Mixed,
42+
default : null
43+
},
44+
createdOn: {
45+
type: Number,
46+
required: true,
47+
default: Date.now()
48+
},
49+
lastUpdateOn: {
50+
type: Number,
51+
required: true,
52+
default: Date.now()
53+
}
54+
})
55+
56+
botHistoryAuditTrailSchema.index({ actionLogId: 1, createdOn:1 }, { unique: true });
57+
58+
botHistoryAuditTrailSchema.statics.addBotHistoryAudit = function (auditObj, callback) {
59+
let audit = new this(auditObj);
60+
audit.save(callback);
61+
};
62+
63+
botHistoryAuditTrailSchema.statics.insertBotHistoryAudit = function (auditList, callback) {
64+
let auditListDB = auditList.map((auditObj) => {
65+
let audit = new this(auditObj);
66+
audit.createdOn = Date.now();
67+
audit.lastUpdateOn = Date.now();
68+
return audit;
69+
});
70+
this.insertMany(auditListDB, callback);
71+
};
72+
73+
botHistoryAuditTrailSchema.statics.findByQuery = function (query, project, options, callback) {
74+
return this.find(query, project, options, callback);
75+
};
76+
77+
botHistoryAuditTrailSchema.statics.findOneByQuery = function (query, project, options, callback) {
78+
return this.findOne(query, project, options, callback);
79+
};
80+
81+
const botHistoryAuditTrail = mongoose.model('botHistoryAuditTrail', botHistoryAuditTrailSchema);
82+
module.exports = botHistoryAuditTrail;

server/app/routes/v1.0/routes_bot.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports.setRoutes = function(app, sessionVerificationFunc) {
2424
*/
2525
app.get('/bot/all',function(req,res) {
2626
var loggedUser = req.session.user.cn;
27-
27+
2828
botService.getAllBotsList(req.query, loggedUser,function(err,data) {
2929
if (err) {
3030
return res.status(500).send(err);
@@ -34,6 +34,30 @@ module.exports.setRoutes = function(app, sessionVerificationFunc) {
3434
});
3535
});
3636

37+
app.post('/bot/history',function(req,res) {
38+
const loggedUser = req.session.user.cn;
39+
const rqObj = req.body;
40+
botService.addBotHistoryAudit(rqObj, loggedUser, function(err, data) {
41+
if (err) {
42+
return res.status(500).send(err);
43+
} else {
44+
return res.status(200).send(data);
45+
}
46+
});
47+
});
48+
49+
app.post('/bot/historyList',function(req,res) {
50+
const loggedUser = req.session.user.cn;
51+
const rqObjList = req.body;
52+
botService.insertBotHistoryAudit(rqObjList, loggedUser, function(err,data) {
53+
if (err) {
54+
return res.status(500).send(err);
55+
} else {
56+
return res.status(200).send(data);
57+
}
58+
});
59+
});
60+
3761
app.get('/bot',function(req,res) {
3862
var actionStatus = null,serviceNowCheck =null;
3963
var loggedUser = req.session.user.cn;

server/app/services/botService.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ var azurecloudProvider = require('_pr/model/classes/masters/cloudprovider/azureC
5252
var vmwareProvider = require('_pr/model/classes/masters/cloudprovider/vmwareCloudProvider.js');
5353
var botAuditTrailSummary = require('_pr/model/audit-trail/bot-audit-trail-summary');
5454

55+
const botHistoryAuditTrail = require('_pr/model/audit-trail/bot-history-audit-trail');
56+
5557
var appConfig = require('_pr/config');
5658
var botService = module.exports = {};
5759

@@ -451,6 +453,8 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
451453

452454
}
453455

456+
} else if(bots[0].type === 'lambda') {
457+
454458
} else {
455459
var error = new Error();
456460
logger.error("task_id"+taskId+" There is no record available in DB against BOT :"+botsId)
@@ -1514,3 +1518,23 @@ botService.getAllBotsList = function getAllBotsList(botsQuery, userName, callbac
15141518
return;
15151519
});
15161520
}
1521+
1522+
botService.addBotHistoryAudit = function addBotHistoryAudit(obj, userName, callback) {
1523+
botHistoryAuditTrail.addBotHistoryAudit(obj, (err, status) => {
1524+
if(err) {
1525+
callback(err, null);
1526+
} else {
1527+
callback(null, status);
1528+
};
1529+
});
1530+
};
1531+
1532+
botService.insertBotHistoryAudit = function insertBotHistoryAudit(objList, userName, callback) {
1533+
botHistoryAuditTrail.insertBotHistoryAudit(objList, (err, status) => {
1534+
if(err) {
1535+
callback(err, null);
1536+
} else {
1537+
callback(null, status);
1538+
};
1539+
});
1540+
};

0 commit comments

Comments
 (0)