Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4fa2419
Merge pull request #23 from IObert/master
Nov 29, 2019
03409db
update ex01 for cds-dk
qmacro Jan 14, 2020
219ffa6
adjust ex02 for cds-dk and new init process
qmacro Jan 14, 2020
a6457ac
update step number and change note
qmacro Jan 14, 2020
8e80bfb
remove cds serve all
qmacro Jan 14, 2020
76f3809
mods to ex03 for cds-dk and new approach
qmacro Jan 14, 2020
924f202
be more explicit about the entity
qmacro Jan 14, 2020
0dfbd2a
folder -> directory aargh
qmacro Jan 14, 2020
ba933b1
mods to ex04 for cds-dk
qmacro Jan 14, 2020
a3afee6
initial mods to ex05 for cds-dk
qmacro Jan 14, 2020
878f24f
complete draft updates for ex05
qmacro Jan 14, 2020
36416b4
npm start -> cds watch
qmacro Jan 14, 2020
c7cbd2b
mods for ex06 for cds-dk
qmacro Jan 14, 2020
b03701a
mods for ex07 for cds-dk
qmacro Jan 14, 2020
d7b6fc6
clean up sh sample
qmacro Jan 14, 2020
5b94d38
move info on new artefact to question
qmacro Jan 14, 2020
20c284a
mods for cds-dk for ex08
qmacro Jan 14, 2020
5540095
mods for cds-dk (incl pin fix for Fiori elements)
qmacro Jan 15, 2020
d403ca3
remove pin - new approach - no records without annos
qmacro Jan 15, 2020
51f10d9
adjust list report para
qmacro Jan 15, 2020
e61a314
remove ui maint in mta.yaml from ex09, do in ex10
qmacro Jan 15, 2020
bd80761
remove ui maint in mta.yaml from ex09, do in ex10
qmacro Jan 15, 2020
cc0f30e
Merge branch 'master' of github.com:SAP-samples/cloud-cap-nodejs-codejam
qmacro Jan 15, 2020
f487559
mods for cds-dk and new mta.yaml
qmacro Jan 15, 2020
6f4ea53
minor mods after review
qmacro Jan 15, 2020
2d87e7a
fix 4004 port number
qmacro Jan 15, 2020
91c746a
cds watch -> npm start
qmacro Jan 15, 2020
693f02b
remove Q1 as we cover this in the exercise
qmacro Jan 15, 2020
68cb4d3
add note to switch back to cds watch
qmacro Jan 15, 2020
b362445
remove reload step after 'using from service'
qmacro Jan 15, 2020
8597efe
fix bad ref to non-existent step
qmacro Jan 15, 2020
24ebf14
add step to specify hana in package.json
qmacro Jan 15, 2020
86280ab
update 10.6 to describe use of profiles
qmacro Jan 17, 2020
d05e841
Update readme.md
qmacro Jan 22, 2020
0096348
Update readme.md
qmacro Jan 22, 2020
684ad94
add experimental run scripts per exercise (1-5)
qmacro Jan 22, 2020
4000016
add automation for 06
qmacro Jan 23, 2020
b931a99
fix Windows curl calls
qmacro Jan 23, 2020
d55dd37
fix step numbering
qmacro Jan 24, 2020
b224faa
show how to set env var in Windows
qmacro Jan 24, 2020
c25ae86
update screenshots for new cds init contents
qmacro Jan 24, 2020
8ef2cf3
Update readme.md
qmacro Feb 5, 2020
c3c3e7b
update screenshot cat-service -> service
qmacro Feb 5, 2020
ca3acc7
Update readme.md
qmacro Feb 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions exercises/01/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Successfully completing this exercise relies on the hardware and software [prere

## Steps

After completing these steps you'll have a working local environment for development of CAP based projects with Node.js.
After completing these steps you'll have a working local environment for development of CAP based projects with Node.js, using the CAP "development kit" package `@sap/cds-dk`.

### 1. Install the CDS command line tool

Expand Down Expand Up @@ -43,7 +43,7 @@ user-agent = "npm/6.4.1 node/v10.15.3 linux x64"
; "npm config ls -l" to show all defaults.
```

:point_right: Next, explore the information about the `@sap/cds-dk` (the dk stands for development kit)package, including its dependencies, with:
:point_right: Next, explore the information about the `@sap/cds-dk` package, including its dependencies, with:

```sh
user@host:~
Expand All @@ -59,15 +59,14 @@ user@host:~
=> npm install --global @sap/cds-dk
```

This should eventually produce output similar to this:
This produces a fair amount of output as it works, but should eventually end with a couple of lines similar to this:

```sh
/Users/d056949/.nvm/versions/node/v10.15.3/bin/cds -> /Users/d056949/.nvm/versions/node/v10.15.3/lib/node_modules/@sap/cds-dk/bin/cds.js
+ @sap/cds-dk@1.1.4
updated 1 package in 27.076s
+ @sap/cds-dk@1.4.2
added 471 packages from 381 contributors in 33.398s
```

Here you can see that the version of the `@sap/cds-dk` package installed is 3.18.4. It may be that the version of `@sap/cds-dk` that is installed when you do this exercise will be different (newer).
Here you can see that the version of the `@sap/cds-dk` package just installed is 1.4.2. It may be that the version of `@sap/cds-dk` that is installed when you do this exercise will be different (newer).

### 2. Install the CDS extension for VS Code

Expand All @@ -77,25 +76,25 @@ Extensions can be installed directly in VS Code from the extension marketplace,

:point_right: Go to the [Cloud section of the SAP Development Tools website](https://tools.hana.ondemand.com/#cloud) and find the "CDS Language Support for Visual Studio Code" section. Follow the instructions there to download and subsequently install the extension.

To install the downloaded extension in VS Code have a look at the screenshot below:
To install the downloaded extension in VS Code have a look at the screenshot below:

![CDS Extension installation in VS Code](vscode-extension-import.png)

When successfully installed, you should see the extension thus (again, the version number may be different):

![CDS Language Support extension installed in VS Code](vscode-extension.png)

> **For macOS users only:** To be able to open VS Code from the command line (which you will be doing in a subsequent exercise) you need to add the installation path of VS Code to the environment variable PATH. There's an option to do this via the `Command Palette` in VS Code.
> **For macOS users only:** To be able to open VS Code from the command line (which you will be doing in a subsequent exercise) you need to add the installation path of VS Code to the environment variable PATH. There's an option to do this via the `Command Palette` in VS Code.

> Open the `Command Palette` with ⇧⌘P. You can also open it via the menu bar: View -> Command Palette.

> ![Command Palette navigation in the menu bar](command-palette.png)

> Search for `code` and press Enter.
> Search for `code` and press Enter.

> ![search for code in the command palette](install-code-path.png)

> A success message for the process should then appear at the bottom right of the screen.
> A success message for the process should then appear at the bottom right of the screen.

> ![message that the 'code' command was successfully installed](sucessfully-installed.png)

Expand Down
14 changes: 14 additions & 0 deletions exercises/01/run.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# https://github.com/SAP-samples/cloud-cap-nodejs-codejam/tree/master/exercises/01

echo EXERCISE 01

echo 1. Install the CDS command line tool
npm set @sap:registry=https://npm.sap.com
npm install --global @sap/cds-dk

echo 2. Install the CDS extension for VS Code \(NOP\)

echo 3. Verify your development environment \(NOP\)

Binary file modified exercises/02/default-shell-windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified exercises/02/initialized-project-in-vscode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified exercises/02/integrated-terminal-in-view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 65 additions & 44 deletions exercises/02/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ After completing these steps you'll be familiar with how you can use the `cds` c

For any new CAP based project you start by indirectly creating a directory containing various basic files. This can be achieved with the CDS command line tool `cds` which you installed in [exercise 01](../01/).

The `cds` tool should be available in your executable path, having been installed globally as part of the Node.js `@sap/cds` package.

:point_right: First, explore the `cds` command line tool by executing it with no parameters; you will see what options are available:
The `cds` tool should be available in your executable path, having been installed globally as part of the Node.js `@sap/cds-dk` package.

```sh
user@host:~
Expand All @@ -36,12 +34,13 @@ COMMANDS

i | init jump-start cds-based projects
c | compile process models selectively
m | import add models from external sources
d | deploy e.g. to databases or cloud
s | serve run servers locally
w | watch restart server on file changes
m | import add models from external sources
r | repl read-eval-event loop
e | env get/set cds configuration
b | build prepare for deployment
d | deploy e.g. to databases or cloud
v | version get detailed version information
? | help get detailed usage information

Expand All @@ -59,34 +58,25 @@ user@host:~
=> cds init --help
```

Amongst other things, you should see a `--modules` option to specify a list of modules to be created when the project is initialized, and also a `--verbose` option. The options `--mta`, `--db-technology` and `--insecure` are related to deployment to Cloud Foundry and access management in that context. `--skip-sample-models` avoids the creation of sample CDS source files which you will build step by step in this CodeJam yourself.

:point_right: Use all of these options to initialize a new project directory called `bookshop` thus:
:point_right: Use some of these options to initialize a new project directory called `bookshop` thus:

```sh
user@host:~
=> cds init --modules db,srv --mta --insecure --db-technology hana --verbose --skip-sample-models bookshop
=> cds init bookshop --add hana,mta
```

You should see output that looks similar to this:

```
Initializing project in folder bookshop.
Copying templates for type db to db ...
Creating mta file /private/tmp/bookshop/mta.yaml ...
Copying templates for type srv to srv ...
Creating mta file /private/tmp/bookshop/mta.yaml ...
Updating npm dependencies in /private/tmp/bookshop/package.json ...
Running npm install...
npm notice created a lockfile as package-lock.json. You should commit this file.
added 120 packages from 178 contributors and audited 220 packages in 6.978s
found 0 vulnerabilities
[cds] - creating new project in current folder
> applying template 'hana'...
> applying template 'mta'...
done.

Done.
Learn about first steps at https://cap.cloud.sap/docs/get-started/in-a-nutshell
Find samples on https://github.com/SAP-samples/cloud-cap-samples
Learn about next steps at https://cap.cloud.sap/docs/get-started
```


### 2. Open the project in VS Code

Now that the project has been initialized, it's time to explore it. The VS Code IDE is a comfortable environment in which to do so, so at this point you will open up the newly created `bookshop` directory in it.
Expand All @@ -111,19 +101,22 @@ The skeleton project that has been initialized is visible in VS Code. This is wh

Briefly, the directories and contents can be described thus:

| Directory | Contents |
| Directory or File | Description |
| -------------- | -------- |
| `.vscode` | VS Code specific files for launch configurations (useful for debugging, which we will cover in [exercise 08](../08/)) |
| `db` | Where the data models (in CDS) are specified. |
| `node_modules` | This is the place where NPM packages (modules) are to be found in a Node.js based project |
| `srv` | Where the service definitions (in CDS) are specified. |
| `mta.yaml` | This is the central descriptor file for the project. It defines all modules (microservices) and backing services (like databases). This information will be used to build the .mtar archive during design time and to deploy & provision the apps and services during deploy time. |
| `.vscode/` | VS Code specific files for launch configurations (useful for debugging, which we will cover in [exercise 08](../08/)). This directory may or may not be visible in VS Code, depending on version and settings. |
| `app/` | Where any UI components live, in case you're building and serving a full stack app. |
| `db/` | Where the data models (in CDS) are specified. |
| `srv/` | Where the service definitions (in CDS) are specified. |
| `.eslintrc` | Configuration for linting of the JavaScript with [ESLint](https://eslint.org/). |
| `.gitignore` | Specification of what content should be ignored when using `git` for source code control, specifically for CAP-based projects. |
| `mta.yaml` | This is the central descriptor file for the project. It defines all modules (microservices) and backing services (like databases). This information will be used to build the .mtar archive during design time and to deploy & provision the apps and services during deploy time. |
| `package.json` | The standard package descriptor file for Node.js based (NPM) packages and projects. |
| README.md | A small 'Getting Started' guide for this project. |

Besides the directories there are also a number of files, including the project's `package.json` (present in any Node.js based project).

### 4. Create a simple data model and service definition

:point_right: Create a new file called `data-model.cds` in the `db/` directory of the recently created project, copy the following lines to the file and save it:
:point_right: Create a new file called `schema.cds` in the `db/` directory of the recently created project, copy the following lines to the file and save it:

```cds:
namespace my.bookshop;
Expand All @@ -137,10 +130,10 @@ entity Books {

> You **may** wish to use VS Code's "auto save" feature, then again you may not. Just in case you do, you can turn it on via the **File -> Auto Save** menu option.

:point_right: Create a new file called `cat-service.cds` in the `srv/` directory of the recently created project, copy the following lines to the file and save it:
:point_right: Create a new file called `service.cds` in the `srv/` directory of the recently created project, copy the following lines to the file and save it:

```cds:
using my.bookshop as my from '../db/data-model';
using my.bookshop as my from '../db/schema';

service CatalogService {
entity Books as projection on my.Books;
Expand All @@ -151,14 +144,16 @@ You have now created a simple data model as well as a service definition for you

### 5. Examine the data model and service definition

The key files in this project as far as the business domain is concerned are the `db/data-model.cds` and the `srv/cat-service.cds` files that you just added.
The key files in this project as far as the business domain is concerned are the `db/schema.cds` and the `srv/service.cds` files that you just added.

:point_right: Have a brief look at the content of each of these files to get a basic understanding of what's there. Note the use of the `namespace` and how it is defined in the data model and referenced in the service definition. Note also the how the different parts of each file are syntax highlighted.


### 6. Start up the service
### 6. Install the dependencies

The `package.json` file that was created when you initialized the project directory contains a list of NPM packages upon which the project is dependent. Before we can start the service up, these dependencies must be installed. Now is a good time to do that.

Now you're going to start up the service in the skeleton project. **VS Code has an integrated terminal which you can and should use for this and subsequent command line activities**.
> VS Code has an integrated terminal which you can and should use for this and subsequent command line activities.

:point_right: Open the integrated terminal in VS Code. Do this by opening the Command Palette and searching for 'integrated terminal'. You may wish to use the keyboard shortcut for this - note there is a keyboard shortcut for toggling the integrated terminal in and out of view as well.

Expand All @@ -171,32 +166,55 @@ This should open up the terminal at the bottom of VS Code like this:
> **Windows users:** Please make sure to select `cmd` as your default shell before you continue:
![default shell](default-shell-windows.png)

:point_right: In the integrated terminal, use the `cds` command line tool with the `serve` command to start serving. Specify `all`, like this, so that `cds` will look for appropriate configuration to serve:
:point_right: In the integrated terminal, making sure first that you're in the project directory itself (where `package.json` is to be found), install the dependencies like this:

```sh
user@host:~/bookshop
=> npm install
```

You should see output that ends something like this:

```sh
npm notice created a lockfile as package-lock.json. You should commit this file.
added 129 packages from 181 contributors and audited 258 packages in 4.762s
found 0 vulnerabilities
```

Great. Now your fledgling service can already be started up!

### 7. Start up the service

:point_right: In the same integrated terminal, use the following command to start up the service:


```sh
user@host:~/bookshop
=> cds serve all
=> npm start
```

You should see output similar to this:

```
[cds] - connect to datasource - hana:db,srv
> bookshop@1.0.0 start /tmp/codejam/bookshop
> npx cds run

[cds] - connect to datasource - hana:undefined
[cds] - serving CatalogService at /catalog
[cds] - service definitions loaded from:

srv/cat-service.cds
db/data-model.cds
srv/service.cds
db/schema.cds

[cds] - launched in: 533.555ms
[cds] - launched in: 583.297ms
[cds] - server listening on http://localhost:4004 ...
[ terminate with ^C ]
```

The OData service is now running, and available via [http://localhost:4004](http://localhost:4004).


### 7. Explore the OData service
### 8. Explore the OData service

While we have no data in the OData service (we don't even have a persistence layer yet!) we can ask the OData service for the two well-known documents: the service document and the metadata document.

Expand All @@ -218,7 +236,7 @@ With a single command, you've initialized a basic OData service project and with

## Questions

1. Why is there an focus on "Contracts First" (As all you need to run a service is a service definition) - what advantages does that bring?
1. Why is there a focus on "Contracts First" (As all you need to run a service is a service definition) - what advantages does that bring?
<!--- UI teams can start to work right away --->

2. What is the difference between the data model and the service definition? Why do we need both?
Expand All @@ -228,4 +246,7 @@ With a single command, you've initialized a basic OData service project and with
<!--- error --->

4. What happened to the `cds` process when you accessed the entityset? Can you think of reasons why this happened?
<!--- crash --->
<!--- crash --->

5. What actually happens when you run `npm start`, and why?
<!-- runs npx cds run, standardized way -->
40 changes: 40 additions & 0 deletions exercises/02/run.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# https://github.com/SAP-samples/cloud-cap-nodejs-codejam/tree/master/exercises/02

echo EXERCISE 02

echo 1. Initialize a new CAP project
cds init bookshop --add hana,mta && cd bookshop

echo 2. Open the project in VS Code \(NOP\)

echo 3. Explore the initialized project structure \(NOP\)

echo 4. Create a simple data model and service definition
cat <<EOSCHEMA > db/schema.cds
namespace my.bookshop;

entity Books {
key ID : Integer;
title : String;
stock : Integer;
}
EOSCHEMA

cat <<EOSERVICE > srv/service.cds
using my.bookshop as my from '../db/schema';

service CatalogService {
entity Books as projection on my.Books;
}
EOSERVICE

echo 5. Examine the data model and service definition \(NOP\)

echo 6. Install the dependencies
npm install

echo 7. Start up the service \(NOP\)

echo 8. Explore the OData service \(NOP\)
Loading