Skip to content
Open
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
29 changes: 23 additions & 6 deletions guides/uis/fiori.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ In essence, the draft choreography defines the following flows:
- Filling in draft data through a series of _PATCH_ events.
- **Saving** the draft back to the active entity, or **discarding** it.

Drafts are isolated from any active data until they are saved/activated. When drafts are discarded, they are removed as if they never existed – with draft locks as the only exception to prevent conflicting changes.
Drafts are isolated from any active data until they're saved/activated. When drafts are discarded, they're removed as if they never existed. Draft locks serve as the mechanism to prevent conflicting changes.


### Draft Locks
Expand Down Expand Up @@ -359,7 +359,7 @@ While this was always possible in CAP Java before, it's available for CAP Node.j
> Directly updating an active entity does **not** bypass [draft locks](#draft-locks).
> If an existing draft locks the entity, direct updates are blocked to prevent lost update situations.

#### Draft-agnostic Requests
#### Draft-agnostic Requests (CAP Node.js)

Taking this further, through <Config>cds.fiori.draft_new_action: true</Config> `IsActiveEntity=true` is assumed by default, so clients that are unaware of drafts or don't need to handle them can ignore all draft-specific requests and parameters:

Expand Down Expand Up @@ -392,12 +392,20 @@ You can also access draft data programmatically from custom code in JavaScript o
In CAP Java, add `IsActiveEntity` as a key parameter to your queries ([learn more](../../java/fiori-drafts#draftservices)):

```java {3}
Select.from(FOO).where(o -> o.ID().eq(201); //> reads active data
Select.from(FOO).where(o -> o.ID().eq(201) .and( //> reads draft data
o.IsActiveEntity().eq(false))
);
Select.from(FOO).where(o -> o.ID().eq(201).and(
o.IsActiveEntity().eq(true))); //> reads active version
Select.from(FOO).where(o -> o.ID().eq(201).and(
o.IsActiveEntity().eq(false))); //> reads draft
```

Alternatively you can define a filtered structured type `activeFoos`, which gives you access to active versions only and then just work with `activeFoos`:

```java
Foo_ activeFoos = CQL.entity(FOO).filter(f -> f.isActiveEntity().eq(true)); //> active versions only
Select.from(activeFoos).byId(201); //> reads active version
```


In CAP Node.js, use the [`Foo.drafts`](../../node.js/cds-reflect#drafts) references to access draft data:

```js {3}
Expand All @@ -413,6 +421,15 @@ this.on ('approveTravel', req => UPDATE (req.subject) .with ({ status: 'A' }))
this.on ('rejectTravel', req => UPDATE (req.subject) .with ({ status: 'X' }))
```

In CAP Java, use an [entity reference](../../java/event-handlers/#entity-reference-arguments) in your handler's method signature which captures the `IsActiveEntity` key component so that you don't have to specify it in your code:

```java
@On(event = TravelService.APPROVE)
public void approveTravel(Travels_ ref) {
db.run(Update.entity(ref).set("status", "A"));
}
```


### Draft Input Validation
###### Validating Drafts
Expand Down
Loading