In this CodeLab, you will enhance sample code to learn more about integrating the S/4HANA Cloud SDK into an application. You will investigate the sample code and perform your own additions to the implementation of a class to retrieve business partners.

What you'll learn

In this step, you will investigate how to build queries to SAP S/4HANA from the Java backend.

First, you will retrieve the list of business partners for the list view in the application. Second, you will take a look at the query retrieving detailed data of a single business partner by ID.

Start the development of queries by looking into the class BusinessPartnerServlet. This is the servlet exposing the business partner APIs.

Looking into the servlet, we can see that the main functionality is moved out into the commands GetAllBusinessPartnersCommand and GetSingleBusinessPartnerByIdCommand.

GetAllBusinessPartnersCommand should return a list of available business partners in SAP S/4HANA system.

The class is almost fully implemented, but the most important part - SAP S/4HANA integration - is left for you to complete.

Your task: Implement the execute method that queries SAP S/4HANA and returns a response.

Here are some hints to help you to understand the required code:

Hint: your final implementation should look similar to:

return service.getAllBusinessPartner().select(BusinessPartner.BUSINESS_PARTNER,
            BusinessPartner.FIRST_NAME, BusinessPartner.LAST_NAME)
            .filter(BusinessPartner.BUSINESS_PARTNER_CATEGORY.eq(CATEGORY_PERSON))
            .execute();

Now, also take a look at the command GetSingleBusinessPartnerByIdCommand.

It was already implemented for you.

Can you find out how the OData "expand" method can be implemented using the Virtual Data Model of the SAP S/4HANA Cloud SDK?

Hint: addresses of business partners are retrieved using expand.

To check whether the queries are implemented correctly, go to the integration-tests folder and remove the @Ignore annotation for the following test: BusinessPartnerServletTest.testGetAll().

Build and run test, on the srv folder and make sure that you get SUCCESS in all the categories shown in the console of WebIDE.

If the unignored test do not show errors, congratulations! You have successfully integrated SAP S/4HANA with your application.

To push your changes to the connected GitHub repository, choose "Git Pane" on the right, choose the files that you have modified, enter the message in the "Commit message" window, and choose commit and push: