Skip to content

Commit

Permalink
Merge pull request #228 from NickPhura/ACRFD-4
Browse files Browse the repository at this point in the history
ACRFD-4: Reason Code support, misc Updates, update dependencies, update readme, update jenkinsfiles and cronjobs.
  • Loading branch information
NickPhura authored Aug 12, 2019
2 parents 5a6152a + 843e77c commit ff64b57
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 194 deletions.
39 changes: 28 additions & 11 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,50 @@ pipeline {
options {
skipDefaultCheckout()
}
environment {
// this credential needs to exist in Jenkins (https://jenkins.io/doc/book/using/using-credentials)
// and should contain the RocketChat Integration Token (https://rocket.chat/docs/administrator-guides/integrations/)
ROCKETCHAT_WEBHOOK_TOKEN = credentials('rocketchat_incoming_webhook_token')
}
stages {
stage('Building: api (master branch)') {
steps {
script {
try {
echo "Building: ${env.JOB_NAME} #${env.BUILD_ID}"
notifyBuild("Building: ${env.JOB_NAME} #${env.BUILD_ID}", "YELLOW")
notifyBuild("Building: ${env.JOB_NAME} ${env.BUILD_ID}", "YELLOW")
echo "Building: env.JOB_NAME=${env.JOB_NAME} env.BUILD_ID=${env.BUILD_ID}"
openshiftBuild bldCfg: 'nrts-prc-api-master', showBuildLogs: 'true'
} catch (e) {
notifyBuild("BUILD ${env.JOB_NAME} #${env.BUILD_ID} ABORTED", "RED")
error('Stopping early…')
notifyBuild("BUILD ${env.JOB_NAME} ${env.BUILD_ID} FAILED", "RED")
error("Building: Failed: ${e}")
}
notifyBuild("Built ${env.JOB_NAME} ${env.BUILD_ID}", "GREEN")
echo "Building: Success"
}
}
}
}
}

