Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | 1x 1x 1x 1x 1x 1x 1x 171x 171x 171x 171x 1x 156x 156x 17x 17x 139x 156x 1x | /*
* GPII Solutions Registry Datasource
*
* Copyright 2016 RtF-I
*
* 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"),
fs = require("fs");
require("kettle");
fluid.registerNamespace("gpii.flowManager.solutionsRegistry");
fluid.defaults("gpii.flowManager.solutionsRegistry.dataSource", {
gradeNames: ["kettle.dataSource"],
members: {
fullSolutionsRegistry: null
},
readOnlyGrade: "gpii.flowManager.solutionsRegistry.dataSource",
invokers: {
getImpl: {
funcName: "gpii.flowManager.solutionsRegistry.dataSource.handle",
args: ["{that}", "{arguments}.1", "{arguments}.2"] // options, directModel
}
},
listeners: {
onCreate: "gpii.flowManager.solutionsRegistry.dataSource.loadSolutionsRegistry"
}
});
gpii.flowManager.solutionsRegistry.dataSource.loadSolutionsRegistry = function (that) {
Iif (!that.options.path) {
fluid.fail("The solutionsRegistry datasource ", that, " needs a \"path\" option pointing to the solution entries folder");
}
var url = fluid.module.resolvePath(that.options.path);
Iif (!fs.existsSync(url)) {
fluid.fail("The path provided to the solutionsRegistry datasource (", url, ") has not been found on the file system");
}
that.fullSolutionsRegistry = require(url);
};
/**
* Handler for get requests of solutions registry. It will return either a full solution registry,
* or if an 'os' is provided in the requestOptions, only the entries for that os will be returned
*
* @param that {Object} the gpii.flowManager.solutionsRegistry.dataSource
* @param requestOptions {Object} currently the only request option supported is "os". If provided,
* the returned solutions registry will be filtered by OS version
*/
gpii.flowManager.solutionsRegistry.dataSource.handle = function (that, requestOptions) {
var promise = fluid.promise();
if (requestOptions.os) { // if "os" is defined, return only solution registry entries for that OS
Eif (requestOptions.os in that.fullSolutionsRegistry) {
promise.resolve(JSON.stringify(that.fullSolutionsRegistry[requestOptions.os]));
} else {
promise.reject({
isError: true,
message: "The requested OS (" + requestOptions.os + ") was not present in the solutions registry",
statusCode: 404
});
}
} else { // if no "os" is requested, return the full solutions registry
promise.resolve(JSON.stringify(that.fullSolutionsRegistry));
}
return promise;
};
/** A mixin grade which automatically expands any %terms corresponding to module names registered in Infusion's module database */
// TODO: This is a duplicate of kettle.dataSource.file.moduleTerms - this should be rewritten after KETTLE-50 is resolved
fluid.defaults("gpii.flowManager.solutionsRegistry.dataSource.moduleTerms", {
gradeNames: "gpii.flowManager.solutionsRegistry.dataSource",
termMap: "@expand:fluid.module.terms()"
});
|