38. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/4/2017 8:04:34 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

38.1 Files compared

# Location File Last Modified
1 rdk.zip\rdk\product\production\rdk\src\resources\activitymanagement\activities activities-operations-resource.js Mon Aug 28 19:41:48 2017 UTC
2 rdk.zip\rdk\product\production\rdk\src\resources\activitymanagement\activities activities-operations-resource.js Tue Oct 3 17:16:06 2017 UTC

38.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 1522
Changed 1 2
Inserted 0 0
Removed 0 0

38.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

38.4 Active regular expressions

No regular expressions were active.

38.5 Comparison detail

  1   'use stric t';
  2   var rdk =  require('. ./../../co re/rdk');
  3   var uriBui lder = rdk .utils.uri Builder;
  4   var httpUt il = rdk.u tils.http;
  5   var _ = re quire('lod ash');
  6   var parseS tring = re quire('xml 2js').pars eString;
  7   var async  = require( 'async');
  8   var activi tyUtils =  require('. ./activity -utils');
  9   var proces sJsonObjec t = activi tyUtils.pr ocessJsonO bject;
  10   var proces sValue = a ctivityUti ls.process Value;
  11   var wrapVa lueInCData  = activit yUtils.wra pValueInCD ata;
  12   var getGen ericJbpmCo nfig = act ivityUtils .getGeneri cJbpmConfi g;
  13   var nullch ecker = rd k.utils.nu llchecker;
  14   var xmlTem plates = a ctivityUti ls.xmlTemp lates;
  15   var activi tyMockQuer y = requir e('./activ ity-query- service-mo ck');
  16   var versio nCompare =  require(' ./../../.. /utils/ver sion-compa re').versi onCompare;
  17  
  18  
  19   JBPMServer Error.prot otype = Er ror.protot ype;
  20  
  21   //wrapper  for activi ty definit ions
  22   //decide w hich funct ion to cal l based on  parameter s
  23   function g etActiviti es(req, re s) {
  24       if (re q.query.si teCode ||  req.query. testIen ||  req.query .type) {
  25           re turn getAc tivityDefi nitionsByQ uery(req,  res);
  26       } else  {
  27           re turn getPr ocessDefin itions(req , res);
  28       }
  29   }
  30  
  31   function d oStartProc ess(config , deployme ntId, proc essDefId,  parameters , processC allback) {
  32  
  33       var ur i = uriBui lder.fromU ri(config. url)
  34           .p ath('/exec ute')
  35           .b uild();
  36  
  37       config .url = uri ;
  38       if (!c onfig.head ers) {
  39           co nfig.heade rs = {};
  40       }
  41  
  42       config .headers[' Content-Ty pe'] = 'ap plication/ xml';
  43       config .headers.A ccept = 'a pplication /xml';
  44       config .headers[' Kie-Deploy ment-Id']  = deployme ntId;
  45  
  46       async. parallel([
  47                function (callback)  {
  48                    var  startProce ssCommandT emplateXML  = xmlTemp lates.star tProcessCo mmandTempl ate;
  49                    var  startProce ssCommandX ML = start ProcessCom mandTempla teXML.repl ace('{Depl oymentId}' , deployme ntId).repl ace('{Proc essId}', p rocessDefI d);
  50                    call back(null,  startProc essCommand XML);
  51                },
  52                function (callback)  {
  53                    var  processPar ametersXML  = '';
  54                    var  itemsList  = '';
  55                    if ( parameters ) {
  56                         var primit iveTypeXML  = xmlTemp lates.para meterTempl ate;
  57                         var comple xObjectXML  = xmlTemp lates.comp lexObjectT emplate;
  58                         var comple xObjectPro pertiesXML  = xmlTemp lates.comp lexObjectP ropertiesX ML;
  59                         var comple xArrayedOb jectProper tiesXML =  xmlTemplat es.complex ArrayedObj ectPropert iesXML;
  60  
  61                         _.each(par ameters, f unction(va lue, key)  {
  62                             var ty pe = typeo f value;
  63  
  64                             //****  Parent Co ntainer Ob ject
  65                             if (ty pe === 'ob ject') {
  66                                 va r objectIt ems = valu e;
  67                                 pr ocessParam etersXML =  processPa rametersXM L + comple xObjectXML .replace(' {Key}', ke y);
  68                                 _. each(objec tItems, fu nction(val ue, key) {
  69                                      type = t ypeof valu e;
  70                                      //the ke y objectTy pe should  match the  class name  in jbpm s tarting wi th a small  letter.
  71                                      if (key  === 'objec tType') {
  72                                          proc essParamet ersXML = p rocessPara metersXML. replace('{ Type}', va lue);
  73                                      } else {
  74                                          if ( type === ' object') {
  75                                               var id = 0 ;
  76                                               if (value  !== null & & value.co nstructor  === Array)  {
  77                                                   for (v ar i = 0;  i < value. length; i+ +) {
  78                                                       id  = i + 1;
  79                                                       it emsList =  itemsList  + complexA rrayedObje ctProperti esXML.repl ace(/{Key} /g, key).r eplace(/{I D}/, id).r eplace('{V alue}', pr ocessValue (value[i]) );
  80                                                   }
  81                                               } else {
  82                                                   itemsL ist = item sList + co mplexObjec tPropertie sXML.repla ce(/{Key}/ g, key).re place('{Va lue}', pro cessJsonOb ject(value ));
  83                                               }
  84                                          } el se {
  85                                               itemsList  = itemsLis t + comple xObjectPro pertiesXML .replace(/ {Key}/g, k ey).replac e('{Value} ', wrapVal ueInCData( value));
  86                                          }
  87                                      }
  88                                 }) ;
  89                                 pr ocessParam etersXML =  processPa rametersXM L.replace( '{Value}',  itemsList );
  90                             } else  {
  91                                 pr ocessParam etersXML =  processPa rametersXM L + primit iveTypeXML .replace(' {Key}', ke y).replace ('{Type}',  type).rep lace('{Val ue}', wrap ValueInCDa ta(value)) ;
  92                             }
  93                         });
  94                    }
  95                    call back(null,  processPa rametersXM L);
  96                }
  97           ],
  98           fu nction(err , results)  {
  99                if (err)  {
  100                    retu rn process Callback(e rr);
  101                }
  102  
  103                var star tProcessCo mmandXML =  results[0 ].replace( '{Paramete rs}', resu lts[1]);
  104                config.b ody = star tProcessCo mmandXML;
  105                config.j son = fals e;
  106  
  107                httpUtil .post(conf ig, functi on(err, re sponse, re sult) {
  108                    if ( err) {
  109                         return pro cessCallba ck(err);
  110                    }
  111  
  112                    pars eString(re sult, func tion(err,  jsonResult ) {
  113                         if (err) {
  114                             return  processCa llback('In valid erro r XML rece ived(' + e rr + ')');
  115                         }
  116  
  117                         if (jsonRe sult['comm and-respon se']) {
  118                             if (js onResult[' command-re sponse'].e xception)  {
  119                                 re turn proce ssCallback (jsonResul t['command -response' ].exceptio n[0].messa ge[0]);
  120                             } else  {
  121                                 if  (jsonResu lt['comman d-response ']['proces s-instance ']) {
  122                                      return p rocessCall back(null,  {
  123                                          mess age: 'Succ ess',
  124                                          data : {
  125                                               processIns tanceId: j sonResult[ 'command-r esponse'][ 'process-i nstance'][ 0].id[0]
  126                                          }
  127                                      });
  128                                 }
  129  
  130                                 re turn proce ssCallback (null, 'Su ccess');
  131                             }
  132                         }
  133  
  134                         return pro cessCallba ck(null, j sonResult) ;
  135                    });
  136  
  137                });
  138           }) ;
  139   }
  140  
  141   function s tartProces s(req, res ) {
  142       req.au dit.dataDo main = 'Ta sks';
  143       req.au dit.logCat egory = 'S TART_PROCE SS';
  144  
  145       var de ploymentId  = req.bod y.deployme ntId || nu ll;
  146  
  147       var id Error;
  148       if (!d eploymentI d) {
  149           id Error = ne w Error('M issing dep loymentId  property/v alue in in put JSON.' );
  150           re q.logger.e rror(idErr or);
  151           re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message);
  152       }
  153  
  154       var pr ocessDefId  = req.bod y.processD efId || nu ll;
  155       if (!p rocessDefI d) {
  156           id Error = ne w Error('M issing pro cessDefId  property/v alue in in put JSON.' );
  157           re q.logger.e rror(idErr or);
  158           re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message);
  159       }
  160  
  161       var pa rameters =  req.body. parameter;
  162  
  163       doStar tProcess(g etGenericJ bpmConfig( req), depl oymentId,  processDef Id, parame ters, func tion(err,  response)  {
  164           if  (err) {
  165                req.logg er.error(e rr);
  166                return r es.status( rdk.httpst atus.bad_r equest).rd kSend(err) ;
  167           }
  168  
  169           re turn res.r dkSend(res ponse);
  170       });
  171   }
  172  
  173   function a bortProces s(req, res ) {
  174       // JBP M Endpoint :
  175       // [PO ST] /runti me/{deploy mentId}/pr ocess/inst ance/{proc InstanceID }/abort
  176       //
  177       // Exa mple Postm an URL:
  178         // http:// IP                /business- central/re st/runtime /VistaCore :VistaTask s:1.0.2/pr ocess/inst ance/1/abo rt
  179  
  180       req.au dit.dataDo main = 'Ta sks';
  181       req.au dit.logCat egory = 'A BORT_PROCE SS';
  182  
  183       var de ploymentId  = req.bod y.deployme ntId || nu ll;
  184  
  185       var id Error;
  186       if (!d eploymentI d) {
  187           id Error = ne w Error('M issing dep loymentId  property/v alue in in put JSON.' );
  188           re q.logger.e rror(idErr or);
  189           re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message);
  190       }
  191  
  192       var pr ocessInsta nceId = re q.body.pro cessInstan ceId || nu ll;
  193       if (!p rocessInst anceId) {
  194           id Error = ne w Error('M issing pro cessInstan ceId prope rty/value  in input J SON.');
  195           re q.logger.e rror(idErr or);
  196           re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message);
  197       }
  198  
  199       var co nfig = get GenericJbp mConfig(re q);
  200  
  201       var ur i = uriBui lder.fromU ri(config. url)
  202           .p ath('/runt ime/')
  203           .p ath(deploy mentId)
  204           .p ath('/proc ess/instan ce/')
  205           .p ath(proces sInstanceI d)
  206           .p ath('/abor t')
  207           .b uild();
  208  
  209       config .url = uri ;
  210       config .headers[' Content-Ty pe'] = 'ap plication/ json';
  211       config .headers.A ccept = 'a pplication /json';
  212  
  213       httpUt il.post(co nfig, func tion(err,  response,  returnedDa ta) {
  214           if  (err) {
  215                req.logg er.error(e rr);
  216                return r es.status( rdk.httpst atus.not_f ound).rdkS end(err);
  217           }
  218  
  219           //  Example R esponse:
  220           //  {
  221           //   "status" : "SUCCESS ",
  222           //   "url": " /business- central/re st/runtime /VistaCore :VistaTask s:1.0.2/pr ocess/inst ance/1/abo rt",
  223           //   "message ": null
  224           // }
  225  
  226           if  (returned Data && re turnedData .hasOwnPro perty('url ')) {
  227                delete r eturnedDat a.url;
  228           }
  229  
  230           if  (returned Data && re turnedData .hasOwnPro perty('sta tus')) {
  231                if (retu rnedData.s tatus.toLo werCase()  === 'succe ss') {
  232                    retu rn res.rdk Send(retur nedData);
  233                }
  234           }
  235  
  236           re turn res.s tatus(rdk. httpstatus .not_found ).rdkSend( returnedDa ta);
  237       });
  238   }
  239  
  240   function g etProcessD efinitions (req, res)  {
  241       req.au dit.dataDo main = 'Ta sks';
  242       req.au dit.logCat egory = 'G ET_PROCESS _DEFINITIO NS';
  243  
  244       // JBP M endpoint : /deploym ent/proces ses
  245       // par ameters:
  246       // pag esize
  247  
  248       var pa gesize;
  249       if (re q.param('p agesize'))  {
  250           pa gesize = r eq.param(' pagesize') ;
  251       }
  252  
  253       var co nfig = get Definition sFetchConf ig(req, pa gesize);
  254  
  255       return  doProcess Definition sFetch(con fig, funct ion(err, f ormattedRe sponse) {
  256           if  (err) {
  257                req.logg er.error(e rr);
  258                return r es.status( rdk.httpst atus.not_f ound).rdkS end(err);
  259           }
  260  
  261           re turn res.r dkSend(for mattedResp onse);
  262       });
  263   }
  264  
  265   function g etDefiniti onsFetchCo nfig(req,  pagesize)  {
  266       var co nfig = get GenericJbp mConfig(re q);
  267  
  268       var ur i = uriBui lder.fromU ri(config. url).path( '/deployme nt/process es');
  269  
  270       // Pag ination no t working  correctly  for the ab ove rest a pi in RedH at BPM 6.1  to get al l availabl e process  definition s in batch es,
  271       // so  as a short  term fix,  increasin g default  pagesize t o 2000 (fr om 200).
  272       // Thi s needs to  be revisi ted once B PM is migr ated to a  new versio n.
  273       pagesi ze = pages ize || 200 0;
  274  
  275       uri.qu ery('pages ize', page size);
  276       config .url = uri .build();
  277  
  278       return  config;
  279   }
  280  
  281   // Activit y Query Se rvice
  282   function g etActivity Definition sByQuery(r eq, res) {
  283       req.au dit.dataDo main = 'Ta sks';
  284       req.au dit.logCat egory = 'G ET_ACTIVIT Y_DEFINITI ONS_BY_QUE RY';
  285  
  286       // tem porary moc k implemen tation
  287       var lo okupObj =  activityMo ckQuery;
  288  
  289       var lo okupKey =  '';
  290  
  291       if (re q.query.si teCode &&  req.query. testIen) {
  292           lo okupKey =  req.query. siteCode +  '_' + req .query.tes tIen;
  293       } else  if (req.q uery.type  && req.que ry.type.to LowerCase( ) === 'not e') {
  294           lo okupKey =  req.query. type;
  295       }
  296  
  297       var ac tivities =  [];
  298       if (lo okupObj[lo okupKey])  {
  299           ac tivities =  lookupObj [lookupKey ];
  300       } else  {
  301           ac tivities =  lookupObj ['default' ];
  302       }
  303  
  304       var co nfig = get Deployment sFetchConf ig(req);
  305  
  306       return  doDeploym entsFetch( config, fu nction(err , formatte dResponse)  {
  307           if  (err) {
  308                req.logg er.error(e rr);
  309                return r es.status( rdk.httpst atus.not_f ound).rdkS end(err);
  310           }
  311  
  312           va r updatedA ctivities  = updateAc tivities(a ctivities,  formatted Response);
  313  
  314           re turn res.r dkSend(upd atedActivi ties);
  315       });
  316  
  317   }
  318  
  319   function g etDeployme ntsFetchCo nfig(req)  {
  320       var co nfig = get GenericJbp mConfig(re q);
  321  
  322       var ur i = uriBui lder.fromU ri(config. url)
  323           .p ath('/depl oyment')
  324           .b uild();
  325  
  326       config .url = uri ;
  327       if (!c onfig.head ers) {
  328           co nfig.heade rs = {};
  329       }
  330  
  331       return  config;
  332   }
  333  
  334   function u pdateActiv ities(acti vities, fo rmattedRes ponse) {
  335       var up datedActiv ities = [] ;
  336       if (ac tivities.l ength > 0  && (format tedRespons e.data &&  formattedR esponse.da ta.items & & formatte dResponse. data.items .length >  0)) {
  337           _. each(activ ities, fun ction(acti vity) {
  338                _.each(f ormattedRe sponse.dat a.items, f unction(de ployment)  {
  339                    var  deployment Title = de ployment.g roupId + ' :' + deplo yment.arti factId;
  340                    if ( deployment Title ===  activity.d eployment)  {
  341                         var deploy mentId = d eployment. groupId +  ':' + depl oyment.art ifactId +  ':' + depl oyment.ver sion;
  342                         activity.d eploymentI d = deploy mentId;
  343                    }
  344                });
  345                updatedA ctivities. push(activ ity);
  346           }) ;
  347       }
  348  
  349       return  updatedAc tivities;
  350   }
  351  
  352   function d oProcessDe finitionsF etch(confi g, callbac k) {
  353  
  354       httpUt il.get(con fig, funct ion(err, r esponse, r eturnedDat a) {
  355           if  (err) {
  356                return c allback(er r);
  357           }
  358  
  359           va r processD efinitions Organizer  = {};
  360           va r processD efinitions  = [];
  361  
  362           if  (returned Data.hasOw nProperty( 'processDe finitionLi st') && Ar ray.isArra y(returned Data.proce ssDefiniti onList)) {
  363                _.each(r eturnedDat a.processD efinitionL ist, funct ion(proces sDefinitio n) {
  364                    if ( processDef inition.ha sOwnProper ty('proces s-definiti on')) {
  365                         processDef inition =  processDef inition['p rocess-def inition'];
  366                    }
  367                    //we  do not ne ed BPM for ms data. R emove the  element.
  368                    if ( processDef inition.ha sOwnProper ty('forms' )) {
  369                         delete pro cessDefini tion.forms ;
  370                    }
  371  
  372                    if ( processDef inition.ha sOwnProper ty('deploy ment-id'))  {
  373                         processDef inition.de ploymentId  = process Definition ['deployme nt-id'];
  374                    }
  375  
  376                    //va lidate wel l-formed p rocess def inition be fore allow ing it to  be sorted
  377                    if ( processDef inition.ha sOwnProper ty('deploy mentId') & &
  378                         _.size(act ivityUtils .parseVers ionFromDep loymentId( processDef inition.de ploymentId )) > 0) {
  379                         //Group ac tivities b y type bef ore sortin g versions  based on  deployment  and proce ss IDs
  380                         var deploy mentKey =  processDef inition.de ploymentId .substring (0, proces sDefinitio n.deployme ntId.lastI ndexOf(':' ));
  381                         if (proces sDefinitio n.hasOwnPr operty('id ')) {
  382                             deploy mentKey +=  '.' + pro cessDefini tion.id;
  383                         }
  384  
  385                         if (!proce ssDefiniti onsOrganiz er.hasOwnP roperty(de ploymentKe y)) {
  386                             proces sDefinitio nsOrganize r[deployme ntKey] = [ ];
  387                         }
  388                         processDef initionsOr ganizer[de ploymentKe y].push(pr ocessDefin ition);
  389                    }
  390                });
  391           }
  392  
  393           _. each(proce ssDefiniti onsOrganiz er, functi on(deploym entsArr) {
  394                deployme ntsArr.sor t(function (a, b) {
  395                    //in tentionall y swap ver sion order s to rever se default  sort orde r
  396                    retu rn version Compare(ac tivityUtil s.parseVer sionFromDe ploymentId (b.deploym entId), ac tivityUtil s.parseVer sionFromDe ploymentId (a.deploym entId));
  397                });
  398                processD efinitions  = process Definition s.concat(d eployments Arr);
  399           }) ;
  400  
  401           va r formatte dResponse  = {
  402                data: {
  403                    item s: process Definition s
  404                }
  405           };
  406  
  407           re turn callb ack(null,  formattedR esponse);
  408       });
  409   }
  410  
  411   function d oDeploymen tsFetch(co nfig, call back) {
  412       httpUt il.get(con fig, funct ion(err, r esponse, r eturnedDat a) {
  413           if  (err) {
  414                return c allback(er r);
  415           }
  416  
  417           va r formatte dResponse  = {
  418                data: {
  419                    item s: []
  420                }
  421           };
  422  
  423           if  (returned Data.hasOw nProperty( 'deploymen tUnitList' ) && Array .isArray(r eturnedDat a.deployme ntUnitList )) {
  424                _.each(r eturnedDat a.deployme ntUnitList , function (deploymen t) {
  425                    form attedRespo nse.data.i tems.push( deployment );
  426                });
  427           }
  428  
  429           re turn callb ack(null,  formattedR esponse);
  430       });
  431   }
  432  
  433   function s endSignal( req, res)  {
  434       req.au dit.dataDo main = 'Ac tivities';
  435       req.au dit.logCat egory = 'S END_SIGNAL ';
  436  
  437       var de ploymentId  = req.bod y.deployme ntId || nu ll;
  438  
  439       var id Error;
  440       if (!d eploymentI d) {
  441           id Error = ne w Error('M issing dep loymentId  property/v alue in in put JSON.' );
  442           re q.logger.e rror(idErr or);
  443           re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message);
  444       }
  445  
  446       var pr ocessInsta nceId = re q.body.pro cessInstan ceId || -1 ;
  447  
  448       var si gnalName =  req.body. signalName  || null;
  449  
  450       if (!s ignalName)  {
  451           id Error = ne w Error('M issing sig nalName pr operty/val ue in inpu t JSON.');
  452           re q.logger.e rror(idErr or);
  453           re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message);
  454       }
  455  
  456       var si gnalConten t = req.bo dy.paramet er;
  457       if (si gnalConten t) {
  458           va r paramete rCount = _ .size(sign alContent) ;
  459           if  (paramete rCount > 1 ) {
  460                idError  = new Erro r('Invalid  number of  parameter s passed i n input JS ON. Only o ne paramet er allowed .');
  461                req.logg er.error(i dError);
  462                return r es.status( rdk.httpst atus.bad_r equest).rd kSend(idEr ror.messag e);
  463           }
  464           //  set signa l issuer c ontext to  the payloa d
  465           va r user = r eq.session .user;
  466           si gnalConten t.signalBo dy = signa lContent.s ignalBody  || {};
  467           si gnalConten t.signalBo dy.executi onUserId =  user.site  + ';' + u ser.duz[us er.site];  // user.ui d includes  the names pace urn:v a:user, JB PM wants i t without  the namesp ace
  468           si gnalConten t.signalBo dy.executi onUserName  = user.la stname + ' ,' + user. firstname;  // JBPM w ants "last name,first name"
  469       }
  470  
  471       var cb  = functio n(err, res ults) {
  472           if  (err) {
  473                req.logg er.error(e rr);
  474  
  475                if (err  instanceof  JBPMServe rError) {
  476                    retu rn res.sta tus(rdk.ht tpstatus.i nternal_se rver_error ).rdkSend( err);
  477                }
  478  
  479                return r es.status( rdk.httpst atus.bad_r equest).rd kSend(err) ;
  480           }
  481           re turn res.r dkSend(res ults);
  482       };
  483       doSign al(getGene ricJbpmCon fig(req),  deployment Id, proces sInstanceI d, signalN ame, signa lContent,  cb);
  484   }
  485  
  486   function d oSignal(co nfig, depl oymentId,  processIns tanceId, s ignalName,  signalCon tent, cb)  {
  487       var ur i = uriBui lder.fromU ri(config. url)
  488           .p ath('/exec ute')
  489           .b uild();
  490  
  491       config .url = uri ;
  492       if (!c onfig.head ers) {
  493           co nfig.heade rs = {};
  494       }
  495  
  496       config .headers[' Content-Ty pe'] = 'ap plication/ xml';
  497       config .headers.A ccept = 'a pplication /xml';
  498       config .headers[' Kie-Deploy ment-Id']  = deployme ntId;
  499  
  500       async. parallel([
  501                function (callback)  {
  502                    var  signalEven tCommandTe mplateXML  = xmlTempl ates.signa lEventComm andTemplat e;
  503                    var  signalEven tCommandXM L = signal EventComma ndTemplate XML.replac e('{Deploy mentId}',  deployment Id)
  504                         .replace(' {ProcessIn stanceId}' , processI nstanceId)
  505                         .replace(' {EventType }', signal Name);
  506                    call back(null,  signalEve ntCommandX ML);
  507                },
  508                function (callback)  {
  509                    var  signalEven tValueXML  = '';
  510                    var  itemsList  = '';
  511                    if ( signalCont ent) {
  512                         signalEven tValueXML  = xmlTempl ates.signa lEventValu eTemplate;
  513                         var comple xObjectPro pertiesXML  = xmlTemp lates.comp lexObjectP ropertiesX ML;
  514                         var value  = _.head(_ .values(si gnalConten t));
  515                         var type =  typeof va lue;
  516  
  517                         //**** Par ent Contai ner Object
  518                         if (type = == 'object ') {
  519                             var ob jectItems  = value;
  520                             _.each (objectIte ms, functi on(value,  key) {
  521                                 ty pe = typeo f value;
  522                                 // the key ob jectType s hould matc h the clas s name in  jbpm start ing with a  small let ter.
  523                                 if  (key ===  'objectTyp e') {
  524                                      signalEv entValueXM L = signal EventValue XML.replac e('{Type}' , value);
  525                                 }  else {
  526                                      if (type  === 'obje ct') {
  527                                          if ( value !==  null && va lue.constr uctor ===  Array) {
  528                                               for (var i  = 0; i <  value.leng th; i++) {
  529                                                   itemsL ist = item sList + co mplexObjec tPropertie sXML.repla ce(/{Key}/ g, key).re place('{Va lue}', pro cessValue( value[i])) ;
  530                                               }
  531                                          } el se {
  532                                               itemsList  = itemsLis t + comple xObjectPro pertiesXML .replace(/ {Key}/g, k ey).replac e('{Value} ', process JsonObject (value));
  533                                          }
  534  
  535                                      } else {
  536                                          item sList = it emsList +  complexObj ectPropert iesXML.rep lace(/{Key }/g, key). replace('{ Value}', w rapValueIn CData(valu e));
  537                                      }
  538                                 }
  539                             });
  540                             signal EventValue XML = sign alEventVal ueXML.repl ace('{Valu e}', items List);
  541                         } else {
  542                             signal EventValue XML = sign alEventVal ueXML.repl ace('{Type }', 'xs:'  + type).re place('{Va lue}', wra pValueInCD ata(value) );
  543                         }
  544                    }
  545                    call back(null,  signalEve ntValueXML );
  546                }
  547           ],
  548           fu nction(err , results)  {
  549                if (err)  {
  550                    retu rn cb(err) ;
  551                }
  552  
  553                var sign alEventCom mandXML =  results[0] .replace(' {EventValu e}', resul ts[1]);
  554                config.b ody = sign alEventCom mandXML;
  555                config.j son = fals e;
  556  
  557                httpUtil .post(conf ig, functi on(err, re sponse, re sult) {
  558                    if ( err) {
  559                         return cb( err);
  560                    }
  561  
  562                    pars eString(re sult, func tion(err,  jsonResult ) {
  563                         if (err) {
  564                             return  cb(new JB PMServerEr ror('Inval id error X ML receive d(' + err  + ')'));
  565                         }
  566  
  567                         if (jsonRe sult['comm and-respon se']) {
  568                             if (js onResult[' command-re sponse'].e xception)  {
  569                                 re turn cb(ne w Error(js onResult[' command-re sponse'].e xception[0 ].message[ 0]));
  570                             } else  {
  571                                 re turn cb(nu ll, 'Succe ss');
  572                             }
  573                         }
  574  
  575                         return cb( null, json Result);
  576                    });
  577  
  578                });
  579           }) ;
  580   }
  581  
  582   function J BPMServerE rror(messa ge, error)  {
  583       this.n ame = 'JBP MServerErr or';
  584       this.e rror = err or;
  585       this.m essage = m essage;
  586   }
  587  
  588   function g etCdsInten tResults(r eq, res) {
  589       req.au dit.dataDo main = 'AC TIVITIES';
  590       req.au dit.logCat egory = 'C DSINTENTRE SULTS';
  591  
  592       var cd sIntentReq uest = req .body;
  593       if (ty peof cdsIn tentReques t !== 'obj ect') {
  594           va r reqError  = new Err or('Invali d request  body');
  595           re q.logger.e rror(reqEr ror);
  596           re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(reqError .message);
  597       }
  598  
  599       var co nfig = {
  600           ti meout: 500 00,
  601           lo gger: req. logger,
  602           ba seUrl: req .app.subsy stems.cds. getInvocat ionUrl(),
  603           ur l: '/cds-r esults-ser vice/cds/i nvokeRules ',
  604           bo dy: cdsInt entRequest
  605       };
  606  
  607       httpUt il.post(co nfig, func tion(err,  response,  body) {
  608           re q.logger.d ebug('call back from  fetch()');
  609  
  610           if  (err) {
  611                req.logg er.error(e rr);
  612                return r es.status( rdk.httpst atus.bad_r equest).rd kSend(err) ;
  613           }
  614  
  615           if  (body.sta tus && bod y.status.c ode !== '0 ') { // 0  == OK
  616                var invo cationErro r = getInv ocationErr or(body.fa ultInfo);
  617                // HTTP  request wa s successf ul but the  CDS Invoc ation serv ice report ed an erro r.
  618                req.logg er.debug({
  619                    invo cationErro r: invocat ionError
  620                }, 'CDS  Intent Res ults: cds  invocation  server re turned err or');
  621                return r es.status( rdk.httpst atus.inter nal_server _error).rd kSend(invo cationErro r);
  622           }
  623           re turn res.r dkSend(bod y);
  624       });
  625   }
  626  
  627   function g etJbpmInst anceByInst anceId(req , res) {
  628       req.au dit.dataDo main = 'AC TIVITIES';
  629       req.au dit.logCat egory = 'J BPM_INSTAN CE_BY_ID';
  630  
  631       var co nfig = get GenericJbp mConfig(re q);
  632  
  633       var de ploymentId  = req.bod y.deployme ntId;
  634       var pr ocessInsta nceId = re q.body.pro cessInstan ceId;
  635  
  636       var id Error;
  637       var fo rmattedRet urnData =  {};
  638  
  639       if (!d eploymentI d) {
  640           id Error = ne w Error('M issing dep loymentId  property/v alue in in put JSON.' );
  641           re q.logger.e rror(idErr or);
  642           re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message);
  643       }
  644  
  645       if (!p rocessInst anceId) {
  646           id Error = ne w Error('M issing pro cessInstan ceId prope rty/value  in input J SON.');
  647           re q.logger.e rror(idErr or);
  648           re turn res.s tatus(rdk. httpstatus .bad_reque st).rdkSen d(idError. message);
  649       }
  650  
  651       format tedReturnD ata.proces sInstanceI d = proces sInstanceI d;
  652  
  653       var ur i = uriBui lder.fromU ri(config. url)
  654           .p ath('/runt ime/')
  655           .p ath(deploy mentId)
  656           .p ath('/with vars/proce ss/instanc e/')
  657           .p ath(proces sInstanceI d)
  658           .b uild();
  659  
  660       config .url = uri ;
  661       config .headers[' Content-Ty pe'] = 'ap plication/ json';
  662       config .headers.A ccept = 'a pplication /json';
  663  
  664       httpUt il.get(con fig, funct ion (err,  response,  returnedDa ta) {
  665           if  (err) {
  666                if (err  instanceof  JBPMServe rError) {
  667                    retu rn res.sta tus(rdk.ht tpstatus.i nternal_se rver_error ).rdkSend( err);
  668                }
  669  
  670                return r es.status( rdk.httpst atus.bad_r equest).rd kSend(err) ;
  671           }
  672  
  673           if (!nullchec ker.isNull ish(return edData) &&  (JSON.str ingify(ret urnedData) .indexOf(' NOT_FOUND' ) > -1)) {
  674                return r es.rdkSend ('NOT_FOUN D');
  675           }
  676  
  677           va r keys = _ .keys(_.ge t(returned Data, 'var iables'));
  678  
  679           // Regular ex pression t o match th e java pac kage refer ence retur ned by JBP M
  680           // eg. "vista core.order .consult.C onsultOrde r@6029c0b3 "
  681           va r objRefRe gEx = /^([ a-zA-Z0-9_ \-\.]+)@([ a-zA-Z0-9] +)/;
  682  
  683           va r objectLi st = [];
  684  
  685          _.e ach(keys,  function(k ey, i) {
  686                var vari ableValue  = _.get(re turnedData , ['variab les', key] );
  687                if(objRe fRegEx.tes t(variable Value)) {
  688                    obje ctList.pus h(key);
  689                } else {
  690                    form attedRetur nData[key]  = variabl eValue;
  691                }
  692           }) ;
  693  
  694           if (objectLis t.length >  0) {
  695                var coun t = 0;
  696                _.each(o bjectList,  function( obj) {
  697                    conf ig = getGe nericJbpmC onfig(req) ;
  698  
  699                    uri  = uriBuild er.fromUri (config.ur l)
  700                    .pat h('/runtim e/')
  701                    .pat h(deployme ntId)
  702                    .pat h('/proces s/instance /')
  703                    .pat h(processI nstanceId)
  704                    .pat h('/variab le/')
  705                    .pat h(obj)
  706                    .bui ld();
  707  
  708                    conf ig.url = u ri;
  709  
  710                    http Util.get(c onfig, fun ction(err,  response,  returnedV ariableDat a) {
  711                         if (err) {
  712                             if (er r instance of JBPMSer verError)  {
  713                                 re turn res.s tatus(rdk. httpstatus .internal_ server_err or).rdkSen d(err);
  714                             }
  715  
  716                             return  res.statu s(rdk.http status.bad _request). rdkSend(er r);
  717                         }
  718  
  719                         var path =  _.get(res ponse, 're quest.uri. path');
  720  
  721                         var objNam e = path.s ubstring(p ath.lastIn dexOf('/')  + 1);
  722  
  723                         formattedR eturnData[ objName] =  returnedV ariableDat a;
  724  
  725                         count++;
  726  
  727                         if(count = == objectL ist.length ) {
  728                             return  res.rdkSe nd(formatt edReturnDa ta);
  729                         }
  730                    });
  731                });
  732           }  else {
  733                return r es.rdkSend (formatted ReturnData );
  734           }
  735       });
  736  
  737   }
  738  
  739   /*
  740    * Retriev e the stat us from th e invocati on result
  741    *
  742    * @param  {object} i nfo the re turned pay load from  an invocat ion call
  743    */
  744   function g etInvocati onError(in fo) {
  745       return  _.map(inf o, functio n(o) {
  746           re turn o.fau lt;
  747       }).joi n(' ');
  748   }
  749  
  750   module.exp orts.getAc tivities =  getActivi ties;
  751   module.exp orts.start Process =  startProce ss;
  752   module.exp orts.doSta rtProcess  = doStartP rocess;
  753   module.exp orts.abort Process =  abortProce ss;
  754   module.exp orts.getDe ploymentsF etchConfig  = getDepl oymentsFet chConfig;
  755   module.exp orts.doDep loymentsFe tch = doDe ploymentsF etch;
  756   module.exp orts.updat eActivitie s = update Activities ;
  757   module.exp orts.sendS ignal = se ndSignal;
  758   module.exp orts.getCd sIntentRes ults = get CdsIntentR esults;
  759   module.exp orts.doSig nal = doSi gnal;
  760   module.exp orts.doPro cessDefini tionsFetch  = doProce ssDefiniti onsFetch;
  761   module.exp orts.getDe finitionsF etchConfig  = getDefi nitionsFet chConfig;
  762   module.exp orts.getJb pmInstance ByInstance Id = getJb pmInstance ByInstance Id;