|
1 | 1 | package sap.capire.emoji_template; |
2 | 2 |
|
3 | | -import java.util.HashSet; |
4 | | -import java.util.Set; |
5 | | -import java.util.stream.Collectors; |
6 | | - |
7 | 3 | import com.sap.cds.Result; |
8 | 4 | import com.sap.cds.reflect.CdsElement; |
9 | 5 | import com.sap.cds.reflect.CdsStructuredType; |
|
13 | 9 | import com.sap.cds.services.handler.EventHandler; |
14 | 10 | import com.sap.cds.services.handler.annotations.After; |
15 | 11 | import com.sap.cds.services.handler.annotations.ServiceName; |
| 12 | +import java.util.HashSet; |
| 13 | +import java.util.Set; |
| 14 | +import java.util.stream.Collectors; |
16 | 15 |
|
| 16 | +/** |
| 17 | + * Event handler that decorates fields annotated with @emoji by appending an emoji. |
| 18 | + */ |
17 | 19 | @ServiceName(value = "*", type = ApplicationService.class) |
18 | 20 | public class EmojiHandler implements EventHandler { |
19 | | - |
20 | 21 | private static final String EMOJI_ANNOTATION_NAME = "@emoji"; |
21 | 22 |
|
22 | 23 | @After(event = CqnService.EVENT_READ) |
23 | | - public void decorateEmoji(CdsReadEventContext ctx) { |
| 24 | + public void decorateEmoji(final CdsReadEventContext ctx) { |
24 | 25 |
|
25 | 26 | ctx.getResult().list().forEach(row -> { |
26 | 27 | Set<String> emojiAnnotatedElments = checkForEmojiAnnotatedElments(ctx.getResult()); |
27 | 28 | row.keySet().forEach(key -> { |
28 | | - if(emojiAnnotatedElments.contains(key)) { |
| 29 | + if (emojiAnnotatedElments.contains(key)) { |
29 | 30 | row.put(key, row.get(key) + " 🙃"); |
30 | 31 | } |
31 | 32 | }); |
32 | | - } |
33 | | - ); |
| 33 | + }); |
34 | 34 | } |
35 | 35 |
|
36 | | - private Set<String> checkForEmojiAnnotatedElments(Result result) { |
| 36 | + private Set<String> checkForEmojiAnnotatedElments(final Result result) { |
37 | 37 | Set<String> annotatedElementNames = new HashSet<>(); |
38 | | - CdsStructuredType rowType = result.rowType();//.annotations().anyMatch(anno -> anno.getName().equals("@emoji"))) |
39 | | - for(CdsElement element : rowType.elements().collect(Collectors.toList())) { |
40 | | - if(element.findAnnotation(EMOJI_ANNOTATION_NAME).isPresent()) { |
| 38 | + CdsStructuredType rowType = result.rowType();// .annotations().anyMatch(anno -> |
| 39 | + // anno.getName().equals("@emoji"))) |
| 40 | + for (CdsElement element : rowType.elements().collect(Collectors.toList())) { |
| 41 | + if (element.findAnnotation(EMOJI_ANNOTATION_NAME).isPresent()) { |
41 | 42 | annotatedElementNames.add(element.getName()); |
42 | 43 | } |
43 | 44 | } |
|
0 commit comments