You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+33-26Lines changed: 33 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Create a crititcality plugin for CAP Java
1
+
# Create a Crititcality Plugin for CAP Java Applications
2
2
3
3
## Prerequisites
4
4
@@ -12,13 +12,17 @@ You need to have the following tools installed:
12
12
13
13
## Requirement
14
14
15
-
Write a CAP Java plugin that provides a handler that can detect CDS enum values annotated with `@criticality.*` and
16
-
ets the integer value according to the [criticality OData vocabulary](https://sap.github.io/odata-vocabularies/vocabularies/UI.html#CriticalityType)
15
+
Write a CAP Java plugin that provides a handler detecting CDS enum values annotated with `@criticality.*` and
16
+
sets the integer value according to the [criticality OData vocabulary](https://sap.github.io/odata-vocabularies/vocabularies/UI.html#CriticalityType)
17
17
to an `criticality` element of the same entity.
18
18
19
-
Bones points: this works for expanded entities, too.
19
+
Bonus points: this works for expanded entities, too.
20
20
21
-
## Create a new plain Java project with Maven
21
+
## With Shortcut: Use the Prebuilt Plugin
22
+
23
+
In case you want to take the shortcut you can change to the `criticality-prebuilt` folder and install it to the plugin to the local Maven repository with `mvn source:jar install`. From here you can continue [extending the base application](#add-the-plugin-to-the-base-application).
24
+
25
+
## Without Shortcut: Create a New Plain Java Project with Maven
22
26
23
27
Use the Maven quickstart archetype to generate a plain, empty Java project:
Replace the generated pom.xml with the following content. It contains the needed dependencies and the correct Java version:
33
37
@@ -67,12 +71,6 @@ Replace the generated pom.xml with the following content. It contains the needed
67
71
<artifactId>cds-services-api</artifactId>
68
72
<version>2.10.0</version>
69
73
</dependency>
70
-
<dependency>
71
-
<groupId>junit</groupId>
72
-
<artifactId>junit</artifactId>
73
-
<version>3.8.1</version>
74
-
<scope>test</scope>
75
-
</dependency>
76
74
</dependencies>
77
75
</project>
78
76
```
@@ -81,28 +79,33 @@ Perform the initial build with `mvn compile`.
81
79
82
80
## Spring Boot Auto Configuration for the handler class
83
81
84
-
Use Spring Boot autoconfiguration to register the handler automatically as soon the dependency is added to the pom.xml.
82
+
Use [Spring Boot auto configuration](https://docs.spring.io/spring-boot/reference/using/auto-configuration.html)to register the handler automatically as soon the dependency is added to the pom.xml of the base application.
85
83
86
84
## Implement the handler
87
85
88
-
Write the handler. Use the following resources as a reference:
86
+
Write the handler. In contrast to the node.js implementation there is no dedicated registration per relevant entity at startup of the application. The handler needs to run for all services and all entities and detects at runtime if an entity is annotated and needs to be processed accordingly.
87
+
88
+
Use the following resources as a reference:
89
+
90
+
*https://cap.cloud.sap/docs/java/event-handlers/ At the core this task is about writing a generic event handler for a CAP Java application. Thus the event handler documentation is the foundation for this.
91
+
*https://cap.cloud.sap/docs/java/reflection-api You use the reflection API to introspect the application's CDS model in order to find relevant entities and elements.
92
+
*https://cap.cloud.sap/docs/java/cds-data In the handler, you need to traverse the data in the result and act according to the information you discovered in the CDS model.
89
93
90
-
*https://cap.cloud.sap/docs/java/reflection-api You use the reflection API to introspect the application's CDS model in
91
-
order to find relevant entities and elements.
92
-
*https://cap.cloud.sap/docs/java/cds-data In the handler, you need to traverse the data in the result and act according
93
-
to the information you discovered in the CDS model.
94
+
## Install the Handler to the Local Maven Repository
94
95
95
-
## Install the handler to the local Maven repo
96
-
In order to consume the new plugin from e.g. the Incidents App you need to install it to the local Maven repo. The `source:jar`
97
-
goal adds the source code to the jar as well. You might need it for debugging. 😈
96
+
Once the plugin is ready it can be consumed in the base application. In order to consume the new plugin from e.g. the Incidents App you need to install it to the local Maven repo. The `source:jar` goal adds the source code to the jar as well. You might need it for debugging. 😈
98
97
99
98
```
100
99
mvn source:jar install
101
100
```
102
101
103
-
## Adjust the model of the target application
102
+
## Add the Plugin to the Base Application
104
103
105
-
Clone the Incidents App for Java: https://github.com/recap-conf/incidents-app-java
104
+
The plugin is now ready to use. The base application's model can be extended and the plugin needs to be added to the list of dependencies.
105
+
106
+
### Adjust the Model of the Base Application
107
+
108
+
Change to the incidents-app-java folder:
106
109
107
110
Create a `criticality.cds file` in the `db` module and paste the following content:
108
111
@@ -142,14 +145,18 @@ Add the dependency of the just created plugin to your `srv/pom.xml`:
142
145
</dependency>
143
146
```
144
147
145
-
Start the application and execute some HTTP requests:
148
+
Start the base application with `mvn spring-boot:run`.
149
+
150
+
Finally, execute some HTTP requests.
146
151
152
+
Directly get the Urgency entities:
147
153
```http
148
154
GET http://localhost:8080/odata/v4/ProcessorService/Urgency
149
155
Authorization: basic YWxpY2U6
156
+
```
150
157
151
-
###
152
-
158
+
Get the Incidents entities with expanded `urgency` association.
159
+
```http
153
160
GET http://localhost:8080/odata/v4/ProcessorService/Incidents?$expand=urgency
0 commit comments