Skip to content

Commit 973a4e8

Browse files
committed
fixes and additions in the readme
1 parent df1222e commit 973a4e8

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

readme.md

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Create a crititcality plugin for CAP Java
1+
# Create a Crititcality Plugin for CAP Java Applications
22

33
## Prerequisites
44

@@ -12,13 +12,17 @@ You need to have the following tools installed:
1212

1313
## Requirement
1414

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)
1717
to an `criticality` element of the same entity.
1818

19-
Bones points: this works for expanded entities, too.
19+
Bonus points: this works for expanded entities, too.
2020

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
2226

2327
Use the Maven quickstart archetype to generate a plain, empty Java project:
2428

@@ -27,7 +31,7 @@ mvn archetype:generate -DgroupId= -DartifactId=criticality -DarchetypeGroupId=co
2731
```
2832

2933

30-
## Add needed dependencies
34+
## Add Needed Dependencies
3135

3236
Replace the generated pom.xml with the following content. It contains the needed dependencies and the correct Java version:
3337

@@ -67,12 +71,6 @@ Replace the generated pom.xml with the following content. It contains the needed
6771
<artifactId>cds-services-api</artifactId>
6872
<version>2.10.0</version>
6973
</dependency>
70-
<dependency>
71-
<groupId>junit</groupId>
72-
<artifactId>junit</artifactId>
73-
<version>3.8.1</version>
74-
<scope>test</scope>
75-
</dependency>
7674
</dependencies>
7775
</project>
7876
```
@@ -81,28 +79,33 @@ Perform the initial build with `mvn compile`.
8179

8280
## Spring Boot Auto Configuration for the handler class
8381

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.
8583

8684
## Implement the handler
8785

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.
8993

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
9495

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. 😈
9897

9998
```
10099
mvn source:jar install
101100
```
102101

103-
## Adjust the model of the target application
102+
## Add the Plugin to the Base Application
104103

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:
106109

107110
Create a `criticality.cds file` in the `db` module and paste the following content:
108111

@@ -142,14 +145,18 @@ Add the dependency of the just created plugin to your `srv/pom.xml`:
142145
</dependency>
143146
```
144147

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.
146151

152+
Directly get the Urgency entities:
147153
```http
148154
GET http://localhost:8080/odata/v4/ProcessorService/Urgency
149155
Authorization: basic YWxpY2U6
156+
```
150157

151-
###
152-
158+
Get the Incidents entities with expanded `urgency` association.
159+
```http
153160
GET http://localhost:8080/odata/v4/ProcessorService/Incidents?$expand=urgency
154161
Authorization: basic YWxpY2U6
155162
```

0 commit comments

Comments
 (0)