Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A sample application that demonstrates the features of the Java SDK for the SAP Cloud Application Programming Model.

License

Notifications You must be signed in to change notification settings

SAP-samples/cloud-cap-samples-java

 
 

Repository files navigation

Welcome to CAP Samples for Java

CI status REUSE status

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.

Outline

Overview

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.

Demonstrated Features

Framework and Infrastructure related Features:

Domain Model related Features:

User Interface related Features:

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.

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 and Apache Maven) as described here. This sample also requires Docker Desktop or compatible alternative as described in testcontainers library documentation.

Clone Build & Run

  1. Clone the project:
  git clone https://github.com/SAP-samples/cloud-cap-samples-java.git
  1. 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.

Database Setup

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.

Deploy to SAP Business Technology Platform, Cloud Foundry

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

Get Support

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.

License

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.

About

A sample application that demonstrates the features of the Java SDK for the SAP Cloud Application Programming Model.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published