1

所以这可能是一个简单的问题,但不知何故我无法理解它。我正在尝试使用 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?我想出的显然不是。我在使用 fluent API 导航到扩展实体时遇到了麻烦。

有任何想法吗?

4

1 回答 1

1

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

遗憾的是,无法过滤SAP OData V2 服务端点的扩展实体。一个后备策略是直接查询实体集合 ( leaf ) 中的“过滤”项目并运行额外的 OData 请求以遍历您的原始实体 ( root )。

在您的情况下,我建议直接查询, 以通过AddressIdAddressEmailAddress解析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;
}
于 2019-05-16T08:52:20.970 回答