All files / universal/gpii/node_modules/preferencesServer/src preferencesGetHandler.js

100% Statements 13/13
50% Branches 1/2
100% Functions 3/3
100% Lines 13/13

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                                  1x 1x   1x                           1x 155x 155x 149x 149x         1x 149x   149x 149x 149x    
/*!
GPII Preferences Server GET Handler
 
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 = require("infusion"),
    gpii = fluid.registerNamespace("gpii");
 
fluid.defaults("gpii.preferencesServer.get.handler", {
    gradeNames: ["kettle.request.http"],
    invokers: {
        handleRequest: {
            funcName: "gpii.preferencesServer.get.getRawPreferences",
            args: [ "{that}", "{preferencesServer}"]
        },
        buildReturnPayload: {
            funcName: "gpii.preferencesServer.get.buildReturnPayload",
            args: [ "{arguments}.0", "{preferencesServer}.ontologyHandler", "{request}"]
        }
    }
});
 
gpii.preferencesServer.get.getRawPreferences = function (request, preferencesServer) {
    var promise = preferencesServer.getRawPreferences(request.req.params.userToken);
    promise.then(function (rawPrefs) {
        Eif (!fluid.isDestroyed(request)) { // TODO: Remove this ugly check when there is a solution for FLUID-5790
            request.buildReturnPayload(rawPrefs);
        }
    }, request.events.onError.fire);
};
 
gpii.preferencesServer.get.buildReturnPayload = function (rawPrefs, ontologyHandler, request) {
    fluid.log("Raw preferences fetched by PreferencesServer: " + JSON.stringify(rawPrefs, null, 2));
    // grab the desired view (ontology) value from parameter (default to "flat") and GET
    var toView = gpii.preferencesServer.getRequestView(request);
    var prefs = ontologyHandler.rawPrefsToOntology(rawPrefs, toView);
    request.events.onSuccess.fire(prefs);
};