Repository: incubator-ignite Updated Branches: refs/heads/ignite-843 903e23467 -> c50535dbf
# IGNITE-843 Refactoring. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/fb0f3178 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/fb0f3178 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/fb0f3178 Branch: refs/heads/ignite-843 Commit: fb0f3178f733a2f13f5d2416c030c0f1852c3f05 Parents: a9af674 Author: Andrey <anovi...@gridgain.com> Authored: Thu Aug 20 13:20:58 2015 +0700 Committer: Andrey <anovi...@gridgain.com> Committed: Thu Aug 20 13:20:58 2015 +0700 ---------------------------------------------------------------------- .../src/main/js/routes/generator/common.js | 42 +++++--------------- .../src/main/js/routes/generator/java.js | 9 +++-- .../src/main/js/routes/generator/xml.js | 9 +++-- .../src/main/js/routes/notebooks.js | 10 ++--- .../src/main/js/routes/public.js | 6 +-- .../src/main/js/routes/utils.js | 37 +++++++++++++++++ 6 files changed, 64 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fb0f3178/modules/control-center-web/src/main/js/routes/generator/common.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/generator/common.js b/modules/control-center-web/src/main/js/routes/generator/common.js index 85b9331..a7a2399 100644 --- a/modules/control-center-web/src/main/js/routes/generator/common.js +++ b/modules/control-center-web/src/main/js/routes/generator/common.js @@ -16,21 +16,14 @@ */ var _ = require('lodash'); +var utils = require('../utils'); -function isDefined(v) { - return !(v === undefined || v === null); -} - -exports.isDefined = isDefined; - -exports.mainComment = mainComment; - -function mainComment() { +exports.mainComment = function mainComment() { return 'This configuration was generated by Ignite Control Center (' - + formatDate(new Date()) + ')'; -} + + exports.formatDate(new Date()) + ')'; +}; -function addLeadingZero(numberStr, minSize) { +function _addLeadingZero(numberStr, minSize) { if (typeof (numberStr) != 'string') numberStr = '' + numberStr; @@ -41,16 +34,14 @@ function addLeadingZero(numberStr, minSize) { return numberStr; } -exports.formatDate = formatDate; - -function formatDate(date) { - var dd = addLeadingZero(date.getDate(), 2); - var mm = addLeadingZero(date.getMonth() + 1, 2); +exports.formatDate = function formatDate(date) { + var dd = _addLeadingZero(date.getDate(), 2); + var mm = _addLeadingZero(date.getMonth() + 1, 2); var yyyy = date.getFullYear(); - return mm + '/' + dd + '/' + yyyy + ' ' + addLeadingZero(date.getHours(), 2) + ':' + addLeadingZero(date.getMinutes(), 2); -} + return mm + '/' + dd + '/' + yyyy + ' ' + _addLeadingZero(date.getHours(), 2) + ':' + _addLeadingZero(date.getMinutes(), 2); +}; exports.builder = function () { var res = []; @@ -209,7 +200,7 @@ exports.javaBuildInClass = javaBuildInClass; * @returns 'true' if given class name is a java build-in type. */ exports.isJavaBuildInClass = function (className) { - return isDefined(javaBuildInClasses[className]); + return utils.isDefined(javaBuildInClasses[className]); }; exports.knownClasses = { @@ -275,17 +266,6 @@ exports.transactionConfiguration = new ClassDescriptor('org.apache.ignite.config txSerializableEnabled: null }); -exports.hasProperty = function (obj, props) { - for (var propName in props) { - if (props.hasOwnProperty(propName)) { - if (obj[propName]) - return true; - } - } - - return false; -}; - /** * Generate properties file with properties stubs for stores data sources. * http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fb0f3178/modules/control-center-web/src/main/js/routes/generator/java.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/generator/java.js b/modules/control-center-web/src/main/js/routes/generator/java.js index 4186573..d27fe6a 100644 --- a/modules/control-center-web/src/main/js/routes/generator/java.js +++ b/modules/control-center-web/src/main/js/routes/generator/java.js @@ -18,6 +18,7 @@ var _ = require('lodash'); var generatorCommon = require("./common"); +var utils = require("../utils"); /** * Convert some name to valid java name. @@ -138,7 +139,7 @@ exports.generateClusterConfiguration = function (cluster, javaClass, clientNearC declareVariable(res, true, 'ipFinder', 'org.apache.ignite.spi.discovery.tcp.ipfinder.jdbc.TcpDiscoveryJdbcIpFinder'); - res.line('ipFinder.setInitSchema(' + (generatorCommon.isDefined(d.Jdbc.initSchema) && d.Jdbc.initSchema) + ');'); + res.line('ipFinder.setInitSchema(' + (utils.isDefined(d.Jdbc.initSchema) && d.Jdbc.initSchema) + ');'); res.line('discovery.setIpFinder(ipFinder);'); res.needEmptyLine = true; @@ -721,7 +722,7 @@ function declareVariable(res, varNew, varName, varFullType, varFullActualType, v function addProperty(res, varName, obj, propName, enumType, setterName) { var val = obj[propName]; - if (generatorCommon.isDefined(val)) { + if (utils.isDefined(val)) { res.emptyLineIfNeeded(); res.line(varName + '.' + getSetterName(setterName ? setterName : propName) @@ -742,7 +743,7 @@ function addProperty(res, varName, obj, propName, enumType, setterName) { function addClassProperty(res, varName, obj, propName) { var val = obj[propName]; - if (generatorCommon.isDefined(val)) { + if (utils.isDefined(val)) { res.emptyLineIfNeeded(); res.line(varName + '.' + getSetterName(propName) + '(' + res.importClass(val) + '.class);'); @@ -796,7 +797,7 @@ function addMultiparamProperty(res, varName, obj, propName, type, setterName) { } function addBeanWithProperties(res, varName, bean, beanPropName, beanVarName, beanClass, props, createBeanAlthoughNoProps) { - if (bean && generatorCommon.hasProperty(bean, props)) { + if (bean && utils.hasProperty(bean, props)) { if (!res.emptyLineIfNeeded()) { res.line(); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fb0f3178/modules/control-center-web/src/main/js/routes/generator/xml.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/generator/xml.js b/modules/control-center-web/src/main/js/routes/generator/xml.js index 75b590b..2983c07 100644 --- a/modules/control-center-web/src/main/js/routes/generator/xml.js +++ b/modules/control-center-web/src/main/js/routes/generator/xml.js @@ -18,6 +18,7 @@ var _ = require('lodash'); var generatorCommon = require("./common"); +var utils = require("../utils"); var dataStructures = require("../../helpers/data-structures.js"); exports.generateClusterConfiguration = function (cluster, clientNearConfiguration) { @@ -126,7 +127,7 @@ exports.generateClusterConfiguration = function (cluster, clientNearConfiguratio case 'Jdbc': res.startBlock('<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.jdbc.TcpDiscoveryJdbcIpFinder">'); - res.line('<property name="initSchema" value="' + (generatorCommon.isDefined(d.Jdbc.initSchema) && d.Jdbc.initSchema) + '"/>'); + res.line('<property name="initSchema" value="' + (utils.isDefined(d.Jdbc.initSchema) && d.Jdbc.initSchema) + '"/>'); res.endBlock('</bean>'); break; @@ -650,7 +651,7 @@ function addElement(res, tag, attr1, val1, attr2, val2) { function addProperty(res, obj, propName, setterName) { var val = obj[propName]; - if (generatorCommon.isDefined(val)) + if (utils.isDefined(val)) addElement(res, 'property', 'name', setterName ? setterName : propName, 'value', escapeAttr(val)); return val; @@ -659,14 +660,14 @@ function addProperty(res, obj, propName, setterName) { function addClassNameProperty(res, obj, propName) { var val = obj[propName]; - if (generatorCommon.isDefined(val)) + if (utils.isDefined(val)) addElement(res, 'property', 'name', propName, 'value', generatorCommon.javaBuildInClass(val)); return val; } function addBeanWithProperties(res, bean, beanPropName, beanClass, props, createBeanAlthoughNoProps) { - if (bean && generatorCommon.hasProperty(bean, props)) { + if (bean && utils.hasProperty(bean, props)) { res.emptyLineIfNeeded(); res.startBlock('<property name="' + beanPropName + '">'); res.startBlock('<bean class="' + beanClass + '">'); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fb0f3178/modules/control-center-web/src/main/js/routes/notebooks.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/notebooks.js b/modules/control-center-web/src/main/js/routes/notebooks.js index ed6fef1..df550a3 100644 --- a/modules/control-center-web/src/main/js/routes/notebooks.js +++ b/modules/control-center-web/src/main/js/routes/notebooks.js @@ -16,7 +16,9 @@ */ var router = require('express').Router(); + var db = require('../db'); +var utils = require('./utils'); /** * Get notebooks names accessed for user account. @@ -108,12 +110,6 @@ router.post('/save', function (req, res) { }); }); -function _randomValueHex(len) { - return require('crypto').randomBytes(Math.ceil(len / 2)) - .toString('hex') // convert to hexadecimal format - .slice(0, len); // return required number of characters -} - /** * Create new notebook for user account. * @@ -128,7 +124,7 @@ router.get('/new', function (req, res) { if (err) return res.status(500).send(err.message); - var name = 'Notebook' + ' ' + _randomValueHex(8); + var name = 'Notebook' + ' ' + utils.randomValueHex(8); (new db.Notebook({space: space.id, name: name, paragraph: []})).save(function (err, notebook) { if (err) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fb0f3178/modules/control-center-web/src/main/js/routes/public.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/public.js b/modules/control-center-web/src/main/js/routes/public.js index 7f4fb8a..d8133b9 100644 --- a/modules/control-center-web/src/main/js/routes/public.js +++ b/modules/control-center-web/src/main/js/routes/public.js @@ -17,11 +17,11 @@ var router = require('express').Router(); var passport = require('passport'); -var crypto = require('crypto'); var nodemailer = require('nodemailer'); var db = require('../db'); var config = require('../helpers/configuration-loader.js'); +var utils = require('./utils'); // GET dropdown-menu template. router.get('/select', function (req, res) { @@ -127,7 +127,7 @@ router.post('/password/forgot', function(req, res) { return res.status(401).send('Can\'t send e-mail with instructions to reset password.<br />' + 'Please ask webmaster to setup smtp server!'); - var token = crypto.randomBytes(20).toString('hex'); + var token = utils.randomValueHex(20); db.Account.findOne({ email: req.body.email }, function(err, user) { if (!user) @@ -150,7 +150,7 @@ router.post('/password/forgot', function(req, res) { subject: 'Password Reset', text: 'You are receiving this because you (or someone else) have requested the reset of the password for your account.\n\n' + 'Please click on the following link, or paste this into your browser to complete the process:\n\n' + - 'http://' + req.headers.host + '/reset/' + token + '\n\n' + + 'http://' + req.headers.host + '/password/reset/' + token + '\n\n' + 'If you did not request this, please ignore this email and your password will remain unchanged.\n\n' + '--------------\n' + 'Apache Ignite Web Control Center\n' http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fb0f3178/modules/control-center-web/src/main/js/routes/utils.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/utils.js b/modules/control-center-web/src/main/js/routes/utils.js new file mode 100644 index 0000000..154b80e --- /dev/null +++ b/modules/control-center-web/src/main/js/routes/utils.js @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +exports.isDefined = function isDefined(v) { + return !(v === undefined || v === null); +}; + +exports.hasProperty = function (obj, props) { + for (var propName in props) { + if (props.hasOwnProperty(propName)) { + if (obj[propName]) + return true; + } + } + + return false; +}; + +exports.randomValueHex = function randomValueHex(len) { + return require('crypto').randomBytes(Math.ceil(len / 2)) + .toString('hex') // convert to hexadecimal format + .slice(0, len); // return required number of characters +};