|
3 | 3 | import com.google.common.base.Joiner; |
4 | 4 | import com.google.common.base.Splitter; |
5 | 5 | import com.google.common.collect.Lists; |
| 6 | +import lombok.extern.java.Log; |
6 | 7 | import ml.anon.model.anonymization.Label; |
7 | 8 | import org.apache.commons.lang3.RandomStringUtils; |
8 | 9 | import org.apache.commons.lang3.RandomUtils; |
|
12 | 13 | import org.springframework.web.bind.annotation.PathVariable; |
13 | 14 | import org.springframework.web.bind.annotation.RequestParam; |
14 | 15 | import org.springframework.web.bind.annotation.RestController; |
| 16 | +import org.springframework.web.util.UriUtils; |
15 | 17 |
|
| 18 | +import java.io.UnsupportedEncodingException; |
16 | 19 | import java.util.ArrayList; |
17 | 20 | import java.util.HashMap; |
18 | 21 | import java.util.List; |
|
22 | 25 | * Created by mirco on 12.07.17. |
23 | 26 | */ |
24 | 27 | @RestController |
25 | | - |
| 28 | +@Log |
26 | 29 | public class ReplacementController { |
27 | 30 |
|
28 | 31 |
|
29 | 32 | private Map<String, String> replacements = new HashMap<>(); |
30 | 33 |
|
| 34 | + |
31 | 35 | @GetMapping(path = "/replacement", params = {"original", "label"}) |
32 | | - public ResponseEntity<String> getReplacement(@RequestParam String original, @RequestParam String label) { |
33 | | - String lookupKey = original+"_"+label; |
| 36 | + public ResponseEntity<String> getReplacement(@RequestParam String original, @RequestParam String label) throws UnsupportedEncodingException { |
| 37 | + String str = UriUtils.decode(original, "UTF-8"); |
| 38 | + String lookupKey = str + "_" + label; |
| 39 | + |
34 | 40 | String existing = replacements.get(lookupKey); |
35 | 41 | String replacement = existing; |
36 | | - while(replacement == null) { |
37 | | - String generate = generate(original, Label.valueOf(label)); |
38 | | - if(!replacements.values().contains(generate)) { |
| 42 | + |
| 43 | + while (replacement == null) { |
| 44 | + String generate = generate(str, Label.valueOf(label)); |
| 45 | + if (!replacements.values().contains(generate)) { |
39 | 46 | replacement = generate; |
40 | 47 | } |
41 | 48 | } |
@@ -72,8 +79,9 @@ private String doGenerate(String original, int count, boolean split) { |
72 | 79 | } |
73 | 80 |
|
74 | 81 |
|
75 | | - @Scheduled(fixedRate = 60000, initialDelay = 10000) |
| 82 | + @Scheduled(fixedRate = 120000, initialDelay = 10000) |
76 | 83 | private void clearMap() { |
| 84 | + log.info("clearing replacements"); |
77 | 85 | replacements.clear(); |
78 | 86 | } |
79 | 87 |
|
|
0 commit comments