From 7b3f8ac974ca5a4dc28fd953a30fe5d493c58f25 Mon Sep 17 00:00:00 2001 From: Marc Becker Date: Wed, 18 Sep 2019 07:07:47 +0000 Subject: [PATCH] CAA160 exercise 2 final state --- products-service/.gitignore | 24 ++++ products-service/.npmrc | 3 + products-service/db/schema.cds | 18 +++ products-service/index.cds | 2 + products-service/package.json | 38 +++++ products-service/pom.xml | 135 ++++++++++++++++++ products-service/srv/admin-service.cds | 6 + products-service/srv/pom.xml | 123 ++++++++++++++++ .../cap/productsservice/Application.java | 13 ++ .../srv/src/main/resources/application.yaml | 7 + 10 files changed, 369 insertions(+) create mode 100644 products-service/.gitignore create mode 100644 products-service/.npmrc create mode 100644 products-service/db/schema.cds create mode 100644 products-service/index.cds create mode 100644 products-service/package.json create mode 100644 products-service/pom.xml create mode 100644 products-service/srv/admin-service.cds create mode 100644 products-service/srv/pom.xml create mode 100644 products-service/srv/src/main/java/com/sap/teched/cap/productsservice/Application.java create mode 100644 products-service/srv/src/main/resources/application.yaml diff --git a/products-service/.gitignore b/products-service/.gitignore new file mode 100644 index 00000000..0ef8139e --- /dev/null +++ b/products-service/.gitignore @@ -0,0 +1,24 @@ +gen/ +edmx/ +schema.sql +*.db + +bin/ +target/ +.classpath +.project +.settings + +node/ +node_modules/ + +.mta/ +*.mtar + +*.log* +gc_history* +hs_err* +*.tgz + +default-env.json +connection.properties diff --git a/products-service/.npmrc b/products-service/.npmrc new file mode 100644 index 00000000..10332f30 --- /dev/null +++ b/products-service/.npmrc @@ -0,0 +1,3 @@ +package-lock=false +registry = https://registry.npmjs.org +@sap:registry = https://npm.sap.com diff --git a/products-service/db/schema.cds b/products-service/db/schema.cds new file mode 100644 index 00000000..33eee4d1 --- /dev/null +++ b/products-service/db/schema.cds @@ -0,0 +1,18 @@ +namespace sap.capire.products; + +using { Currency, cuid, managed, sap.common.CodeList } from '@sap/cds/common'; + +entity Products : cuid, managed { + title : localized String(111); + descr : localized String(1111); + stock : Integer; + price : Decimal(9,2); + currency : Currency; + category : Association to Categories; +} + +entity Categories : CodeList { + key ID : Integer; + parent : Association to Categories; + children : Composition of many Categories on children.parent = $self; +} diff --git a/products-service/index.cds b/products-service/index.cds new file mode 100644 index 00000000..581fba09 --- /dev/null +++ b/products-service/index.cds @@ -0,0 +1,2 @@ +using from './db/schema'; +using from './srv/admin-service'; diff --git a/products-service/package.json b/products-service/package.json new file mode 100644 index 00000000..9459ef4a --- /dev/null +++ b/products-service/package.json @@ -0,0 +1,38 @@ +{ + "name": "@sap/capire-products", + "version": "1.0.0", + "description": "A reuse package providing domain models and services to manage product catalogs.", + "license": "ISC", + "repository": "https://github.wdf.sap.corp/cap/samples", + "scripts": { + "build": "cds build/all --clean", + "schema": "cds compile srv --to sql > srv/src/main/resources/schema.sql", + "deploy": "cds deploy" + }, + "dependencies": { + "@sap/cds": "^3.0.0" + }, + "devDependencies": { + "sqlite3": "^4.1.0" + }, + "cds": { + "build": { + "target": "." + }, + "requires": { + "db": { + "kind": "sqlite", + "model": [ + "db", + "srv" + ], + "credentials": { + "database": "sqlite.db" + } + } + }, + "odata": { + "version": "v4" + } + } +} diff --git a/products-service/pom.xml b/products-service/pom.xml new file mode 100644 index 00000000..92f9f9aa --- /dev/null +++ b/products-service/pom.xml @@ -0,0 +1,135 @@ + + 4.0.0 + + com.sap.teched.cap + products-service-parent + ${revision} + pom + + products-service parent + + + + 1.0-SNAPSHOT + + + 1.8 + 1.0.1 + 1.2.1 + 2.1.7.RELEASE + + v10.4.1 + https://nodejs.org/dist/ + + + + srv + + + + + + + com.sap.cds + cds-services-bom + ${cds.services.version} + pom + import + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + + + + + + + com.github.eirslett + frontend-maven-plugin + 1.6 + + + install-node-and-npm + generate-sources + + install-node-and-npm + + + ${node.url} + ${node.version} + true + + + + + npm install + generate-sources + + npm + + + install + + + + + cds build + generate-sources + + npm + + + run build + + + + + cds schema + generate-sources + + npm + + + run schema + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + ${jdk.version} + ${jdk.version} + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + true + + + + + diff --git a/products-service/srv/admin-service.cds b/products-service/srv/admin-service.cds new file mode 100644 index 00000000..acc100d4 --- /dev/null +++ b/products-service/srv/admin-service.cds @@ -0,0 +1,6 @@ +using { sap.capire.products as db } from '../db/schema'; + +service AdminService { + entity Products as projection on db.Products; + entity Categories as projection on db.Categories; +} diff --git a/products-service/srv/pom.xml b/products-service/srv/pom.xml new file mode 100644 index 00000000..b04b95dd --- /dev/null +++ b/products-service/srv/pom.xml @@ -0,0 +1,123 @@ + + 4.0.0 + + + products-service-parent + com.sap.teched.cap + ${revision} + + + products-service + jar + + products-service + + + + + com.sap.cds + cds-starter-spring-boot-odata + + + + org.xerial + sqlite-jdbc + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + false + + + + + repackage + + + + + + + + com.github.eirslett + frontend-maven-plugin + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.0.0 + + + generate-sources + + add-source + + + + src/gen/java + + + + + + + + + com.sap.cds + cds4j-maven-plugin + ${cds4j.version} + + ${project.basedir}/src/gen + + + + cds4j-generate-model + generate-sources + + generate + + + ${project.basedir}/src/main/resources/edmx/csn.json + + localized.* + + + + + + + + + maven-clean-plugin + 3.0.0 + + + + src/gen + false + + + src/main/resources + + edmx/** + schema.sql + + false + + + + + + + \ No newline at end of file diff --git a/products-service/srv/src/main/java/com/sap/teched/cap/productsservice/Application.java b/products-service/srv/src/main/java/com/sap/teched/cap/productsservice/Application.java new file mode 100644 index 00000000..af45c1c9 --- /dev/null +++ b/products-service/srv/src/main/java/com/sap/teched/cap/productsservice/Application.java @@ -0,0 +1,13 @@ +package com.sap.teched.cap.productsservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/products-service/srv/src/main/resources/application.yaml b/products-service/srv/src/main/resources/application.yaml new file mode 100644 index 00000000..82facf82 --- /dev/null +++ b/products-service/srv/src/main/resources/application.yaml @@ -0,0 +1,7 @@ +--- +spring: + profiles: default + datasource: + url: "jdbc:sqlite:sqlite.db" + driver-class-name: org.sqlite.JDBC + initialization-mode: never