diff --git a/.gitignore b/.gitignore index 3b12bdd..7088833 100644 --- a/.gitignore +++ b/.gitignore @@ -30,8 +30,10 @@ npm-debug.log testem.log /typings package-lock.json +seed/package-lock.json yarn-error.log yarn.lock +seed/yarn.lock debug.log # Project Files diff --git a/api/controllers/application.js b/api/controllers/application.js index 4f9bc3c..ce0e910 100644 --- a/api/controllers/application.js +++ b/api/controllers/application.js @@ -276,7 +276,7 @@ exports.protectedDelete = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -443,7 +443,7 @@ exports.protectedPut = function(args, res, next) { defaultLog.info('o:', o); return Actions.sendResponse(res, 200, o); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -476,7 +476,7 @@ exports.protectedPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -507,7 +507,7 @@ exports.protectedUnPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); diff --git a/api/controllers/comment.js b/api/controllers/comment.js index 8737404..a891ba6 100644 --- a/api/controllers/comment.js +++ b/api/controllers/comment.js @@ -281,7 +281,7 @@ exports.protectedPut = function(args, res, next) { defaultLog.info('o:', o); return Actions.sendResponse(res, 200, o); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -309,7 +309,7 @@ exports.protectedPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -337,7 +337,7 @@ exports.protectedUnPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); diff --git a/api/controllers/commentperiod.js b/api/controllers/commentperiod.js index 5f69196..898e723 100644 --- a/api/controllers/commentperiod.js +++ b/api/controllers/commentperiod.js @@ -157,7 +157,7 @@ exports.protectedPut = function(args, res, next) { defaultLog.info('o:', o); return Actions.sendResponse(res, 200, o); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -186,7 +186,7 @@ exports.protectedDelete = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -214,7 +214,7 @@ exports.protectedPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -240,7 +240,7 @@ exports.protectedUnPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); diff --git a/api/controllers/decision.js b/api/controllers/decision.js index 8f051f9..53c0544 100644 --- a/api/controllers/decision.js +++ b/api/controllers/decision.js @@ -146,7 +146,7 @@ exports.protectedPut = function(args, res, next) { defaultLog.info('o:', o); return Actions.sendResponse(res, 200, o); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -174,7 +174,7 @@ exports.protectedDelete = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -201,7 +201,7 @@ exports.protectedPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -227,7 +227,7 @@ exports.protectedUnPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); diff --git a/api/controllers/document.js b/api/controllers/document.js index 8f06f0a..e6d6dad 100644 --- a/api/controllers/document.js +++ b/api/controllers/document.js @@ -341,7 +341,7 @@ exports.protectedDelete = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -368,7 +368,7 @@ exports.protectedPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -394,7 +394,7 @@ exports.protectedUnPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -446,7 +446,7 @@ exports.protectedPut = function(args, res, next) { // defaultLog.info("o:", o); return Actions.sendResponse(res, 200, o); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); diff --git a/api/controllers/feature.js b/api/controllers/feature.js index 5b81a18..2ab015f 100644 --- a/api/controllers/feature.js +++ b/api/controllers/feature.js @@ -146,7 +146,7 @@ exports.protectedPut = function(args, res, next) { defaultLog.info('o:', o); return Actions.sendResponse(res, 200, o); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -174,7 +174,7 @@ exports.protectedPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); @@ -200,7 +200,7 @@ exports.protectedUnPublish = function(args, res, next) { } ); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); diff --git a/api/controllers/search.js b/api/controllers/search.js index a9b24ec..10b76aa 100644 --- a/api/controllers/search.js +++ b/api/controllers/search.js @@ -1,8 +1,6 @@ -var _ = require('lodash'); var defaultLog = require('winston').loggers.get('default'); var Actions = require('../helpers/actions'); var TTLSUtils = require('../helpers/ttlsUtils'); -var request = require('request'); var _accessToken = null; exports.protectedTTLSGetApplicationsByFileNumber = function(args, res, rest) { @@ -79,219 +77,3 @@ exports.protectedTTLSGetApplicationByDisp = function(args, res, rest) { exports.protectedOptions = function(args, res, rest) { res.status(200).send(); }; - -exports.publicGetClientsInfoByDispositionId = function(args, res, next) { - var dtId = args.swagger.params.dtId.value; - defaultLog.info('Searching arcgis for client info on Disposition Transaction ID:', dtId); - - var searchURL = - 'http://maps.gov.bc.ca/arcgis/rest/services/mpcm/bcgw/MapServer/dynamicLayer/query?layer=%7B%22id%22%3A1%2C%22source%22%3A%7B%22type%22%3A%22dataLayer%22%2C%22dataSource%22%3A%7B%22type%22%3A%22table%22%2C%22workspaceId%22%3A%22MPCM_ALL_PUB%22%2C%22dataSourceName%22%3A%22WHSE_TANTALIS.TA_INTEREST_HOLDER_VW%22%7D%7D%7D&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&maxAllowableOffset=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&returnDistinctValues=false&f=json&where=DISPOSITION_TRANSACTION_SID='; - return new Promise(function(resolve, reject) { - request.get({ url: searchURL + "'" + dtId + "'" }, function(err, res, body) { - if (err) { - reject(err); - } else if (res.statusCode !== 200) { - reject(res.statusCode + ' ' + body); - } else { - var obj = {}; - try { - defaultLog.info('ArcGIS Call Complete.', body); - obj = JSON.parse(body); - } catch (e) { - defaultLog.error('Parsing Failed.', e); - } - var clients = []; - _.each(obj.features, function(i) { - clients.push(i.attributes); - }); - resolve(clients); - } - }); - }) - .then(function(data) { - return Actions.sendResponse(res, 200, data); - }) - .catch(function(err) { - defaultLog.error(err); - return Actions.sendResponse(res, 400, err); - }); -}; - -// Get BCGW features by CLID -exports.publicGetBCGW = function(args, res, next) { - // Build match query if on appId route - // Pad with leading zeros to make CLID seven digits - var clid = _.padStart(args.swagger.params.crownLandsId.value, 7, '0'); - defaultLog.info('Searching BCGW for CLID:', clid); - - // TODO: Error handling. - - // var searchURL = "https://openmaps.gov.bc.ca/geo/pub/WHSE_TANTALIS.TA_CROWN_TENURES_SVW/ows?service=wfs&version=2.0.0&request=getfeature&typename=pub:WHSE_TANTALIS.TA_CROWN_TENURES_SVW&outputFormat=application/json&PROPERTYNAME=CROWN_LANDS_FILE&CQL_FILTER=CROWN_LANDS_FILE="; - var searchURL = - 'https://openmaps.gov.bc.ca/geo/pub/WHSE_TANTALIS.TA_CROWN_TENURES_SVW/ows?service=wfs&version=2.0.0&request=getfeature&typename=PUB:WHSE_TANTALIS.TA_CROWN_TENURES_SVW&outputFormat=json&srsName=EPSG:4326&CQL_FILTER=CROWN_LANDS_FILE='; - return new Promise(function(resolve, reject) { - request.get({ url: searchURL + "'" + clid + "'" }, function(err, res, body) { - if (err) { - reject(err); - } else if (res.statusCode !== 200) { - reject(res.statusCode + ' ' + body); - } else { - var obj = {}; - try { - defaultLog.info('BCGW Call Complete.', body); - obj = JSON.parse(body); - } catch (e) { - defaultLog.error('Parsing Failed.', e); - resolve(obj); - } - - // Search for this in our DB in case it's already been imported. - try { - var result = _.chain(obj.features) - .groupBy('properties.DISPOSITION_TRANSACTION_SID') - .toPairs() - .map(function(currentItem) { - return _.zipObject(['SID', 'sids'], currentItem); - }) - .value(); - - obj.sidsFound = []; - result - .reduce(function(current, code) { - return current.then(function() { - var Application = require('mongoose').model('Application'); - return new Promise(function(complete, fail) { - Application.findOne({ tantalisID: code.SID, isDeleted: false }, function(err, o) { - if (err) { - fail(); - } - if (o) { - obj.sidsFound.push(code.SID); // NB: SID is string (tantalisID is number) - } else { - defaultLog.info('Nothing found'); - } - complete(); - }); - }); - }); - }, Promise.resolve()) - .then(function() { - resolve(obj); - }); - } catch (e) { - // Error, don't tag the isImported on it. - resolve(obj); - } - } - }); - }) - .then(function(data) { - return Actions.sendResponse(res, 200, data); - }) - .catch(function(err) { - defaultLog.error(err); - return Actions.sendResponse(res, 400, err); - }); -}; - -// Get local shapes -exports.publicGetDispositionTransactionId = function(args, res, next) { - return new Promise(function(resolve, reject) { - var Feature = require('mongoose').model('Feature'); - - var query = {}; - if (args.swagger.params.dtId && args.swagger.params.dtId.value !== undefined) { - _.assignIn(query, { 'properties.DISPOSITION_TRANSACTION_SID': args.swagger.params.dtId.value }); - } - - return Feature.find(query, function(err, data) { - if (err) { - return Actions.sendResponse(res, 400, err); - } else { - var featureCollection = {}; - featureCollection.crs = {}; - featureCollection.crs.properties = {}; - featureCollection.crs.properties.name = 'urn:ogc:def:crs:EPSG::4326'; - featureCollection.totalFeatures = data.length; - featureCollection.features = data; - featureCollection.type = 'FeatureCollection'; - return Actions.sendResponse(res, 200, featureCollection); - } - }); - }); -}; - -// Get BCGW features by DTID -exports.publicGetBCGWDispositionTransactionId = function(args, res, next) { - // Build match query if on dtId route - var dtId = args.swagger.params.dtId.value; - defaultLog.info('Searching BCGW for DTID:', dtId); - - // TODO: Error handling. - - var searchURL = - 'https://openmaps.gov.bc.ca/geo/pub/WHSE_TANTALIS.TA_CROWN_TENURES_SVW/ows?service=wfs&version=2.0.0&request=getfeature&typename=PUB:WHSE_TANTALIS.TA_CROWN_TENURES_SVW&outputFormat=json&srsName=EPSG:4326&CQL_FILTER=DISPOSITION_TRANSACTION_SID='; - return new Promise(function(resolve, reject) { - request.get({ url: searchURL + "'" + dtId + "'" }, function(err, res, body) { - if (err) { - reject(err); - } else if (res.statusCode !== 200) { - reject(res.statusCode + ' ' + body); - } else { - var obj = {}; - try { - defaultLog.info('BCGW Call Complete.', body); - obj = JSON.parse(body); - } catch (e) { - defaultLog.error('Parsing Failed.', e); - resolve(obj); - } - - // Search for this in our DB in case it's already been imported. - try { - var result = _.chain(obj.features) - .groupBy('properties.DISPOSITION_TRANSACTION_SID') - .toPairs() - .map(function(currentItem) { - return _.zipObject(['SID', 'sids'], currentItem); - }) - .value(); - - obj.sidsFound = []; - result - .reduce(function(current, code) { - return current.then(function() { - var Application = require('mongoose').model('Application'); - return new Promise(function(complete, fail) { - Application.findOne({ tantalisID: code.SID, isDeleted: false }, function(err, o) { - if (err) { - fail(); - } - if (o) { - obj.sidsFound.push(code.SID); // NB: SID is string (tantalisID is number) - } else { - defaultLog.info('Nothing found'); - } - complete(); - }); - }); - }); - }, Promise.resolve()) - .then(function() { - resolve(obj); - }); - } catch (e) { - // Error, don't tag the isImported on it. - resolve(obj); - } - } - }); - }) - .then(function(data) { - return Actions.sendResponse(res, 200, data); - }) - .catch(function(err) { - defaultLog.error(err); - return Actions.sendResponse(res, 400, err); - }); -}; diff --git a/api/controllers/user.js b/api/controllers/user.js index 86adba5..21d7417 100644 --- a/api/controllers/user.js +++ b/api/controllers/user.js @@ -88,7 +88,7 @@ exports.protectedPut = function(args, res, next) { defaultLog.info('o:', o); return Actions.sendResponse(res, 200, o); } else { - defaultLog.info("Couldn't find that object!"); + defaultLog.warn("Couldn't find that object!"); return Actions.sendResponse(res, 404, {}); } }); diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 745b9d3..8905ddd 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -1996,213 +1996,6 @@ paths: schema: $ref: "#/definitions/Error" -### -### Search BCGW Routes -### - /public/search/bcgw/crownLandsId/{crownLandsId}: - x-swagger-router-controller: search - options: - tags: - - search - summary: "Pre-flight request" - operationId: protectedOptions - description: "Options on 'Search BCGW by Crown Lands ID' route" - parameters: - - name: crownLandsId - in: path - description: "Crown Lands ID of Crown Lands object(s) to get" - required: true - type: string - responses: - "200": - description: "Success" - schema: - $ref: "#/definitions/Search" - "403": - description: "Access Denied" - schema: - $ref: "#/definitions/Error" - get: - tags: - - search - summary: "Search BCGW by Crown Lands ID" - operationId: publicGetBCGW - description: "Retrieve Crown Lands objects from the BCGW" - parameters: - - name: crownLandsId - in: path - description: "Crown Lands ID of object(s) to get" - required: true - type: string - - in: query - name: fields - description: "Search fields to return" - required: false - type: array - collectionFormat: pipes - items: - type: string - enum: *searchFields - responses: - "200": - description: "Success" - schema: - $ref: "#/definitions/Search" - "403": - description: "Access Denied" - schema: - $ref: "#/definitions/Error" - /public/search/bcgw/getClientsInfoByDispositionId/{dtId}: - x-swagger-router-controller: search - options: - tags: - - search - summary: "Pre-flight request" - operationId: protectedOptions - description: "Options on 'Search BCGW Client Info by Disposition ID' route" - parameters: - - name: dtId - in: path - description: "Disposition Transaction ID to get client info about" - required: true - type: string - responses: - "200": - description: "Success" - schema: - $ref: "#/definitions/Search" - "403": - description: "Access Denied" - schema: - $ref: "#/definitions/Error" - get: - tags: - - search - summary: "Search BCGW Client Info by Disposition ID" - operationId: publicGetClientsInfoByDispositionId - description: "Retrieve Client Info objects from the BCGW" - parameters: - - name: dtId - in: path - description: "Disposition Transaction ID get client info about" - required: true - type: string - responses: - "200": - description: "Success" - schema: - $ref: "#/definitions/Search" - "403": - description: "Access Denied" - schema: - $ref: "#/definitions/Error" - /public/search/bcgw/dispositionTransactionId/{dtId}: - x-swagger-router-controller: search - options: - tags: - - search - summary: "Pre-flight request" - operationId: protectedOptions - description: "Options on 'Search BCGW by Disposition Transaction ID' route" - parameters: - - name: dtId - in: path - description: "Disposition Transaction ID of Tantalis object(s) to get" - required: true - type: string - responses: - "200": - description: "Success" - schema: - $ref: "#/definitions/Search" - "403": - description: "Access Denied" - schema: - $ref: "#/definitions/Error" - get: - tags: - - search - summary: "Search BCGW by Disposition Transaction ID" - operationId: publicGetBCGWDispositionTransactionId - description: "Retrieve Tantalis objects from the BCGW" - parameters: - - name: dtId - in: path - description: "Disposition Transaction ID of Tantalis object(s) to get" - required: true - type: string - - in: query - name: fields - description: "Search fields to return" - required: false - type: array - collectionFormat: pipes - items: - type: string - enum: *searchFields - responses: - "200": - description: "Success" - schema: - $ref: "#/definitions/Search" - "403": - description: "Access Denied" - schema: - $ref: "#/definitions/Error" - /public/search/dispositionTransactionId/{dtId}: - x-swagger-router-controller: search - options: - tags: - - search - summary: "Pre-flight request" - operationId: protectedOptions - description: "Options on 'Get Features by Disposition Transaction ID' route" - parameters: - - name: dtId - in: path - description: "Disposition Transaction ID of Tantalis object(s) to get" - required: true - type: string - responses: - "200": - description: "Success" - schema: - $ref: "#/definitions/Search" - "403": - description: "Access Denied" - schema: - $ref: "#/definitions/Error" - get: - tags: - - search - summary: "Get a list of Features by Disposition Transaction ID" - operationId: publicGetDispositionTransactionId - description: "Retrieve Feature objects from local database" - parameters: - - name: dtId - in: path - description: "Disposition Transaction ID of Features to get" - required: true - type: string - - in: query - name: fields - description: "Search fields to return" - required: false - type: array - collectionFormat: pipes - items: - type: string - enum: *searchFields - responses: - "200": - description: "Success" - schema: - $ref: "#/definitions/Search" - "403": - description: "Access Denied" - schema: - $ref: "#/definitions/Error" - ### ### Search Tantalis Routes ### diff --git a/api/test/search.test.js b/api/test/search.test.js index 5676e14..e90ef30 100644 --- a/api/test/search.test.js +++ b/api/test/search.test.js @@ -2,10 +2,6 @@ const test_helper = require('./test_helper'); const app = test_helper.app; const mongoose = require('mongoose'); const request = require('supertest'); -const nock = require('nock'); -const arcGisResponse = require('./fixtures/arcgis_response.json'); -const crownlandsResponse = require('./fixtures/crownlands_response.json'); -const tantalisResponse = require('./fixtures/tantalis_response.json'); const fieldNames = []; const TTLSUtils = require('../helpers/ttlsUtils'); @@ -17,7 +13,6 @@ function publicParamsWithDtId(req) { const searchController = require('../controllers/search.js'); require('../helpers/models/application'); require('../helpers/models/feature'); -const Application = mongoose.model('Application'); const Feature = mongoose.model('Feature'); app.get('/api/search/ttlsapi/crownLandFileNumber/:id', function(req, res) { @@ -32,24 +27,10 @@ app.get('/api/search/ttlsapi/dispositionTransactionId/:id', function(req, res) { return searchController.protectedTTLSGetApplicationByDisp(params, res); }); -app.get('/api/public/search/bcgw/getClientsInfoByDispositionId/:id', function(req, res) { - return searchController.publicGetClientsInfoByDispositionId(publicParamsWithDtId(req), res); -}); - -app.get('/api/public/search/bcgw/crownLandsId/:id', function(req, res) { - let extraFields = test_helper.buildParams({ crownLandsId: req.params.id }); - let params = test_helper.createSwaggerParams(fieldNames, extraFields); - return searchController.publicGetBCGW(params, res); -}); - app.get('/api/public/search/dispositionTransactionId/:id', function(req, res) { return searchController.publicGetDispositionTransactionId(publicParamsWithDtId(req), res); }); -app.get('/api/public/search/bcgw/dispositionTransactionId/:id', function(req, res) { - return searchController.publicGetBCGWDispositionTransactionId(publicParamsWithDtId(req), res); -}); - describe('GET /api/search/ttlsapi/crownLandFileNumber/', () => { let clFileNumber = 555555; const firstResult = { DISPOSITION_TRANSACTION_SID: 111111 }; @@ -190,175 +171,6 @@ describe('GET /api/search/ttlsapi/dispositionTransactionId/', () => { }); }); -describe('GET /api/public/search/bcgw/getClientsInfoByDispositionId', () => { - const arcGisDomain = 'http://maps.gov.bc.ca/'; - const searchPath = - '/arcgis/rest/services/mpcm/bcgw/MapServer/dynamicLayer/query?layer=%7B%22id%22%3A1%2C%22source%22%3A%7B%22type%22%3A%22dataLayer%22%2C%22dataSource%22%3A%7B%22type%22%3A%22table%22%2C%22workspaceId%22%3A%22MPCM_ALL_PUB%22%2C%22dataSourceName%22%3A%22WHSE_TANTALIS.TA_INTEREST_HOLDER_VW%22%7D%7D%7D&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&maxAllowableOffset=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&returnDistinctValues=false&f=json&where=DISPOSITION_TRANSACTION_SID='; - const argGis = nock(arcGisDomain); - let dispositionId = 666666; - let urlEncodedDispositionId = `%27${dispositionId}%27`; - - describe('When the arcgis call returns successfully', () => { - beforeEach(() => { - argGis.get(searchPath + urlEncodedDispositionId).reply(200, arcGisResponse); - }); - - test('returns the features data from the search', done => { - request(app) - .get('/api/public/search/bcgw/getClientsInfoByDispositionId/' + dispositionId) - .expect(200) - .then(response => { - expect(response.body.length).toBe(2); - let firstFeature = response.body[0]; - expect(firstFeature).toHaveProperty('DISPOSITION_TRANSACTION_SID'); - expect(firstFeature).toHaveProperty('CITY'); - expect(firstFeature).toHaveProperty('INTERESTED_PARTY_SID'); - done(); - }); - }); - }); - - describe('When the arcgis call returns with an error', () => { - let arcGisErrorResponse = { - msg: 'Beep boop, something went wrong' - }; - beforeEach(() => { - argGis.get(searchPath + urlEncodedDispositionId).reply(400, arcGisErrorResponse); - }); - - test('returns a 400 if the arcgis response status is not 200', done => { - request(app) - .get('/api/public/search/bcgw/getClientsInfoByDispositionId/' + dispositionId) - .expect(400) - .then(response => { - expect(response.body).toEqual('400 {"msg":"Beep boop, something went wrong"}'); - done(); - }); - }); - }); - - describe('when the arcgis call returns 200, but error in body', () => { - let arcGisErrorResponse = { - error: { - code: 400, - message: 'Invalid or missing input parameters.', - details: [] - } - }; - - beforeEach(() => { - argGis.get(searchPath + urlEncodedDispositionId).reply(200, arcGisErrorResponse); - }); - - // TODO: shouldn't this test read more like: 'returns a 400 if the arcgis response body is unsuccessful' - // Returns an empty array if response body is invalid - test('returns an empty array if the arcgis response body is unsuccessful', done => { - request(app) - .get('/api/public/search/bcgw/getClientsInfoByDispositionId/' + dispositionId) - // .expect(400) - .expect(200) - .then(response => { - // expect(response.body).toBe(arcGisErrorResponse); - expect(response.body).toEqual([]); - done(); - }); - }); - }); -}); - -describe('GET /api/public/search/bcgw/crownLandsId/ ', () => { - const bcgwDomain = 'https://openmaps.gov.bc.ca/'; - const searchPath = - '/geo/pub/WHSE_TANTALIS.TA_CROWN_TENURES_SVW/ows?service=wfs&version=2.0.0&request=getfeature&typename=PUB:WHSE_TANTALIS.TA_CROWN_TENURES_SVW&outputFormat=json&srsName=EPSG:4326&CQL_FILTER=CROWN_LANDS_FILE='; - const bcgw = nock(bcgwDomain); - let crownlandsId = 7777; - // crownlands id with 7 digits - let paddedCrownlandsId = `%27000${crownlandsId}%27`; - - describe('when bcgw call is successful', () => { - beforeEach(() => { - bcgw.get(searchPath + paddedCrownlandsId).reply(200, crownlandsResponse); - }); - - test('returns the features data from the search', done => { - request(app) - .get('/api/public/search/bcgw/crownLandsId/' + crownlandsId) - .expect(200) - .then(response => { - expect(response.body.features).toBeDefined(); - let firstFeature = response.body.features[0]; - expect(firstFeature).toHaveProperty('properties'); - expect(firstFeature.properties).toHaveProperty('DISPOSITION_TRANSACTION_SID'); - expect(firstFeature.properties).toHaveProperty('CROWN_LANDS_FILE'); - expect(firstFeature.properties).toHaveProperty('TENURE_STATUS'); - done(); - }); - }); - - test('it adds the SID to the response sidsFound property if there is a matching application in the db', done => { - let crownlandSID = crownlandsResponse.features[0].properties.DISPOSITION_TRANSACTION_SID; - let existingApplication = new Application({ - tantalisID: crownlandSID - }); - existingApplication.save().then(() => { - request(app) - .get('/api/public/search/bcgw/crownLandsId/' + crownlandsId) - .expect(200) - .then(response => { - expect(response.body.sidsFound).toBeDefined(); - expect(response.body.sidsFound).toEqual([crownlandSID.toString()]); - done(); - }); - }); - }); - }); - - describe('When the bcgw call returns with an error', () => { - let bcgwErrorResponse = { - msg: 'Beep boop, something went wrong' - }; - beforeEach(() => { - bcgw.get(searchPath + paddedCrownlandsId).reply(400, bcgwErrorResponse); - }); - - test('returns a 400 if the bcgw response status is not 200', done => { - request(app) - .get('/api/public/search/bcgw/crownLandsId/' + crownlandsId) - .expect(400) - .then(response => { - expect(response.body).toEqual('400 {"msg":"Beep boop, something went wrong"}'); - done(); - }); - }); - }); - - describe('when the bcgw call returns 200, but error in body', () => { - let bcgwErrorResponse = { - error: { - code: 400, - message: 'Invalid or missing input parameters.', - details: [] - } - }; - - beforeEach(() => { - bcgw.get(searchPath + paddedCrownlandsId).reply(200, bcgwErrorResponse); - }); - - test('returns an empty array if the arcgis response body is unsuccessful', done => { - request(app) - .get('/api/public/search/bcgw/crownLandsId/' + crownlandsId) - // .expect(400) - .expect(200) - .then(response => { - // expect(response.body).toBe(arcGisErrorResponse); - expect(response.body).toMatchObject(bcgwErrorResponse); - done(); - }); - }); - }); -}); - describe('GET /api/public/search/dispositionTransactionId', () => { let dispositionId = 666666; @@ -384,95 +196,3 @@ describe('GET /api/public/search/dispositionTransactionId', () => { }); }); }); - -describe('GET /api/public/search/bcgw/dispositionTransactionId', () => { - const bcgwDomain = 'https://openmaps.gov.bc.ca'; - const searchPath = - '/geo/pub/WHSE_TANTALIS.TA_CROWN_TENURES_SVW/ows?service=wfs&version=2.0.0&request=getfeature&typename=PUB:WHSE_TANTALIS.TA_CROWN_TENURES_SVW&outputFormat=json&srsName=EPSG:4326&CQL_FILTER=DISPOSITION_TRANSACTION_SID='; - const bcgw = nock(bcgwDomain); - let dispositionId = 666666; - let urlEncodedDispositionId = `%27${dispositionId}%27`; - - describe('When the bcgw call returns successfully', () => { - beforeEach(() => { - bcgw.get(searchPath + urlEncodedDispositionId).reply(200, tantalisResponse); - }); - - test('returns the features data from the search', done => { - request(app) - .get('/api/public/search/bcgw/dispositionTransactionId/' + dispositionId) - .expect(200) - .then(response => { - let firstFeature = response.body.features[0]; - expect(firstFeature).toHaveProperty('properties'); - expect(firstFeature.properties).toHaveProperty('DISPOSITION_TRANSACTION_SID'); - expect(firstFeature.properties).toHaveProperty('CROWN_LANDS_FILE'); - expect(firstFeature.properties).toHaveProperty('TENURE_STATUS'); - done(); - }); - }); - - test('it adds the SID to the response sidsFound property if there is a matching application in the db', done => { - let dispositionTransactionId = crownlandsResponse.features[0].properties.DISPOSITION_TRANSACTION_SID; - let existingApplication = new Application({ - tantalisID: dispositionTransactionId - }); - existingApplication.save().then(() => { - request(app) - .get('/api/public/search/bcgw/dispositionTransactionId/' + dispositionId) - .expect(200) - .then(response => { - expect(response.body.sidsFound).toBeDefined(); - expect(response.body.sidsFound).toEqual([dispositionTransactionId.toString()]); - done(); - }); - }); - }); - }); - - describe('When the bcgw call returns with an error', () => { - let bcgwErrorResponse = { - msg: 'Beep boop, something went wrong' - }; - beforeEach(() => { - return bcgw.get(searchPath + urlEncodedDispositionId).reply(400, bcgwErrorResponse); - }); - - test('returns a 400 if the arcgis response status is not 200', done => { - request(app) - .get('/api/public/search/bcgw/dispositionTransactionId/' + dispositionId) - .expect(400) - .then(response => { - expect(response.body).toEqual('400 {"msg":"Beep boop, something went wrong"}'); - done(); - }); - }); - }); - - describe('when the bcgw call returns 200, but error in body', () => { - let bcgwErrorResponse = { - error: { - code: 400, - message: 'Invalid or missing input parameters.', - details: [] - } - }; - - beforeEach(() => { - return bcgw.get(searchPath + urlEncodedDispositionId).reply(200, bcgwErrorResponse); - }); - - // TODO: shouldn't this test read more like: 'returns a 400 if the bcgw response body is unsuccessful' - test('returns an empty array if the bcgw response body is unsuccessful', done => { - request(app) - .get('/api/public/search/bcgw/dispositionTransactionId/' + dispositionId) - // .expect(400) - .expect(200) - .then(response => { - // expect(response.body).toBe(bcgwErrorResponse); - expect(response.body).toMatchObject(bcgwErrorResponse); - done(); - }); - }); - }); -}); diff --git a/seed/shapesMigration/updateShapes.js b/seed/shapesMigration/updateShapes.js index c099bfb..9de2b64 100644 --- a/seed/shapesMigration/updateShapes.js +++ b/seed/shapesMigration/updateShapes.js @@ -6,7 +6,7 @@ * a. Fetches all ACRFD applications that have reached a retired state (assumes 6 months is the retirement period), and unpublishes any found. * 3. AUthenticates with Tantalis * 4. Updates non-deleted ACRFD applications: - * a. Fetches all Tantalis applications that have had an update within the last 1 week. + * a. Fetches all Tantalis applications that have had their status history effective date update within the last 1 week. * b. Fetches all non-deleted ACRFD tantalisIDs. * c. For each ACRFD application with a matching Tantalis application: * i. Updates the ACRFD application features and meta to match whatever is in Tantalis (the source of truth). @@ -44,7 +44,7 @@ var _accessToken = ''; var args = process.argv.slice(2); defaultLog.info('======================================================='); if (args.length !== 8) { - defaultLog.info( + defaultLog.error( 'Please specify proper parameters: ' ); defaultLog.info('Example: node updateShapes.js admin admin http localhost 3000 client_id grant_type auth_endpoint'); @@ -115,9 +115,12 @@ var loginToACRFD = function(username, password) { body: body }, function(error, res, body) { - if (error || res.statusCode !== 200) { - defaultLog.error(' - loginToACRFD error:', error, res); - reject(null); + if (error) { + defaultLog.error(' - loginToACRFD error:', error); + reject(error); + } else if (res.statusCode !== 200) { + defaultLog.error(' - loginToACRFD error:', res.statusCode, body); + reject(res.statusCode + ' ' + body); } else { var data = JSON.parse(body); jwt_login = data.access_token; @@ -151,20 +154,17 @@ var renewJWTLogin = function() { }; /** - * Fetches all ACRFD applications that have a retired status AND a statusHistoryEffectiveDate within the past 2 weeks 6 months ago. + * Fetches all ACRFD applications that have a retired status AND a statusHistoryEffectiveDate older than 6 months ago. * * @returns {Promise} promise that resolves with the list of retired applications. */ var getApplicationsToUnpublish = function() { defaultLog.info(' - fetching retired applications.'); return new Promise(function(resolve, reject) { - var sinceDate = moment() - .subtract(6, 'months') - .subtract(2, 'weeks'); var untilDate = moment().subtract(6, 'months'); - // get all applications that are in a retired status, and that have a last status update date within in the past week 6 months ago. - var queryString = `?statusHistoryEffectiveDate[since]=${sinceDate.toISOString()}&statusHistoryEffectiveDate[until]=${untilDate.toISOString()}`; + // get all applications that are in a retired status and that have a last status update date older than 6 months ago. + var queryString = `?statusHistoryEffectiveDate[until]=${untilDate.toISOString()}`; retiredStatuses.forEach(status => (queryString += `&status[eq]=${encodeURIComponent(status)}`)); request.get( @@ -176,9 +176,12 @@ var getApplicationsToUnpublish = function() { } }, function(error, res, body) { - if (error || res.statusCode !== 200) { - defaultLog.error(' - getApplicationsToUnpublish error:', error, res); - reject(null); + if (error) { + defaultLog.error(' - getApplicationsToUnpublish error:', error); + reject(error); + } else if (res.statusCode !== 200) { + defaultLog.error(' - getApplicationsToUnpublish error:', res.statusCode, body); + reject(res.statusCode + ' ' + body); } else { var data = JSON.parse(body); @@ -213,9 +216,12 @@ var unpublishApplications = function(applicationsToUnpublish) { body: JSON.stringify(currentApp) }, function(error, res, body) { - if (error || res.statusCode !== 200) { - defaultLog.error(' - unpublishApplications error:', error, body); - reject(null); + if (error) { + defaultLog.error(' - unpublishApplications error:', error); + reject(error); + } else if (res.statusCode !== 200) { + defaultLog.error(' - unpublishApplications error:', res.statusCode, body); + reject(res.statusCode + ' ' + body); } else { defaultLog.info(` - Unpublished application, _id: ${currentApp._id}`); var data = JSON.parse(body); @@ -251,7 +257,7 @@ const updateACRFDApplication = function(acrfdAppID) { defaultLog.error(' - updateACRFDApplication error:', error); reject(error); } else if (res.statusCode !== 200) { - defaultLog.warn(' - updateACRFDApplication response statusCode:', res.statusCode); + defaultLog.error(' - updateACRFDApplication error:', res.statusCode, body); reject(res.statusCode + ' ' + body); } else { var obj = {}; @@ -288,10 +294,10 @@ var getAllACRFDApplicationIDs = function() { }, function(error, res, body) { if (error) { - defaultLog.error(' - getAllApplicationIDs error:', error); + defaultLog.error(' - getAllACRFDApplicationIDs error:', error); reject(error); } else if (res.statusCode !== 200) { - defaultLog.warn(' - updateACRFDApplication response statusCode:', res.statusCode); + defaultLog.error(' - getAllACRFDApplicationIDs error:', res.statusCode, body); reject(res.statusCode + ' ' + body); } else { var obj = {}; @@ -331,7 +337,9 @@ loginToACRFD(username, password) }) .then(function() { defaultLog.info('-----------------------------------------------'); - defaultLog.info('4. Fetching all Tantalis applications that have been updated in the last week.'); + defaultLog.info( + '4. Fetching all Tantalis applications that have had their status history effective date updated in the last week.' + ); var lastWeek = moment() .subtract(1, 'week') .format('YYYYMMDD'); @@ -372,8 +380,8 @@ loginToACRFD(username, password) defaultLog.info('======================================================='); }) .catch(function(error) { - defaultLog.info('-----------------------------------------------'); - defaultLog.info(' - General error:', error); - defaultLog.info('======================================================='); + defaultLog.error('-----------------------------------------------'); + defaultLog.error(' - General error:', error); + defaultLog.error('======================================================='); process.exit(1); });