Skip to content

Commit

Permalink
Merge pull request #515 from Optum/master
Browse files Browse the repository at this point in the history
R1.0.5
  • Loading branch information
johnlegeyt authored Jun 5, 2019
2 parents c939939 + 51c8907 commit c170328
Show file tree
Hide file tree
Showing 16 changed files with 870 additions and 399 deletions.
35 changes: 35 additions & 0 deletions api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ paths:
items:
$ref: '#/components/schemas/Service'
description: successful response

post:
tags:
- services
Expand Down Expand Up @@ -970,6 +971,21 @@ paths:
application/json:
schema:
description: successful response
/report:
get:
tags:
- report
description: retrieves a report of total services, users, etc
responses:
200:
description: report
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Report'
description: report

components:
securitySchemes:
Expand Down Expand Up @@ -1113,6 +1129,25 @@ components:
type: array
items:
type: string
Report:
title: Report
type: object
properties:
totalServices:
type: integer
activeServices:
type: integer
draftServices:
type: integer
archiveServices:
type: integer
users:
type: integer
systems:
type: integer
totalTransactions:
type: integer

tags:
- name: services
description: ''
Expand Down
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const System = require('./models/common/System');
const MQService = require('./models/mq/MQService');
const constants = require('./lib/util/constants');
const fuseHelper = require('./lib/util/fuse');
const reportingRouter = require('./routes/report');
global.__basedir = __dirname;

// connect to database
Expand Down Expand Up @@ -174,6 +175,7 @@ function init() {
const recorderController = require('./controllers/recorderController');
app.use('/recording',recorder.recordingRouter);
app.use('/api/recording',recorder.apiRouter);
app.use('/api/report/',reportingRouter.router);

const mqController = require('./controllers/mqController');
mqController.registerAllMQServices();
Expand Down
236 changes: 236 additions & 0 deletions controllers/reportingController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
const MQService = require('../models/mq/MQService');
const Service = require('../models/http/Service');
//const Recording = require('../models/http/Recording');
const User = require('../models/common/User');
const System = require('../models/common/System');
const DraftService = require ('../models/common/DraftService');
const Archive = require ('../models/common/Archive');


function getAllServicesByGroups(){
return new Promise(
function(resolve, reject){
Service.aggregate(
{
$group:{
_id:"$sut.name",
totalServices:
{
$sum:1
}
}
},{
$project:
{
sut:"$_id",
services:"$totalServices",
_id:false
}
}

).then(function(result){
resolve(result);
}).catch(function(err){
reject(err);
});
}
);
}

function getTotalTransactionCount(){

return new Promise(
function(resolve, reject){
Service.aggregate(
{
$group:{_id:null,totalTransactions: {$sum:"$txnCount"}}
}
).then(function(result){
resolve(result[0].totalTransactions);
})
.catch(function(err){
reject(err);
});



}
);




}


/**
* Returns a promise that returns the # of total Services+MQServices. Does not include archive/drafts
* @return A promise that returns the # of total Services+MQServices
*/
function getCountOfAllServices(){
return new Promise(function(resolve,reject){
Service.count({},function(err,serviceCount){
if(err)
reject(err);
else{
MQService.count({},function(err,mqServiceCount){
if(err)
reject(err);
else{
resolve(mqServiceCount+serviceCount);
}
});
}
});
});
}

/**
* Returns a promise that returns the # of active Services+MQServices. Does not include archive/drafts
* @return A promise that returns the # of active Services+MQServices
*/
function getCountOfActiveServices(){
return new Promise(function(resolve,reject){
Service.count({running:true},function(err,serviceCount){
if(err)
reject(err);
else{
MQService.count({running:true},function(err,mqServiceCount){
if(err)
reject(err);
else{
resolve(mqServiceCount+serviceCount);
}
});
}
});
});
}


/**
* Returns a promise that evaluates to the # of draft services
*/
function getCountOfDraftServices(){
return new Promise(function(resolve,reject){
DraftService.count({},
function(err,count){
if(err)
reject(err);
else
resolve(count);


}
);
});
}

/**
* Returns a promise that evaluates to the # of archive services
*/
function getCountOfArchiveServices(){
return new Promise(function(resolve,reject){
Archive.count({},
function(err,count){
if(err)
reject(err);
else
resolve(count);


}
);
});
}

/**
* Returns a promise that evaluates to the # of users
*/
function getCountOfUsers(){
return new Promise(function(resolve,reject){
User.count({},
function(err,count){
if(err)
reject(err);
else
resolve(count);


}
);
});
}

/**
* Returns a promise that evaluates to the # of Systems
*/
function getCountOfSystems(){
return new Promise(function(resolve,reject){
System.count({},
function(err,count){
if(err)
reject(err);
else
resolve(count);


}
);
});
}

/**
* Runs + returns a full report
* @param {*} req express req
* @param {*} rsp express rsp
* @param {*} next next middleware
*/
function fullReport(req,rsp,next){
var report = {};
var promises = [];
var promiseLabels = [];

//Build list of promises
promises.push(getCountOfAllServices());
promiseLabels.push("totalServices");

promises.push(getCountOfActiveServices());
promiseLabels.push("activeServices");

promises.push(getCountOfDraftServices());
promiseLabels.push("draftServices");

promises.push(getCountOfArchiveServices());
promiseLabels.push("archiveServices");

promises.push(getCountOfUsers());
promiseLabels.push("users");

promises.push(getCountOfSystems());
promiseLabels.push("systems");

promises.push(getTotalTransactionCount());
promiseLabels.push("totalTransactions");

promises.push(getAllServicesByGroups());
promiseLabels.push("servicesByGroup");

Promise.all(promises).then(
function(vals){
for(let i = 0; i < vals.length; i++){
report[promiseLabels[i]] = vals[i];
}
rsp.json(report);
}
,
function(err){
handleError(err,rsp,500);
}
);

}

module.exports = {
fullReport : fullReport
}
3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ <h4 class="modal-title">Publish Success!</h4>
<div ng-show="virt.type === 'REST'">
<p><b>Operations:</b></p>
<fieldset ng-repeat="op in virt.operations">
<p class="wordwrap">{{ op.verb }} {{ mockiatoHost + virt.baseUrl + op.path }}</p>
<p class="wordwrap" ng-show="!op.queries">{{ op.verb }} {{ mockiatoHost + virt.baseUrl + op.path }}</p>
<p class="wordwrap" ng-show="op.queries">{{ op.verb }} {{ mockiatoHost + virt.baseUrl + op.path + op.queries }}</p>
<p ng-show="op.verb === 'POST' || op.verb === 'PUT'" class="tab">Required Headers: Name = Content-Type | Value = application/json</p>
<p ng-show="op.verb === 'DELETE'" class="tab">Note: if you included a request payload for DELETE, be sure to use the required headers in your request: Name = Content-Type | Value = application/json</p></br>
</fieldset>
Expand Down
Loading

0 comments on commit c170328

Please sign in to comment.