Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
74dde50
GPII-3138: Added CouchDB views for retrieving snapset data.
cindyli Jun 27, 2018
ee30bb2
GPII-3138: Update snapsets in the data base
klown Jul 6, 2018
1c0f38a
GPII-3138: Update snapsets in the data base
klown Jul 6, 2018
b5dd8c0
GPII-3138: Update snapsets in the data base
klown Jul 6, 2018
f7068c0
GPII-3138: Update snapsets in the data base
klown Jul 9, 2018
e2f4e63
GPII-3138: Update snapsets in the data base
klown Jul 9, 2018
554ae82
GPII-3138: Update snapsets in the data base
klown Jul 9, 2018
f145f66
GPII-3138: Delete and reload snapsets in the data base
klown Jul 10, 2018
8f54a33
GPII-3138: Merged upstream master GPII branch into GPII-3138
klown Jul 16, 2018
67f7bd6
GPII-3138: Add a couchDB view to return all GPII keys.
cindyli Jul 18, 2018
c48d7ae
Merge pull request #1 from cindyli/GPII-3138
klown Jul 18, 2018
f029df2
GPII-3138: Merged Cindy's pull request with new database view
klown Jul 18, 2018
5f2f1b5
GPII-3138: Delete and (re)load snapsets into the database
klown Jul 20, 2018
750cdf3
GPII-3138: Delete and reload snapsets into the database
klown Jul 23, 2018
0e41600
GPII-3138: Delete and reload snapsets into the database
klown Jul 24, 2018
22d6605
GPII-3138: Delete and load snapsets Prefs Safes.
klown Jul 25, 2018
574236f
GPII-3138: Delete and load snapsets Prefs Safes into the database.
klown Jul 25, 2018
d6547d3
GPII-3138: Delete and load snapsets Prefs Safes into the database.
klown Jul 25, 2018
8520379
GPII-3138: Delete and load snapsets into the database
klown Jul 25, 2018
ef1e721
GPII-3138: Merged upstream GPII master branch.
klown Jul 26, 2018
0181c42
GPII-3138: Delete and load snapsets into the database
klown Jul 27, 2018
9bb64af
GPII-3138: Update snapsets into the database
klown Jul 30, 2018
a4541ba
GPII-3138: Update snapsets into the database
klown Jul 30, 2018
e026465
GPII-3138: Merged changes from upstreasm master GPII branch.
klown Jul 31, 2018
f4c41a6
GPII-3138: Update snapsets into the database
klown Jul 31, 2018
6723b6e
GPII-3138: Update snapsets into the database
klown Jul 31, 2018
2e0bb55
GPII-3138: Update snapsets into the database
klown Jul 31, 2018
fae02da
GPII-3138: Use UUIDs for demo user keys as well as creating 20 empty …
cindyli Aug 1, 2018
831a762
Merge pull request #2 from cindyli/GPII-3138
klown Aug 1, 2018
582b3d7
GPII-3138: Update snapsets in the database
klown Aug 5, 2018
c401c97
GPII-3138: Update snapsets in the database
klown Aug 7, 2018
54defe7
GPII-3138: Update snapsets in the database
klown Aug 7, 2018
58fdde7
GPII-3138: Update snapsets in the database
klown Aug 9, 2018
0862af6
GPII-3138: Merged changes from upstream master GPII branch.
klown Aug 10, 2018
79abd7d
GPII-3138: Merged changes from upstream master GPII branch
klown Aug 27, 2018
2b8cbeb
GPII-3138: Update snapsets in the database
klown Aug 28, 2018
59f03a8
GPII-3138: Update snapsets in the database
klown Aug 30, 2018
6ee716e
GPII-3138: Update snapsets in the database
klown Sep 10, 2018
9a090a1
GPII-3138: Update snapsets in the database
klown Sep 11, 2018
a9eec11
GPII-3138: Update snapsets in the database
klown Sep 11, 2018
a4cf452
GPII-3138: Update snapsets in the database
klown Sep 12, 2018
63c1a11
GPII-3138: Update snapsets in the database
klown Sep 13, 2018
7ce1b84
GPII-3138: Update snapsets in the database
klown Sep 18, 2018
afc6888
GPII-3138: Update snapsets in the database
klown Sep 19, 2018
75456ba
GPII-3138: Update snapsets in the database
klown Sep 19, 2018
230c8f0
GPII-3138: Update snapsets in the database
klown Sep 19, 2018
23b27e4
GPII-3138 Merged upstream master GPII branch
klown Oct 9, 2018
33f1741
GPII-3138: Update snapsets in the database.
klown Oct 9, 2018
2c48ca5
GPII-3138: Update snapsets in the database
klown Oct 11, 2018
d9ac25e
GPII-3138: Update snapsets in the database
klown Oct 15, 2018
ebde69d
GPII-3138: Update snapsets in the database
klown Oct 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gpii/node_modules/testing/src/PouchTestCaseHolder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@
"test:vagrantProduction": "vagrant ssh -c 'cd /home/vagrant/sync/universal; DISPLAY=:0; ./scripts/vagrantCloudBasedContainers.sh'",
"posttest": "node node_modules/nyc/bin/nyc.js report -r text-summary -r html --report-dir reports --temp-directory coverage",
"start": "node gpii.js",
"postinstall": "node scripts/browserifyTestDependency.js && node scripts/convertPrefs.js testData/preferences/ build/dbData/ && node scripts/convertPrefs.js tests/data/preferences/ build/tests/dbData/"
"postinstall": "node scripts/browserifyTestDependency.js && node scripts/convertPrefs.js testData/preferences/ build/dbData/snapset/ snapset && node scripts/convertPrefs.js testData/preferences/ build/dbData/user/ user && node scripts/convertPrefs.js tests/data/preferences/ build/tests/dbData/ user"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this README section to add which set of data are converted to what prefs type and why? Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but I'm not sure about everything. Here's what I know and where I'm unclear:

  1. %universal/testData/preferences/ are converted into a set of "snapset" PrefsSafes and their associated GPII keys and placed in the %universal/build/dbData/snapset/ folder. These are used to update the snapset preferences in CouchDB used with a running GPII.
  2. %universal/testData/preferences/ are also converted but into a set of "user" PrefsSafes and GPII keys, and placed in the %universal/build/dbData/user/ folder. I can't remember what these are for.
  3. %universal/tests/data/preferences/ are converted into a set of "user" PrefsSafes and GPII keys and placed in the %universal/build/tests/dbData/ folder. These are used during testing with PouchDB

