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