Warm tip: This article is reproduced from stackoverflow.com, please click
java sap-cloud-sdk

Getters methods missing on custom VDM object

发布于 2020-04-23 10:49:42

I created a custom business object in S/4Hana Cloud.

custom object screenshot

Then get the metadata, and finally add to my java project.

Now I need to read the table and use some of the fields for subsequent logics.

I retrieve table this way:

cockpitSetupList = new DefaultCscCockpitSetupService().getAllCSCCOCKPIT_SETUP()
                    .orderBy(CSCCOCKPIT_SETUP.COCKPIT_TYPE, Order.ASC)
                    .execute();

I would like to read the value of the fields, so I loop it and read the field value like this:

for (CSCCOCKPIT_SETUP cockpitsetup : allCockpitSetup) {

// read all the product for the sales Organization sent from cockpit setup
    String salesOrganizationInString = 
    String.valueOf(cockpitsetup.SALES_ORGANIZATION);
    allProductsPerSalesOrganization = products.getAllProductSalesPerSalesOrganization(salesOrganizationInString);

But, it does not give the value of the field, but something like:

"com.sunstar.vdm.namespaces.csccockpitsetup.field.CSCCOCKPIT_SETUPField@d6ba2449"

By using whitelisted APIs, for instance, I have getters for each field of the API.

Could you guys tell me why I do not see getter methods on custom VDM objects?

Remarks: I´ve created two additional custom object and none of them brings getters.

Adding the metadata file: [removed to character limit] Adding my POM file:

    <dependencies>
        <dependency>
            <groupId>com.sap.cloud.s4hana.cloudplatform</groupId>
            <artifactId>scp-neo</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sap.cloud.s4hana</groupId>
            <artifactId>s4hana-all</artifactId>
        </dependency>
       <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.sap.cloud</groupId>
            <artifactId>neo-javaee7-wp-api</artifactId>
            <scope>provided</scope>
        </dependency>
         <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>3.0.0.RELEASE</version>
        </dependency>
<!--        commented out to get VDM getters -->
<!--         <dependency>-->
<!--            <groupId>org.projectlombok</groupId>-->
<!--            <artifactId>lombok</artifactId>-->
<!--            <scope>provided</scope>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>1.1.2</version>
        </dependency>
<!--    custom VDM-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
<!--     custom VDM   -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

Also, a list of the methods generated: methods BR, Pietro

Questioner
Pietro Henrique
Viewed
26
MatKuhr 2020-02-09 22:27

I assume you used the generator to generate the VDM based on the metadata. If so and if possible, please share the metadata.

Assuming the above, the field that you are trying to use does not and is not meant to hold any data. It is to be used when building OData requests, so in select and filter operations.

In order to access the data you would indeed need getters on the entity type. Be sure to include lombok as dependency in your project as we use the @Data annotation in the generated code:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
</dependency>

I generated the code locally and I see that the annotation is present on the entity. So there should be getters present. I setup a small project and the following code compiles:

final CSCCOCKPIT_SETUP setup = new CSCCOCKPIT_SETUP();
final String salesOrganization = setup.getSalesOrganization();

If you don't see the methods in your IDE you might need to install or enable a lombok plugin for the linter & autocomplete to work properly.