The main problem is number 2, but am I right about everything else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Number 2 is also for running integration tests with PouchDB. Both data sets from build/dbData/user/ and build/tests/dbData are loaded by [PouchTestCaseHolder|https://github.com//pull/626/files#diff-9a09cbe02e1a616b46e9ff110b1b1452R48].

}
}
8 changes: 4 additions & 4 deletions scripts/convertPrefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ https://github.com/GPII/universal/blob/master/LICENSE.txt
*/

// This script reads files from an input directory that contains preferences JSON5 files and convert them to JSON files of GPII keys and
// preferences safes suitable for direct loading into CouchDB or PouchDB, which comply with the new GPII data model:
// preferences safes suitable for direct loading into CouchDB or PouchDB, which comply with the new GPII data model:
// https://wiki.gpii.net/w/Keys,_KeyTokens,_and_Preferences in the target directory
// Usage: node scripts/convertPrefs.js {input_path} {target_path}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the usage too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

//
Expand All @@ -25,14 +25,14 @@ var fs = require("fs"),

var inputDir = process.argv[2];
var targetDir = process.argv[3];
var prefsSafeType = process.argv[4];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either check prefsSafeType must be provided or change this line to

var prefsSafeType = process.argv[4] || "user";

to set "user" as the default if this argument is optional.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've modified the code to use the "or" form. Still ... shouldn't we check that it's either "snapset" or "user" and quit if it's neither -- what if someone entered "group" for the type, for example? Or, will there be other types of prefsSafes in the future?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Harmless to check. I cannot tell at the moment if there will be other types of prefsSafes in the future.


