Skip to content

Commit

Permalink
Merge pull request #190 from NickPhura/PRC-996-2
Browse files Browse the repository at this point in the history
PRC-996-2: Only update recently changed Applications.  Fix meta update logic.
  • Loading branch information
NickPhura authored Feb 5, 2019
2 parents ee0577e + bc1d981 commit 0f4edc2
Show file tree
Hide file tree
Showing 3 changed files with 388 additions and 395 deletions.
6 changes: 3 additions & 3 deletions api/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ exports.publicGetClientsInfoByDispositionId = function (args, res, next) {

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({ url: searchURL + "'" + dtId + "'" }, function (err, res, body) {
request.get({ url: searchURL + "'" + dtId + "'" }, function (err, res, body) {
if (err) {
reject(err);
} else if (res.statusCode !== 200) {
Expand Down Expand Up @@ -119,7 +119,7 @@ exports.publicGetBCGW = function (args, res, next) {
// 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({ url: searchURL + "'" + clid + "'" }, function (err, res, body) {
request.get({ url: searchURL + "'" + clid + "'" }, function (err, res, body) {
if (err) {
reject(err);
} else if (res.statusCode !== 200) {
Expand Down Expand Up @@ -217,7 +217,7 @@ exports.publicGetBCGWDispositionTransactionId = function (args, res, next) {

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({ url: searchURL + "'" + dtId + "'" }, function (err, res, body) {
request.get({ url: searchURL + "'" + dtId + "'" }, function (err, res, body) {
if (err) {
reject(err);
} else if (res.statusCode !== 200) {
Expand Down
70 changes: 62 additions & 8 deletions api/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var _ = require('lodash');
var mongoose = require('mongoose');
var clamav = require('clamav.js');
var fs = require('fs');
var qs = require('qs');
var request = require('request');
var turf = require('@turf/turf');
var helpers = require('@turf/helpers');
Expand All @@ -29,7 +29,7 @@ exports.buildQuery = function (property, values, query) {
}
return _.assignIn(query, { [property]: {
$in: oids
}
}
});
};

Expand Down Expand Up @@ -103,7 +103,7 @@ exports.runDataQuery = function (modelType, role, query, fields, sortWarmUp, sor
_.each(defaultFields, function (f) {
projection[f] = 1;
});

// Add requested fields - sanitize first by including only those that we can/want to return
_.each(fields, function (f) {
projection[f] = 1;
Expand Down Expand Up @@ -134,9 +134,9 @@ exports.runDataQuery = function (modelType, role, query, fields, sortWarmUp, sor
}
}
},

sortWarmUp, // Used to setup the sort if a temporary projection is needed.

!_.isEmpty(sort) ? { $sort: sort } : null,

sort ? { $project: projection } : null, // Reset the projection just in case the sortWarmUp changed it.
Expand Down Expand Up @@ -169,7 +169,7 @@ exports.runDataQuery = function (modelType, role, query, fields, sortWarmUp, sor
exports.loginWebADE = function () {
// Login to webADE and return access_token for use in subsequent calls.
return new Promise(function (resolve, reject) {
request({ url: webADEAPI + "oauth/token?grant_type=client_credentials&disableDeveloperFilter=true",
request.get({ url: webADEAPI + "oauth/token?grant_type=client_credentials&disableDeveloperFilter=true",
headers : {
"Authorization" : "Basic " + new Buffer(username + ":" + password).toString("base64")
}
Expand All @@ -196,7 +196,7 @@ exports.loginWebADE = function () {
exports.getApplicationByFilenumber = function (accessToken, clFile) {
return new Promise(function (resolve, reject) {
console.log("Looking up file:", _tantalisAPI + "landUseApplications?fileNumber=" + clFile);
request({
request.get({
url: _tantalisAPI + "landUseApplications?fileNumber=" + clFile,
auth: {
bearer: accessToken
Expand Down Expand Up @@ -244,7 +244,7 @@ exports.getApplicationByFilenumber = function (accessToken, clFile) {
exports.getApplicationByDispositionID = function (accessToken, disp) {
return new Promise(function (resolve, reject) {
console.log("Looking up disposition:", _tantalisAPI + "landUseApplications/" + disp);
request({
request.get({
url: _tantalisAPI + "landUseApplications/" + disp,
auth: {
bearer: accessToken
Expand Down Expand Up @@ -364,4 +364,58 @@ exports.getApplicationByDispositionID = function (accessToken, disp) {
}
});
});
};


/**
* Fetches all application IDs from Tantalis given the filter params provided.
*
* @param {string} accessToken Tantalis API access token. (required)
* @param {object} [filterParams={}] Object containing Tantalis query filters. See Tantalis API Spec. (optional)
* @returns an array of matching Tantalis IDs.
*/
exports.getAllApplicationIDs = function (accessToken, filterParams = {}) {
return new Promise(function (resolve, reject) {
const queryString = `?${qs.stringify(filterParams)}`;

console.log("Looking up all applications:", _tantalisAPI + "landUseApplications" + queryString);

request.get({
url: _tantalisAPI + "landUseApplications" + queryString,
auth: {
bearer: accessToken
}
},
function (err, res, body) {
if (err || (res && res.statusCode !== 200)) {
console.log("TTLS API ResponseCode:", err == null ? res.statusCode : err);
console.log("TTLS API ResponseCode:", body);
if (!err && res && res.statusCode) {
err = {};
err.statusCode = res.statusCode;
}
reject(err);
} else {
try {
var applicationIDs = [];

var response = JSON.parse(body);
_.forEach(response.elements, function (obj) {
if (obj) {
applicationIDs.push(obj.landUseApplicationId);
}
});
if (applicationIDs.length) {
resolve(applicationIDs);
} else {
console.log("No applications found.");
resolve([]);
}
} catch (e) {
console.log("Object Parsing Failed:", e);
reject(e);
}
}
});
});
};
Loading

0 comments on commit 0f4edc2

Please sign in to comment.