Perform filter on expanded entity with SAP Cloud SDK

柔情痞子 提交于 2021-01-28 12:19:00

问题


So this might be an easy one, but I somehow can't wrap my head around it. I am trying to find a business partner by its e-mail address using the SAP Cloud SDK.

This is what I have so far:

final List<BusinessPartner> businessPartners = new DefaultBusinessPartnerService()
                        .getAllBusinessPartner()
                        .select(BusinessPartner.BUSINESS_PARTNER,
                                BusinessPartner.TO_BUSINESS_PARTNER_ADDRESS
                                        .select(BusinessPartnerAddress.TO_EMAIL_ADDRESS
                                                .select(AddressEmailAddress.SEARCH_EMAIL_ADDRESS)))
                        .filter(AddressEmailAddress.SEARCH_EMAIL_ADDRESS.eq(email)) //something like this?
                        .top(10)
                        .execute();

Now, how can I perform a filter operation on the expanded entity AddressEmailAddress? The one I came up with obviously doesn't. I have troubles navigating to the expanded entity using the fluent API.

Any ideas?


回答1:


Since my proposal worked for you. Let me rephrase the comment as answer.

Unfortunately it's not possible to filter on expanded entities for SAP OData V2 service endpoints. A fallback strategy would be to directly query for the "filtered" item in the entity collection (leaf) and run additional OData requests to traverse to your original entity (root).

In your case, I would recommend querying directly for the AddressEmailAddress, to resolve BusinessPartnerAddress by the AddressId. Next step is to resolve BusinessPartner by the businessPartner field, e.g.

public List<BusinessPartner> getBusinessPartnersByEmail(
    @Nonnull BusinessPartnerService service,
    @Nonnull String email
)
    throws ODataException
{
    List<AddressEmailAddress> emailAddresses = service
        .getAllAddressEmailAddress()
        .filter(AddressEmailAddress.SEARCH_EMAIL_ADDRESS.eq(email))
        .execute();

    List<BusinessPartnerAddress> addresses = new LinkedList<>();
    for( AddressEmailAddress emailAddress : emailAddresses ) {
        addresses.addAll(
            service
                .getAllBusinessPartnerAddress()
                .filter(BusinessPartnerAddress.ADDRESS_ID.eq(emailAddress.getAddressID()))
                .execute());
    }

    List<BusinessPartner> businessPartners = new LinkedList<>();
    for( BusinessPartnerAddress address : addresses ) {
        businessPartners.add(service.getBusinessPartnerByKey(address.getBusinessPartner()).execute());
    }

    return businessPartners;
}


来源:https://stackoverflow.com/questions/56144905/perform-filter-on-expanded-entity-with-sap-cloud-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!