A full-stack multitenant library management application built with SAP Cloud Application Programming Model (CAP) for Java, designed for deployment on SAP Business Technology Platform (BTP).
This application provides comprehensive library management capabilities with support for books, members, and loan tracking. It includes automatic fine calculation, email validation, duplicate prevention, and is designed for SaaS multitenancy deployment.
- π Book Management: Create, read, update, and delete books with automatic stock tracking
- π₯ Member Management: Register and manage library members with email validation
- π Loan Management: Track book loans with automatic due date calculation (30 days)
- π° Fine Calculation: Automatic fine calculation for overdue returns (βΉ10/day)
- π Return Processing: Book return with fine calculation and stock updates
- β Automatic stock validation (prevents over-lending)
- β Duplicate book prevention (updates stock instead of creating duplicates)
- β Email validation for members
- β Email verification for book returns (security feature)
- β Prevents member deletion if they have active loans
- β Automatic stock increment/decrement on loan/return
- π OAuth2 authentication via XSUAA
- π’ Multitenancy ready with SaaS Registry integration
- π RESTful OData V4 API
- π SAP HANA Cloud database support
- π Cloud Foundry deployment ready
- π Blue-green deployment support
| Layer | Technology |
|---|---|
| Backend Framework | SAP CAP Java (Spring Boot 3.5.8) |
| Database | SAP HANA Cloud / H2 (local) |
| Build Tool | Maven 3.x |
| Runtime | Java 17 |
| API Protocol | OData V4 |
| Authentication | XSUAA (OAuth2) |
| Routing | Application Router |
| Deployment | Cloud Foundry (SAP BTP) |
Before you begin, ensure you have the following installed:
- Java 17 or higher (Download)
- Maven 3.6+ (Download)
- Node.js 18+ and npm (Download)
- SAP Cloud Foundry CLI (for deployment) - Install Guide
- Cloud MTA Build Tool (for building) -
npm install -g mbt
-
Clone the repository
git clone <your-repository-url> cd library-management
-
Install root dependencies
npm install
-
Install service dependencies and build
cd srv mvn clean install -DskipTests cd ..
After clean install, go to srv/src/gen and mark the java folder as "Generated Sources Root" in your IDE.
-
Navigate to service directory
cd srv -
Run the application
mvn spring-boot:run
-
Access the application
- π Application: http://localhost:8080
- π OData Service: http://localhost:8080/odata/v4/LibraryService
- π Service Metadata: http://localhost:8080/odata/v4/LibraryService/$metadata
The Multi-Target Application (MTA) archive bundles all components for deployment:
# Build the MTA archive
mbt build
# Output: mta_archives/library-management_1.0.0.mtarThis command:
- β
Builds the Java service (
srv) - β
Packages the database module (
db) - β
Packages the application router (
approuter) - β
Creates a deployable
.mtarfile
Build Java Service:
cd srv
mvn clean package -DskipTestsBuild Database Module:
cd db
npm install- SAP BTP Account (Trial or Production)
- Cloud Foundry Space with appropriate entitlements
- Required Services:
- SAP HANA Cloud (or hdi-shared for trial)
- XSUAA
- SaaS Registry (for multitenancy)
cf login -a <api-endpoint>cf target -o <your-org> -s <your-space>cf deploy mta_archives/library-management_1.0.0.mtarDeployment process includes:
- β Creating/updating services (library-db, library-uaa, library-registry)
- β Deploying database schema (library-management-db-deployer)
- β Deploying Java service (library-management-srv)
- β Deploying application router (library-management-approuter)
Expected deployment time: 8-12 minutes
# Check applications
cf apps
# Check services
cf services
# View application logs
cf logs library-management-srv --recentAfter successful deployment:
Application URLs:
- Service:
https://<org>-<space>-library-management-srv.cfapps.<region>.hana.ondemand.com - Approuter:
https://<org>-<space>-library-management-approuter.cfapps.<region>.hana.ondemand.com
Base URL: https://<your-app-url>/odata/v4/LibraryService
| Method | Endpoint | Description |
|---|---|---|
| GET | /Books |
List all books |
| POST | /Books |
Create a new book |
| GET | /Books({ID}) |
Get book by ID |
| PATCH | /Books({ID}) |
Update book |
| DELETE | /Books({ID}) |
Delete book |
Example Book Entity:
{
"title": "Clean Code",
"author": "Robert C. Martin",
"stock": 5
}| Method | Endpoint | Description |
|---|---|---|
| GET | /Members |
List all members |
| POST | /Members |
Register a member |
| GET | /Members({ID}) |
Get member by ID |
| PATCH | /Members({ID}) |
Update member |
| DELETE | /Members({ID}) |
Delete member |
Example Member Entity:
{
"name": "John Doe",
"email": "john.doe@example.com"
}| Method | Endpoint | Description |
|---|---|---|
| GET | /Loans |
List all loans |
| POST | /Loans |
Create a loan |
| GET | /Loans({ID}) |
Get loan by ID |
Example Loan Entity:
{
"bookId": "book-uuid",
"memberId": "member-uuid",
"loanDate": "2026-01-11",
"dueDate": "2026-02-10",
"returnDate": null
}Return Book:
POST /odata/v4/LibraryService/returnBook
Content-Type: application/json
{
"loanId": "loan-uuid",
"email": "john.doe@example.com"
}
Response: { "value": 50 } // Fine amount| Method | Endpoint | Description |
|---|---|---|
| GET | /mt/v1.0/subscriptions/dependencies |
Get subscription dependencies |
| PUT | /mt/v1.0/subscriptions/tenants/{tenantId} |
Subscribe a tenant |
| DELETE | /mt/v1.0/subscriptions/tenants/{tenantId} |
Unsubscribe a tenant |
- Mock authentication enabled by default
- No login required for testing
- OAuth2 authentication via XSUAA
- Role-based access control
- Two main roles:
- Admin: Full access to all operations
- MTCallback: Subscription management
- Go to BTP Cockpit
- Navigate to your subaccount β Security β Role Collections
- Assign users to role collections
# Add a book
curl -X POST http://localhost:8080/odata/v4/LibraryService/Books \
-H "Content-Type: application/json" \
-d '{
"title": "The Pragmatic Programmer",
"author": "David Thomas",
"stock": 3
}'
# Register a member
curl -X POST http://localhost:8080/odata/v4/LibraryService/Members \
-H "Content-Type: application/json" \
-d '{
"name": "Jane Smith",
"email": "jane.smith@example.com"
}'curl -X POST http://localhost:8080/odata/v4/LibraryService/Loans \
-H "Content-Type: application/json" \
-d '{
"bookId": "<book-id>",
"memberId": "<member-id>",
"loanDate": "2026-01-11",
"dueDate": "2026-02-10"
}'curl -X POST http://localhost:8080/odata/v4/LibraryService/returnBook \
-H "Content-Type: application/json" \
-d '{
"loanId": "<loan-id>",
"email": "jane.smith@example.com"
}'
# Response: { "fine": 0 } // No fineIf the book is returned 5 days late:
# Response: { "fine": 50 } // βΉ10 Γ 5 days = βΉ50Key configurations:
cds:
multitenancy:
enabled: true # Enable multitenancy
tenantId: request # Extract tenant from request
security:
authentication-strategy: never # Disable auth for subscription endpointsDefines OAuth2 security:
- Scopes:
Admin,Callback,mtcallback - Role templates
- Grant authorities for SaaS Registry
Multi-Target Application descriptor:
- Defines modules (db, srv, approuter)
- Configures services (HANA, XSUAA, SaaS Registry)
- Sets up routes and dependencies
What Works:
- β All CRUD operations
- β Business logic (loans, returns, fines)
- β Subscription API endpoints (return HTTP 200)
- β Single-tenant deployment
What Doesn't Work:
- β Multitenancy with tenant-specific HDI containers
- β Tenant database isolation
- β Full SaaS subscription flow
Why: Trial accounts don't have access to HANA Cloud's HDI container provisioning for tenants.
Solution: For production multitenancy, deploy to a production BTP account with HANA Cloud service.
Maven build fails:
# Clean and rebuild
cd srv
mvn clean install -UMTA build fails:
# Clean build artifacts
rm -rf mta_archives/ node_modules/ srv/target/
npm install
mbt buildService creation fails:
# Check service status
cf services
# View service creation logs
cf service library-dbApplication won't start:
# View application logs
cf logs library-management-srv --recent
# Check application details
cf app library-management-srvDatabase connection errors:
- Verify HANA service is running
- Check service binding:
cf env library-management-srv
Authentication errors:
- Verify XSUAA service configuration
- Check xs-security.json is correctly deployed
# Update Node.js dependencies
npm update
# Update Maven dependencies
cd srv
mvn versions:display-dependency-updates# Remove all build artifacts
rm -rf mta_archives/ node_modules/ srv/target/ db/gen/
# Reinstall and rebuild
npm install
mbt build# Rebuild and redeploy
mbt build
cf deploy mta_archives/library-management_1.0.0.mtarMembers (1) ββ< (N) Loans (N) >ββ (1) Books
Books:
- ID (UUID, Primary Key)
- title (String)
- author (String)
- stock (Integer)
- Managed fields (createdAt, createdBy, modifiedAt, modifiedBy)
Members:
- ID (UUID, Primary Key)
- name (String)
- email (String, unique)
- Managed fields
Loans:
- ID (UUID, Primary Key)
- bookId (UUID, Foreign Key)
- memberId (UUID, Foreign Key)
- loanDate (Date)
- dueDate (Date, auto-calculated as loanDate + 30 days)
- returnDate (Date, nullable)
- fine (Integer, default 0)
- Managed fields
- SAP Cloud Application Programming Model
- SAP Business Technology Platform
- Spring Boot Framework
Version: 1.0.0
Last Updated: January 11, 2026
Status: β
Production Ready (Single-tenant) |