All files / universal.klown/gpii/node_modules/contextManager/src ContextManagerUtilities.js

95.45% Statements 21/22
90% Branches 9/10
100% Functions 3/3
95.45% Lines 21/22

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                                    3x 3x   3x   3x         3x 140x   140x 240x 140x     100x 100x 141x 141x 141x     141x 141x 87x     100x 30x     140x 140x    
/*!
 * 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;
};