@@ -183,14 +183,14 @@ public Response init() {
183
183
// ------------------------------ Bot communication ----------------------------
184
184
185
185
@ POST
186
- @ Path ("/showGreeting " )
186
+ @ Path ("/showConsentMenu " )
187
187
@ Consumes (MediaType .TEXT_PLAIN )
188
188
@ Produces (MediaType .APPLICATION_JSON )
189
189
@ ApiResponses (
190
190
value = { @ ApiResponse (
191
191
code = HttpURLConnection .HTTP_OK ,
192
192
message = "Returned menu." ) })
193
- public Response showGreeting (String body ) throws ParseException {
193
+ public Response showConsentMenu (String body ) throws ParseException {
194
194
JSONParser parser = new JSONParser (JSONParser .MODE_PERMISSIVE );
195
195
String channel = "" ;
196
196
@@ -259,16 +259,7 @@ public Response showGreeting(String body) throws ParseException {
259
259
res .put ("closeContext" , "true" );
260
260
return Response .ok ().entity (res ).build ();
261
261
262
- case 1 : // consentLevels();
263
- logger .info ("Showing consent options..." );
264
- String consentLevelString = getConsentLevelsFormatted ();
265
-
266
- res = new JSONObject ();
267
- res .put ("text" , "" + consentLevelString );
268
- res .put ("closeContext" , "true" );
269
- return Response .ok ().entity (res ).build ();
270
-
271
- case 2 : // storeConsent(body);
262
+ case 1 : // storeConsent(body);
272
263
logger .info ("Starting consent storage for user " + agent .getLoginName ());
273
264
consentProcessing .add (channel );
274
265
String consentLevels = getConsentLevelsFormatted ();
@@ -286,7 +277,7 @@ public Response showGreeting(String body) throws ParseException {
286
277
res .put ("closeContext" , "false" );
287
278
return Response .ok ().entity (res ).build ();
288
279
289
- case 3 : // showConsent(body);
280
+ case 2 : // showConsent(body);
290
281
List <BigInteger > givenConsent ;
291
282
try {
292
283
givenConsent = getConsentLevelsForLoginName (agent .getLoginName ());
@@ -312,7 +303,7 @@ public Response showGreeting(String body) throws ParseException {
312
303
}
313
304
break ;
314
305
315
- case 4 : // revokeConsent(body);
306
+ case 3 : // revokeConsent(body);
316
307
logger .info ("Revoking consent for user " + agent .getLoginName ());
317
308
try {
318
309
revokeUserConsent (agent .getLoginName ());
@@ -326,15 +317,6 @@ public Response showGreeting(String body) throws ParseException {
326
317
}
327
318
break ;
328
319
329
- case 5 : // verifyData(body)
330
- logger .info ("LRS Data requested for user " + agent .getLoginName ());
331
- String resText = getStatementsForUserEmail (email );
332
-
333
- res = new JSONObject ();
334
- res .put ("text" , resText + "\n Melde Dich, falls ich noch etwas fuer Dich tun kann." );
335
- res .put ("closeContext" , "true" );
336
- return Response .ok ().entity (res ).build ();
337
-
338
320
default :
339
321
break ;
340
322
}
@@ -349,11 +331,9 @@ public Response showGreeting(String body) throws ParseException {
349
331
choosingFunction .add (channel );
350
332
String greeting =
351
333
"Hallo, ich kann folgendes fuer dich tun: \n "
352
- + "[1] Informationen zu moeglichen Datenverarbeitungseinwilligungen anzeigen. \n "
353
- + "[2] Einwilligung zur Datenverarbeitung abgeben. \n "
354
- + "[3] Einwilligung zur Datenverarbeitung anzeigen. \n "
355
- + "[4] Einwilligung zur Datenverarbeitung widerrufen. \n "
356
- + "[5] Gespeicherte Daten aus Learning Record Store anzeigen. \n "
334
+ + "[1] Einwilligung zur Datenverarbeitung abgeben. \n "
335
+ + "[2] Einwilligung zur Datenverarbeitung anzeigen. \n "
336
+ + "[3] Einwilligung zur Datenverarbeitung widerrufen. \n "
357
337
+ "[0] Abbrechen. \n "
358
338
+ "Um eine Funktion zu nutzen, gib die entsprechende Nummer ein." ;
359
339
@@ -373,275 +353,70 @@ public Response showGreeting(String body) throws ParseException {
373
353
res .put ("closeContext" , "true" );
374
354
return Response .ok ().entity (res ).build ();
375
355
}
376
-
377
- @ GET
378
- @ Path ("/consentLevels" )
379
- @ Produces (MediaType .APPLICATION_JSON )
380
- @ ApiResponses (
381
- value = { @ ApiResponse (
382
- code = HttpURLConnection .HTTP_OK ,
383
- message = "Returned consent levels." ) })
384
- public Response consentLevels () throws ParseException {
385
- String consentLevelString = getConsentLevelsFormatted ();
386
- JSONObject responseBody = new JSONObject ();
387
- responseBody .put ("text" , "" + consentLevelString );
388
- responseBody .put ("closeContext" , "true" );
389
- return Response .ok ().entity (responseBody ).build ();
390
- }
391
-
356
+
392
357
@ POST
393
- @ Path ("/storeConsent" )
394
- @ Consumes (MediaType .TEXT_PLAIN )
395
- @ Produces (MediaType .APPLICATION_JSON )
396
- @ ApiResponses (
397
- value = { @ ApiResponse (
398
- code = HttpURLConnection .HTTP_OK ,
399
- message = "Consent level set." ) })
400
- public Response storeConsent (String body ) {
401
- JSONParser parser = new JSONParser (JSONParser .MODE_PERMISSIVE );
402
- String channel = "" ;
403
-
404
- try {
405
- JSONObject bodyObj = (JSONObject ) parser .parse (body );
406
- channel = bodyObj .getAsString ("channel" );
407
-
408
- // Get corresponding agent
409
- UserAgentImpl agent = getAgentFromUserEmail (bodyObj .getAsString ("email" ));
410
- if (agent == null ) {
411
- JSONObject err = new JSONObject ();
412
- err .put ("text" , "Zu deiner Email ist kein las2peer User registriert. Bitte registriere Dich um diesen Service zu nutzen." );
413
- err .put ("closeContext" , "true" );
414
- return Response .ok ().entity (err ).build ();
415
- }
416
-
417
- // Check if consent storage was already started.
418
- if (consentProcessing .contains (channel )) {
419
- logger .info ("Continue consent storage for user " + agent .getLoginName ());
420
-
421
- // Get consent level from message
422
- String chosenConsentLevels = bodyObj .getAsString ("msg" ).split ("\\ ." )[0 ];
423
-
424
- try {
425
- List <BigInteger > levels = new ArrayList <BigInteger >();
426
- for (String s : chosenConsentLevels .split ("\\ ," )) {
427
- // TODO Validate if consent object with that level exists!
428
- levels .add (new BigInteger (s ));
429
- }
430
- storeUserConsentLevels (agent .getLoginName (), levels );
431
-
432
- } catch (NumberFormatException e ) {
433
- // Build error but don't close context when ID is not valid.
434
- JSONObject err = new JSONObject ();
435
- err .put ("text" , "Bitte gib eine oder mehrere gueltige Ids ein." );
436
- err .put ("closeContext" , "false" );
437
- return Response .ok ().entity (err ).build ();
438
- }
439
-
440
- consentProcessing .remove (channel );
441
-
442
- // Build response and close context.
443
- JSONObject res = new JSONObject ();
444
- res .put ("text" , "Einwilligung erfolgreich gespeichert." );
445
- res .put ("closeContext" , "true" );
446
- return Response .ok ().entity (res ).build ();
447
- } else {
448
- logger .info ("Starting consent storage for user " + agent .getLoginName ());
449
- consentProcessing .add (channel );
450
- String consentLevelString = getConsentLevelsFormatted ();
451
-
452
- // Build response and close context.
453
- JSONObject res = new JSONObject ();
454
- res .put ("text" , "Bitte gib die Ids (z.B. 1,2) der Datenverarbeitungsoptionen an, mit denen Du einverstanden bist. \n " + consentLevelString );
455
- res .put ("closeContext" , "false" );
456
- return Response .ok ().entity (res ).build ();
457
- }
458
- } catch (ParseException e ) {
459
- // TODO Auto-generated catch block
460
- e .printStackTrace ();
461
- } catch (EthereumException e ) {
462
- // TODO Auto-generated catch block
463
- e .printStackTrace ();
464
- }
465
-
466
- if (!channel .isEmpty ()) {
467
- consentProcessing .remove (channel );
468
- }
469
-
470
- JSONObject err = new JSONObject ();
471
- err .put ("text" , "Etwas ist bei der Anfrage schiefgegangen." );
472
- err .put ("closeContext" , "true" );
473
- return Response .ok ().entity (err ).build ();
474
- }
475
-
476
-
477
- @ POST
478
- @ Path ("/showConsent" )
479
- @ Consumes (MediaType .TEXT_PLAIN )
358
+ @ Path ("/showGreeting" )
480
359
@ Produces (MediaType .APPLICATION_JSON )
481
360
@ ApiResponses (
482
361
value = { @ ApiResponse (
483
362
code = HttpURLConnection .HTTP_OK ,
484
- message = "Consent retrieved and displayed." ) })
485
- public Response showConsent (String body ) {
363
+ message = "Delivered greeting." ) })
364
+ public Response showGreeting (String body ) {
365
+ logger .info ("Greeting user..." );
486
366
JSONParser parser = new JSONParser (JSONParser .MODE_PERMISSIVE );
487
-
367
+ StringBuilder resBuilder = new StringBuilder ();
368
+
488
369
try {
489
370
JSONObject bodyObj = (JSONObject ) parser .parse (body );
490
-
491
- // Get corresponding agent
492
- UserAgentImpl agent = getAgentFromUserEmail (bodyObj . getAsString ( " email" ) );
371
+ String email = bodyObj . getAsString ( "email" );
372
+
373
+ UserAgentImpl agent = getAgentFromUserEmail (email );
493
374
if (agent == null ) {
494
375
JSONObject err = new JSONObject ();
495
- err .put ("text" , "Zu deiner Email ist kein las2peer User registriert. Bitte registriere Dich um diesen Service zu nutzen." );
376
+ err .put ("text" , "Zu Deiner Email ist kein las2peer User registriert. Bitte registriere Dich um diesen Service zu nutzen." );
496
377
err .put ("closeContext" , "true" );
497
378
return Response .ok ().entity (err ).build ();
498
379
}
499
-
500
- // Retrieve stored consent levels
501
- List <BigInteger > givenConsent = getConsentLevelsForLoginName (agent .getLoginName ());
502
-
503
- String resText = "" ;
504
- if (givenConsent == null || givenConsent .isEmpty ()) {
505
- resText += "Aktuell liegt uns keine Einwilligung zu Deinem User vor." ;
506
- } else {
507
- resText += "Es liegt eine Einwilligung zu folgenden Services/Zugriffsarten vor: \n " ;
508
- for (BigInteger consent : givenConsent ) {
509
- resText += consentLevelMap .get (consent .intValue ()).toString ();
510
- resText += "\n " ;
511
- }
512
- }
513
-
514
- JSONObject res = new JSONObject ();
515
- res .put ("text" , resText );
516
- res .put ("closeContext" , "true" );
517
- return Response .ok ().entity (res ).build ();
518
- } catch (ParseException e ) {
519
- // TODO Auto-generated catch block
520
- e .printStackTrace ();
521
- } catch (EthereumException e ) {
522
- // TODO Auto-generated catch block
523
- e .printStackTrace ();
524
- }
525
-
526
- JSONObject err = new JSONObject ();
527
- err .put ("text" , "Etwas ist bei der Anfrage schiefgegangen." );
528
- err .put ("closeContext" , "true" );
529
- return Response .ok ().entity (err ).build ();
530
- }
531
-
532
- @ POST
533
- @ Path ("/revokeConsent" )
534
- @ Consumes (MediaType .TEXT_PLAIN )
535
- @ Produces (MediaType .APPLICATION_JSON )
536
- @ ApiResponses (
537
- value = { @ ApiResponse (
538
- code = HttpURLConnection .HTTP_OK ,
539
- message = "Revoked consent." ) })
540
- public Response revokeConsent (String body ) {
541
- JSONParser parser = new JSONParser (JSONParser .MODE_PERMISSIVE );
542
-
543
- try {
544
- JSONObject bodyObj = (JSONObject ) parser .parse (body );
545
-
546
- // Get corresponding agent
547
- UserAgentImpl agent = getAgentFromUserEmail (bodyObj .getAsString ("email" ));
548
- if (agent == null ) {
549
- JSONObject errorMsg = new JSONObject ();
550
- errorMsg .put ("text" , "Zu deiner Email ist kein las2peer User registriert. Bitte registriere Dich um diesen Service zu nutzen." );
551
- errorMsg .put ("closeContext" , "true" );
552
- return Response .ok ().entity (errorMsg ).build ();
553
- }
554
-
555
- revokeUserConsent (agent .getLoginName ());
556
-
557
- JSONObject responseBody = new JSONObject ();
558
- responseBody .put ("text" , "Deine Einstellungen wurden angepasst." );
559
- responseBody .put ("closeContext" , "true" );
560
- return Response .ok ().entity (responseBody ).build ();
561
- } catch (ParseException e ) {
562
- // TODO Auto-generated catch block
563
- e .printStackTrace ();
564
- } catch (EthereumException e ) {
565
- // TODO Auto-generated catch block
566
- e .printStackTrace ();
567
- }
568
-
569
- JSONObject errorMsg = new JSONObject ();
570
- errorMsg .put ("text" , "Etwas ist bei der Anfrage schiefgegangen." );
571
- errorMsg .put ("closeContext" , "true" );
572
- return Response .ok ().entity (errorMsg ).build ();
573
- }
574
-
575
- @ POST
576
- @ Path ("/showLogEntries" )
577
- @ Consumes (MediaType .TEXT_PLAIN )
578
- @ Produces (MediaType .APPLICATION_JSON )
579
- @ ApiResponses (
580
- value = { @ ApiResponse (
581
- code = HttpURLConnection .HTTP_OK ,
582
- message = "Showed log entries." ) })
583
- public Response showLogEntries (String body ) {
584
- JSONParser parser = new JSONParser (JSONParser .MODE_PERMISSIVE );
585
-
586
- try {
587
- JSONObject bodyObj = (JSONObject ) parser .parse (body );
588
-
589
- // Get corresponding agent
590
- UserAgentImpl agent = getAgentFromUserEmail (bodyObj .getAsString ("email" ));
591
- if (agent == null ) {
592
- JSONObject errorMsg = new JSONObject ();
593
- errorMsg .put ("text" , "Zu deiner Email ist kein las2peer User registriert. Bitte registriere Dich um diesen Service zu nutzen." );
594
- errorMsg .put ("closeContext" , "true" );
595
- return Response .ok ().entity (errorMsg ).build ();
596
- }
597
-
598
- logger .info ("Requesting logs for user " + agent .getLoginName ());
599
-
600
- String res = "" ;
601
- res += getLogEntries (agent .getLoginName ()).toString ();
602
-
603
- logger .info ("Showing logs: " + res );
604
-
605
- JSONObject responseBody = new JSONObject ();
606
- responseBody .put ("text" , res );
607
- responseBody .put ("closeContext" , "true" );
608
- return Response .ok ().entity (responseBody ).build ();
380
+
381
+ resBuilder .append ("Hi, \n " );
382
+ resBuilder .append ("ich helfe Dir dabei, mehr Transparenz und Kontrolle in Bezug auf Deine persoenlichen Daten aus der Lernumgebung zu erhalten. \n " );
383
+ resBuilder .append ("Moechtest Du dazu weitere Informationen erhalten?" );
609
384
} catch (ParseException e ) {
610
- // TODO Auto-generated catch block
611
- e .printStackTrace ();
612
- } catch (EthereumException e ) {
613
- // TODO Auto-generated catch block
614
385
e .printStackTrace ();
386
+ resBuilder .append ("Leider ist bei Deiner Anfrage etwas schief gegangen." );
615
387
}
616
388
617
- JSONObject errorMsg = new JSONObject ();
618
- errorMsg .put ("text" , "Your request failed." );
619
- errorMsg .put ("closeContext" , "true" );
620
- return Response .ok ().entity (errorMsg ).build ();
389
+ JSONObject res = new JSONObject ();
390
+ res .put ("text" , resBuilder . toString () );
391
+ res .put ("closeContext" , "true" );
392
+ return Response .ok ().entity (res ).build ();
621
393
}
622
394
623
395
@ POST
624
- @ Path ("/verifyData " )
396
+ @ Path ("/showLrsData " )
625
397
@ Produces (MediaType .APPLICATION_JSON )
626
398
@ ApiResponses (
627
399
value = { @ ApiResponse (
628
400
code = HttpURLConnection .HTTP_OK ,
629
- message = "Verifed xApi statements ." ) })
630
- public Response verifyData (String body ) {
401
+ message = "Retrieved relevant learning analytics data ." ) })
402
+ public Response showLrsData (String body ) {
631
403
logger .info ("Data requested..." );
632
404
JSONParser parser = new JSONParser (JSONParser .MODE_PERMISSIVE );
633
- String resText = "" ;
405
+ StringBuilder resBuilder = new StringBuilder () ;
634
406
635
407
try {
636
408
JSONObject bodyObj = (JSONObject ) parser .parse (body );
637
- resText += getStatementsForUserEmail (bodyObj .getAsString ("email" ));
409
+ resBuilder . append ( getStatementsForUserEmail (bodyObj .getAsString ("email" ) ));
638
410
} catch (ParseException e ) {
639
- // TODO Auto-generated catch block
640
411
e .printStackTrace ();
412
+ resBuilder .append ("Leider ist bei Deiner Anfrage etwas schief gegangen." );
641
413
}
414
+
415
+ resBuilder .append ("\n " );
416
+ resBuilder .append ("Melde Dich, falls ich noch etwas fuer Dich tun kann." );
642
417
643
418
JSONObject res = new JSONObject ();
644
- res .put ("text" , resText );
419
+ res .put ("text" , resBuilder . toString () );
645
420
res .put ("closeContext" , "true" );
646
421
return Response .ok ().entity (res ).build ();
647
422
}
0 commit comments