Skip to content

Commit 4bbff33

Browse files
author
bengtson.lennart
committed
Added reply for incoming message during storage/revoke
1 parent bb2247b commit 4bbff33

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/main/i5/las2peer/services/privacyControl/PrivacyControlService.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ public class PrivacyControlService extends RESTService {
8585

8686
private final static String DEFAULT_CONFIG_FILE = "etc/consentConfiguration.xml";
8787

88-
private static ConcurrentMap<String, String> userToMoodleToken = new ConcurrentHashMap<>();
89-
9088
private static ReadWriteRegistryClient registryClient;
9189

9290
private static VerificationRegistry verificationRegistry;
@@ -96,10 +94,12 @@ public class PrivacyControlService extends RESTService {
9694
private static String consentRegistryAddress;
9795

9896
private static HashMap<Integer, ConsentLevel> consentLevelMap = new HashMap<Integer, ConsentLevel>();
97+
private static ConcurrentMap<String, List<BigInteger>> consentCache = new ConcurrentHashMap<>();
98+
private static ConcurrentMap<String, String> userToMoodleToken = new ConcurrentHashMap<>();
99+
99100
private static HashSet<String> consentProcessing = new HashSet<String>();
100101
private static HashSet<String> choosingFunction = new HashSet<String>();
101-
102-
private static ConcurrentMap<String, List<BigInteger>> consentCache = new ConcurrentHashMap<>();
102+
private static HashSet<String> processingAction = new HashSet<String>();
103103

104104
private static boolean initialized = false;
105105

@@ -187,7 +187,14 @@ public Response showConsentMenu(String body) throws ParseException {
187187
return Response.ok().entity(err).build();
188188
}
189189

190-
if (consentProcessing.contains(channel)) {
190+
if (processingAction.contains(channel)) {
191+
logger.info("Got message while processing...");
192+
JSONObject res = new JSONObject();
193+
res.put("text", "Bitte warte, bis die Aktion ausgefuehrt wurde.");
194+
res.put("closeContext", "false");
195+
return Response.ok().entity(res).build();
196+
197+
} else if (consentProcessing.contains(channel)) {
191198
// Proceed with storage
192199
logger.info("Continuing consent storage for user " + email);
193200

@@ -202,12 +209,15 @@ public Response showConsentMenu(String body) throws ParseException {
202209
}
203210
levels.add(new BigInteger(s));
204211
}
205-
storeUserConsentLevels(email, levels);
206212
consentProcessing.remove(channel);
207-
213+
214+
processingAction.add(channel);
215+
storeUserConsentLevels(email, levels);
216+
processingAction.remove(channel);
217+
208218
// Build response and close context.
209219
JSONObject res = new JSONObject();
210-
res.put("text", "Deine Einwilligung wurde erfolgreich gespeichert. \n" + "Melde dich, falls ich noch etwas fuer dich tun kann.");
220+
res.put("text", "Deine Einwilligung wurde erfolgreich gespeichert.");
211221
res.put("closeContext", "true");
212222
return Response.ok().entity(res).build();
213223

@@ -221,9 +231,8 @@ public Response showConsentMenu(String body) throws ParseException {
221231
e.printStackTrace();
222232
}
223233
consentProcessing.remove(channel);
224-
}
225-
226-
if (choosingFunction.contains(channel)) {
234+
235+
} else if (choosingFunction.contains(channel)) {
227236
// If options have been displayed, parse number and evaluate which function to execute.
228237
String chosenOption = bodyObj.getAsString("msg").split("\\.")[0];
229238
try {
@@ -288,10 +297,12 @@ public Response showConsentMenu(String body) throws ParseException {
288297
case 3: // revokeConsent(body);
289298
logger.info("Revoking consent for user " + email);
290299
try {
300+
processingAction.add(channel);
291301
revokeUserConsent(email);
292-
302+
processingAction.remove(channel);
303+
293304
res = new JSONObject();
294-
res.put("text", "Deine Einstellungen wurden angepasst. \n" + "Melde dich, falls ich noch etwas fuer dich tun kann.");
305+
res.put("text", "Deine Einstellungen wurden angepasst.");
295306
res.put("closeContext", "true");
296307
return Response.ok().entity(res).build();
297308
} catch (EthereumException e) {
@@ -309,6 +320,7 @@ public Response showConsentMenu(String body) throws ParseException {
309320
err.put("closeContext", "false");
310321
return Response.ok().entity(err).build();
311322
}
323+
312324
} else {
313325
choosingFunction.add(channel);
314326
StringBuilder menuBuilder = new StringBuilder();
@@ -396,7 +408,6 @@ public Response showLrsData(String body) {
396408

397409
resBuilder.append("\n");
398410
resBuilder.append("Wenn du in Zukunft direkt zu dieser Ansicht springen moechtest, dann schreibe mich an mit: 'Daten' \n");
399-
resBuilder.append("Melde dich, falls ich noch etwas fuer dich tun kann.");
400411

401412
JSONObject res = new JSONObject();
402413
res.put("text", resBuilder.toString());

0 commit comments

Comments
 (0)