Skip to content

Commit bc516cd

Browse files
authored
refactor: simpler annotations, cloud sdk, structure
2 parents 0a78b30 + 0f30bcc commit bc516cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2955
-2598
lines changed

.cdsprettier.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"maxDocCommentLine": 80,
3+
"formatDocComments": true,
4+
"tabSize": 2,
5+
"alignPostAnnotations": false,
6+
"alignColonsInAnnotations": false,
7+
"alignValuesInAnnotations": false
8+
}

.prettierrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
tabWidth: 2,
3+
semi: true,
4+
printWidth: 100,
5+
trailingComma: "all",
6+
};

CHANGELOG.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,26 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
3636
- Fixed handling of unmanaged composition of many
3737
- Proper casing of the operation enum type
3838

39-
4039
### Changed
4140

4241
- Added warning and mitigation for multi-tenant deployments with MTX
4342
- Added a disclaimer of upcoming new version having a minimum requirement of CDS 8.6 for multitenancy fix
4443
- Changed the default limit on non-HANA databases from 255 to 5000 characters for all String values
4544
- Updated peer dependency from CDS7 to CDS8
4645

47-
4846
## Version 1.0.7 - 20.08.24
4947

5048
### Added
5149

52-
- A global switch to preserve change logs for deleted data
53-
- For hierarchical entities, a method to determine their structure and a flag to indicate whether it is a root entity was introduced. For child entities, information about the parent is recorded.
54-
50+
- A global switch to preserve change logs for deleted data
51+
- For hierarchical entities, a method to determine their structure and a flag to indicate whether it is a root entity was introduced. For child entities, information about the parent is recorded.
5552

5653
### Fixed
5754

5855
- CDS 8 does not support queries for draft-enabled entities on the application service anymore. This was causing: SqliteError: NOT NULL constraint failed: (...).DraftAdministrativeData_DraftUUID
5956
- CDS 8 deprecated cds.transaction, causing change logs of nested documents to be wrong, replaced with req.event
6057
- CDS 8 rejects all direct CRUD requests for auto-exposed Compositions in non-draft cases. This was affecting test cases, since the ChangeView falls into this category
61-
- req._params and req.context are not official APIs and stopped working with CDS 8, replaced with official APIs
58+
- req.\_params and req.context are not official APIs and stopped working with CDS 8, replaced with official APIs
6259
- When running test cases in CDS 8, some requests failed with a status code of 404
6360
- ServiceEntity is not captured in the ChangeLog table in some cases
6461
- When modeling an inline entity, a non-existent association and parent ID was recorded
@@ -70,22 +67,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
7067
- Data marked as personal data using data privacy annotations won't get change-tracked anymore to satisfy product standards
7168
- Restructured Documentation
7269

73-
7470
## Version 1.0.6 - 29.04.24
7571

7672
### Fixed
7773

78-
- Storage of wrong ObjectID in some special scenarios
79-
- Missing localization of managed fields
80-
- Views without keys won't get the association and UI facet pushed anymore
74+
- Storage of wrong ObjectID in some special scenarios
75+
- Missing localization of managed fields
76+
- Views without keys won't get the association and UI facet pushed anymore
8177

8278
### Added
8379

84-
- A method to disable automatic generation of the UI Facet
80+
- A method to disable automatic generation of the UI Facet
8581

8682
### Changed
8783

88-
- Improved documentation of the @changelog Annotation
84+
- Improved documentation of the @changelog Annotation
8985

9086
## Version 1.0.5 - 15.01.24
9187

@@ -112,7 +108,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
112108

113109
### Added
114110

115-
- Added note about using `SAPUI5 v1.120.0` or later for proper lazy loading of the *Change History* table.
111+
- Added note about using `SAPUI5 v1.120.0` or later for proper lazy loading of the _Change History_ table.
116112
- In README, add warning about tracking personal data.
117113

118114
### Changed
@@ -141,4 +137,3 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
141137
### Added
142138

143139
- Initial release
144-

CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Instances of abusive, harassing, or otherwise unacceptable behavior may be repor
1010

1111
We use GitHub to manage reviews of pull requests.
1212

