-
Notifications
You must be signed in to change notification settings - Fork 0
/
Serverbu.js
346 lines (263 loc) · 9.09 KB
/
Serverbu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
var express = require("express");
var app = express();
var cfenv = require("cfenv");
var bodyParser = require('body-parser')
var serverAd = 'http://18.221.90.80:3000';
//
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
///
// parse application/json
app.use(bodyParser.json())
function createGuid()
{
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
/**
* Endpoint to get a JSON array of all the visitors in the database
* REST API example:
* <code>
* GET http://184.172.242.210:31090/api/visitors
* </code>
*
* Response:
* [ "Bob", "Jane" ]
* @return An array of all the visitor names
*/
app.get("/api/lmatid", function (request, response) {
var theGuid = createGuid();
var names = {lmatid:theGuid};
if(true) {
response.json(names);
return;
}
});
/**
* Endpoint to get a JSON array of all the visitors in the database
* REST API example:
* <code>
* GET http://184.172.242.210:31090/api/visitors
* </code>
*
* Response:
* [ "Bob", "Jane" ]
* @return An array of all the visitor names
*/
app.get("/api/registerIdentity", function (request, response) {
var theGuid = createGuid();
var r = response
var theType = request.query['type'];
var theValue = request.query['value'];
console.log ("value = " + theValue);
if (theValue == ""){
theValue = createGuid();
}//request.query['value'];
var theMetaData = request.query['metaData'];//request.query['metaData'];
var theBody = '{"$class": "com.integraledger.identityregistry.RegisterIdentity","identityId":"' + theGuid + '","identityType":"' + theType+ '","metaData":"'+theMetaData+'","value":"' + theValue+ '"}';
console.log (theBody);
var cb = function callback(error, response, body) {
//if (!error && response.statusCode == 200) {
//var info = JSON.parse(body);
// console.log(info.stargazers_count + " Stars");
// console.log(info.forks_count + " Forks");
var names = {'identityId':theGuid}; //, 'identityType':theType,'value':theValue, 'metaData': theMetaData
r.json(names);
// r.send({'LMATID', theGuid});
return;
// }
}
if(true) {
// console.log ('x ' + theMetaData);
var request = require('request');
var options = {
url: serverAd + '/api/RegisterIdentity',
headers: {
'Content-Type': 'application/json', 'Accept': 'application/json'
},
body:theBody//,"metaData":"md1", "value":"v1"
};
request
.post(options,cb)
.on('response', function(response) {
})
}
});
app.get("/api/registerKey", function (request, response) {
// o String keyValue
// --> User owner
var r = response;
var theOwner = request.query['owner'];
var theValue = request.query['value'];
var theBody = '{"$class": "com.integraledger.identityregistry.RegisterKey","owner":"'+theOwner+'","keyValue":"' + theValue+ '"}';
var cb = function callback(error, response, body) {
var theResponse = {'theKey':theValue}; //, 'identityType':theType,'value':theValue, 'metaData': theMetaData
r.json(theResponse);
return;
}
if(true) {
// console.log ('x ' + theMetaData);
var request = require('request');
var options = {
url: serverAd + '/api/RegisterKey',
headers: {
'Content-Type': 'application/json', 'Accept': 'application/json'
},
body:theBody//,"metaData":"md1", "value":"v1"
};
request
.post(options,cb)
.on('response', function(response) {
})
}
});
app.get("/api/postToClio", function (request, response) {
var r = response
var theLMAT = request.query['LMAT'];
var cb = function callback(error, response, body) {
var theJSON = JSON.parse(body)
var theData= theJSON['data']['id'];
console.log (`${body} |||||| ${theData}`);
var names = {'ClioID':theData};
r.json(names);
return;
}
if(true) {
var request = require('request');
var options = {
url: `https://app.goclio.com/api/v4/matters?data[client][id]=941888686&data[description]=${encodeURIComponent('Created from Integra API Call')}&data[client_reference]=${theLMAT}`,
headers: {
'Content-Type': 'application/json', 'Authorization': 'Bearer UskTXxAGVeQwulmfirrCYVMcdztfy1zEaXY7TA26'
}
};
request
.post(options,cb)
.on('response', function(response) {
})
}
});
app.get("/api/identityExists", function (request, response) {
var r = response
var theId = request.query['id'];
var cb = function callback(error, response, body) {
//if (!error && response.statusCode == 200) {
//var info = JSON.parse(body);
// console.log(info.stargazers_count + " Stars");
// console.log(info.forks_count + " Forks");
// console.log(response);
// console.log(body);
// var names = {'exists':'x' + body};
var res= JSON.parse(body);
var exists = res.length==0?false:true
var names = {'exists':exists};
r.json(names);
// r.send({'LMATID', theGuid});
return;
// }
}
//url: 'http://18.221.90.80:3000/api/queries/idExists?identityId=' + theId
var component = encodeURIComponent(`{"where":{"identityId": "${theId}"}}`);
console.log ('xxxxxhttp://18.221.90.80:3000/api/IntegraIdentity?filter=' + component)
if(true) {
var request = require('request');
var options = {
url: serverAd + '/api/IntegraIdentity?filter=' + component,
headers: {
'Content-Type': 'application/json', 'Accept': 'application/json'
}
};
request
.get(options,cb)
.on('response', function(response) {
})
}
});
app.get("/api/valueExists", function (request, response) {
var r = response
var theId = request.query['value'];
var cb = function callback(error, response, body) {
//if (!error && response.statusCode == 200) {
//var info = JSON.parse(body);
// console.log(info.stargazers_count + " Stars");
// console.log(info.forks_count + " Forks");
// console.log(response);
// console.log(body);
// var names = {'exists':'x' + body};
// console.log (body);
var res= JSON.parse(body);
var exists = res.length==0?false:true
var names = {'exists':exists};
r.json(names);
// r.send({'LMATID', theGuid});
return;
// }
}
var component = encodeURIComponent(`{"where":{"value": "${theId}"}}`);
//http://18.221.90.80:3000/api/queries/valueExists?value=
if(true) {
var request = require('request');
var options = {
url:serverAd + '/api/HashVal?filter=' + component,
headers: {
'Content-Type': 'application/json', 'Accept': 'application/json'
}
};
request
.get(options,cb)
.on('response', function(response) {
})
}
});
app.get("/api/keyForOwner", function (request, response) {
var r = response
var theOwner = request.query['owner'];
var cb = function callback(error, response, body) {
var res= JSON.parse(body);
console.log(res);
//var exists = res.length==0?false:true;
if (res.length > 0){
var rec = res[0];
console.log(rec);
var theKey = rec['keyValue'];
var names = {'key':theKey};
r.json(names);
}
else{
r.json({'key':'No Key'}) ;
}
// r.send({'LMATID', theGuid});
return;
// }
}
//http://18.221.90.80:3000/api/queries/keyForOwner?owner=' + 'resource%3Acom.integraledger.identityregistry.User%23' + theOwner
var component = `{"where":{"owner": "${theOwner}"}}`;
if(true) {
var request = require('request');
var options = {
url: serverAd + '/api/Key?filter=' + component,
headers: {
'Content-Type': 'application/json', 'Accept': 'application/json'
}
};
request
.get(options,cb)
.on('response', function(response) {
})
}
});
// load local VCAP configuration and service credentials
var vcapLocal;
try {
vcapLocal = require('./vcap-local.json');
console.log("Loaded local VCAP", vcapLocal);
} catch (e) { }
const appEnvOpts = vcapLocal ? { vcap: vcapLocal} : {}
const appEnv = cfenv.getAppEnv(appEnvOpts);
//serve static file (index.html, images, css)
app.use(express.static(__dirname + '/views'));
var port = process.env.PORT || 3004;
app.listen(port, function() {
console.log("To view your app, open this link in your browser: http://18.221.90.80:" + port);
});