-
Notifications
You must be signed in to change notification settings - Fork 62
GPII-1987: Implement data loaders to load preferences and authorization test data into CouchDB #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 29 commits
c8d74d7
ef671e4
3c0c6ca
64c175e
83a426a
c4cd5b4
22e41d1
5f7285d
de78b86
19b8436
a27423b
a06801d
745bbfc
23762e9
6ce660c
ec33391
7798a42
eef277d
1bd667d
cf907b9
47764a8
908f9ff
e036123
89c14cf
86bb666
0b0a07f
c88e17c
521f72c
025cba4
67715b9
0e75218
1af51a9
72aab68
34e211e
4f7f072
3907f0c
24b45c3
2818200
8d03025
2778b60
f6a1d79
2da973e
f02e7d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| This directory contains these scripts: | ||
|
|
||
| * **browserifyTestDependency.js**: To browserify test dependencies required for running some web tests. | ||
| * **dataLoader-auth.js**: To load authorization test data into CouchDB. | ||
| * **dataLoader-prefs.js**: To load preferences test data into CouchDB. | ||
|
|
||
| ## Browserify Test Dependencies: | ||
|
|
||
| **Script name:** `browserifyTestDependency.js` | ||
|
|
||
| This script runs as a npm postinstall step to browserify some node modules that are required for running a few web tests. The creation of this script is to work around the issue that some of these node modules are only pulled in as `devDependencies`(see [GPII package.json](../package.json)), which means the browserifying should only occurs when GPII runs in the development mode. This script ensures the present of these node modules before proceeding with the browserifying. It prevents the failure of running `npm install` when setting up GPII in the production mode. | ||
|
|
||
| To start this script, run the following command in the `universal` directory: | ||
|
|
||
| ``` | ||
| node scripts/browserifyTestDependency.js | ||
| ``` | ||
|
|
||
| ## Data Loaders | ||
|
|
||
| Data loaders are used for setting up GPII production environment by loading authorization and/or preferences test data into CouchDB. See [Data Loader issue ticket](https://issues.gpii.net/browse/GPII-1987) for details. | ||
|
|
||
| ### Preferences Data Loader | ||
|
|
||
| **Script name:** `dataLoader-prefs.js` | ||
|
|
||
| Preferences Data Loader reads all json files from the given directory. Each json file is loaded as a individual CouchDB document with its file name as the corresponding document id. | ||
|
|
||
| To start the data loading, run the following command in the `universal` directory: | ||
|
|
||
| ``` | ||
| node scripts/dataLoader-prefs.js | ||
| ``` | ||
|
|
||
| #### How to config Preferences Data Loader | ||
|
|
||
| `dataLoader-prefs.js` instantiates the infusion component `gpii.dataLoader.prefsDataLoader` to load preferences data. | ||
|
|
||
| #### Component Options | ||
|
|
||
| | Option | Type | Description | Default | | ||
| | ----------------- | ---------- | ----------- | ------- | | ||
| | `dbName` | String | Required. The name of the CouchDB database to be created for loading preferences data. If the dabase already exists, delete it and recreate. | preferences | | ||
|
||
| | `dataPath` | String | Required. The directory where all preference json files reside. | %universal/testData/preferences/ | | ||
|
||
| | `couchDbUrl` | String | Required. The URL to the CouchDB. | http://localhost:5984 | | ||
|
|
||
| #### Supported Events | ||
|
|
||
| | Event | Description | Parameters | Parameters Description | | ||
| | ----- | ----------- | ---------- | ---------------------- | | ||
| | `onDataLoaded` | Fires when all preference data has been loaded into the CouchDB. | None | | | ||
| | `onDataLoadedError` | Fires when an error occurs at loading preference data. | errorMsg | The error message. | | ||
|
|
||
| ### Authorization Data Loader | ||
|
|
||
| **Script name:** `dataLoader-auth.js` | ||
|
|
||
| Authorization Data Loader reads given json files from the file system and load them into CouchDB as they are. | ||
|
|
||
| To start the data loading, run the following command in the `universal` directory: | ||
|
|
||
| ``` | ||
| node scripts/dataLoader-auth.js | ||
| ``` | ||
|
|
||
| #### How to config Authorization Data Loader | ||
|
|
||
| `dataLoader-auth.js` instantiates the infusion component `gpii.dataLoader.authDataLoader` to load authorization data. | ||
|
|
||
| #### Component Options | ||
|
|
||
| | Option | Type | Description | Default | | ||
| | ----------------- | ---------- | ----------- | ------- | | ||
| | `dbName` | String | Required. The name of the CouchDB database to be created for loading authorization data. If the dabase already exists, delete it and recreate. | auth | | ||
|
||
| | `dataFile` | Array | Required. An array of data files to be loaded. | ["%universal/testData/security/TestOAuth2DataStore.json", "%universal/gpii/node_modules/gpii-oauth2/gpii-oauth2-datastore/dbViews/views.json"] | | ||
| | `couchDbUrl` | String | Required. The URL to the CouchDB. | `http://localhost:5984` | | ||
|
|
||
| #### Supported Events | ||
|
|
||
| | Event | Description | Parameters | Parameters Description | | ||
| | ----- | ----------- | ---------- | ---------------------- | | ||
| | `onDataLoaded` | Fires when all preference data has been loaded into the CouchDB. | None | | | ||
| | `onDataLoadedError` | Fires when an error occurs at loading preference data. | errorMsg | The error message. | | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /*! | ||
| Copyright 2016-2017 OCAD University | ||
|
|
||
| Licensed under the New BSD license. You may not use this file except in | ||
| compliance with this License. | ||
|
|
||
| The research leading to these results has received funding from the European Union's | ||
| Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016. | ||
|
|
||
| You may obtain a copy of the License at | ||
| https://github.com/GPII/universal/blob/master/LICENSE.txt | ||
| */ | ||
|
|
||
| /** | ||
| * The data loader to load GPII authorization server data into CouchDB. | ||
| * Before running this script, make sure CouchDB is started and ready for handling | ||
| * database operation requests. | ||
| */ | ||
|
|
||
| "use strict"; | ||
|
|
||
| var fluid = require("infusion"), | ||
| gpii = fluid.registerNamespace("gpii"); | ||
|
|
||
| fluid.setLogging(true); | ||
|
|
||
| require("./shared/authDataLoader.js"); | ||
|
|
||
| gpii.dataLoader.authDataLoader({ | ||
| dbName: "auth", | ||
| dataFile: [ | ||
| "%universal/testData/security/TestOAuth2DataStore.json", | ||
| "%universal/gpii/node_modules/gpii-oauth2/gpii-oauth2-datastore/dbViews/views.json" | ||
| ], | ||
| couchDbUrl: "http://localhost:5984" | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /*! | ||
| Copyright 2016-2017 OCAD University | ||
|
|
||
| Licensed under the New BSD license. You may not use this file except in | ||
| compliance with this License. | ||
|
|
||
| The research leading to these results has received funding from the European Union's | ||
| Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016. | ||
|
|
||
| You may obtain a copy of the License at | ||
| https://github.com/GPII/universal/blob/master/LICENSE.txt | ||
| */ | ||
|
|
||
| /** | ||
| * The data loader to load GPII preferences data into CouchDB. | ||
| * Before running this script, make sure CouchDB is started and ready for handling | ||
| * database operation requests. | ||
| */ | ||
|
|
||
| "use strict"; | ||
|
|
||
| var fluid = require("infusion"), | ||
| gpii = fluid.registerNamespace("gpii"); | ||
|
|
||
| fluid.setLogging(true); | ||
|
|
||
| require("./shared/prefsDataLoader.js"); | ||
|
|
||
| gpii.dataLoader.prefsDataLoader({ | ||
| dbName: "preferences", | ||
| dataPath: "%universal/testData/preferences/", | ||
| couchDbUrl: "http://localhost:5984" | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /*! | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd prefer to see all the contents of scripts/shared placed into a fresh "micromodule" named dataLoader, and all the tests can then be similarly named, since tests/scripts looks rather peculiar |
||
| Copyright 2017 OCAD University | ||
|
|
||
| Licensed under the New BSD license. You may not use this file except in | ||
| compliance with this License. | ||
|
|
||
| The research leading to these results has received funding from the European Union's | ||
| Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016. | ||
|
|
||
| You may obtain a copy of the License at | ||
| https://github.com/GPII/universal/blob/master/LICENSE.txt | ||
| */ | ||
|
|
||
| "use strict"; | ||
|
|
||
| var fluid = require("infusion"), | ||
| gpii = fluid.registerNamespace("gpii"); | ||
|
|
||
| require("./dataLoader.js"); | ||
|
|
||
| fluid.defaults("gpii.dataLoader.authDataLoader", { | ||
| gradeNames: ["gpii.dataLoader", "gpii.dataLoader.reporter"], | ||
| databases: { | ||
| expander: { | ||
| funcName: "gpii.dataLoader.authDataLoader.constructAuthData", | ||
| args: ["{that}.options.dbName", "{that}.options.dataFile"] | ||
| } | ||
| }, | ||
| listeners: { | ||
| "onCreate.load": { | ||
| listener: "gpii.dataLoader.performLoad", | ||
| args: ["{that}.options.dbName", "{that}"] | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * Construct the value of `options.databases` that to be accepted by `gpii.dataLoader` (See dataLoader.js). | ||
| * | ||
| * @param dbName {String} The database name; | ||
| * @param dataFile {Array} An array of data paths to files to be loaded into the database. | ||
| */ | ||
| gpii.dataLoader.authDataLoader.constructAuthData = function (dbName, dataFile) { | ||
| var togo = {}; | ||
| fluid.set(togo, dbName + ".dataFile", dataFile); | ||
|
||
|
|
||
| return togo; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct throughout infusion -> Infusion