MCPcopy Index your code
hub / github.com/SAP-samples/cloud-cap-samples-java

github.com/SAP-samples/cloud-cap-samples-java @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
167 symbols 388 edges 41 files 20 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Welcome to CAP Samples for Java

CI status REUSE status

Welcome to the bookshop-java project. It demonstrates how to build business applications using the CAP Java SDK providing a book shop web application as an example. The application in this project enables browsing books, managing books, and managing orders.

Book Object Page

Outline

Overview

This sample application shows how to conveniently create business applications based on CDS domain models, persisting data with H2, or SAP HANA, and exposing an OData V4 frontend with an SAP Fiori frontend on top.

This sample uses Spring Boot as an application framework. Although a CAP Java application isn’t required to build on Spring Boot, it’s the first choice of framework, as it’s seamlessly integrated.

The domain models are defined using CDS entity definitions.

By default, an in-memory H2 database is used for data persistency. Once productively deployed to SAP Business Technology Platform, SAP HANA can be used.

Services are defined using CDS Service Models. The OData V4 Protocol Adapter translates the CDS service models into corresponding OData schemas and maps the incoming OData requests to the corresponding CDS services.

Although CAP provides generic event handlers to serve most CRUD requests out-of-the-box, it’s possible to add business logic through Custom Event Handlers.

A SAP Fiori UI is added using predefined SAP Fiori elements templates. SAP Fiori annotations add information to the service definitions, on how to render the data.

CAP provides built-in multitenancy support with out-of-the box tenant isolation. The sample application demonstrates usage of MTX sidecar based on streamlined MTX and can be deployed as multitenant application. The deprecated classic MTX setup is shown in the mtx-classic branch for reference.

Demonstrated Features

Framework and Infrastructure related Features:

Domain Model related Features:

Service Model related Features:

User Interface related Features:

CDS Maven Plugin Features:

Getting Started

The following sections describe how to set up, build, and run the project.

Prerequisites

Make sure you have set up a development environment (that means, you’ve installed the CDS Compiler, Java 21, and Apache Maven) as described here. This sample application requires a Java 21 compatible JDK. We recommend using SapMachine 21.

Clone Build & Run

  1. Clone the project:

bash git clone https://github.com/SAP-samples/cloud-cap-samples-java.git

  1. Build and run the application:

mvn spring-boot:run

[!NOTE] Please note that some IDEs may interfere with their autobuild when launching the application from the CLI using Maven. Therefore, please ensure that no IDEs are running in parallel or launch the application natively from your preferred IDE as described below.

  1. Use the following links in the browser to check if everything works fine:

  2. http://localhost:8080: This should show the automatically generated index page of served paths.

  3. http://localhost:8080/fiori.html: This is the actual bookshop application UI.
  4. http://localhost:8080/swagger/index.html: This is providing a Swagger UI for the CatalogService API.

You'll start with a predefined stock of books as this procedure starts the bookshop application with a CSV-initialized in-memory H2 database.

Two mock users in addition to the default mock users are defined for local development: - User: user, password: user to browse books - User: admin, password: admin to manage books and orders

Testing in hybrid mode

You can test the GenreHierarchyTest on H2 using the profile default as well as on HANA using the profile cloud

cds bind --exec -- mvn clean install -Dspring.profiles.active=cloud

Using VS Code

VS Code supports the project out-of-the-box, when using the Extension Pack for Java. To launch the application in VS Code navigate to the Application class and click on Run or Debug.

Using Eclipse

Use the following steps to import the project to Eclipse:

  1. Import the project using File > Import > Existing Maven Projects.

    Now, you should see the projects bookshop and bookshop-parent in the project/package explorer view.

  2. In Project Explorer, change the property "Package Presentation" from "Flat" to "Hierarchical" for better understanding.

Building and Running

  1. To compile the project, right-click the file pom.xml in the bookshop-parent project root folder and select Run as > Maven build.

    In the following dialog, enter the string clean install into the field labeled with "Goals" and click "Run".

    Note: This step also compiles the CDS artifacts, thus repeat this once you made changes to the CDS model. This step also generates source files, therefore refresh the "bookshop" project in your IDE.

  2. To run the application, right-click the bookshop project root in the Package Explorer and select Run as > Spring Boot App (make sure you have Spring Tools 4 installed).

    This step creates a default Run Configuration named Bookshop - Application and starts the application afterwards. To go on with the next step, stop the application again.

  3. Then, set the default working directory by editing your Run Configuration via Run > Run Configurations > Bookshop - Application. On the tab Arguments change the default Working Directory to:

    ${workspace_loc:bookshop-parent}

    Afterward, click Run. This step starts the applications main method located in src/main/java/my/bookshop/Application.java.

Using IntelliJ Idea (Community and Ultimate)

IntelliJ can handle the project more or less out-of-the-box. Since some of the event handlers in the project rely on the code generated from the CDS model the build path of

Core symbols most depended-on inside this repo

get
called by 49
srv/src/main/java/my/bookshop/config/CustomFeatureToggleProvider.java
where
called by 9
srv/src/main/java/my/bookshop/handlers/NotesServiceHandler.java
ref
called by 8
srv/src/main/java/my/bookshop/handlers/NotesServiceHandler.java
info
called by 5
srv/src/main/java/my/bookshop/health/AppActuator.java
ensureSelected
called by 4
srv/src/main/java/my/bookshop/handlers/NotesServiceHandler.java
where
called by 4
srv/src/main/java/my/bookshop/handlers/AdminServiceAddressHandler.java
createConfigChange
called by 4
srv/src/main/java/my/bookshop/handlers/AdminServiceAuditHandler.java
GET
called by 3
app/vue/app.js

Shape

Method 119
Class 31
Function 17

Languages

Java90%
TypeScript10%

Modules by API surface

srv/src/test/java/my/bookshop/GenreHierarchyTest.java12 symbols
srv/src/main/java/my/bookshop/handlers/AdminServiceAuditHandler.java12 symbols
srv/src/test/java/my/bookshop/NotesServiceITest.java11 symbols
srv/src/main/java/my/bookshop/handlers/CatalogServiceHandler.java11 symbols
srv/src/main/java/my/bookshop/handlers/AdminServiceHandler.java11 symbols
srv/src/main/java/my/bookshop/handlers/NotesServiceHandler.java10 symbols
app/vue/app.js10 symbols
srv/src/test/java/my/bookshop/CatalogServiceTest.java9 symbols
srv/src/test/java/my/bookshop/CatalogServiceITest.java8 symbols
srv/src/test/java/my/bookshop/AdminServiceTest.java6 symbols
srv/src/test/java/my/bookshop/AdminServiceAddressITestBase.java6 symbols
srv/src/main/java/my/bookshop/handlers/AdminServiceAddressHandler.java6 symbols

For agents

$ claude mcp add cloud-cap-samples-java \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact