<commit_before>// Copyright 2015, EMC, Inc.

'use strict';

var di = require('di'),
    express = require('express');

module.exports = pollerRouterFactory;

di.annotate(pollerRouterFactory,
    new di.Inject(
        'Services.Waterline',
        'Http.Services.RestApi',
        'Protocol.Task',
        'Constants',
        'Promise',
        '_'
    )
);

/**
 * pollerRouterFactory extends the express router with the additional routes
 * specific to devices.  Uses the provided or injected dependencies to do so.
 * @private
 * @param {DomainService} domainService instance of the data service
 * @param {PollerService} pollerService instance of the poller service
 * @param presenter
 * @param {Promise} Promise
 * @returns {Router} returns the router that has been extended with our verbs
 */
function pollerRouterFactory (waterline, rest, taskProtocol, Constants, Promise, _) {
    var router = express.Router();

    var pollerLibrary = [
        {
            name: 'ipmi',
            node: true,
            config: [
                {
                    key: 'host',
                    type: 'string'
                },
                {
                    key: 'user',
                    type: 'string',
                    defaultsTo: 'admin'
                },
                {
                    key: 'password',
                    type: 'string',
                    defaultsTo: '<PASSWORD>'
                },
                {
                    key: 'alerts',
                    type: 'json',
                    required: false
                }
            ]
        },
        {
            name: 'snmp',
            config: [
                {
                    key: 'host',
                    type: 'string',
                    required: true
                },
                {
                    key: 'communityString',
                    type: 'string',
                    required: true
                },
                {
                    key: 'extensionMibs',
                    type: 'string[]'
                }
            ]
        }
    ];

    /**
     * @api {get} /api/1.1/pollers/library GET /library
     * @apiVersion 1.1.0
     * @apiDescription get list of possible pollers services
     * @apiName pollers-library-get
     * @apiGroup pollers
     * @apiSuccess {json} pollers list of the available library pollers.
     */

    router.get('/pollers/library', rest(function () {
        return pollerLibrary;
    }));


    /**
     * @api {get} /api/1.1/pollers/library/:identifier GET /library/:identifier
     * @apiVersion 1.1.0
     * @apiDescription get a single poller
     * @apiName pollers-library-service-get
     * @apiGroup pollers
     * @apiParamExample {String }Identifier-Example:
     *      "ipmi"
     * @apiError NotFound There is no poller in the library with <code>identifier</code>
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *       "error": "Not Found"
     *     }
     */

    router.get('/pollers/library/:identifier', rest(function (req) {
        return _.detect(pollerLibrary, { name: req.params.identifier });
    }));

    var pollerWorkItems = {
        ipmi: Constants.WorkItems.Pollers.IPMI,
        snmp: Constants.WorkItems.Pollers.SNMP
    };

    function deserializePoller(poller) {
        if (poller) {
            if (poller.type) {
                poller.name = pollerWorkItems[poller.type];
            }
            poller = _.pick(poller, 'name', 'node', 'config', 'pollInterval', 'paused');
        }
        return poller;
    }

    function serializePoller(poller) {
        if (poller) {
            poller.type = _.findKey(pollerWorkItems, function (workItem) {
                return workItem === poller.name;
            });
            delete poller.name;
        }
        return poller;
    }

    /**
     * @api {get} /api/1.1/pollers GET /<commit_msg>added deserialization for numeric oids in pollers<commit_after>// Copyright 2015, EMC, Inc.

'use strict';

var di = require('di'),
    express = require('express');

module.exports = pollerRouterFactory;

di.annotate(pollerRouterFactory,
    new di.Inject(
        'Services.Waterline',
        'Http.Services.RestApi',
        'Protocol.Task',
        'Constants',
        'Promise',
        '_'
    )
);

/**
 * pollerRouterFactory extends the express router with the additional routes
 * specific to devices.  Uses the provided or injected dependencies to do so.
 * @private
 * @param {DomainService} domainService instance of the data service
 * @param {PollerService} pollerService instance of the poller service
 * @param presenter
 * @param {Promise} Promise
 * @returns {Router} returns the router that has been extended with our verbs
 */
function pollerRouterFactory (waterline, rest, taskProtocol, Constants, Promise, _) {
    var router = express.Router();

    var pollerLibrary = [
        {
            name: 'ipmi',
            node: true,
            config: [
                {
                    key: 'host',
                    type: 'string'
                },
                {
                    key: 'user',
                    type: 'string',
                    defaultsTo: 'admin'
                },
                {
                    key: 'password',
                    type: 'string',
                    defaultsTo: '<PASSWORD>'
                },
                {
                    key: 'alerts',
                    type: 'json',
                    required: false
                }
            ]
        },
        {
            name: 'snmp',
            config: [
                {
                    key: 'host',
                    type: 'string',
                    required: true
                },
                {
                    key: 'communityString',
                    type: 'string',
                    required: true
                },
                {
                    key: 'extensionMibs',
                    type: 'string[]'
                }
            ]
        }
    ];

    /**
     * @api {get} /api/1.1/pollers/library GET /library
     * @apiVersion 1.1.0
     * @apiDescription get list of possible pollers services
     * @apiName pollers-library-get
     * @apiGroup pollers
     * @apiSuccess {json} pollers list of the available library pollers.
     */

    router.get('/pollers/library', rest(function () {
        return pollerLibrary;
    }));


    /**
     * @api {get} /api/1.1/pollers/library/:identifier GET /library/:identifier
     * @apiVersion 1.1.0
     * @apiDescription get a single poller
     * @apiName pollers-library-service-get
     * @apiGroup pollers
     * @apiParamExample {String }Identifier-Example:
     *      "ipmi"
     * @apiError NotFound There is no poller in the library with <code>identifier</code>
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *       "error": "Not Found"
     *     }
     */

    router.get('/pollers/library/:identifier', rest(function (req) {
        return _.detect(pollerLibrary, { name: req.params.identifier });
    }));

    var pollerWorkItems = {
        ipmi: Constants.WorkItems.Pollers.IPMI,
        snmp: Constants.WorkItems.Pollers.SNMP
    };

    function deserializePoller(poller) {
        if (poller) {
            if (poller.type) {
                poller.name = pollerWorkItems[poller.type];
            }
            poller = _.pick(poller, 'name', 'node', 'config', 'pollInterval', 'paused');
        }
        return poller;
    }

    function serializePoller(poller) {
        if (poller) {
            poller.type = _.findKey(pollerWorkItems, function (workItem) {
                return workItem === poller.name;
            });
            delete poller.name;
        }
        return waterline.workitems.deserialize(poller);
    }

    /**
     * @api {get} /api/1.1/pollers GET /
{'fraction_non_alphanumeric': 0.11146135417980078, 'fraction_numerical': 0.00529567519858782, 'mean_word_length': 1.447392780006171, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4357471', 'n_tokens_mistral': 2242, 'n_tokens_neox': 2131, 'n_words': 516}