Commit 6f4c7c2d authored by priit's avatar priit
Browse files

Confitav wrapperi conf

parent b13bfd93
......@@ -5,7 +5,6 @@ var ServiceRequest = require(__base + '/src/model/serviceRequest');
var WrapperService = require(__base + '/src/service/wrapperService');
router.post('/', function ( req, res ) {
logger.debug('post in');
var serviceRequest = new ServiceRequest( req.body );
......@@ -21,7 +20,6 @@ router.post('/', function ( req, res ) {
});
router.get('/:instanceId', function(req, res) {
logger.debug('get in');
var wrapperService = new WrapperService();
wrapperService.getServiceResponse(req.params.instanceId, function (err, data) {
......
......@@ -138,7 +138,9 @@ function SessionService() {
};
this.saveSession = function (session, callback) {
daoService.set(session.id, session, callback);
daoService.set(session.id, session, function (err) {
callback(err, session);
});
};
this.getApiResponse = function (session, callback) {
......
......@@ -17,15 +17,19 @@ function WrapperService() {
var Processor = require(__base + '/wrapper/' + config.service.staticOptions.wrapper);
var processor = new Processor();
processor.process(serviceRequest, session, function ( error ) {
processor.process(serviceRequest, session, function ( error, session, finalPipecontent ) {
sessionService.closeSession(session, finalPipecontent, function (err, session) {
logger.debug('Sessioon on lõpetanud ja savestatud');
if (session.isAsync == false) {
if (error) return callback(error);
self.getServiceResponse(session.id, callback);
}
});
});
});
});
};
this._initSession = function(serviceRequest, callback){
......
var logger = require('log4js').getLogger('wrapper');
var config = require('./../config');
var executorService = require('./../src/service/executorService');
var sessionService = require('../src/service/sessionService');
var Session = require('../src/model/session');
var CommandModel = require('../src/mapper/commandModel');
var fs = require('fs');
......@@ -13,17 +12,13 @@ function ContentTokenizer(){
this.process = function (requestBody, session, callback) {
var pipeContent = requestBody.service.pipecontent;
var sourceText = new Buffer(pipeContent.content, 'base64').toString();
console.log(sourceText);
self.getCommandModel(session, sourceText, function (err, model) {
//kasuta executor servicet ja saa selle väljund
executorService.execute( model, function ( error, response ) {
/* response = { isSuccess: BOOLEAN, stdOutPath: STRING, outputPaths: { key: value, ...} } */
logger.debug('Väline programm on lõpetanud');
fs.readFile(response.outputPaths.outputPath, function (err, output) {
var wrapperOutput = output.toString();
......@@ -34,20 +29,20 @@ function ContentTokenizer(){
for(i in outputStrings){
var string = outputStrings[i];
var start = sourceText.indexOf(string);
var stringStart = globalStart + start;
var stringLength = string.length;
sourceText = sourceText.slice(start + stringLength);
//eemaldan lähteteksti alguse, et korduvad sõnad ei jääks sama asukohaga
globalStart = globalStart + start + stringLength;
sourceText = sourceText.slice(start + stringLength); //eemaldan lähteteksti alguse, et korduvad sõnad ei jääks sama asukohaga
globalStart = stringStart + stringLength;
var token = {
idx: i,
value: string,
position: {
location: {
start: stringStart,
end: stringStart + stringLength
end: globalStart
}
};
tokens.push(token);
......@@ -57,9 +52,10 @@ function ContentTokenizer(){
var finalPipecontent = requestBody.service.pipecontent;
session.message = Session.messages.OK;
sessionService.closeSession(session, finalPipecontent, function (err, session) {
return callback();
});
logger.debug('Pipecontenti mappimine on lõpetatud');
return callback(null, session, finalPipecontent);
});
});
......
Supports Markdown
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