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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | rdk.zip\rdk\product\production\rdk\src\resources\cds-intent | cds-intent.js | Fri Aug 25 15:36:55 2017 UTC |
| 2 | rdk.zip\rdk\product\production\rdk\src\resources\cds-intent | cds-intent.js | Tue Oct 3 17:16:26 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 790 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| 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 |
No regular expressions were active.
| 1 | 'use stric t'; | |
| 2 | ||
| 3 | var rdk = require('. ./../core/ rdk'); | |
| 4 | var nullch ecker = rd k.utils.nu llchecker; | |
| 5 | var _ = re quire('lod ash'); | |
| 6 | ||
| 7 | var dbName = 'intent '; | |
| 8 | var intent Collection = 'cdsint ent'; | |
| 9 | ||
| 10 | ||
| 11 | function c reateInitD b(logger) { | |
| 12 | return function initIntent (dbConnect ion) { | |
| 13 | /* | |
| 14 | * Index for intents | |
| 15 | * | |
| 16 | * Note: It' s both spa rse and un ique - so we will st ill need t o make sur e required fields ar e present, | |
| 17 | * because s copeId is optional. Unfortuna tely Mongo doesn't l et us have only that 'column' set as spa rse, | |
| 18 | * so we hav e to deal with that programmat ically. | |
| 19 | * / | |
| 20 | db Connection .collectio n(intentCo llection). ensureInde x({ | |
| 21 | name: 1, | |
| 22 | scope: 1 , | |
| 23 | scopeId: 1 | |
| 24 | }, { | |
| 25 | sparse: true, | |
| 26 | unique: true | |
| 27 | }, function( error) { | |
| 28 | if (erro r) { | |
| 29 | logg er.error({ | |
| 30 | error: err or | |
| 31 | }, ' error ensu ring ' + i ntentColle ction + ' index'); | |
| 32 | retu rn; | |
| 33 | } | |
| 34 | }) ; | |
| 35 | }; | |
| 36 | } | |
| 37 | ||
| 38 | ||
| 39 | // Intent | |
| 40 | ||
| 41 | /** | |
| 42 | * @api {g et} /resou rce/cds/in tent/regis try Get In tent | |
| 43 | * @apiNam e GetInten t | |
| 44 | * @apiGro up Intent | |
| 45 | * @apiPar am {String } [name] I ntent name | |
| 46 | * @apiPar am {String } [scope] Intent Sco pe | |
| 47 | * @apiPar am {String } [scopeId ] Intent S cope Id | |
| 48 | * @apiDes cription R eturns the intent or intents t hat match the uri qu ery parame ters. The values fo r "name" | |
| 49 | * and "sc ope" are r equired. For ease o f use, the se can be wildcarded by passin g in a '*' . This wa y we can | |
| 50 | * use thi s method t o either g et a singl e entity o r return a list of e ntities wh ich might be useful for testin g | |
| 51 | * or othe r future u ses. | |
| 52 | * @apiExa mple {js} Example us age: | |
| 53 | * curl -i http:// IP /resource/ cds/intent /registry? name=First Engine&sco pe=Enterpr ise | |
| 54 | * @apiSuc cess {json } payload Json objec t containi ng a list of all dat apoint val ues for th e given ur i paramete rs. | |
| 55 | * @apiSuc cessExampl e {json} G etIntent-R esponse | |
| 56 | * HTTP/1. 1 200 OK | |
| 57 | * { | |
| 58 | * "stat us": 200, | |
| 59 | * "data ": [ | |
| 60 | * { | |
| 61 | * "descr iption": " A Mock Int ent", | |
| 62 | * "globa lName": "E nterprise/ /FirstEngi ne", | |
| 63 | * "gover nance": nu ll, | |
| 64 | * "id": "", | |
| 65 | * "invoc ations": [ | |
| 66 | * { | |
| 67 | * "dataFor mat": "app lication/j son+fhir", | |
| 68 | * "dataQue ries": nul l, | |
| 69 | * "engineN ame": "eng ineOne", | |
| 70 | * "name": null, | |
| 71 | * "rules": [ | |
| 72 | * { | |
| 73 | * "id": "gen derAgeRule ", | |
| 74 | * "propertie s": { | |
| 75 | * "delay ": "10" | |
| 76 | * } | |
| 77 | * } | |
| 78 | * ] | |
| 79 | * } | |
| 80 | * ], | |
| 81 | * "name" : "FirstEn gine", | |
| 82 | * "scope ": "Enterp rise", | |
| 83 | * "scope Id": null, | |
| 84 | * "_id": "5567576e 258aab9705 1eb64a" | |
| 85 | * } | |
| 86 | * ] | |
| 87 | * } | |
| 88 | */ | |
| 89 | function g etIntent(r eq, res) { | |
| 90 | req.lo gger.debug ('cds-inte nt.getInte nt()'); | |
| 91 | ||
| 92 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 93 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS inten t resource is unavai lable.'); | |
| 94 | } | |
| 95 | ||
| 96 | req.ap p.subsyste ms.cds.get CDSDB(res. logger, db Name, crea teInitDb(r es.logger) , function (error, db Connection ) { | |
| 97 | if (error) { | |
| 98 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 99 | } | |
| 100 | ||
| 101 | va r name = r eq.query.n ame; | |
| 102 | va r scope = req.query. scope; | |
| 103 | va r scopeId = req.quer y.scopeId; | |
| 104 | ||
| 105 | va r match = {}; | |
| 106 | if (name !== '*' && nu llchecker. isNotNulli sh(name)) { | |
| 107 | match.na me = name; | |
| 108 | } | |
| 109 | if (scope != = '*' && n ullchecker .isNotNull ish(scope) ) { | |
| 110 | match.sc ope = scop e; | |
| 111 | } | |
| 112 | if (nullchec ker.isNotN ullish(sco peId)) { | |
| 113 | if (scop eId !== '* ') { //if it's not w ildcard, u se it. if it is a w ildcard, l et them al l match | |
| 114 | matc h.scopeId = scopeId; | |
| 115 | } | |
| 116 | } else { | |
| 117 | match.sc opeId = nu ll; | |
| 118 | } | |
| 119 | ||
| 120 | db Connection .collectio n(intentCo llection). find(match ).toArray( function(e rr, result ) { | |
| 121 | if (err === null & & _.isEmpt y(result)) { | |
| 122 | retu rn res.sta tus(rdk.ht tpstatus.n ot_found). rdkSend('N o intents found'); | |
| 123 | } | |
| 124 | if (err !== null) { | |
| 125 | retu rn res.sta tus(rdk.ht tpstatus.i nternal_se rver_error ).rdkSend( err); | |
| 126 | } | |
| 127 | res.stat us(rdk.htt pstatus.ok ).rdkSend( { | |
| 128 | data : result | |
| 129 | }); | |
| 130 | }) ; | |
| 131 | }); | |
| 132 | } | |
| 133 | ||
| 134 | ||
| 135 | /** | |
| 136 | * @api {p ost} /reso urce/cds/i ntent/regi stry Creat e Intent | |
| 137 | * @apiNam e CreateIn tent | |
| 138 | * @apiGro up Intent | |
| 139 | * @apiDes cription R eturns the intent or intents t hat match the uri qu ery parame ters. The values fo r "name" | |
| 140 | * and "sc ope" are r equired. For ease o f use, the se can be wildcarded by passin g in a '*' . This wa y we can | |
| 141 | * use thi s method t o either g et a singl e entity o r return a list of e ntities wh ich might be useful for testin g | |
| 142 | * or othe r future u ses. | |
| 143 | * @apiSuc cess (Succ ess 201) { json} json echo of t he created intent | |
| 144 | * @apiSuc cessExampl e {json} G etIntent-R esponse | |
| 145 | * { | |
| 146 | * "stat us": 201, | |
| 147 | * "data ": [ | |
| 148 | * { | |
| 149 | * "descr iption": " A Mock Int ent", | |
| 150 | * "globa lName": "E nterprise/ /FirstEngi ne", | |
| 151 | * "gover nance": nu ll, | |
| 152 | * "id": "", | |
| 153 | * "invoc ations": [ | |
| 154 | * { | |
| 155 | * "dataFor mat": "app lication/j son+fhir", | |
| 156 | * "dataQue ries": nul l, | |
| 157 | * "engineN ame": "eng ineOne", | |
| 158 | * "name": null, | |
| 159 | * "rules": [ | |
| 160 | * { | |
| 161 | * "id": "gen derAgeRule ", | |
| 162 | * "propertie s": { | |
| 163 | * "delay ": "10" | |
| 164 | * } | |
| 165 | * } | |
| 166 | * ] | |
| 167 | * } | |
| 168 | * ], | |
| 169 | * "name" : "FirstEn gine", | |
| 170 | * "scope ": "Enterp rise", | |
| 171 | * "scope Id": null, | |
| 172 | * "_id": "5567576e 258aab9705 1eb64a" | |
| 173 | * } | |
| 174 | * ] | |
| 175 | * } | |
| 176 | * @apiErr or Missing IntentName | |
| 177 | * @apiErr orExample Error-Resp onse: | |
| 178 | * HTTP/1. 1 400 Inte rnal Serve r Error | |
| 179 | * { | |
| 180 | * "sta tus": 400, | |
| 181 | * "mes sage": "Mi ssing requ ired inten t name" | |
| 182 | * } | |
| 183 | * @apiErr or Missing IntentScop e | |
| 184 | * @apiErr orExample Error-Resp onse: | |
| 185 | * HTTP/1. 1 400 Inte rnal Serve r Error | |
| 186 | * { | |
| 187 | * "sta tus": 400, | |
| 188 | * "mes sage": "Mi ssing requ ired inten t scope" | |
| 189 | * } | |
| 190 | * @apiErr or IntentE xistatus | |
| 191 | * @apiErr orExample Error-Resp onse: | |
| 192 | * HTTP/1. 1 409 Inte rnal Serve r Error | |
| 193 | * { | |
| 194 | * "sta tus": 409, | |
| 195 | * "mes sage": "An intent wi th that na me/scope/s copeId com bination e xistatus, can not be created" | |
| 196 | * } | |
| 197 | */ | |
| 198 | function p ostIntent( req, res) { | |
| 199 | req.lo gger.debug ('cds-inte nt.postInt ent()'); | |
| 200 | ||
| 201 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 202 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS inten t resource is unavai lable.'); | |
| 203 | } | |
| 204 | ||
| 205 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r eq.logger) , function (error, db Connection ) { | |
| 206 | if (error) { | |
| 207 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 208 | } | |
| 209 | va r intent = req.body; | |
| 210 | ||
| 211 | if (!intent || !intent .name) { | |
| 212 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend('Mis sing requi red intent name'); | |
| 213 | } | |
| 214 | if (!intent || !intent .scope) { | |
| 215 | res.stat us(rdk.htt pstatus.ba d_request) .rdkSend(' Missing re quired int ent scope' ); | |
| 216 | } | |
| 217 | va r match = {}; | |
| 218 | ma tch.name = intent.na me; | |
| 219 | ma tch.scope = intent.s cope; | |
| 220 | if (nullchec ker.isNotN ullish(int ent.scopeI d)) { | |
| 221 | match.sc opeId = in tent.scope Id; | |
| 222 | } else { | |
| 223 | match.sc opeId = nu ll; | |
| 224 | } | |
| 225 | ||
| 226 | db Connection .collectio n(intentCo llection). find(match ).toArray( function(e rr, result ) { | |
| 227 | if (!err && result .length > 0) { | |
| 228 | retu rn res.sta tus(rdk.ht tpstatus.c onflict).r dkSend('An intent wi th that na me/scope/s copeId com bination e xists. St atus, can not be cre ated'); | |
| 229 | } | |
| 230 | delete i ntent._id; | |
| 231 | dbConnec tion.colle ction(inte ntCollecti on).insert (intent, f unction(er r, result) { | |
| 232 | var message = (err === n ull) ? res ult.ops : err; | |
| 233 | if ( err === nu ll && _.is Empty(resu lt)) { | |
| 234 | return res .status(rd k.httpstat us.bad_req uest).rdkS end(messag e); | |
| 235 | } | |
| 236 | res. status(rdk .httpstatu s.created) .rdkSend(m essage); | |
| 237 | }); | |
| 238 | }) ; | |
| 239 | }); | |
| 240 | } | |
| 241 | ||
| 242 | ||
| 243 | /** | |
| 244 | * @api {p ut} /resou rce/cds/in tent/regis try Put In tent | |
| 245 | * @apiNam e PutInten t | |
| 246 | * @apiGro up Intent | |
| 247 | * @apiPar am {String } name Int ent name | |
| 248 | * @apiPar am {String } scope In tent Scope | |
| 249 | * @apiPar am {String } [scopeId ] Intent S cope Id | |
| 250 | * @apiDes cription U pdates the specified intent re cord. Not e: The pa rameters m ust match any | |
| 251 | * specifi ed in the document. Those fie lds essent ially form a primary key for t his record , | |
| 252 | * and cha nging them is essent ially a ne w record, and not an update. | |
| 253 | * @apiSuc cess {json } payload Json objec t containi ng a numbe r indicati ng the num ber of rec ords updat ed. | |
| 254 | * @apiSuc cessExampl e {json} P utIntent-R esponse | |
| 255 | * HTTP/1. 1 200 OK | |
| 256 | * { | |
| 257 | * "sta tus": 200, | |
| 258 | * "dat a": 1 | |
| 259 | * } | |
| 260 | * @apiErr or Missing IntentName | |
| 261 | * @apiErr orExample Error-Resp onse: | |
| 262 | * HTTP/1. 1 400 Inte rnal Serve r Error | |
| 263 | * { | |
| 264 | * "sta tus": 400, | |
| 265 | * "mes sage": "Mi ssing requ ired inten t name" | |
| 266 | * } | |
| 267 | * @apiErr or Missing IntentScop e | |
| 268 | * @apiErr orExample Error-Resp onse: | |
| 269 | * HTTP/1. 1 400 Inte rnal Serve r Error | |
| 270 | * { | |
| 271 | * "sta tus": 400, | |
| 272 | * "mes sage": "Mi ssing requ ired inten t scope" | |
| 273 | * } | |
| 274 | * @apiErr or IntentD oesNotExis t | |
| 275 | * @apiErr orExample Error-Resp onse: | |
| 276 | * HTTP/1. 1 409 Inte rnal Serve r Error | |
| 277 | * { | |
| 278 | * "sta tus": 400, | |
| 279 | * "mes sage": "In tent does not exist" | |
| 280 | * } | |
| 281 | */ | |
| 282 | function p utIntent(r eq, res) { | |
| 283 | req.lo gger.debug ('cds-inte nt.putInte nt()'); | |
| 284 | ||
| 285 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 286 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS inten t resource is unavai lable.'); | |
| 287 | } | |
| 288 | ||
| 289 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r es.logger) , function (error, db Connection ) { | |
| 290 | if (error) { | |
| 291 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 292 | } | |
| 293 | va r intent = req.body; | |
| 294 | ||
| 295 | va r name = r eq.query.n ame; | |
| 296 | va r scope = req.query. scope; | |
| 297 | va r scopeId = req.quer y.scopeId; | |
| 298 | ||
| 299 | if (nullchec ker.isNull ish(name)) { | |
| 300 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend('Mis sing requi red intent name'); | |
| 301 | } | |
| 302 | if (nullchec ker.isNull ish(scope) ) { | |
| 303 | res.stat us(rdk.htt pstatus.ba d_request) .rdkSend(' Missing re quired int ent scope' ); | |
| 304 | } | |
| 305 | va r match = {}; | |
| 306 | ma tch.name = name; | |
| 307 | ma tch.scope = scope; | |
| 308 | if (nullchec ker.isNotN ullish(sco peId)) { | |
| 309 | match.sc opeId = sc opeId; | |
| 310 | } else { | |
| 311 | match.sc opeId = nu ll; | |
| 312 | } | |
| 313 | ||
| 314 | in tent.name = name; | |
| 315 | in tent.scope = scope; | |
| 316 | db Connection .collectio n(intentCo llection). find(match ).toArray( function(e rr, result ) { | |
| 317 | if (err || result. length === 0) { | |
| 318 | retu rn res.sta tus(rdk.ht tpstatus.n ot_found). rdkSend('I ntent does not exist '); | |
| 319 | } | |
| 320 | dbConnec tion.colle ction(inte ntCollecti on).update (match, in tent, func tion(err, updateResu lt) { | |
| 321 | if ( err) { | |
| 322 | return res .status(rd k.httpstat us.bad_req uest).rdkS end(err); | |
| 323 | } | |
| 324 | ||
| 325 | if ( _.get(upda teResult, 'result.nM odified', 0) !== 1) { | |
| 326 | return res .status(rd k.httpstat us.bad_req uest).rdkS end('Inten t unable t o be updat ed'); | |
| 327 | } | |
| 328 | ||
| 329 | retu rn res.sta tus(rdk.ht tpstatus.o k).rdkSend (updateRes ult); | |
| 330 | }); | |
| 331 | }) ; | |
| 332 | }); | |
| 333 | } | |
| 334 | ||
| 335 | ||
| 336 | /** | |
| 337 | * @api {d elete} /re source/cds /intent/re gistry Del ete Intent | |
| 338 | * @apiNam e DeleteIn tent | |
| 339 | * @apiGro up Intent | |
| 340 | * @apiPar am {String } [name] I ntent name | |
| 341 | * @apiPar am {String } [scope] Intent Sco pe | |
| 342 | * @apiPar am {String } [scopeId ] Intent S cope Id | |
| 343 | * @apiDes cription D eletes the specified intent re cord. Not e: The pa rameters m ust match any | |
| 344 | * specifi ed in the document. Those fie lds essent ially form a primary key for t his record , and chan ging | |
| 345 | * them is essential ly a new r ecord, and not an up date. | |
| 346 | * @apiSuc cess {json } payload Json objec t containi ng a numbe r indicati ng the num ber of rec ords updat ed. | |
| 347 | * @apiSuc cessExampl e {json} D eleteInten t-Response | |
| 348 | * HTTP/1. 1 200 OK | |
| 349 | * { | |
| 350 | * "sta tus": 200, | |
| 351 | * mess age": 1 | |
| 352 | * } | |
| 353 | */ | |
| 354 | function d eleteInten t(req, res ) { | |
| 355 | req.lo gger.debug ('cds-inte nt.deleteI ntent()'); | |
| 356 | ||
| 357 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 358 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS inten t resource is unavai lable.'); | |
| 359 | } | |
| 360 | ||
| 361 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, crea teInitDb(r es.logger) , function (error, db Connection ) { | |
| 362 | if (error) { | |
| 363 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 364 | } | |
| 365 | va r name = r eq.query.n ame; | |
| 366 | va r scope = req.query. scope; | |
| 367 | va r scopeId = req.quer y.scopeId; | |
| 368 | ||
| 369 | va r match = {}; | |
| 370 | ma tch.name = name; | |
| 371 | ma tch.scope = scope; | |
| 372 | if (nullchec ker.isNotN ullish(sco peId)) { | |
| 373 | match.sc opeId = sc opeId; | |
| 374 | } else { | |
| 375 | match.sc opeId = nu ll; | |
| 376 | } | |
| 377 | ||
| 378 | if (!name && !scope && !scopeId) { | |
| 379 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend('Mis sing a req uired inte nt identif ier (name, scope, or scopeId)' ); | |
| 380 | } | |
| 381 | ||
| 382 | db Connection .collectio n(intentCo llection). remove(mat ch, functi on(err, re sult) { | |
| 383 | var mess age = (err === null) ? result : err; | |
| 384 | if (err === null & & result = == 0) { | |
| 385 | retu rn res.sta tus(rdk.ht tpstatus.n ot_found). rdkSend(me ssage); | |
| 386 | } | |
| 387 | res.stat us(rdk.htt pstatus.ok ).rdkSend( message); | |
| 388 | }) ; | |
| 389 | }); | |
| 390 | } | |
| 391 | ||
| 392 | ||
| 393 | module.exp orts.getIn tent = get Intent; | |
| 394 | module.exp orts.postI ntent = po stIntent; | |
| 395 | module.exp orts.putIn tent = put Intent; | |
| 396 | module.exp orts.delet eIntent = deleteInte nt; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.