使用 SAP Cloud SDK 对扩展实体执行筛选

Perform filter on expanded entity with SAP Cloud SDK

所以这可能是一个简单的问题,但我不知何故无法理解它。 我正在尝试使用 SAP Cloud SDK 通过电子邮件地址查找业务合作伙伴。

这是我目前拥有的:

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();

现在,如何对展开的实体进行筛选操作AddressEmailAddress?我想出的那个显然没有。我在使用流畅 API 导航到扩展实体时遇到问题。

有什么想法吗?

因为我的建议对你有效。让我将评论改写为答案。

遗憾的是,无法对 SAP OData V2 服务端点的 expanded 实体进行过滤。后备策略是直接查询实体集合中的 "filtered" 项 (leaf) 和 运行 额外的 OData 请求以遍历到您的原始实体 (root).

对于您的情况,我建议直接查询 AddressEmailAddress,以通过 AddressId 解析 BusinessPartnerAddress。下一步是通过 businessPartner 字段解析 BusinessPartner,例如

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;
}