/*!
* GPII Context Manager Utilities
*
* Copyright 2014 Raising the Floor - International
*
* 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 = fluid || require("infusion"),
gpii = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.contextManager.utils");
gpii.contextManager.utils.transformTypeLookup = {
"http://registry.gpii.net/conditions/inRange": "fluid.transforms.inRange",
"http://registry.gpii.net/conditions/timeInRange": "gpii.transformer.timeInRange"
};
gpii.contextManager.utils.findActiveContexts = function (currentContext, matchData) {
var activeContexts = [ "gpii-default" ];
// do nothing if there is no NP set yet
fluid.each(matchData.inferredConfiguration, function (content, contextId) {
if (content.conditions === undefined) {
return;
}
// massage conditions to be proper transform specs:
var isActive = true;
fluid.each(content.conditions, function (condition) {
var entry = fluid.copy(condition);
entry.type = gpii.contextManager.utils.transformTypeLookup[condition.type];
Iif (entry.type === undefined) {
fluid.fail("ERROR: Failed to find the condition type: " + condition.type + " - Dropping attempt to find active contexts");
}
var result = fluid.model.transformWithRules(currentContext, { evaluations: { transform: entry }});
if (result.evaluations !== true) {
isActive = false;
}
});
if (isActive) {
activeContexts.unshift(contextId);
}
});
fluid.log("Active contexts calculated to be: " + activeContexts);
return activeContexts;
};
|