Commit 669143a5 authored by Indrek Jentson's avatar Indrek Jentson Committed by Indrek Jentson

Koodi parandused

Signed-off-by: default avatarIndrek Jentson <indrek.jentson@cgi.com>
parent e165c1f3
......@@ -3,7 +3,6 @@ keeleliin-wrapper-service.iml
config.js
node_modules
.idea
dump.rdb
scan
tmp_tests/contentTokenizer.js
tmp_tests/jmeter.log
......@@ -12,4 +11,5 @@ tmp_tests/189megafile
keeleliin.log
coverage
global_config/local_global.js
updateWrappers.sh
\ No newline at end of file
updateWrappers.sh
/wrapper.log
......@@ -2,5 +2,5 @@
var server = require('./www/server');
server.startCluster(1, function ( err ) {
console.log('Server started ' + process.pid);
console.log('Server started ' + process.pid);
});
\ No newline at end of file
......@@ -68,8 +68,8 @@ config.serverUrl = 'http://localhost';
config.wrapper = { //teenuse seadistus
id: 'concat', // Unikaalne lühinimi
title: 'Lihtne konjateneerija', //Avalik nimi
description: 'Konkateneerib etteantud failid üheks suureks failiks', //Kirjeldus
title: 'Lihtne konkateneerija', //Avalik nimi
description: 'Liidab etteantud failid üheks suureks failiks', //Kirjeldus
port: 3002, // port
class: 'simpleLocalCommand', // wrapperi failinimi wrapper kaustast, mida utiliidi käivitamiseks kasutatakse
command: { commandTemplate: 'cat [data]' }, // utiliidi käsurea käsk
......@@ -80,7 +80,7 @@ config.wrapper = { //teenuse seadistus
options: ['0', '1'], // Võimalikud sobivad väärtused
value: '1', // Soovituslik vaikeväärtus
filter: function (value) { // parameerile rakendatav filter. Antud juhul viiaks väärtus boolean kujule
return value == 1;
return value === 1;
},
required: true, // kas mittetühi väärtus on nõutud
allowEmpty: false, // kas parameeter peab olema saadetud
......
......@@ -69,7 +69,7 @@ config.isAsyncParamDescription = {
options: ['0', '1'],
value: '1',
filter: function (value) {
return value == 1;
return value === 1;
},
required: true,
allowEmpty: false,
......
This diff is collapsed.
{
"name": "keeleliin-wrapper-service",
"version": "0.0.0",
"version": "1.1.0",
"private": true,
"scripts": {
"start": "node ./app.js",
"test": "./node_modules/.bin/istanbul test _mocha -- -R spec --timeout 15000"
"test": "mocha"
},
"dependencies": {
"JSONStream": "^1.0.4",
"async": "^1.4.0",
"body-parser": "~1.12.4",
"debug": "~2.2.0",
"express": "~4.12.4",
"body-parser": "^1.18.3",
"debug": "^4.1.1",
"express": "~4.16.0",
"fs": "0.0.2",
"graceful-fs": "^4.1.2",
"is-gzip": "^1.0.0",
"is-tar": "^1.0.0",
"is-zip": "^1.0.0",
"istextorbinary": "^1.0.2",
"jade": "~1.9.2",
"log4js": "^0.6.26",
"mime": "^1.3.4",
"mkdirp": "~0.5.0",
"morgan": "~1.5.3",
"morgan": "~1.9.0",
"multer": "0.1.6",
"node-schedule": "^0.2.9",
"nodejs-disks": "^0.2.1",
"nodemailer": "^1.4.0",
"pug": "^2.0.3",
"randomstring": "^1.0.5",
"recursive-readdir": "^1.2.1",
"recursive-readdir": "^2.2.2",
"redis": "^0.12.1",
"request": "^2.57.0",
"rimraf": "^2.4.0",
......@@ -37,8 +35,9 @@
},
"devDependencies": {
"assert": "^1.3.0",
"istanbul": "^0.3.15",
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"should": "^7.0.1",
"supertest": "^1.0.1"
"supertest": "^3.3.0"
}
}
......@@ -20,7 +20,7 @@ function LocalCommand( commandModel ) {
self._parseParams();
var paramsArray = commandParts.slice(commandParts);
self.command = paramsArray.shift();
self.commandParams = paramsArray.filter(function (value) { return value != '' && value != null && value != undefined; });
self.commandParams = paramsArray.filter(function (value) { return value !== '' && value != null && value !== undefined; });
return self;
};
......@@ -45,7 +45,7 @@ function LocalCommand( commandModel ) {
var newCommandParts = [];
for (i in commandParts) {
if( commandParts[i] == propertyItem){
if( commandParts[i] === propertyItem){
if(Array.isArray(value)){
for(j in value){
newCommandParts.push(value[j]);
......
......@@ -37,12 +37,12 @@ function ServiceRequest( requestBody, requestFiles ) {
value = mapping.filter(value);
}
if(mapping.required == true && value == undefined){
if(mapping.required === true && value === undefined){
self.setMessage(property, 'Väli on nõutud');
continue;
}
if(mapping.allowEmpty == false && (value === null || value === '') ){
if(mapping.allowEmpty === false && (value === null || value === '') ){
self.setMessage(property, 'Väli on täitmata');
continue;
}
......@@ -68,12 +68,12 @@ function ServiceRequest( requestBody, requestFiles ) {
var fileItem = self.files[fileId];
if(!fileItem){
logger.error('Nõutud faili ei saadetud' + fileId, self.files);
logger.error('Nõutud faili ei saadetud: ' + fileId, self.files);
self.setMessage(fileId, 'Nõutud faili ei saadetud');
return innerCb();
}
if(requestFile.isList == false && Array.isArray( fileItem )){
if(requestFile.isList === false && Array.isArray( fileItem )){
self.setMessage(fileId, 'Lubatud on ainult 1 fail');
return innerCb();
}
......@@ -81,16 +81,15 @@ function ServiceRequest( requestBody, requestFiles ) {
if(requestFile.sizeLimit > 0){
var limitLeft = requestFile.sizeLimit;
var stat = fs.statSync(fileItem.path);
limitLeft = limitLeft - stat.size;
if( Array.isArray( fileItem ) ){
for(i in fileItem){
var fileItemItem = fileItem[i];
var stat = fs.statSync(fileItemItem.path);
stat = fs.statSync(fileItemItem.path);
limitLeft = limitLeft - stat.size;
}
} else {
var stat = fs.statSync(fileItem.path);
limitLeft = limitLeft - stat.size;
}
if(limitLeft < 0){
......
......@@ -30,7 +30,7 @@ var CleanerService = function () {
fs.readdir(folder, function(err, files) {
logger.debug('readFolder');
if(files != undefined && files.length > 0){
if(files !== undefined && files.length > 0){
self.checkOnIndex(0, files, folder, function (err) {
if(err){
return logger.error(err);
......@@ -65,7 +65,7 @@ var CleanerService = function () {
return continueScan();
}
if(stat == undefined){
if(stat === undefined){
logger.error('Stat is undefined for: ' + filePath);
return continueScan();
}
......
......@@ -20,7 +20,7 @@ var DaoService = function(){
this.set = function(key, value, cb){
this.client.set(prefix + key, JSON.stringify(value), function (err, reply) {
if(cb != undefined){
if(cb !== undefined){
self.client.expire(prefix + key, config.wrapper.sessionMaxLifetime );
cb(err, reply);
}
......@@ -30,7 +30,7 @@ var DaoService = function(){
this.get = function(key, cb){
this.client.get(prefix + key, function(err, reply) {
if(cb != undefined){
if(cb !== undefined){
if(err){
return cb(err);
}
......@@ -42,7 +42,7 @@ var DaoService = function(){
this.delete = function(key, cb){
this.client.del(prefix + key, function (err, reply) {
if(cb != undefined){
if(cb !== undefined){
cb(err, reply);
}
} );
......
......@@ -86,7 +86,7 @@ function LocalExecutor() {
process.on('close', function (code, signal) {
logger.debug('child process terminated due to receipt of signal: ' + signal + ' code: ' + code);
if(signal == 'SIGKILL'){
if(signal === 'SIGKILL'){
response.isSuccess = false;
response.errors.push({util:' Utiliidi töö katkestati!'});
}
......
......@@ -12,7 +12,7 @@ var InstallService = function() {
var wrapper = config.wrapper;
var serviceConfig = self.getConfiguration();
if(!config.integration || config.integration.length == 0){
if(!config.integration || config.integration.length === 0){
return cb('Servereid ei ole seadistatud');
}
......
......@@ -71,7 +71,7 @@ function SessionService() {
var sessionFilePath = self.getNewFilePath(session.id);
FileUtil.mv(tmpFile.path, sessionFilePath, function(err){
if(err) return callback(err);
if(session.requestFiles[tmpFile.fieldname] == undefined){
if(session.requestFiles[tmpFile.fieldname] === undefined){
session.requestFiles[tmpFile.fieldname] = []
}
session.requestFiles[tmpFile.fieldname].push( sessionFilePath );
......@@ -195,11 +195,11 @@ function SessionService() {
response.errors = session.errors;
}
if (session.message == Session.messages.RUNNING) {
if (session.message === Session.messages.RUNNING) {
response.recheckInterval = session.recheckInterval;
}
if (session.message != Session.messages.OK) {
if (session.message !== Session.messages.OK) {
return callback(null, {response: response});
}
......
......@@ -4,7 +4,7 @@
var logger = require('log4js').getLogger('statistics_service');
var async = require('async');
var os = require('os');
var njds = require('nodejs-disks');
// var njds = require('nodejs-disks');
function StatisticsService() {
var self = this;
......
......@@ -14,7 +14,7 @@ function WrapperService() {
return callback(err);
}
if (session.isAsync == true) {
if (session.isAsync === true) {
self.getServiceResponse(session.id, callback);
}
......@@ -28,7 +28,7 @@ function WrapperService() {
sessionService.closeSession(session, function (err, session) {
logger.debug('Sessioon on lõpetanud ja savestatud. isAsync:' + session.isAsync);
if (session.isAsync == false) {
if (session.isAsync === false) {
logger.debug('Send response');
if(err){
return callback(err);
......@@ -91,7 +91,7 @@ function WrapperService() {
return callback(err);
}
var processor = new Processor();
if(processor.kill != undefined){
if(processor.kill !== undefined){
processor.kill( session, function (err, response) {
callback(null, mapResponse(err, response));
});
......
......@@ -9,7 +9,7 @@ var assert = require('assert');
var request = require('supertest');
describe('Routing', function() {
var url = 'http://127.0.0.1:' + config.port;
var url = 'http://127.0.0.1:' + config.wrapper.port;
before(function(done) {
server.startInstance( function(){
......@@ -62,7 +62,7 @@ describe('Routing', function() {
throw err;
}
res.body.should.have.property('errors');
res.body.errors.session.should.equal('Sessiooni ei leitud');
res.body.errors.should.equal('Sessiooni ei leitud');
done();
})
});
......@@ -88,10 +88,11 @@ describe('Routing', function() {
throw err;
}
res.body.response.should.have.property('sessionId');
res.body.response.message.should.equal('OK');
res.body.response.should.have.property('pipecontent');
res.body.response.pipecontent.should.not.equal(undefined);
res.body.should.have.property('success');
res.body.success.should.equal(false);
res.body.should.have.property('errors');
res.body.errors.should.have.property('content');
res.body.errors.content.should.equal('Nõutud faili ei saadetud');
done();
});
});
......@@ -118,7 +119,8 @@ describe('Routing', function() {
}
res.body.should.have.property('errors');
res.body.errors.should.have.property('pipecontent');
res.body.errors.should.have.property('content');
res.body.errors.content.should.equal('Nõutud faili ei saadetud');
done();
});
});
......
......@@ -10,9 +10,9 @@ var fs = require('fs');
describe('File util', function() {
var tmpPath = config.service.staticParams.tmpPath;
var mvSource = tmpPath + 'mvSource';
var mvTarget = tmpPath + 'mvTarget';
var tmpPath = config.fs.tmpPath;
var mvSource = tmpPath + '/mvSource';
var mvTarget = tmpPath + '/mvTarget';
before(function(done) {
done();
......
......@@ -15,7 +15,7 @@ var encoding = 'utf-8';
var i = 0;
function loop(cb){
i++;
if(i % 100000 == 0){
if(i % 100000 === 0){
console.log(i);
}
if(i < 2300000){
......@@ -42,7 +42,7 @@ function parse(){
var index = 0;
parser.on('data', function (obj) {
index++;
if(index % 100000 == 0){
if(index % 100000 === 0){
console.log(index);
console.log(obj); // whatever you will do with each JSON object
}
......
......@@ -45,7 +45,7 @@ function ArchiveExtractor() {
logger.debug('Check for callback. count:' + count + ' isClosed: ' + isClosed);
if (count == 0 && isClosed == true) {
if (count === 0 && isClosed === true) {
session.message = Session.messages.OK;
return callback(null, session);
}
......@@ -58,7 +58,7 @@ function ArchiveExtractor() {
.pipe(unzip.Parse())
.on('entry', function(entry) {
count++;
var isFile = ('File' == entry.type);
var isFile = ('File' === entry.type);
var savePath = SessionService.getStorePath(session.id);
var fullpath = path.join(savePath, entry.path);
......
......@@ -17,7 +17,11 @@ var bodyParser = require('body-parser');
var multer = require('multer');
var cluster = require('cluster');
var http = require('http');
var config = require('./../config');
try {
var config = require('./../config');
} catch (e) {
console.error('Can not read configuration: ' + e.toString());
}
var controllers = require('./../controllers/index');
var routerMiddleware = require('./../middlewares/router');
var errorhandlerMiddleware = require('./../middlewares/errorhandler');
......@@ -27,7 +31,7 @@ var cleanerService = require('./../src/service/cleanerService');
var installService = require('./../src/service/integration/installService');
app.set('views', path.join(__base, 'views'));// view engine setup
app.set('view engine', 'jade');// view engine setup
app.set('view engine', 'pug');// view engine setup
app.use(express.static(__base + '/public'));
log4js.configure(config.log4js);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment