1

I've created a project with CAP NG where I'm using the VDM to extract BusinessPartners from the ES5 backend located here https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/. I imported the EDMX successfully and also the classes are generated with VDM. However if I try to get the methods from BusinessPartner class, many "set" methods are not exposed, as you can see from this picture: enter image description here

If I try to manually create the BusinessPartner entities like in this piece of code:

    @On(event = CdsService.EVENT_READ, entity = "CatalogService.BusinessPartner")
public void getBusinessPartners(CdsReadEventContext context) {
    log.info("Entering " + getClass().getSimpleName() + ":getBusinessPartners");
    System.out.println("Entering " + getClass().getSimpleName() + ":getBusinessPartners");

    // Get name of destination for ECC
    final String DESTINATION_HEADER_KEY = "es5";

    final Map<Object, Map<String, Object>> result = new HashMap<>();

    try {
        HttpDestination dest = DestinationAccessor.getDestination(DESTINATION_HEADER_KEY).asHttp();

        final List<BusinessPartner> businessPartners = new DefaultGWSAMPLEBASICService().getAllBusinessPartner()
                .top(5).executeRequest(dest);

        final List<cds.gen.catalogservice.BusinessPartner> capBusinessPartners = new ArrayList<>();

        int i = 0;
        for (final BusinessPartner bp : businessPartners) {
            final cds.gen.catalogservice.BusinessPartner capBusinessPartner = com.sap.cds.Struct
                    .create(cds.gen.catalogservice.BusinessPartner.class);

                i = i + 1;
                capBusinessPartner.setBusinessPartnerID("010000000" + i);
                capBusinessPartner.setCompanyName("SAP");
                capBusinessPartner.setEmailAddress("info@acme.com");
                capBusinessPartner.setPhoneNumber("474848848");

            // capBusinessPartner.setBusinessPartnerID(bp.);
            // capBusinessPartner.setFirstName(s4BusinessPartner.getFirstName());
            // capBusinessPartner.setSurname(s4BusinessPartner.getLastName());
            // capBusinessPartner.setId(s4BusinessPartner.getBusinessPartner());
            // capBusinessPartner.setSourceDestination(destinationName);

            capBusinessPartners.add(capBusinessPartner);
        }

        capBusinessPartners.forEach(capBusinessPartner -> {
            result.put(capBusinessPartner.getBusinessPartnerID(), capBusinessPartner);
        });

    } catch (Exception e) {
    log.info(e.getMessage());
    System.out.println(e.getMessage());
    }

    context.setResult(result.values());

}

they are simply not retrieve. I just get a blank page: enter image description here My project is here https://github.com/simfer/myspringbootapp and I'm using SAP Business Application Studio on Trial Landscape.

Simmaco

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
  • Could you update your question to make it more clear on which class you are lacking what? I believe what you were lacking were getters, not setters as you write in your question? Just to make it clear for other people stumbling about this as well. – MatKuhr Nov 13 '20 at 09:28
  • By using the "Lombok" extension I've been able to have the getters. Unfortunately here it's not easy to publish answers because the length of messages is short. I cannot add entire logs. – Simmaco Ferriero Nov 13 '20 at 11:30

2 Answers2

0

You need a dependency on Lombok. The getters for the Cloud SDK Business Partner are being generated by the Lombok annotation @Getter. Add the dependency as described here.

To make it visible in your IDE you often need a plugin as Alex pointed out in his answer.

MatKuhr
  • 505
  • 4
  • 13
  • Hi, I've changed the service as you can see from the updated file and I checked that the Lombok is already in place as you can see here https://github.com/simfer/myspringbootapp/blob/master/srv/pom.xml. Anyway the result is always the same. – Simmaco Ferriero Nov 12 '20 at 18:04
0

Unfortunately the Cloud SDK generator generates code that is dependent on Lombok annotations and the processing of them. Until we have loosened the dependency, you will need to add "Lombok" to your VS Code instance:

  • In the left panel, click on Open VSX Registry, search for "lombok", click "install".

  • A dialog will popup in the bottom-right corner, confirm to restart the application. After initialization the missing methods should appear.

Extensions: Open VSX Registry

Alexander Dümont
  • 903
  • 1
  • 5
  • 9
  • Hi Alexander, thanks for your help. I've added the "Lombok" extension to the BAS and adapted the Java service code as you can see from my repository. However, when I run the service I get no data and below I get the following error: INFO 6 --- [nio-8080-exec-9] c.m.handlers.CatalogServiceHandler : HTTP response code of OData service request contains an error. 2020-11-13T09:22:58.31+0100 [APP/PROC/WEB/0] OUT HTTP response code of OData service request contains an error. – Simmaco Ferriero Nov 13 '20 at 08:33
  • That means that the OData service you called responded with an error. Check the docs on how to [handle OData errors with the Cloud SDK](https://sap.github.io/cloud-sdk/docs/java/features/odata/use-typed-odata-v2-client-in-sap-cloud-sdk-for-java#error-handling). – MatKuhr Nov 13 '20 at 09:19
  • I've updated the code to catch the ODataException and also increased the log level by setting the environment variable SET_LOGGING_LEVEL: '{ROOT: DEBUG, com.sap.cloud.sdk: DEBUG, customer: DEBUG}'. However the output log is always the same. The error says "HTTP response code of OData service request contains an error.", but I don't see a way to get more information about the error. – Simmaco Ferriero Nov 13 '20 at 10:23
  • Do you log out the error object you obtain by invoking `getError()` on the exception? The error should have a message, odata error code and probably some content in "innererror" – MatKuhr Nov 13 '20 at 10:55
  • First of all the ODataServiceErrorException is not available. So I used the other two ODataDeserializationException and ODataResponseException, but no further information got from the error. – Simmaco Ferriero Nov 13 '20 at 11:28
  • I see something different if I change the annotation from @On(event = CdsService.EVENT_READ, entity = "CatalogService.BusinessPartner") to @On(event = CdsService.EVENT_READ, entity = "BusinessPartner"). I don't know why but in this case I get a different error: SQLException executing >>SELECT T0.CompanyName, T0.BusinessPartnerID, T0.PhoneNumber, T0.EmailAddress FROM CatalogService_BusinessPartner T0 ORDER BY T0.BusinessPartnerID LIMIT ? with parameters('LOCALE' = 'en')<< It's not clear at all which is the correct form to use. If you clone my repository you can check by yourself. – Simmaco Ferriero Nov 13 '20 at 11:28
  • Could you please create a new question for this because it's unrelated to the original question. And in that please differentiate which call exactly is throwing the exceptions. – MatKuhr Nov 13 '20 at 12:41
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/224526/discussion-between-simmaco-ferriero-and-matkuhr). – Simmaco Ferriero Nov 13 '20 at 13:30