Welcome to the PostgreSQL bookshop-java sample. It demonstrates how to build business applications using the CAP Java SDK using PostgreSQL. The application in this project enables browsing books and managing books.
This sample application shows how to conveniently create business applications based on CDS domain models, persisting data with PostgreSQL, 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.
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.
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.
Framework and Infrastructure related Features:
- PostgreSQL database support with Liquibase for schema evolution.
- Application configuration for Spring and CDS using application.yaml
- Mocking users for local development
- Authentication & Authorization (including user-specific restrictions with
@restrict
in the Admin Service) - Cloud Foundry Deployment using MTA with XSUAA Service Bindings
- Application Router configuration including authentication via the XSUAA Service. See package.json, xs-app.json and xs-security.json
Domain Model related Features:
- Use of Aspects in the Model Definition such as the
managed
orcuid
Aspect in Books - Input validation using model annotation
@assert.format
- Data Localization for Books
User Interface related Features:
- Support for SAP Fiori Elements
- SAP Fiori Draft based Editing for Books
- SAP Fiori annotations specific for Browse Books and Manage Books UIs
- Value Help for Authors
- Model Localization for English and German language for static texts
CDS Maven Plugin Features:
- Install Node.js in the default version.
- Execute arbitrary npm commands.
- Generate Java POJOs for type-safe access to the CDS model.
- Clean project from artifacts of the previous build.
The following sections describe how to set up, build, and run the project.
Make sure you have set up a development environment (that means, you’ve installed the CDS Compiler, Java and Apache Maven) as described here. This sample also requires Docker Desktop or compatible alternative as described in testcontainers library documentation.
- Clone the project:
git clone https://github.com/SAP-samples/cloud-cap-samples-java.git
- Build and run the application:
mvn spring-boot:test-run
In the IDE use the TestApplication to run the application with the PostgreSQL container created by testcontainer.
This application is built to use only PostgreSQL as the database. It is used in the tests, can be started locally and, when deployed to SAP BTP, can use PostgreSQL service available there.
This sample uses Liquibase for deployment and evolution of database schema. You can find more on that in CAP Database Guide.
To start the application with built-in PostgresSQL container run mvn spring-boot:test-run
. Make sure that you have Docker Desktop or compatible alternative up and running. You will see that application created PostgreSQL container, deployed the database there and your application is up and running.
Regular run with mvn spring-boot:run
will require datasource to be specified explicitly. You may adapt the default configuration if you want to use this sample with persistent database or with PostgreSQL deployed in the cloud.
Unit tests require Docker environment and will fail if executed without one.
CAP Java applications can be deployed to the SAP Business Technology Platform as single tenant application.
Prerequisites:
- Install the Cloud MTA Build Tool:
npm install -g mbt
. - Install the Cloud Foundry Command Line Interface.
- Get an SAP Business Technology Platform account to deploy the services and applications.
- Ensure you have an entitlement for PostgreSQL, hyperscaler option with appropriate plan in the same space.
- Ensure that your CF instances are connected to Internet to download SAPMachine JRE 17 as it is available in
sap_java_buildpack
in online mode only and you run in the landscape where the PostgreSQL, hyperscaler option is available.
Deploy Application:
- Run
mbt build
- Run
cf login
- Run
cf deploy mta_archives/bookshop-pg_1.0.0.mtar
In case you have a question, find a bug, or otherwise need support, please use our community. See the documentation at https://cap.cloud.sap for more details about CAP.
Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.