Repository navigation
Move draft user description docu from Java to Fiori guide - #2969
rjayasinghe wants to merge 4 commits into
Conversation
Moves the "Showing a Custom User Description" section from the Java-specific fiori-drafts page into the shared guides/uis/fiori page, marked as Java-only via a warning callout. The Java page now has a learn-more link pointing to the new location. Closes https://github.wdf.sap.corp/cds-java/home/issues/2972
Control PanelHi, I'm an AI-powered Review Bot that helps you with summarizing and reviewing pull requests.
|
| ```java | ||
| @Component | ||
| @ServiceName(value = "*", type = DraftService.class) | ||
| public class UserDescriptionHandler implements EventHandler { | ||
|
|
||
| @Autowired private UserInfo userInfo; | ||
|
|
||
| @Before | ||
| protected void addDraftFields(DraftCreateEventContext context, List<CdsData> entries) { | ||
| CdsDataProcessor.Filter filter = | ||
| (path, element, type) -> "InProcessByUserDescription".equals(element.getName()); | ||
| CdsDataProcessor.Generator generator = (path, element, isNull) -> description(); | ||
| CdsDataProcessor.create().addGenerator(filter, generator).process(entries, context.getTarget()); | ||
| } | ||
|
|
||
| private String description() { | ||
| return userInfo.getAdditionalAttribute("given_name") | ||
| + " " | ||
| + userInfo.getAdditionalAttribute("family_name"); | ||
| } | ||
| } | ||
| ``` |
There was a problem hiding this comment.
This handler is specific for CAP Java. I guess it should be possible to have a corresponding handler for CAP Node.js
-> https://github.tools.sap/cap/cdsnode/issues/708#issuecomment-677683
There was a problem hiding this comment.
https://github.tools.sap/cap/cdsnode/issues/708#issuecomment-677683
This handler is specific for Order. A corresponding handler in AP Java would be simpler, of course:
@Before
protected void addDraftFields(DraftCreateEventContext context, List<Order> orders) {
orders.forEach(o -> o.setInProcessByUserDescription(description()));
}
private String description() {
return userInfo.getAdditionalAttribute("given_name")
+ " "
+ userInfo.getAdditionalAttribute("family_name");
}There was a problem hiding this comment.
please check if this looks good now :)
|
|
||
| **2. Register a handler** on draft events across all draft services to populate the field: | ||
|
|
||
| This is how the handler could look for CAP Java: |
There was a problem hiding this comment.
| This is how the handler could look for CAP Java: | |
| This is how the handler could look for CAP Java that fills in the user decription for the draft-enabled entity `Orders`: |
| @Autowired private UserInfo userInfo; | ||
|
|
||
| @Before | ||
| protected void addDraftFields(DraftCreateEventContext context, List<Order> orders) { |
There was a problem hiding this comment.
| protected void addDraftFields(DraftCreateEventContext context, List<Order> orders) { | |
| protected void addDraftFields(DraftCreateEventContext context, List<Orders> orders) { |
|
|
||
| ```javascript | ||
| srv.on('PATCH', Order, req => { | ||
| req.data.LastChangedByUserDescription = req.user.attr.firstName + ' ' + req.user.attr.lastName |
There was a problem hiding this comment.
There are three striking differences compared to the Java handler:
- the Java handler handles multiple orders whereas this handler handles a single order
- the Java handler changes
InProcessByUserDescriptionwhereas this handler changesLastChangedByUserDescription - the Java handlers uses the claims
given_nameandfamily_namewheras this handler usesfirstNameandlastName
I think this needs to be clarified.
There was a problem hiding this comment.
This proposal by @schiwekM for CAP Node.js used givenName and familyName.
There was a problem hiding this comment.
OK. Sadly we can't have the tip at line 535 for both runtimes..
There was a problem hiding this comment.
@agoerler harmonized javascript and java version.
Summary
java/fiori-drafts.mdinto the sharedguides/uis/fiori.mdunder the Fiori Draft Support section::: warning Only Java(consistent with how other Java-only features are marked in that file)#draft-user-description) with a.learn-morelink pointing to the new locationCloses https://github.wdf.sap.corp/cds-java/home/issues/2972