cancel
Showing results for 
Search instead for 
Did you mean: 

Enhancements to CAP Java Multitenant sample

john_barrow
Product and Topic Expert
Product and Topic Expert

Hi - I'm using the Java CAP sample to implement my own multi-tenant application running on BTP. So far everything is working as expected 🙂

I need to add some features that aren't covered in the sample and am looking for some guidance on how to achieve:

1. Programmatically create a custom route for the newly subscribed tenant. From a Node.js sample it looks like this is possible via a number of REST calls to different Cloud Foundry APIs. Is this also how it needs to be done from a CAP Java application also? Any guides on how to do this?

2. In the @After("Subscribe") event, I'd like to persist some tenant-specific information into the newly created tenant HDI container. It seems like i need to add the user/tenant context to be able to persist to the tenant schema, but I'm not sure how to do this. Any pointers on how to do this from CAP Java?

Once i have this working I would be happy to contribute it back to the sample application.

Accepted Solutions (0)

Answers (1)

Answers (1)

john_barrow
Product and Topic Expert
Product and Topic Expert
0 Kudos

To answer question 2, this code does what i need:

@Autowired
private PersistenceService persistenceService;

@After(event = MtSubscriptionService.EVENT_SUBSCRIBE)
public void afterSubscription(MtSubscribeEventContext context) {
   context.getCdsRuntime().requestContext().modifyUser(user -> user.setTenant(context.getTenantId())).run(
      newContext -> {
         persistenceService.run(Insert.into(<my entity>.class).entries(<data to insert>));
      }
   );
}
dasriyan
Explorer
0 Kudos

Hello john.barrow,

I trying to build a multi tenant application using CAP. My requirement is similar. I want to insert a few records after tenant subscription event. But I am not using CDS. So can please help me in figuring out how to do the same using JDBCTemplate or Datasource