Skip to content

Commit 334b079

Browse files
committed
added emoji plugin to sample
1 parent acc5a02 commit 334b079

11 files changed

Lines changed: 102 additions & 81 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package sap.capire.repository_template;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
import java.util.stream.Collectors;
6+
7+
import com.sap.cds.Result;
8+
import com.sap.cds.reflect.CdsElement;
9+
import com.sap.cds.reflect.CdsStructuredType;
10+
import com.sap.cds.services.cds.ApplicationService;
11+
import com.sap.cds.services.cds.CdsReadEventContext;
12+
import com.sap.cds.services.cds.CqnService;
13+
import com.sap.cds.services.handler.EventHandler;
14+
import com.sap.cds.services.handler.annotations.After;
15+
import com.sap.cds.services.handler.annotations.ServiceName;
16+
17+
@ServiceName(value = "*", type = ApplicationService.class)
18+
public class EmojiHandler implements EventHandler {
19+
20+
private static final String EMOJI_ANNOTATION_NAME = "@emoji";
21+
22+
@After(event = CqnService.EVENT_READ)
23+
public void decorateEmoji(CdsReadEventContext ctx) {
24+
25+
ctx.getResult().list().forEach(row -> {
26+
Set<String> emojiAnnotatedElments = checkForEmojiAnnotatedElments(ctx.getResult());
27+
row.keySet().forEach(key -> {
28+
if(emojiAnnotatedElments.contains(key)) {
29+
row.put(key, row.get(key) + " 🙃");
30+
}
31+
});
32+
}
33+
);
34+
}
35+
36+
private Set<String> checkForEmojiAnnotatedElments(Result result) {
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()) {
41+
annotatedElementNames.add(element.getName());
42+
}
43+
}
44+
return annotatedElementNames;
45+
}
46+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package sap.capire.repository_template;
2+
3+
import com.sap.cds.services.runtime.CdsRuntimeConfiguration;
4+
import com.sap.cds.services.runtime.CdsRuntimeConfigurer;
5+
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
public class EmojiHandlerRuntimeConfiguration implements CdsRuntimeConfiguration {
10+
11+
private static final Logger logger = LoggerFactory.getLogger(EmojiHandlerRuntimeConfiguration.class);
12+
13+
@Override
14+
public void eventHandlers(CdsRuntimeConfigurer configurer) {
15+
16+
configurer.eventHandler(new EmojiHandler());
17+
logger.info("Registered EmojiHandler event handler.");
18+
}
19+
20+
}

srv/src/main/java/sap/capire/repository_template/PluginConfiguration.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

srv/src/main/java/sap/capire/repository_template/emoji/CloudHandler.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

srv/src/main/java/sap/capire/repository_template/emoji/MockedHandler.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sap.capire.repository_template.EmojiHandlerRuntimeConfiguration

tests/incident-app/pom.xml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
<build>
5454
<plugins>
5555
<!-- JAVA VERSION -->
56-
5756
<plugin>
5857
<artifactId>maven-compiler-plugin</artifactId>
5958
<version>3.14.0</version>
@@ -62,6 +61,27 @@
6261
<encoding>UTF-8</encoding>
6362
</configuration>
6463
</plugin>
64+
65+
<!-- CDS MAVEN PLUGIN -->
66+
<plugin>
67+
<groupId>com.sap.cds</groupId>
68+
<artifactId>cds-maven-plugin</artifactId>
69+
<version>${cds.services.version}</version>
70+
<executions>
71+
<execution>
72+
<id>cds.install-node</id>
73+
<goals>
74+
<goal>install-node</goal>
75+
</goals>
76+
</execution>
77+
<execution>
78+
<id>cds.resolve</id>
79+
<goals>
80+
<goal>resolve</goal>
81+
</goals>
82+
</execution>
83+
</executions>
84+
</plugin>
6585
<!-- MAKE SPRING BOOT PLUGIN RUNNABLE FROM ROOT -->
6686
<plugin>
6787
<groupId>org.springframework.boot</groupId>
@@ -130,4 +150,4 @@
130150
</plugin>
131151
</plugins>
132152
</build>
133-
</project>
153+
</project>

tests/incident-app/srv/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
<artifactId>spring-boot-starter-test</artifactId>
6363
<scope>test</scope>
6464
</dependency>
65+
66+
<dependency>
67+
<groupId>sap.capire</groupId>
68+
<artifactId>repository-template</artifactId>
69+
<version>${revision}</version>
70+
</dependency>
6571
</dependencies>
6672

6773
<build>

tests/incident-app/srv/services.cds

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using { sap.capire.incidents as my } from '../db/schema';
2+
// using from 'sap.capire.repository-template';
23

34
/**
45
* Service used by support personell, i.e. the incidents' 'processors'.
@@ -18,4 +19,8 @@ service AdminService {
1819

1920
annotate ProcessorService.Incidents with @odata.draft.enabled;
2021
annotate ProcessorService with @(requires: 'support');
21-
annotate AdminService with @(requires: 'admin');
22+
annotate AdminService with @(requires: 'admin');
23+
24+
annotate my.Incidents with {
25+
title @emoji
26+
};

tests/incident-app/srv/src/main/java/customer/incident_app/handler/ProcessorServiceHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package customer.incident_management.handler;
1+
package customer.incident_app.handler;
22

33
import cds.gen.processorservice.Incidents;
44
import cds.gen.processorservice.ProcessorService_;
@@ -53,7 +53,6 @@ public void ensureNoUpdateOnClosedIncidents(Incidents incident) {
5353
if (in.getStatusCode().equals("C")) {
5454
throw new ServiceException(ErrorStatuses.CONFLICT, "Can't modify a closed incident");
5555
}
56-
5756
}
5857

5958
}

0 commit comments

Comments
 (0)