@@ -399,40 +399,41 @@ module.exports = (function () {
399
399
return Q . all ( promises ) ;
400
400
} ;
401
401
402
- var getAnalysisIndicesReplace = function ( versionId , sessionId , user ) {
402
+ var getAnalysisIndicesReplace = function ( defaultConfig , versionId , sessionId , user ) {
403
403
return analysis . findById ( versionId , true ) . then ( function ( result ) {
404
404
if ( ! result ) {
405
- throw {
406
- message : 'versionId not found' ,
407
- status : 404
408
- } ;
405
+ // Use the default analysis files
406
+ result = { } ;
407
+ result . indicesPath = defaultConfig . analysisFolder + '/indices.json' ;
409
408
}
410
409
var data = fs . readFileSync ( result . indicesPath , 'utf8' ) ;
411
410
var returnObject = { indices : [ ] } ;
412
411
var obj = JSON . parse ( data ) ;
413
- obj . indices . forEach ( function ( indice ) {
414
- returnObject . indices . push ( indice . replace ( obj . sessionKey , sessionId ) ) ;
415
- } ) ;
416
- if ( user && obj . userKey && obj . query ) {
417
- if ( obj . userKey ) {
418
- var string = JSON . stringify ( obj . query ) ;
419
- var stringWithUser = string . replace ( obj . userKey , user ) ;
420
- returnObject . query = JSON . parse ( stringWithUser ) ;
412
+ if ( obj . indices ) {
413
+ obj . indices . forEach ( function ( indice ) {
414
+ returnObject . indices . push ( indice . replace ( obj . sessionKey , sessionId ) ) ;
415
+ } ) ;
416
+ if ( user && obj . userKey && obj . query ) {
417
+ if ( obj . userKey ) {
418
+ var string = JSON . stringify ( obj . query ) ;
419
+ var stringWithUser = string . replace ( obj . userKey , user ) ;
420
+ returnObject . query = JSON . parse ( stringWithUser ) ;
421
+ }
421
422
}
422
423
}
423
424
return returnObject ;
424
425
} ) ;
425
426
} ;
426
427
427
- sessions . deleteAnalysisData = function ( sessionId , esClient ) {
428
- return sessions . find ( { _id : sessionId } , true ) . then ( function ( result ) {
428
+ sessions . deleteAnalysisData = function ( defaultConfig , sessionId , esClient ) {
429
+ return sessions . findById ( sessionId , true ) . then ( function ( result ) {
429
430
if ( ! result ) {
430
431
throw {
431
432
message : 'Session not found' ,
432
433
status : 404
433
434
} ;
434
435
}
435
- return getAnalysisIndicesReplace ( result . versionId , sessionId ) . then ( function ( result ) {
436
+ return getAnalysisIndicesReplace ( defaultConfig , result . versionId , sessionId ) . then ( function ( result ) {
436
437
var deferred = Q . defer ( ) ;
437
438
esClient . indices . delete ( {
438
439
index : result . indices
@@ -449,15 +450,15 @@ module.exports = (function () {
449
450
} ) ;
450
451
} ;
451
452
452
- sessions . deleteUserData = function ( sessionId , userData , esClient ) {
453
- return sessions . find ( { _id : sessionId } , true ) . then ( function ( result ) {
453
+ sessions . deleteUserData = function ( defaultConfig , sessionId , userData , esClient ) {
454
+ return sessions . findById ( sessionId , true ) . then ( function ( result ) {
454
455
if ( ! result ) {
455
456
throw {
456
457
message : 'Session not found' ,
457
458
status : 404
458
459
} ;
459
460
}
460
- return getAnalysisIndicesReplace ( result . versionId , sessionId , userData ) . then ( function ( result ) {
461
+ return getAnalysisIndicesReplace ( defaultConfig , result . versionId , sessionId , userData ) . then ( function ( result ) {
461
462
var deferred = Q . defer ( ) ;
462
463
463
464
if ( ! result . query ) {
0 commit comments