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-engine | cds-engine.js | Fri Aug 25 15:36:55 2017 UTC |
| 2 | rdk.zip\rdk\product\production\rdk\src\resources\cds-engine | cds-engine.js | Tue Oct 3 17:16:24 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 640 |
| Changed | 2 | 4 |
| 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 | // set up the packag es we need | |
| 4 | var rdk = require('. ./../core/ rdk'); | |
| 5 | var _ = re quire('lod ash'); | |
| 6 | var Object Id = requi re('mongod b').Object ID; | |
| 7 | ||
| 8 | var dbName = 'engine '; | |
| 9 | var engCol lection = 'engines'; | |
| 10 | var testId = require ('../../ut ils/mongo- utils').va lidateMong oDBId; | |
| 11 | ||
| 12 | ||
| 13 | /* | |
| 14 | * Return a named en gine | |
| 15 | */ | |
| 16 | /** | |
| 17 | * @api {g et} /resou rces/cds/e ngine/regi stry Reque st CDS Eng ine by nam e, id, fil ter | |
| 18 | * | |
| 19 | * @apiNam e getEngin e | |
| 20 | * @apiGro up CDS Eng ine | |
| 21 | * | |
| 22 | * @apiPar am {String } [name] E ngine name | |
| 23 | * @apiPar am {String } [id] 24 digit HEX number doc id | |
| 24 | * @apiPar am {String } [filter] A mongo d b match sp ecificatio n, i.e. | |
| 25 | * {"name" :"engineOn e", "type" : "OpenCDS ","environ ment.cpus" :8} | |
| 26 | * | |
| 27 | * @apiSuc cess (Succ ess 200) { json[]} da ta A Engin e array | |
| 28 | * | |
| 29 | * @apiSuc cessExampl e Success- Response: HTTP/1.1 2 00 OK | |
| 30 | * { | |
| 31 | * "da ta": [{ | |
| 32 | * "_id" : | |
| 33 | * "555f4e dee2d9ecea b4e53ec8", | |
| 34 | * "name ": "engine One", | |
| 35 | * "desc ription": "engine on e registry entry", | |
| 36 | * "clas s": "com.c ognitive.c ds.invocat ion.model. EngineInfo ", | |
| 37 | * "type ": "OpenCD S", | |
| 38 | * "vers ion": "2.0 .5", | |
| 39 | * "envi ronment": { | |
| 40 | * "environme nt": "url= http:// IP /opencds-d ecision-su pport-serv ice,memory =32,cpus= 8,java_ver sion=7,web service=to mcat,webse rvice_vers ion=7", | |
| 41 | * }] | |
| 42 | * } | |
| 43 | * @apiErr or (Error 404) data The entry for id, na me, filter not locat ed | |
| 44 | * @apiErr orExample Error-Resp onse: HTTP /1.1 404 N ot Found | |
| 45 | * { "data ": null } | |
| 46 | * | |
| 47 | */ | |
| 48 | function g etEngine(r eq, res) { | |
| 49 | req.lo gger.debug ('cds-engi ne.getEngi ne()'); | |
| 50 | ||
| 51 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 52 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS engin e resource is unavai lable.'); | |
| 53 | } | |
| 54 | ||
| 55 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, null , function (error, db Connection ) { | |
| 56 | if (error) { | |
| 57 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 58 | } | |
| 59 | re q.logger.d ebug('cds- engine.get Engine() C DS Engine Registry g etEngine c alled'); | |
| 60 | ||
| 61 | va r id = nul l; | |
| 62 | va r name = n ull; | |
| 63 | va r filter = null; | |
| 64 | va r status = rdk.https tatus.ok; // 200; | |
| 65 | va r message = ''; | |
| 66 | va r match = {}; | |
| 67 | ||
| 68 | if (req.quer y.name) { | |
| 69 | name = r eq.query.n ame; | |
| 70 | } | |
| 71 | if (req.quer y.id) { | |
| 72 | id = req .query.id; | |
| 73 | message = testId(i d); | |
| 74 | if (mess age) { | |
| 75 | retu rn res.sta tus(rdk.ht tpstatus.b ad_request ).rdkSend( message); | |
| 76 | } | |
| 77 | } | |
| 78 | if (req.quer y.filter) { | |
| 79 | filter = req.query .filter; | |
| 80 | } | |
| 81 | ||
| 82 | if (id) { | |
| 83 | match._i d = new Ob jectId(id) ; | |
| 84 | } else if (n ame && nam e !== '*') { | |
| 85 | match.na me = name; | |
| 86 | } | |
| 87 | if (filter) { // Suppo rts a mong o match ob ject | |
| 88 | message = null; | |
| 89 | try { | |
| 90 | matc h = JSON.p arse(filte r); | |
| 91 | } catch (err) { | |
| 92 | retu rn res.sta tus(rdk.ht tpstatus.b ad_request ).rdkSend( err.messag e); | |
| 93 | } | |
| 94 | } | |
| 95 | db Connection .collectio n(engColle ction).fin d(match).t oArray(fun ction(err, result) { | |
| 96 | var mess age = (err === null) ? result : err; | |
| 97 | if (err === null & & _.isEmpt y(result)) { | |
| 98 | stat us = rdk.h ttpstatus. not_found; | |
| 99 | } | |
| 100 | res.stat us(status) .rdkSend(m essage); | |
| 101 | }) ; | |
| 102 | }); | |
| 103 | } | |
| 104 | ||
| 105 | ||
| 106 | /* | |
| 107 | * Store e ngine | |
| 108 | */ | |
| 109 | /** | |
| 110 | * @api {p ost} /reso urces/cds/ engine/reg istry Crea te CDS Eng ine regist ry entry | |
| 111 | * | |
| 112 | * @apiNam e postEngi ne | |
| 113 | * @apiGro up CDS Eng ine | |
| 114 | * | |
| 115 | * @apiHea der {appli cation/jso n} Content -Type | |
| 116 | * @apiHea der {json} content C DS Engine registry e ntry requi res a name field | |
| 117 | * | |
| 118 | * @apiSuc cess (Succ ess 201) { json} data Engine JS ON documen t | |
| 119 | * @apiSuc cessExampl e Success- Response: HTTP/1.1 2 01 Created | |
| 120 | * { | |
| 121 | * "da ta": [{ | |
| 122 | * "name ": "engine One", | |
| 123 | * "desc ription": "engine on e registry entry", | |
| 124 | * "clas s": "com.c ognitive.c ds.invocat ion.model. EngineInfo ", | |
| 125 | * "type ": "OpenCD S", | |
| 126 | * "vers ion": "2.0 .5", | |
| 127 | * "environme nt": "url= http:// IP /opencds-d ecision-su pport-serv ice,memory =32,cpus= 8,java_ver sion=7,web service=to mcat,webse rvice_vers ion=7", | |
| 128 | * "_id" : "555f4ed ee2d9eceab 4e53ec8" | |
| 129 | * }] | |
| 130 | * } | |
| 131 | * @apiErr or (Error 400) {json } error Mi ssing or i nvalid fie ld(s) | |
| 132 | * @apiErr orExample Error-Resp onse: HTTP /1.1 400 B ad Request | |
| 133 | * { "erro r": "Missi ng | |
| 134 | * required C DS engine registry e ntry name" } | |
| 135 | * @apiErr or (Error 409) {json } error CD S Engine r egistry en try name e xists | |
| 136 | * @apiErr orExample Error-Resp onse: HTTP /1.1 409 C onflict | |
| 137 | * { "erro r": "CDS E ngine | |
| 138 | * registry e ntry exist s, can not be create d" } | |
| 139 | * | |
| 140 | */ | |
| 141 | function p ostEngine( req, res) { | |
| 142 | req.lo gger.debug ('cds-engi ne.postEng ine()'); | |
| 143 | ||
| 144 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 145 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS engin e resource is unavai lable.'); | |
| 146 | } | |
| 147 | ||
| 148 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, null , function (error, db Connection ) { | |
| 149 | if (error) { | |
| 150 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 151 | } | |
| 152 | re q.logger.d ebug('cds- engine.pos tEngine() Engine Reg istry post Engine cal led'); | |
| 153 | ||
| 154 | va r status = rdk.https tatus.crea ted; | |
| 155 | va r message = ''; | |
| 156 | va r engine = req.body; | |
| 157 | ||
| 158 | if (!engine || !engine .name) { / / What oth er propert ies should be valida ted??? | |
| 159 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend('Mis sing requi red CDS en gine name' ); | |
| 160 | } | |
| 161 | de lete engin e._id; | |
| 162 | db Connection .collectio n(engColle ction).fin d({ | |
| 163 | name: en gine.name | |
| 164 | }) .toArray(f unction(er r, result) { | |
| 165 | if (!err && result .length > 0) { | |
| 166 | mess age = 'CDS engine de scriptor e xists, can not be cr eated'; | |
| 167 | retu rn res.sta tus(rdk.ht tpstatus.c onflict).r dkSend(mes sage); | |
| 168 | } | |
| 169 | dbConnec tion.colle ction(engC ollection) .insert(en gine, func tion(err, result) { | |
| 170 | mess age = (err === null) ? result. ops : err; | |
| 171 | if ( err) { | |
| 172 | status = r dk.httpsta tus.bad_re quest; | |
| 173 | } | |
| 174 | retu rn res.sta tus(status ).rdkSend( message); | |
| 175 | }); | |
| 176 | }) ; | |
| 177 | }); | |
| 178 | } | |
| 179 | ||
| 180 | ||
| 181 | /* | |
| 182 | * update engine | |
| 183 | */ | |
| 184 | /** | |
| 185 | * @api {p ut} /resou rces/cds/e ngine/regi stry Modif y CDS Engi ne registr y entry | |
| 186 | * | |
| 187 | * @apiNam e putEngin e | |
| 188 | * @apiGro up CDS Eng ine | |
| 189 | * | |
| 190 | * @apiHea der {appli cation/jso n} Content -Type | |
| 191 | * @apiHea der {json} content E ngine obje ct | |
| 192 | * | |
| 193 | * @apiSuc cess (Succ ess 200) { json} data update co unt | |
| 194 | * @apiSuc cessExampl e Success- Response: HTTP/1.1 2 00 Success | |
| 195 | * { "data ": 1 } | |
| 196 | * | |
| 197 | * @apiErr or (Error 400) {json } error Mi ssing or i nvalid fie ld(s) | |
| 198 | * @apiErr orExample Error-Resp onse: HTTP /1.1 400 B ad Request | |
| 199 | * { "erro r": "Missi ng require d CDS engi ne name" } | |
| 200 | * @apiErr or (Error 404) {json } error no t found | |
| 201 | * @apiErr orExample Error-Resp onse: HTTP /1.1 404 N ot Found | |
| 202 | * { "erro r": "CDS E ngine regi stry entry not found " } | |
| 203 | */ | |
| 204 | function p utEngine(r eq, res) { | |
| 205 | req.lo gger.debug ('cds-engi ne.putEngi ne()'); | |
| 206 | ||
| 207 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 208 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS engin e resource is unavai lable.'); | |
| 209 | } | |
| 210 | ||
| 211 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, null , function (error, db Connection ) { | |
| 212 | if (error) { | |
| 213 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 214 | } | |
| 215 | re q.logger.d ebug('cds- engine.put Engine() E ngine Regi stry putEn gine calle d'); | |
| 216 | ||
| 217 | va r status = rdk.https tatus.ok; | |
| 218 | va r message = ''; | |
| 219 | va r engine = req.body; | |
| 220 | ||
| 221 | if (!engine || !engine .name) { | |
| 222 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend('Mis sing requi red CDS En gine regis tration na me'); | |
| 223 | } | |
| 224 | db Connection .collectio n(engColle ction).fin d({ | |
| 225 | name: en gine.name | |
| 226 | }) .toArray(f unction(er r, result) { | |
| 227 | if (err || _.isEmp ty(result) ) { | |
| 228 | retu rn res.sta tus(rdk.ht tpstatus.n ot_found). rdkSend('C DS Engine registry e ntry not f ound'); | |
| 229 | } | |
| 230 | delete e ngine._id; | |
| 231 | dbConnec tion.colle ction(engC ollection) .update({ | |
| 232 | name : engine.n ame | |
| 233 | }, engin e, functio n(err, res ult) { | |
| 234 | mess age = (err === null) ? result : err; | |
| 235 | if ( err) { | |
| 236 | status = r dk.httpsta tus.bad_re quest; | |
| 237 | } | |
| 238 | retu rn res.sta tus(status ).rdkSend( message); | |
| 239 | }); | |
| 240 | }) ; | |
| 241 | }); | |
| 242 | } | |
| 243 | ||
| 244 | ||
| 245 | /* | |
| 246 | * Delete a engine | |
| 247 | */ | |
| 248 | /** | |
| 249 | * @api {d elete} /re sources/cd s/engine/r egistry De lete CDS E ngine regi stry entry by name o r id | |
| 250 | * | |
| 251 | * @apiNam e deleteEn gine | |
| 252 | * @apiGro up CDS Eng ine | |
| 253 | * | |
| 254 | * @apiPar am {String } [name] C DS engine name | |
| 255 | * @apiPar am {String } [id] 24 digit HEX number doc id | |
| 256 | * | |
| 257 | * @apiSuc cess (Succ ess 200) { Number} da ta Delete count | |
| 258 | * @apiSuc cessExampl e Success- Response: HTTP/1.1 2 00 OK | |
| 259 | * { "data ": 1 } | |
| 260 | * | |
| 261 | * @apiErr or (Error 404) {Numb er} data T he specifi ed engine entry was not | |
| 262 | * found | |
| 263 | * @apiErr orExample Error-Resp onse: HTTP /1.1 404 N ot Found | |
| 264 | * { "data ": 0 } | |
| 265 | * | |
| 266 | */ | |
| 267 | function d eleteEngin e(req, res ) { | |
| 268 | req.lo gger.debug ('cds-engi ne.deleteE ngine()'); | |
| 269 | ||
| 270 | if (_. isUndefine d(req.app. subsystems .cds)) { | |
| 271 | re turn res.s tatus(rdk. httpstatus .service_u navailable ).rdkSend( 'CDS engin e resource is unavai lable.'); | |
| 272 | } | |
| 273 | ||
| 274 | req.ap p.subsyste ms.cds.get CDSDB(req. logger, db Name, null , function (error, db Connection ) { | |
| 275 | if (error) { | |
| 276 | return r es.status( rdk.httpst atus.servi ce_unavail able).rdkS end('CDS p ersistence store is unavailabl e.'); | |
| 277 | } | |
| 278 | re q.logger.d ebug('cds- engine.del eteEngine( ) Engine R egistry de leteEngine called'); | |
| 279 | ||
| 280 | va r status = rdk.https tatus.ok; | |
| 281 | va r id = nul l; | |
| 282 | va r name = n ull; | |
| 283 | va r match = {}; | |
| 284 | va r message = null; | |
| 285 | if (req.quer y.name) { | |
| 286 | name = r eq.query.n ame; | |
| 287 | } | |
| 288 | if (req.quer y.id) { | |
| 289 | id = req .query.id; | |
| 290 | } | |
| 291 | if (id) { | |
| 292 | message = testId(i d); | |
| 293 | if (!mes sage) { | |
| 294 | matc h._id = ne w ObjectId (id); | |
| 295 | } else { | |
| 296 | retu rn res.sta tus(rdk.ht tpstatus.b ad_request ).rdkSend( message); | |
| 297 | } | |
| 298 | } else if (n ame) { | |
| 299 | match.na me = name; | |
| 300 | } else { | |
| 301 | return r es.status( rdk.httpst atus.bad_r equest).rd kSend('Eit her id or name param eter requi red'); | |
| 302 | } | |
| 303 | ||
| 304 | db Connection .collectio n(engColle ction).rem ove(match, function( err, resul t) { | |
| 305 | var mess age = (err === null) ? result : err; | |
| 306 | if (_.is Empty(err) && result .result.n !== 1) { | |
| 307 | stat us = rdk.h ttpstatus. not_found; | |
| 308 | mess age = 'Eng ine regist ry entry n ot found'; | |
| 309 | } | |
| 310 | if (!_.i sEmpty(err )) { | |
| 311 | stat us = rdk.h ttpstatus. bad_reques t; | |
| 312 | } | |
| 313 | res.stat us(status) .rdkSend(m essage); | |
| 314 | }) ; | |
| 315 | }); | |
| 316 | } | |
| 317 | ||
| 318 | ||
| 319 | module.exp orts.getEn gine = get Engine; | |
| 320 | module.exp orts.postE ngine = po stEngine; | |
| 321 | module.exp orts.putEn gine = put Engine; | |
| 322 | module.exp orts.delet eEngine = deleteEngi ne; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.