Skip to content

Commit e452db4

Browse files
Nagucorjayasingherenejeglinsky
authored
Remove "as" call function code snippet (#2157)
Opening pull request according: #2156 and #2155 Closes: #2155 Closes: #2156 --------- Co-authored-by: Robin <[email protected]> Co-authored-by: René Jeglinsky <[email protected]> Co-authored-by: Robin <[email protected]>
1 parent bab30f8 commit e452db4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

get-started/in-a-nutshell.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ You can have this _.js_ file created automatically with [`cds add handler`](../t
556556
In CAP Java, you can add custom handlers for your service as so called EventHandlers. As CAP Java integrates with Spring Boot, you need to provide your custom code in classes, annotated with `@Component`, for example. Use your favorite Java IDE to add a class like the following to the `srv/src/main/java/` folder of your application. {.impl .java}
557557

558558
::: code-group
559-
```java [srv/src/main/java/com/sap/capire/bookshop/handlers/CatalogServiceHandler.java]
559+
```java [srv/src/main/java/com/cap/capire/bookshop/handlers/CatalogServiceHandler.java]
560560
@Component
561561
@ServiceName(CatalogService_.CDS_NAME)
562562
public class CatalogServiceHandler implements EventHandler {
@@ -609,7 +609,7 @@ module.exports = CatalogService
609609
Now that you have created the classes for your custom handlers it's time to add the actual logic. You can achieve this by adding methods annotated with CAP's `@Before`, `@On`, or `@After` to your new class. The annotation takes two arguments: the event that shall be handled and the entity name for which the event is handled.
610610

611611
::: code-group
612-
```java [srv/src/main/java/com/sap/capire/bookshop/handlers/CatalogServiceHandler.java]
612+
```java [srv/src/main/java/com/cap/capire/bookshop/handlers/CatalogServiceHandler.java]
613613
@After(event = CqnService.EVENT_READ, entity = Books_.CDS_NAME)
614614
public void addDiscountIfApplicable(List<Books> books) {
615615
for (Books book : books) {
@@ -623,7 +623,7 @@ Now that you have created the classes for your custom handlers it's time to add
623623

624624
:::details Code including imports
625625
::: code-group
626-
```java [srv/src/main/java/com/sap/capire/bookshop/handlers/CatalogServiceHandler.java]
626+
```java [srv/src/main/java/com/cap/capire/bookshop/handlers/CatalogServiceHandler.java]
627627
package com.sap.capire.bookshop.handlers;
628628

629629
import java.util.List;
@@ -696,7 +696,7 @@ module.exports = CatalogService
696696
<span class="impl java">
697697

698698
::: code-group
699-
```java [srv/src/main/java/com/sap/capire/bookshop/handlers/SubmitOrderHandler.java]
699+
```java [srv/src/main/java/com/cap/capire/bookshop/handlers/SubmitOrderHandler.java]
700700
@Component
701701
@ServiceName(CatalogService_.CDS_NAME)
702702
public class SubmitOrderHandler implements EventHandler {
@@ -710,7 +710,7 @@ public class SubmitOrderHandler implements EventHandler {
710710
@On
711711
public void onSubmitOrder(SubmitOrderContext context) {
712712
Select<Books_> byId = Select.from(cds.gen.catalogservice.Books_.class).byId(context.getBook());
713-
Books book = persistenceService.run(byId).single().as(Books.class);
713+
Books book = persistenceService.run(byId).single(Books.class);
714714
if (context.getQuantity() > book.getStock())
715715
throw new IllegalArgumentException(context.getQuantity() + " exceeds stock for book #" + book.getTitle());
716716
book.setStock(book.getStock() - context.getQuantity());
@@ -723,7 +723,7 @@ public class SubmitOrderHandler implements EventHandler {
723723

724724
:::details Code including imports
725725
::: code-group
726-
```java [srv/src/main/java/com/sap/capire/bookshop/handlers/CatalogService.java]
726+
```java [srv/src/main/java/com/cap/capire/bookshop/handlers/SubmitOrderHandler.java]
727727
package com.sap.capire.bookshop.handlers;
728728

729729
import org.springframework.stereotype.Component;
@@ -751,7 +751,7 @@ public class SubmitOrderHandler implements EventHandler {
751751
@On
752752
public void onSubmitOrder(SubmitOrderContext context) {
753753
Select<Books_> byId = Select.from(cds.gen.catalogservice.Books_.class).byId(context.getBook());
754-
Books book = persistenceService.run(byId).single().as(Books.class);
754+
Books book = persistenceService.run(byId).single(Books.class);
755755
if (context.getQuantity() > book.getStock())
756756
throw new IllegalArgumentException(context.getQuantity() + " exceeds stock for book #" + book.getTitle());
757757
book.setStock(book.getStock() - context.getQuantity());

0 commit comments

Comments
 (0)