You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,7 @@ This plugin can be consumed by the CAP application deployed on BTP to store thei
25
25
- Attachment changelog: Provides the capability to view complete audit trail of attachments.
26
26
- Localization of error messages and UI fields: Provides the capability to have the UI fields and error messages translated to the local language of the leading application.
27
27
- Attachment Upload Status: Upload Status is the new field which displays the upload status of attachment when being uploaded.
28
+
- Active entity attachment creation: Provides the capability to create attachments directly on active (non-draft) entities.
28
29
29
30
## Table of Contents
30
31
@@ -45,6 +46,7 @@ This plugin can be consumed by the CAP application deployed on BTP to store thei
45
46
-[Support for Edit of Link type attachments](#support-for-edit-of-link-type-attachments)
46
47
-[Support for Localization](#support-for-localization)
47
48
-[Support for Attachment Upload Status](#support-for-attachment-upload-status)
49
+
-[Support for Attachment creation in Active Entities](#support-for-attachment-creation-in-active-entities)
### Support for Attachment Creation in Active Entities
1338
+
1339
+
By default, the SDM CAP plugin handles attachment creation through the **draft flow** — attachments are first created on a draft entity and later activated. This feature adds support for creating attachments **directly on active entities**, which is useful in scenarios where the parent entity bypasses the draft lifecycle (e.g., programmatic entity creation, background jobs, or APIs that operate on active records).
1340
+
1341
+
### How It Works
1342
+
1343
+
When an attachment is created, the plugin automatically determines whether the parent entity is in a **draft** or **active** context:
1344
+
1345
+
1.**Draft detection:** The plugin queries the parent entity's draft table to check if the parent record exists there. If it does, the standard draft flow is used.
1346
+
2.**Active entity flow:** If the parent record is **not** found in the draft table, the plugin treats it as an active entity context. In this case:
1347
+
- The attachment content is uploaded to the SAP Document Management repository.
1348
+
- The SDM metadata (`objectId`, `folderId`, `repositoryId`, etc.) is temporarily stored in-memory.
1349
+
- After the framework completes the database INSERT, an `@After` handler updates the active entity record with the SDM metadata.
1350
+
3.**Backwards compatibility:** If the context cannot be determined (e.g., the model has no draft table), the plugin defaults to the draft flow to ensure existing applications continue to work without changes.
1351
+
1352
+
### Key Behavior
1353
+
1354
+
-**Automatic detection:** No configuration is required. The plugin automatically detects whether to use the draft or active entity flow based on the parent entity's presence in the draft table.
1355
+
-**Duplicate handling:** If an attachment with the same filename already exists on the active entity, the plugin gracefully handles the duplicate by reusing the existing attachment record.
1356
+
1357
+
### Usage in Leading Applications
1358
+
1359
+
To create attachments on active entities, the leading application needs to trigger an `INSERT` on the attachment entity through the `ApplicationService` (or `DraftService`, which extends it). The plugin intercepts the content automatically and routes it through the active entity flow.
1360
+
1361
+
#### Steps
1362
+
1363
+
1.**Build the attachment data** with the required fields:
|`mimeType`|`String`| The MIME type of the content |
1371
+
|`content`|`InputStream`| An `InputStream` containing the file content |
1372
+
1373
+
2.**Execute the INSERT** using the `ApplicationService`. See this [example](https://github.com/cap-java/sdm/blob/e89c3c4f9fee6a18b20dfec2650b1d05ff244bc3/cap-notebook/demoapp/srv/src/main/java/customer/demoapp/handlers/AdminServiceHandler.java#L142)
0 commit comments