Skip to content
Open
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
5 changes: 4 additions & 1 deletion .cdsrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"extensibility": true,
"toggles": true
},
"profile": "with-mtx-sidecar"
"profile": "with-mtx-sidecar",
"cdsc": {
"draftUserDescription": true
}
}
34 changes: 34 additions & 0 deletions srv/src/main/java/my/bookshop/handlers/UserDescriptionHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package my.bookshop.handlers;

import com.sap.cds.CdsData;
import com.sap.cds.CdsDataProcessor;
import com.sap.cds.services.draft.DraftCreateEventContext;
import com.sap.cds.services.draft.DraftService;
import com.sap.cds.services.handler.EventHandler;
import com.sap.cds.services.handler.annotations.Before;
import com.sap.cds.services.handler.annotations.ServiceName;
import com.sap.cds.services.request.UserInfo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@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");
}
}
13 changes: 13 additions & 0 deletions srv/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@ cds:
password: admin
roles:
- admin
additional:
given_name: Paul
family_name: Müller
attributes:
businessPartner:
- "10401010"
minad:
password: minad
roles:
- admin
additional:
given_name: Emma
family_name: Maier
Comment thread
agoerler marked this conversation as resolved.
attributes:
businessPartner:
- "1000020"
user:
password: user
server.servlet.encoding:
Expand Down