13-
* If you are a new contributor, see: [Steps to Contribute](#steps-to-contribute)
13+
- If you are a new contributor, see: [Steps to Contribute](#steps-to-contribute)
1414

15-
* Before implementing your change, create an issue that describes the problem you would like to solve or the code that should be enhanced. Please note that you are willing to work on that issue.
15+
- Before implementing your change, create an issue that describes the problem you would like to solve or the code that should be enhanced. Please note that you are willing to work on that issue.
1616

17-
* The team will review the issue and decide whether it should be implemented as a pull request. In that case, they will assign the issue to you. If the team decides against picking up the issue, the team will post a comment with an explanation.
17+
- The team will review the issue and decide whether it should be implemented as a pull request. In that case, they will assign the issue to you. If the team decides against picking up the issue, the team will post a comment with an explanation.
1818

1919
## Steps to Contribute
2020

@@ -28,11 +28,11 @@ You are welcome to contribute code in order to fix a bug or to implement a new f
2828

2929
The following rule governs code contributions:
3030

31-
* Contributions must be licensed under the [Apache 2.0 License](./LICENSE)
32-
* Due to legal reasons, contributors will be asked to accept a Developer Certificate of Origin (DCO) when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses [the standard DCO text of the Linux Foundation](https://developercertificate.org/).
31+
- Contributions must be licensed under the [Apache 2.0 License](./LICENSE)
32+
- Due to legal reasons, contributors will be asked to accept a Developer Certificate of Origin (DCO) when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses [the standard DCO text of the Linux Foundation](https://developercertificate.org/).
3333

3434
## Issues and Planning
3535

36-
* We use GitHub issues to track bugs and enhancement requests.
36+
- We use GitHub issues to track bugs and enhancement requests.
3737

38-
* Please provide as much context as possible when you open an issue. The information you provide must be comprehensive enough to reproduce that issue for the assignee.
38+
- Please provide as much context as possible when you open an issue. The information you provide must be comprehensive enough to reproduce that issue for the assignee.

README.md

Lines changed: 56 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -18,138 +18,92 @@ See [Getting Started](https://cap.cloud.sap/docs/get-started) on how to jumpstar
1818

1919
Usage of this plugin requires a valid subscription of the [SAP Print Service](https://help.sap.com/docs/SCP_PRINT_SERVICE).
2020

21-
To integrate the print functionality in your application, simply annotate any action with `@print`. This annotation automatically manages the process of sending documents to the print queues, requiring no additional setup for handling print jobs.
21+
## Usage
2222

23-
### Required Fields
23+
To use this plugin to print documents there are two main steps:
2424

25-
The following three fields should be annotated with the corresponding `@print` annotations:
25+
1. Add required annotations to your CDS model:
26+
a. Entity
27+
b. Action
28+
2. Configure print queues to select from available options. (Optional, but recommended)
2629

27-
1. **`@print.queue`**: Specifies the queue to which the document should be sent for printing.
28-
2. **`@print.numberOfCopies`**: Defines the number of copies to be printed.
29-
3. **`@print.fileContent`**: Provides the file content to be printed. You can also specify the file name using the `fileNameField` property.
30+
### Annotations in CDS model
3031

31-
#### Example
32+
#### Entity
33+
34+
First of all, the entity needs to be annotated to define the content and the name of the document to be printed.
3235

3336
```cds
34-
@print.fileContent: {
35-
fileNameField: '<Field Name>',
37+
entity Incidents : cuid {
38+
@print.fileContent
39+
file : LargeBinary @Core.MediaType: 'application/pdf';
40+
@print.fileName
41+
fileName : String;
3642
}
37-
```
38-
39-
Multiple fields can be annotated with `@print.fileContent` to send several documents to the print queue in a single action.
40-
41-
### Main Document
4243
43-
To designate a specific document as the primary document for printing, annotate it with `@print.MainDocument`:
44-
45-
```cds
46-
@print.MainDocument
47-
invoiceContent,
4844
```
4945

50-
This ensures the specified document is treated as the main document when multiple documents are involved.
51-
52-
## Print Queue Configuration
53-
54-
You can retrieve all available print queues from the Print Service Application for selection by defining a `Queues` entity with **skip persistency**. This setup will offer a value help for the print queues, allowing users to select from available options.
46+
- `@print.fileContent`: Annotates the field containing the document content to be printed.
47+
- `@print.fileName`: Annotates the field containing the name of the document
5548

56-
### Define the `Queues` Entity
49+
#### Annotation of actions
5750

58-
Define an entity like `Product` and associate it with the `Queues` entity as shown below:
51+
Sending a print request works via bound actions annotated with `@print`. The parameter of the action are used to define the print job details.
5952

60-
#### Example
6153
```cds
62-
entity Product {
63-
qName : Association to one Queues;
64-
}
65-
66-
@cds.skip.persistence
67-
entity Queues {
68-
key ID : String;
69-
description : String;
70-
}
71-
```
54+
service IncidentService {
55+
entity Incidents as projection on db.Incidents actions {
7256
73-
#### Annotating with `@print.queue`
74-
75-
Once the `Queues` entity is defined, specify it in the `@print.queue` annotation like so:
76-
77-
```cds
78-
@print.queue: {
79-
SourceEntity: 'Queues'
57+
@print
58+
action printIncidentFile(
59+
@Common: {
60+
ValueListWithFixedValues,
61+
ValueList: {
62+
$Type: 'Common.ValueListType',
63+
CollectionPath: 'Queues',
64+
Parameters: [{
65+
$Type: 'Common.ValueListParameterInOut',
66+
LocalDataProperty: qnameID,
67+
ValueListProperty: 'ID'
68+
}]
69+
},
70+
Label: 'Print Queues',
71+
}
72+
@print.queue
73+
qnameID: String,
74+
@print.numberOfCopies
75+
@UI.ParameterDefaultValue : 1
76+
copies: Integer
77+
);
78+
};
8079
}
81-
qName
8280
```
8381

84-
### Parameterizing Print Queue in Actions
82+
- `@print`: Annotates the action that triggers the print job.
83+
- `@print.queue`: Annotates the parameter specifying the print queue. It is recommended to use a value help for this parameter to select from available print queues. See TOOD
84+
- `@print.numberOfCopies`: Annotates the parameter specifying the number of copies to print
8585

86-
Alternatively, if the print queue is passed as a parameter in the action, you can annotate it directly within the action definition. This can be done as follows:
86+
### Queues
8787

88-
#### In Database Definition:
88+
Every print request needs to specify a print queue it is send to. It is recommended to provide a value help for the print queue selection. To enbale this, define an entity as projection on the `Queues` entity provided by the print service. When this projection is in place, the plugin automatically provides the available print queues coming from the print service.
8989

9090
```cds
91-
entity Product {
92-
qName : Association to one Queues;
93-
}
94-
95-
@cds.skip.persistence
96-
entity Queues {
97-
key ID : String;
98-
description : String;
99-
}
100-
```
101-
102-
#### In Service Definition:
91+
using {sap.print as sp} from '@cap-js/print';
10392
104-
```cds
105-
service MyService {
106-
@print
107-
action print(
108-
@print.queue: {
109-
SourceEntity: 'Queues'
110-
}
111-
@Common: {
112-
ValueListWithFixedValues,
113-
ValueList: {
114-
$Type: 'Common.ValueListType',
115-
CollectionPath: 'Queues',
116-
Parameters: [{
117-
$Type: 'Common.ValueListParameterInOut',
118-
LocalDataProperty: qnameID,
119-
ValueListProperty: 'ID'
120-
}]
121-
},
122-
Label: 'Print Queues',
123-
}
124-
qnameID: String
125-
);
126-
127-
entity Queues as projection on db.Queues;
93+
service IncidentService {
94+
entity Queues as projection on sp.Queues;
12895
}
12996
```
13097

131-
In this setup, the `qnameID` parameter will be used to dynamically select the print queue from the `Queues` entity. The `Common.ValueList` provides a drop-down selection for available queues during runtime.
98+
## Local Development
13299

100+
When running the application locally, i.e. `cds watch`, the print service is mocked. This mock implementation prints the print job details to the console instead of sending it to the actual print service. It also provides a number of sample print queues for selection.
133101

134-
## Note
102+
## Hybrid Testing
135103

136-
If you are running the application in a production way locally(E.g. adding VCAP_SERVICES in `default-env.json`), add the environmental variable `SUBSCRIBER_SUBDOMAIN_FOR_LOCAL_TESTING=<Your subscriber subdomain name>` in the `package.json` as shown below.
104+
You can also run the application locally with a binding to the cloud print service with CAP profiles. For more information, see [Hybrid Testing](https://cap.cloud.sap/docs/advanced/hybrid-testing#hybrid-testing). You need an instance of the SAP Print Service.
137105

138-
#### Example
139-
140-
```json
141-
"scripts": {
142-
"start": "SUBSCRIBER_SUBDOMAIN_FOR_LOCAL_TESTING=sub01 cds-serve"
143-
}
144-
```
145-
146-
If you are running the application in offline mode which is without remote connection to the online environment, you can add the environmental variable `PRINT_CONSOLE_MODE=true cds watch` in the `package.json` as shown below.
147-
148-
```json
149-
"scripts": {
150-
"watch-offline": "PRINT_CONSOLE_MODE=true cds watch"
151-
}
152-
```
106+
TODO: More doc about setting up the print service
153107

154108
## Support, Feedback, Contributing
155109

0 commit comments

Comments
 (0)