/cloud-cap-hana-swapi

SAP Cloud Application Programming Model fun sample to demonstrate many-to-many relationships.

Primary LanguageCAP CDSApache License 2.0Apache-2.0

cloud-cap-hana-swapi - bi-directional, many-to-many SAP Cloud Application Programming Model example

REUSE status

Description

SWAPI - the Star Wars API. This sample is based upon the sample at swapi.dev which in turn was based upon swapi.co. The original source can be found at https://github.com/Juriy/swapi.

The original project was a data set and data model based in Python that exposed data from the Star Wars movies sourced originally from the community wiki: Wookiepedia. It encompasses data about the People, Films, Species, Starships, Vehicles and Planets from Star Wars.

The projects described above have fallen out of maintenance but still offered the opportunity for a fun yet challenging learning experience from a non-trivial data model. The many bi-directional, many-to-many relationships with the data provides a good basis for an SAP Cloud Application Programming Model and Fiori Draft UI sample.

Data Model

Films

film diagram

People

people diagram

Planets

planet diagram

Species

species diagram

Starships

starships diagram

Vehicles

vehicles diagram

Requirements

Download and Installation

The original data model and data source files are in in the oldPython\resources folder.

The rest of the operations can be performed within the cap folder and there are scripts in the package.json file major operations.

You can use npm run build to perform the cds build and should be ran before deployment to HANA or whenever you make changes to the data model.

You can run npm run hana to deploy the content to your HANA database. Just be sure from the terminal that you are logged into the cf/xs cli and targeting the Account/Org/Space where you want the content to live. By default this command will create an HDI Container instance named starwars. Note: due to some strange circumstances in the latest versions of CAP it seems the /gen/srv folder is getting cleared after any deployment to HANA. Therefore just execute a cds build or npm run build after any deployment to restore the /gen folder until we find the root cause of this issue.

You can run the command npm run load. This command will read the original JSON data files from the source project and load them into your HANA database using Cloud Application Programming Model CQL. The loading script is convertData.js

The command npm start or cds run will start the service running locally. It will open the standard CAP test page where you can explore the OData Services or the Fiori UI.

From the Cloud Application Programming Model preview (which opens locally when using npm start or cds run), you can access the Swagger UI test tool (with entity diagrams), test the OData services or metadata calls directly in the browser, or access the Fiori preview UI for each of the main entities.

CDS Test Page

Fiori Preview List

Fiori Preveiw Overview Edit

Known Issues

If you receive an error like the following when running the convertData script

[Error: SQLITE_BUSY: database is locked] {
  errno: 5,
  code: 'SQLITE_BUSY',
  query: 'DELETE FROM star_wars_People'
}

This is caused by the parallel nature of the loading of the data in SQLite. The default script with its parallel loading works fine when you use HANA as the target persistence. However if you are using SQLite for your tempoary testing persistence, then you can use the alternative convertDataLite script instead.

Note: due to some strange circumstances in the latest versions of CAP it seems the /gen/srv folder is getting cleared after any deployment to HANA. Therefore just execute a cds build or npm run build after any deployment to restore the /gen folder until we find the root cause of this issue.

How to obtain support

This project is provided "as-is": there is no guarantee that raised issues will be answered or addressed in future releases.

License

Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.

Star Wars and all associated names are copyright Lucasfilm ltd. All data in this sample has been freely collected from open sources such as Wookiepedia under CC-BY-SA .