var prefsSafes = [];
var gpiiKeys = [];
var count = 0;

var filenames = fs.readdirSync(inputDir);

console.log("Converting preferences data in the source directory " + inputDir + " to the target directory " + targetDir + " ...");
console.log("Converting preferences data in the source directory " + inputDir + " to the target directory " + targetDir + " as " + prefsSafeType + " Prefs Safes ...");

// Read and loop thru json5 files in the input directory
rimraf(targetDir, function () {
Expand Down Expand Up @@ -61,7 +61,7 @@ rimraf(targetDir, function () {
"_id": prefsSafeId,
"type": "prefsSafe",
"schemaVersion": "0.1",
"prefsSafeType": "user",
"prefsSafeType": prefsSafeType,
"name": gpiiKey,
"password": null,
"email": null,
Expand Down
324 changes: 324 additions & 0 deletions scripts/deleteAndLoadSnapsets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
/*!
Copyright 2018 OCAD University

Licensed under the New BSD license. You may not use this file except in
compliance with this License.

You may obtain a copy of the License at
https://github.com/GPII/universal/blob/master/LICENSE.txt
*/

// This script modifies the preferences data base:
// 1. Finds all the Prefs Safes of type "snapset" (prefsSafesType = "snapset"),
// 2. Finds all the GPII Keys associated with each snapset Prefs Safe
// 3. Deletes the found Prefs Safes and associated GPII Keys
//
// A sample command that runs this script:
// node deleteSnapsets.js $COUCHDBURL

"use strict";

var http = require("http"),
url = require("url"),
fs = require("fs"),
fluid = require("infusion");

var gpii = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.dataLoader");
fluid.setLogging(fluid.logLevel.INFO);

var dbLoader = gpii.dataLoader;

// Handle command line
if (process.argv.length < 5) {
fluid.log("Usage: node deleteAndLoadSnapsets.js $COUCHDB_URL $STATIC_DATA_DIR $BUILD_DATA_DIR [--justDelete]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have --justDelete flag. Could you explain it in the code comment at the beginning of the script too? Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. (Glad you like it).

process.exit(1);
}
dbLoader.couchDbUrl = process.argv[2];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stashing these variable command-line arguments onto the global namespace and then fishing them out in various functions seems like an unfortunate design. Please write a standard top-level function which accumulates these into a local variable rather than writing this material at top level, and then feed these in as function arguments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

dbLoader.staticDataDir = process.argv[3];
dbLoader.buildDataDir = process.argv[4];
if (process.argv.length > 5 && process.argv[5] === "--justDelete") { // for debugging.
dbLoader.justDelete = true;
} else {
dbLoader.justDelete = false;
}

dbLoader.prefsSafesViewUrl = dbLoader.couchDbUrl + "/_design/views/_view/findSnapsetPrefsSafes";
dbLoader.gpiiKeysViewUrl = dbLoader.couchDbUrl + "/_design/views/_view/findAllGpiiKeys";
dbLoader.parsedCouchDbUrl = url.parse(dbLoader.couchDbUrl);
dbLoader.snapsetPrefsSafes = [];
dbLoader.gpiiKeys = [];

fluid.log("COUCHDB_URL: '" +
dbLoader.parsedCouchDbUrl.protocol + "//" +
dbLoader.parsedCouchDbUrl.hostname + ":" +
dbLoader.parsedCouchDbUrl.port +
dbLoader.parsedCouchDbUrl.pathname +
"'");

fluid.log("STATIC_DATA_DIR: '" + dbLoader.staticDataDir + "'");
fluid.log("BUILD_DATA_DIR: '" + dbLoader.buildDataDir + "'");

/**
* Find the Prefs Safes of type "snapset", mark them to be deleted and add
* them to an array of records to remove.
* @param {String} responseString - The response from the database query for
* retrieving the snapset PrefsSafes records
* @return {Array} - The snapset PrefsSafes records marked for deletion.
*/
dbLoader.processSnapsets = function (responseString) {
fluid.log("Processing the snapset Prefs Safes records...");
dbLoader.snapSets = JSON.parse(responseString);
fluid.each(dbLoader.snapSets.rows, function (aSnapset) {
aSnapset.value._deleted = true;
dbLoader.snapsetPrefsSafes.push(aSnapset.value);
});
fluid.log("\tSnapset Prefs Safes marked for deletion.");
return dbLoader.snapsetPrefsSafes;
};

/**
* Find the GPII Key records that are associated with a snapset PrefsSafe, mark
* them for deletion, and add them to array of records to delete.
* @param {String} responseString - The response from the database query for
* retrieving all the GPII Keys.
* @return {Array} - The GPII Key records marked for deletion.
*/
dbLoader.processGpiiKeys = function (responseString) {
fluid.log("Processing the GPII Keys...");
var gpiiKeyRecords = JSON.parse(responseString);
dbLoader.gpiiKeys = dbLoader.markPrefsSafesGpiiKeysForDeletion(
gpiiKeyRecords, dbLoader.snapsetPrefsSafes
);
fluid.log("\tGPII Keys associated with snapset Prefs Safes marked for deletion.");
return dbLoader.gpiiKeys;
};

/**
* Given all the GPII Keys records in the database, find the ones that reference
* a snapset PrefsSafe. As each GPII Key is found it is marked for
* deletion.
* @param {Array} gpiiKeyRecords - Array of GPII Key records from the database.
* @param {Array} snapSets - Array of snapset Prefs Safes whose id references
* its associated GPII Key record.
* @return {Array} - the values from the gpiiKeyRecords that are snapset GPII Keys.
*/
dbLoader.markPrefsSafesGpiiKeysForDeletion = function (gpiiKeyRecords, snapSets) {
var gpiiKeysToDelete = [];
fluid.each(gpiiKeyRecords.rows, function (gpiiKeyRecord) {
var gpiiKey = fluid.find(snapSets, function (aSnapSet) {
if (gpiiKeyRecord.value.prefsSafeId === aSnapSet._id) {
return gpiiKeyRecord.value;
}
}, null);
if (gpiiKey !== null) {
gpiiKey._deleted = true;
gpiiKeysToDelete.push(gpiiKey);
}
});
return gpiiKeysToDelete;
};

/**
* Utility to wrap all the pieces to make a bulk documents deletion request
* for the snapset Prefs Safes and their associated GPII keys. Its intended use
* is the parameter of the appropriate promise.then() call.
*/
dbLoader.doBatchDelete = function () {
var docsToRemove = dbLoader.snapsetPrefsSafes.concat(dbLoader.gpiiKeys);
var execBatchDelete = dbLoader.createBulkDocsRequest(
docsToRemove, dbLoader.batchDeleteResponse
);
execBatchDelete();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this executes the request blind and provides no way for the caller to wait for conclusion. As a general design note, these should all be functions which return promises.

};

/**
* Create a function that makes a bulk docs POST request using the given data.
* @param {Object} dataToPost - JSON data to POST and process in bulk.
* @param {Object} responseHandler - http response handler for the request.
* @return {Function} - A function that wraps an http request to execute the
* POST.
*/
dbLoader.createBulkDocsRequest = function (dataToPost, responseHandler) {
return function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faulty design here which does not wait for conclusion of the request. Return a promise instead.

var postOptions = {
hostname: dbLoader.parsedCouchDbUrl.hostname,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid fishing these variables out as globals and instead accept a structured options argument which encodes them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

port: dbLoader.parsedCouchDbUrl.port,
path: "/gpii/_bulk_docs",
method: "POST",
headers: {
"Accept": "application/json",
"Content-Length": 0, // filled in below
"Content-Type": "application/json"
}
};
var batchPostData = JSON.stringify({"docs": dataToPost});
postOptions.headers["Content-Length"] = Buffer.byteLength(batchPostData);
var batchDocsRequest = http.request(postOptions, responseHandler);
batchDocsRequest.write(batchPostData);
batchDocsRequest.end();
return batchDocsRequest;
};
};

/**
* Generate a response handler, setting up the given promise to resolve/reject
* at the correct time.
* @param {Function} handleEnd - Function to call that deals with the response
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document signature of this function, possibly using an @callback JSDocs directive

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below.

* data when the response receives an "end" event.
* @param {Promise} promise - Promose to resolve/reject on a response "end" or
* "error" event.
* @param {String} errorMsg - Optional error message to prepend to the error
* received from a response "error" event.
* @return {Function} - Function reponse callback for an http request.
*/
dbLoader.createResponseHandler = function (handleEnd, promise, errorMsg) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return a promise rather than accepting one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've suggested returning a promise in related comments. I've made changes elsewhere to do that. But not here, and here's why: The point of this function was to create and configure a response callback to pass, ultimately, to http.request(). This function, createResponseHandler(), returns an anonymous response callback. Further, that's why the promise was passed in so it could be resolved or rejected based on what happened in the callback.

I tried to rework the logic so as to return a promise instead, but couldn't figure out a graceful way to pass the response handler around. Also, after the switch to return a promise "everywhere else", and to use fluid.promise.sequence() to string the steps together, changing the logic here seemed moot.

return function (response) {
var responseString = "";

response.setEncoding("utf8");
response.on("data", function (chunk) {
responseString += chunk;
});
response.on("end", function () {
if (response.statusCode >= 400) { // error
var fullErrorMsg = errorMsg +
response.statusCode + " - " +
response.statusMessage;
// Document-not-found or 404 errors include a reason in the
// response.
// http://docs.couchdb.org/en/stable/api/basics.html#http-status-codes
if (response.statusCode === 404) {
fullErrorMsg = fullErrorMsg + ", " +
JSON.parse(responseString).reason;
}
promise.reject(fullErrorMsg);
}
else {
var value = handleEnd(responseString);
promise.resolve(value);
}
});
response.on("error", function (e) {
fluid.log(errorMsg + e.message);
promise.reject(e);
});
};
};

/**
* Quit the whole process because a request of the database has failed, and log
* the error. Use this function when the failure has not actually modified the
* database; for example, when getting all the current snapset Prefs Safes. If
* that failed, that database is as it was, but there is no point in continuing.
* @param {String} errorMsg - The reason why database access failed.
*/
dbLoader.bail = function (errorMsg) {
fluid.log (errorMsg);
process.exit(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an appropriate place to write code which destroys the whole process. Instead push this into the top-level orchestrator's rejection handler, if necessary - but I believe it won't be. Any rejection will terminate the whole activity by default, if you use fluid.promise.sequence.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've got it. After reworking orchestrate() to use fluid.promise.sequence(), I've puat the exit code in the promise returned by the sequence, see line 517. Is that what you mean?

};

/**
* General mechanism to create a database request, set up an error handler and
* return. It is up to the caller to trigger the request by calling its end()
* function.
* @param {String} databaseURL - URL to query the database with.
* @param {Function} handleResponse - callback that processes the response from
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, use @callback/@typedef

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below.

* the request.
* @param {String} errorMsg - optional error message for request errors.
* @return {http.ClientRequest} - The http request object.
*/
dbLoader.queryDatabase = function (databaseURL, handleResponse, errorMsg) {
var aRequest = http.request(databaseURL, handleResponse);
aRequest.on("error", function (e) {
fluid.log(errorMsg + e.message);
});
return aRequest;
};

/**
* Get all the json files from the given directory, then loop to put their
* contents into an array of Objects.
* @param {String} dataDir - Directory containing the files to load.
* @return {Array} - Each element of the array is an Object based on the
* contents of each file loaded.
*/
dbLoader.getDataFromDirectory = function (dataDir) {
var contentArray = [];
var files = fs.readdirSync(dataDir);
files.forEach(function (aFile) {
if (aFile.endsWith(".json")) {
var fileContent = fs.readFileSync(dataDir + "/" + aFile, "utf-8");
contentArray = contentArray.concat(JSON.parse(fileContent));
}
});
return contentArray;
};

// Load the static data first. If the database is fresh, there won't be any
// views to use to find the snapset Prefs Safes. This ensures they are loaded
// regardless. If the data base already has these views, then this is
// essentially a no-op.
var staticData = dbLoader.getDataFromDirectory(dbLoader.staticDataDir);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, please house all this random top-level material in a function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

var staticDataPromise = fluid.promise();
var staticDataResponse = dbLoader.createResponseHandler(
function () {
fluid.log("Loading static data from '" + dbLoader.staticDataDir + "'");
},
staticDataPromise
);
var execStaticDataRequest = dbLoader.createBulkDocsRequest(staticData, staticDataResponse);
execStaticDataRequest();

// Secondly, get the snapsets Prefs Safes.
var snapsetsPromise = fluid.promise();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write functions which produce these rather than assigning them as globals. Then write a separate function which orchestrates them together in a sequence.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

var getSnapSetsResponse = dbLoader.createResponseHandler(
dbLoader.processSnapsets,
snapsetsPromise,
"Error retrieving snapsets Prefs Safes: "
);
var snapSetsRequest = dbLoader.queryDatabase(
dbLoader.prefsSafesViewUrl,
getSnapSetsResponse,
"Error requesting snapsets Prefs Safes: "
);
staticDataPromise.then(function () { snapSetsRequest.end(); }, dbLoader.bail);

// Thirdly, the associated GPII Keys.
var gpiiKeysPromise = fluid.promise();
var getGpiiKeysResponse = dbLoader.createResponseHandler(
dbLoader.processGpiiKeys,
gpiiKeysPromise,
"Error finding snapset Prefs Safes associated GPII Keys: "
);
var getGpiiKeysRequest = dbLoader.queryDatabase(
dbLoader.gpiiKeysViewUrl,
getGpiiKeysResponse,
"Error requesting GPII Keys: "
);
snapsetsPromise.then(function () { getGpiiKeysRequest.end(); }, dbLoader.bail);

// Next, delete the snapset Prefs Safes and their GPII Keys in batch.
var batchDeletePromise = fluid.promise();
dbLoader.batchDeleteResponse = dbLoader.createResponseHandler(
function () { fluid.log("Snapset Prefs Safes and associated GPII Keys deleted."); },
batchDeletePromise
);
gpiiKeysPromise.then(dbLoader.doBatchDelete, dbLoader.bail);

if (dbLoader.justDelete) {
batchDeletePromise.then(function () { fluid.log("Done."); }, dbLoader.bail);
} else {
// Finally, load the latest snapsets data from the build data.
var buildData = dbLoader.getDataFromDirectory(dbLoader.buildDataDir);
var buildDataPromise = fluid.promise();
var buildDataResponse = dbLoader.createResponseHandler(
function () {
fluid.log ("Bulk loading of build data from '" + dbLoader.buildDataDir + "'");
},
buildDataPromise
);
var execBuildDataRequest = dbLoader.createBulkDocsRequest(buildData, buildDataResponse);
batchDeletePromise.then(execBuildDataRequest, dbLoader.bail);
buildDataPromise.then(function () { fluid.log("Done."); }, dbLoader.bail);
}
Loading