Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update name of plugin & ReadMe #15

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .cdsrc.json

This file was deleted.

125 changes: 61 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,124 +6,121 @@ This plugin can be consumed by the CAP application deployed on BTP to store thei
### Table of Contents

- [Setup](#setup)
- [Use `attachments-sdm`](#use-attachments-sdm)
- [Test-drive Hybrid](#test-drive-hybrid)
- [Contributing](#contributing)
- [Use `sdm`](#use-sdm)
- [Testing the application locally](#testing-the-application-locally)
- [Support, Feedback, Contributing](#support-feedback-contributing)
- [Code of Conduct](#code-of-conduct)
- [Licensing](#licensing)

## Setup

To enable attachments-sdm, simply add this self-configuring plugin package to your project:
In this guide, we use the [Incidents Management reference sample app](https://github.com/cap-js/incidents-app) as the base application, to add `Attachments` type to the CDS model.

> **Note:** This plugin is yet to be released. After the release, to enable SDM, simply add this self-configuring plugin package to your project using the following command:
>
> ```sh
> npm add @cap-js/sdm
> ```

Prior to release follow below steps to enable sdm plugin

1. Clone the incidents-app repository:

```sh
npm add @cap-js/attachments-sdm
git clone https://github.com/cap-js/incidents-app.git
```

In this guide, we use the [Incidents Management reference sample app](https://github.com/cap-js/incidents-app) as the base application, to add `Attachments` type to the CDS model.
2. Clone the sdm repository:

```sh
git clone https://github.com/cap-js/sdm.git
```

3. Open terminal, navigate to sdm root folder and generate tarball:

```sh
npm pack

> [!Note]
> To be able to use the Fiori _uploadTable_ feature, you must ensure ^1.121.0 SAPUI5 version is updated in the application's _index.html_
This will generate a file with name cap-js-sdm-1.0.0.tgz
```

4. Copy the path of .tgz file generated in step 3 and in terminal navigate to incidents-app root folder and execute:

```sh
npm install <path-to-.tgz file>
```

## Use Attachments-sdm
## Use sdm

**To use Attachments-sdm, create an element with an `Attachments` type.** Following the [best practice of separation of concerns](https://cap.cloud.sap/docs/guides/domain-modeling#separation-of-concerns), we do so in a separate file _db/attachments.cds_:
**To use sdm plugin in incidents-app, create an element with an `Attachments` type.** Following the [best practice of separation of concerns](https://cap.cloud.sap/docs/guides/domain-modeling#separation-of-concerns), create a separate file _db/attachments.cds_ and paste the below content in it:

```
using { sap.capire.incidents as my } from './schema';
using { Attachments } from '@cap-js/attachments';
using { Attachments } from '@cap-js/sdm';

extend my.Incidents with { attachments: Composition of many Attachments }
```

**Create a SAP Document Management Service instance and key. Using the contents from key onboard a repository and configure the onboarded repositoryId under cds.requires in package.json**
**Create a SAP Document Management Service instance and key. Using credentials from key [onboard a repository](https://help.sap.com/docs/document-management-service/sap-document-management-service/onboarding-repository) and configure the onboarded repositoryId under cds.requires in package.json**

```
"attachments-sdm": {
"sdm": {
"settings": {
"repositoryId": "<repository-Id>"
}
}
```

## Test-drive Hybrid
## Testing the application locally

For using SAP Document Management Service to store attachments, use the instance-name and service-key values of SAP Document Management Service Integration Option in the below setup.

1. Log in to Cloud Foundry space:
1. Install cds-dk globally

```sh
npm i @sap/cds-dk -g
```

2. Log in to Cloud Foundry space:

```sh
cf login -a <CF-API> -o <ORG-NAME> -s <SPACE-NAME>
```

2. To bind to the service continue with the steps below.
3. To bind to the service continue with the steps below.

In the project directory, you can generate a new file \_.cdsrc-private.json by running:

```sh
cds bind attachments -2 <INSTANCE-NAME>:<SERVICE-KEY> --kind sdm
cds bind sdm -2 <INSTANCE-NAME>:<SERVICE-KEY> --kind sdm
```

3. **Start the server**:
4. **Start the server**:

- _Default_ scenario (In memory database):
```sh
cds watch --profile hybrid
```

4. **Navigate to the object page** of the incident `Solar panel broken`:

Go to [Object page for incident **Solar panel broken**](<http://localhost:4004/incidents/app/#/Incidents(ID=3583f982-d7df-4aad-ab26-301d4a157cd7,IsActiveEntity=true)>)

5. The `Attachments` type has generated an out-of-the-box Attachments table (see 1) at the bottom of the Object page:
<img width="1300" alt="Attachments Table" style="border-radius:0.5rem;" src="etc/facet.png">

6. **Upload a file** by going into Edit mode and either using the **Upload** button on the Attachments table or by drag/drop. Then click the **Save** button to have that file stored in SAP Document Management Integration Option. We demonstrate this by uploading the PDF file from [_xmpl/db/content/Solar Panel Report.pdf_](./xmpl/db/content/Solar%20Panel%20Report.pdf):
<img width="1300" alt="Upload an attachment" style="border-radius:0.5rem;" src="etc/upload.gif">

7. **Delete a file** by going into Edit mode and selecting the file(s) and by using the **Delete** button on the Attachments table. Then click the **Save** button to have that file deleted from the resource (SAP Document Management Integration Option). We demonstrate this by deleting the previously uploaded PDF file: `Solar Panel Report.pdf`
<img width="1300" alt="Delete an attachment" style="border-radius:0.5rem;" src="etc/delete.gif">

## Test-drive Cloud

1. Log in to Cloud Foundry space:
5. **Navigate to the object page** of the incident `Solar panel broken`:

```sh
cf login -a <CF-API> -o <ORG-NAME> -s <SPACE-NAME>
* Open http://localhost:4004 in a browser.
* If prompted for sign-in, enter alice in username field and click on Sign In button.
* Click on /incidents/webapp under Web Applications.
* Click on incident with title Solar panel broken.
```

2. Bind your CAP application to SAP Document Management Service Integration Option instance or continue with the steps below.

In mta.yml of your CAP application add **sdm** as a dependency under srv module:
Or, directly navigate to [Object page for incident **Solar panel broken.**](<http://localhost:4004/incidents/webapp/index.html#/Incidents(ID=3583f982-d7df-4aad-ab26-301d4a157cd7,IsActiveEntity=true)>)

```sh
modules:
- name: cap-srv
type: nodejs
path: gen/srv
requires:
- name: sdm
```

Under resources of mta.yml add below lines:

```sh
resources:
- name: sdm
type: org.cloudfoundry.managed-service
parameters:
service: sdm
service-plan: free
```

3. Build & Deploy the project:
6. The `Attachments` type has generated an out-of-the-box Attachments table (see 1) at the bottom of the Object page:
<img width="1300" alt="Attachments Table" style="border-radius:0.5rem;" src="etc/facet.png">

```sh
mbt build
cf deploy <path-to-mtar file>
```
7. **Upload a file** by going into Edit mode and either using the **Upload** button on the Attachments table or by drag/drop. Then click the **Save** button to have that file stored in SAP Document Management Integration Option. We demonstrate this by uploading the PDF file from [_xmpl/db/content/Solar Panel Report.pdf_](./xmpl/db/content/Solar%20Panel%20Report.pdf):
<img width="1300" alt="Upload an attachment" style="border-radius:0.5rem;" src="etc/upload.gif">

4. Once the deployment is successfull open the HTML5 application and follow steps (4 - 7) mentioned in [Test-drive Hybrid](#test-drive-hybrid) section of this README.
8. **Delete a file** by going into Edit mode and selecting the file(s) and by using the **Delete** button on the Attachments table. Then click the **Save** button to have that file deleted from the resource (SAP Document Management Integration Option). We demonstrate this by deleting the previously uploaded PDF file: `Solar Panel Report.pdf`
<img width="1300" alt="Delete an attachment" style="border-radius:0.5rem;" src="etc/delete.gif">

## Support, Feedback, Contributing

Expand Down
2 changes: 1 addition & 1 deletion lib/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function fetchAccessToken(credentials) {
}

function getConfigurations() {
return cds.env.requires?.["attachments-sdm"]?.settings || {};
return cds.env.requires?.["sdm"]?.settings || {};
}

module.exports = {
Expand Down
17 changes: 0 additions & 17 deletions manifest.yml

This file was deleted.

26 changes: 0 additions & 26 deletions mta.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@cap-js/attachments-sdm",
"name": "@cap-js/sdm",
"version": "1.0.0",
"description": "CAP plugin for effortless integration of CAP applications with SAP Document Management Service.",
"main": "cds-plugin.js",
Expand Down Expand Up @@ -39,8 +39,8 @@
"cds": {
"requires": {
"kinds": {
"attachments-sdm": {
"impl": "@cap-js/attachments-sdm/lib/sdm"
"sdm": {
"impl": "@cap-js/sdm/lib/sdm"
}
},
"[development]": {
Expand Down
Loading
Loading