def notifyBuild(String msg = '', String colour = 'GREEN') {
if (colour == 'YELLOW') {
colorCode = '#FFFF00'
} else if (colour == 'GREEN') {
def notifyBuild(String msg = '', String colour = '') {
if (colour == 'GREEN') {
colorCode = '#00FF00'
} else {
} else if (colour == 'YELLOW') {
colorCode = '#FFFF00'
} else if (colour == 'RED') {
colorCode = '#FF0000'
} else {
colorCode = '#000000' // black
}

// Send notifications
slackSend (color: colorCode, message: msg)
String rocketChatMessage = "{ \"attachments\": [{ \"text\":\"${msg}\", \"color\":\"${colorCode}\" }] }"

String rocketChatWebHookURL = "https://chat.pathfinder.gov.bc.ca/hooks/${ROCKETCHAT_WEBHOOK_TOKEN}"

// Send notifications to RocketChat
try {
sh "curl -X POST -H 'Content-type: application/json' --data '${rocketChatMessage}' ${rocketChatWebHookURL}"
} catch (e) {
echo "Notify: Failed: ${e}"
}
}
39 changes: 28 additions & 11 deletions Jenkinsfile - develop
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,50 @@ pipeline {
options {
skipDefaultCheckout()
}
environment {
// this credential needs to exist in Jenkins (https://jenkins.io/doc/book/using/using-credentials)
// and should contain the RocketChat Integration Token (https://rocket.chat/docs/administrator-guides/integrations/)
ROCKETCHAT_WEBHOOK_TOKEN = credentials('rocketchat_incoming_webhook_token')
}
stages {
stage('Building: api (develop branch)') {
steps {
script {
try {
echo "Building: ${env.JOB_NAME} #${env.BUILD_ID}"
notifyBuild("Building: ${env.JOB_NAME} #${env.BUILD_ID}", "YELLOW")
notifyBuild("Building: ${env.JOB_NAME} ${env.BUILD_ID}", "YELLOW")
echo "Building: env.JOB_NAME=${env.JOB_NAME} env.BUILD_ID=${env.BUILD_ID}"
openshiftBuild bldCfg: 'nrts-prc-api', showBuildLogs: 'true'
} catch (e) {
notifyBuild("BUILD ${env.JOB_NAME} #${env.BUILD_ID} ABORTED", "RED")
error('Stopping early…')
notifyBuild("BUILD ${env.JOB_NAME} ${env.BUILD_ID} FAILED", "RED")
error("Building: Failed: ${e}")
}
notifyBuild("Built ${env.JOB_NAME} ${env.BUILD_ID}", "GREEN")
echo "Building: Success"
}
}
}
}
}

def notifyBuild(String msg = '', String colour = 'GREEN') {
if (colour == 'YELLOW') {
colorCode = '#FFFF00'
} else if (colour == 'GREEN') {
def notifyBuild(String msg = '', String colour = '') {
if (colour == 'GREEN') {
colorCode = '#00FF00'
} else {
} else if (colour == 'YELLOW') {
colorCode = '#FFFF00'
} else if (colour == 'RED') {
colorCode = '#FF0000'
} else {
colorCode = '#000000' // black
}

// Send notifications
slackSend (color: colorCode, message: msg)
String rocketChatMessage = "{ \"attachments\": [{ \"text\":\"${msg}\", \"color\":\"${colorCode}\" }] }"

String rocketChatWebHookURL = "https://chat.pathfinder.gov.bc.ca/hooks/${ROCKETCHAT_WEBHOOK_TOKEN}"

// Send notifications to RocketChat
try {
sh "curl -X POST -H 'Content-type: application/json' --data '${rocketChatMessage}' ${rocketChatWebHookURL}"
} catch (e) {
echo "Notify: Failed: ${e}"
}
}
39 changes: 28 additions & 11 deletions Jenkinsfile - hotfix
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,50 @@ pipeline {
options {
skipDefaultCheckout()
}
environment {
// this credential needs to exist in Jenkins (https://jenkins.io/doc/book/using/using-credentials)
// and should contain the RocketChat Integration Token (https://rocket.chat/docs/administrator-guides/integrations/)
ROCKETCHAT_WEBHOOK_TOKEN = credentials('rocketchat_incoming_webhook_token')
}
stages {
stage('Building: api (hotfix branch)') {
steps {
script {
try {
echo "Building: ${env.JOB_NAME} #${env.BUILD_ID}"
notifyBuild("Building: ${env.JOB_NAME} #${env.BUILD_ID}", "YELLOW")
notifyBuild("Building: ${env.JOB_NAME} ${env.BUILD_ID}", "YELLOW")
echo "Building: env.JOB_NAME=${env.JOB_NAME} env.BUILD_ID=${env.BUILD_ID}"
openshiftBuild bldCfg: 'nrts-prc-api-hotfix', showBuildLogs: 'true'
} catch (e) {
notifyBuild("BUILD ${env.JOB_NAME} #${env.BUILD_ID} ABORTED", "RED")
error('Stopping early…')
notifyBuild("BUILD ${env.JOB_NAME} ${env.BUILD_ID} FAILED", "RED")
error("Building: Failed: ${e}")
}
notifyBuild("Built ${env.JOB_NAME} ${env.BUILD_ID}", "GREEN")
echo "Building: Success"
}
}
}
}
}

def notifyBuild(String msg = '', String colour = 'GREEN') {
if (colour == 'YELLOW') {
colorCode = '#FFFF00'
} else if (colour == 'GREEN') {
def notifyBuild(String msg = '', String colour = '') {
if (colour == 'GREEN') {
colorCode = '#00FF00'
} else {
} else if (colour == 'YELLOW') {
colorCode = '#FFFF00'
} else if (colour == 'RED') {
colorCode = '#FF0000'
} else {
colorCode = '#000000' // black
}

// Send notifications
slackSend (color: colorCode, message: msg)
String rocketChatMessage = "{ \"attachments\": [{ \"text\":\"${msg}\", \"color\":\"${colorCode}\" }] }"

String rocketChatWebHookURL = "https://chat.pathfinder.gov.bc.ca/hooks/${ROCKETCHAT_WEBHOOK_TOKEN}"

// Send notifications to RocketChat
try {
sh "curl -X POST -H 'Content-type: application/json' --data '${rocketChatMessage}' ${rocketChatWebHookURL}"
} catch (e) {
echo "Notify: Failed: ${e}"
}
}
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,41 @@ npm run lint-fix

The API is defined in `swagger.yaml`.

If the this nrts-prc-api is running locally, you can view the api docs at: `http://localhost:3000/api/docs/`
If this project is running locally, you can view the api docs at: `http://localhost:3000/api/docs/`

This project uses npm package `swagger-tools` via `./app.js` to automatically generate the express server and its routes.
This project uses npm package `swagger-tools` via `./app.js` to automatically generate the express server and its routes, based on the contents of `swagger.yaml`.

Useful Note: The handler function for each route is specified by the `operationId` field.

Recommend reviewing the [Open API Specification](https://swagger.io/docs/specification/about/) before making any changes to the `swagger.yaml` file.

# Logging

A centralized logger has been created (see `api/helpers/logger.js`).

## Logger configuration
The loggers log level can be configured via an environment variable: `LOG_LEVEL`

Set this variable to one of: `error`, `warn`, `info`, `debug`

Default value: `info`

## Instantiating the logger in your class/file
```
const log = require('./logger)('a meaningful label, typically the class name`)
```

## Using the logger
```
log.error('Used when logging unexpected errors. Generally these will only exist in catch() blocks');
log.warn('Used when logging soft errors. For example, if your request finished but returned a 404 not found');
log.info('General log messages about the state of the application');
log.debug('Useful for logging objects and other developer data', JSON.stringify(myObject));
```

# Testing

## Info
Expand Down
25 changes: 24 additions & 1 deletion api/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var tagList = [
'publishDate',
'purpose',
'status',
'reason',
'subpurpose',
'subtype',
'tantalisID',
Expand Down Expand Up @@ -353,6 +354,7 @@ exports.protectedPost = function(args, res, next) {
delete obj.type;
delete obj.subtype;
delete obj.status;
delete obj.reason;
delete obj.tenureStage;
delete obj.location;
delete obj.businessUnit;
Expand Down Expand Up @@ -386,6 +388,7 @@ exports.protectedPost = function(args, res, next) {
savedApp.type = data.TENURE_TYPE;
savedApp.subtype = data.TENURE_SUBTYPE;
savedApp.status = data.TENURE_STATUS;
savedApp.reason = data.TENURE_REASON;
savedApp.tenureStage = data.TENURE_STAGE;
savedApp.location = data.TENURE_LOCATION;
savedApp.businessUnit = data.RESPONSIBLE_BUSINESS_UNIT;
Expand Down Expand Up @@ -524,10 +527,11 @@ exports.protectedRefresh = function(args, res, next) {
var Application = require('mongoose').model('Application');
Application.findOne({ _id: objId }, function(err, applicationObject) {
if (applicationObject) {
defaultLog.debug('applicationObject:', JSON.stringify(applicationObject));
defaultLog.debug('application before refresh:', JSON.stringify(applicationObject));

TTLSUtils.updateApplication(applicationObject).then(
updatedApplicationAndFeatures => {
defaultLog.debug('application after refresh:', JSON.stringify(applicationObject));
return Actions.sendResponse(res, 200, updatedApplicationAndFeatures);
},
error => {
Expand Down Expand Up @@ -692,6 +696,25 @@ var addStandardQueryFilters = function(query, args) {
}
_.assignIn(query, { status: { $in: queryArray } });
}
if (args.swagger.params.reason && args.swagger.params.reason.value !== undefined) {
var queryString = qs.parse(args.swagger.params.reason.value);
var queryArray = [];
if (queryString.eq) {
if (Array.isArray(queryString.eq)) {
queryArray = queryString.eq;
} else {
queryArray.push(queryString.eq);
}
_.assignIn(query, { reason: { $in: queryArray } });
} else if (queryString.ne) {
if (Array.isArray(queryString.ne)) {
queryArray = queryString.ne;
} else {
queryArray.push(queryString.ne);
}
_.assignIn(query, { reason: { $nin: queryArray } });
}
}
if (args.swagger.params.agency && args.swagger.params.agency.value !== undefined) {
_.assignIn(query, { agency: args.swagger.params.agency.value });
}
Expand Down
1 change: 1 addition & 0 deletions api/helpers/models/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = require('../models')('Application', {
publishDate: { type: Date },
purpose: { type: String },
status: { type: String },
reason: { type: String },
subpurpose: { type: String },
subtype: { type: String },
tantalisID: { type: Number, default: 0 },
Expand Down
1 change: 1 addition & 0 deletions api/helpers/models/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = require('../models')('Feature', {
INTRID_SID: { type: Number, default: 0 },
TENURE_STAGE: { type: String, default: '' },
TENURE_STATUS: { type: String, default: '' },
TENURE_REASON: { type: String, default: '' },
TENURE_TYPE: { type: String, default: '' },
TENURE_SUBTYPE: { type: String, default: '' },
TENURE_PURPOSE: { type: String, default: '' },
Expand Down
Loading

0 comments on commit ff64b57

Please sign in to comment.