Commit b8595379 authored by priit's avatar priit
Browse files

Väljundile laiendi määramise võimalus

parent 6b67bba8
......@@ -4,6 +4,8 @@ var sessionService = require('../service/sessionService');
function CommandModel(){
var self = this;
this.stdOutExtension = 'txt';
this.session = null;
this.serviceProperties = {};//näiteks local command template
this.outputPaths = {}; //väljundfailid
......@@ -15,6 +17,10 @@ function CommandModel(){
self.session = session;
};
this.setStdOutExtension = function (stdOutExtension) {
this.stdOutExtension = stdOutExtension;
};
this.setTextValue = function (key, value) {
self.keyValues[key] = value;
};
......@@ -31,8 +37,8 @@ function CommandModel(){
/*
* Kasutatava programmi väljund
* */
this.addOutputPath = function (key) {
self.outputPaths[key] = sessionService.getNewSessionFilePath( self.session );
this.addOutputPath = function (key, options) {
self.outputPaths[key] = sessionService.getNewSessionFilePath( self.session, options );
logger.debug('Output path added: ' + key +' ' + self.outputPaths[key] );
};
......@@ -50,7 +56,7 @@ function CommandModel(){
this._storeToFile = function (index, callback) {
var fileValue = fileValues[index];
sessionService.storeToFile(self.session.id, fileValue['value'], function (err, path) {
sessionService.storeToFile(self.session.id, fileValue['value'],{}, function (err, path) {
if(err) return callback(err);
self.keyValues[fileValue['key']] = path;
......
......@@ -13,7 +13,7 @@ function LocalExecutor() {
var response = {
isSuccess:true,
stdOutPath: sessionService.getNewSessionFilePath(commandModel.session),
stdOutPath: sessionService.getNewSessionFilePath(commandModel.session, {extension: commandModel.stdOutExtension}),
errors: []
};
......@@ -23,7 +23,6 @@ function LocalExecutor() {
this._executeLocalCommand = function (localCommand, response, callback) {
var command = localCommand.command;
var commandParams = localCommand.commandParams;
......
......@@ -80,16 +80,10 @@ function SessionService() {
return config.service.staticParams.storagePath + '/' + sessionId;
};
this.getNewFilePath = function (sessionId) {
var sessionPath = self.getStorePath(sessionId);
return sessionPath + '/' + randomstring.generate(10);
};
this.storeToFile = function (sessionId, value, callback) {
this.storeToFile = function (sessionId, value, options, callback) {
var writeFile = function () {
var filePath = self.getNewFilePath(sessionId);
var filePath = self.getNewFilePath(sessionId, options);
fs.writeFile(filePath, value, function (err) {
if (err) {
logger.error(err);
......@@ -108,8 +102,19 @@ function SessionService() {
self.saveSession(session, callback);
};
this.getNewSessionFilePath = function (session) {
return self.getStorePath(session.id) + '/' + randomstring.generate(10);
this.getNewSessionFilePath = function (session, options) {
return self.getNewFilePath(session.id, options);
};
this.getNewFilePath = function (sessionId, options) {
var path = self.getStorePath(sessionId) + '/' + randomstring.generate(10);
if(options){
if(options.extension){
path = path + '.' + options.extension;
}
}
return path;
};
this.checkSessionDir = function (sessionId, callback) {
......
......@@ -41,7 +41,7 @@ function Lausestaja(){
this.getCommandModel = function (session, callback) {
var model = new CommandModel();
model.serviceProperties.commandTemplate = config.availableWappers.LAUSESTAJA.commandTemplate;
model.serviceProperties.commandTemplate = config.availableCommands.LAUSESTAJA.commandTemplate;
model.init( session );
model.setTextValue('data', session.requestFiles.content);
model.render(function (err) {
......
......@@ -41,7 +41,7 @@ function Morfyhestaja(){
this.getCommandModel = function (session, callback) {
var model = new CommandModel();
model.serviceProperties.commandTemplate = config.availableWappers.MORFANALYZER.commandTemplate;
model.serviceProperties.commandTemplate = config.availableCommands.MORFANALYZER.commandTemplate;
model.init( session );
model.setTextValue('data', session.requestFiles.content);
model.render(function (err) {
......
var logger = require('log4js').getLogger('wrapper');
var config = require('./../config');
var localExecutor = require('./../src/service/executor/localExecutor');
var Session = require('../src/model/session');
var CommandModel = require('../src/mapper/commandModel');
var fs = require('fs');
var mime = require('mime');
var path = require('path');
function Osalausestaja(){
var self = this;
this.process = function ( session, callback) {
self.getCommandModel(session, function (err, model) {
logger.debug('GetCommandModel callback');
if(err) return callback(err);
localExecutor.execute( model, function ( err, response ) {
if(err) return callback(err);
logger.debug('Program is finished');
if(response.isSuccess){
session.message = Session.messages.OK;
} else {
session.setErrors(response.errors);
}
session.addOutputFile('output', {
type: 'output',
fileName: path.basename(response.stdOutPath),
filePath: response.stdOutPath,
contentType: mime.lookup(response.stdOutPath)
});
return callback( err, session );
});
});
};
this.getCommandModel = function (session, callback) {
var model = new CommandModel();
model.serviceProperties.commandTemplate = config.availableCommands.OSALAUSESTAJA.commandTemplate;
model.init( session );
model.setTextValue('data', session.requestFiles.content);
model.render(function (err) {
logger.debug('Render callback');
callback(err, model);
});
}
}
module.exports = Osalausestaja;
\ No newline at end of file
......@@ -69,7 +69,7 @@ function Tokenizer(){
var mapping = JSON.stringify(tokens);
logger.debug('Failide mappimine on lõpetatud');
SessionService.storeToFile(session.id, mapping, function (error, mappingPath) {
SessionService.storeToFile(session.id, mapping, { extension:'txt' }, function (error, mappingPath) {
session.addOutputFile('output', {
type: 'output',
fileName: path.basename(model.outputPaths.outputPath1),
......@@ -97,10 +97,10 @@ function Tokenizer(){
this.getCommandModel = function (session, callback) {
var model = new CommandModel();
model.serviceProperties.commandTemplate = config.availableWappers.TOKENIZER.commandTemplate;
model.serviceProperties.commandTemplate = config.availableCommands.TOKENIZER.commandTemplate;
model.init( session );
model.setTextValue('data', session.requestFiles.content);
model.addOutputPath('outputPath1');
model.addOutputPath('outputPath1', {extension: 'txt'});
model.render(function (err) {
logger.debug('Render callback');
callback(err, model);
......
......@@ -47,24 +47,34 @@ config.log4js = {
config.availableWappers = {
TOKENIZER : {
class: 'tokenizer',
class: 'tokenizer'
},
MORFANALYZER : {
class: 'morfanalyzer'
},
LAUSESTAJA : {
class: 'lausestaja'
},
OSALAUSESTAJA : {
class: 'osalausestaja'
},
ARCHIVE_EXTRACTOR: {
class: 'archiveExtractor'
}
};
config.availableCommands = {
TOKENIZER : {
commandTemplate: 'python /var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/tokenizer/tokenizer.py -i [data] -o [outputPath1]'
},
MORFANALYZER : {
class: 'morfanalyzer',
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./morfanalyzer.sh [data]'
},
LAUSESTAJA : {
class: 'lausestaja',
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./lausestaja.sh [data]'
},
OSALAUSESTAJA : {
class: 'osalausestaja',
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./osalausestaja.sh [data]'
},
ARCHIVE_EXTRACTOR: {
class: 'archiveExtractor',
commandTemplate: ''
}
};
......
var config = require('./global');
config.port = 3005;
config.service.title = 'Osalausestaja';
config.service.staticParams.uniqueId = 'subsentence';
config.service.staticParams.wrapper = config.availableWappers.OSALAUSESTAJA.class;
module.exports = config;
\ No newline at end of file
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