Skip to content
Merged
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
7 changes: 3 additions & 4 deletions app/admin/fiori-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ annotate AdminService.Books with @(UI : {
Label : '{i18n>Admin}',
Target : '@UI.FieldGroup#Admin'
},
{
// TODO: should work dynamically
@UI.Hidden,
{
$Type : 'UI.ReferenceFacet',
Label : '{i18n>Contents}',
Target : 'contents/@UI.PresentationVariant'
Target : 'contents/@UI.PresentationVariant',
@UI.Hidden: { $edmJson: { $Path: '/Info/hideTreeTable' } }
}
],
FieldGroup #General : {Data : [
Expand Down
5 changes: 5 additions & 0 deletions srv/admin-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ service AdminService @(requires: 'admin') {
entity Upload @odata.singleton {
csv : LargeBinary @Core.MediaType: 'text/csv';
}

@cds.persistence.skip
@readonly entity Info @odata.singleton {
hideTreeTable: Boolean;
}
}

// Deep Search Items
Expand Down
18 changes: 14 additions & 4 deletions srv/src/main/java/my/bookshop/handlers/AdminServiceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.function.Supplier;
import java.util.stream.Stream;

import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import com.sap.cds.Result;
Expand All @@ -28,6 +29,7 @@
import com.sap.cds.services.ErrorStatuses;
import com.sap.cds.services.EventContext;
import com.sap.cds.services.ServiceException;
import com.sap.cds.services.cds.CdsReadEventContext;
import com.sap.cds.services.cds.CdsUpdateEventContext;
import com.sap.cds.services.cds.CqnService;
import com.sap.cds.services.draft.DraftCancelEventContext;
Expand All @@ -46,6 +48,8 @@
import cds.gen.adminservice.BooksAddToOrderContext;
import cds.gen.adminservice.BooksCovers;
import cds.gen.adminservice.Books_;
import cds.gen.adminservice.Info;
import cds.gen.adminservice.Info_;
import cds.gen.adminservice.OrderItems;
import cds.gen.adminservice.OrderItems_;
import cds.gen.adminservice.Orders;
Expand All @@ -64,17 +68,16 @@
class AdminServiceHandler implements EventHandler {

private final AdminService.Draft adminService;

private final PersistenceService db;

private final Messages messages;

private final CqnAnalyzer analyzer;
private final Environment env;

AdminServiceHandler(AdminService.Draft adminService, PersistenceService db, Messages messages, CdsModel model) {
AdminServiceHandler(AdminService.Draft adminService, PersistenceService db, Messages messages, CdsModel model, Environment env) {
this.adminService = adminService;
this.db = db;
this.messages = messages;
this.env = env;

// model is a tenant-dependant model proxy
this.analyzer = CqnAnalyzer.create(model);
Expand Down Expand Up @@ -301,6 +304,13 @@ public void restoreCoversUpId(CqnStructuredTypeRef ref, BooksCovers cover) {
cover.setUpId((String) analyzer.analyze(ref).rootKeys().get(Books.ID));
}

@On(event = CqnService.EVENT_READ, entity = Info_.CDS_NAME)
Copy link
Member

@mofterdinger mofterdinger Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be shortened to:

Suggested change
@On(event = CqnService.EVENT_READ, entity = Info_.CDS_NAME)
@On(entity = Info_.CDS_NAME)

CdsReadEventContext implies a read event

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, or we remove CdsReadEventContext from the signature, as it is not used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, also fine with me. I didn't recognize the auto merge, sorry.

public Info readInfo(CdsReadEventContext context) {
Info info = Info.create();
info.setHideTreeTable(!env.matchesProfiles("cloud"));
return info;
}

private Supplier<ServiceException> notFound(String message) {
return () -> new ServiceException(ErrorStatuses.NOT_FOUND, message);
}
Expand Down