发布于2021-08-03 08:32 阅读(877) 评论(0) 点赞(15) 收藏(0)
我使用 VDM 生成器为 S/4 中的自定义 OData 服务创建客户端类。我正在尝试使用生成的 *Service 类从实体集中获取信息,使用自定义$filter
和$expand
参数,但似乎没有办法这样做。(FluentHelperRead
该类没有任何定义自定义参数的方法,就像ODataQueryBuilder
has 一样)。
现在这就是我正在使用的(它有效):
/**
* Query the I_MaintenancePlan entity set filtered by a list of Maint.Plan IDs
* (The navigation property to_CallHistory will be preloaded via $expand)
*/
public List<MaintenancePlan> getMaintenancePlansById(final Iterable<String> maintPlanIds)
throws ODataException {
// Build lightweight $filter with the IDs
String[] filterParts = StreamSupport.stream(maintPlanIds.spliterator(), false)
.map(e -> String.format("MaintenancePlan eq '%s'", StringUtils.urlEncode(e)))
.toArray(String[]::new);
if (filterParts.length == 0)
return new ArrayList<>(0);
String filter = String.join(" or ", filterParts);
ErpConfigContext erpConfig = new ErpConfigContext(DESTINATION_NAME);
List<MaintenancePlan> result = ODataQueryBuilder.withEntity(ZCUSTOMODATASRVService.DEFAULT_SERVICE_PATH, "I_MaintenancePlan")
.withoutMetadata()
.expand("to_CallHistory")
.param("$filter", filter)
.withHeader("sap-client", erpConfig.getSapClient().getValue())
.withHeader("sap-language", erpConfig.getLocale().getLanguage())
.build()
.execute(erpConfig)
.asList(MaintenancePlan.class);
return result;
}
(ZCUSTOMODATASRVService
并且MaintenancePlan
是生成的 VDM 类)
这是我想使用的(仅使用 VDM 类):
ZCUSTOMODATASRVService service = new DefaultZCUSTOMODATASRVService();
List<MaintenancePlan> result = service.getAllMaintenancePlan()
.param("$filter", filter)
.param("$expand", "to_CallHistory")
.execute(erpConfig);
有没有办法做到这一点?
根据您的元数据,您的 VDM 调用可能如下所示:
List<MaintenancePlan> =
new DefaultZCUSTOMODATASRVService()
.getAllMaintenancePlan()
.filter(MaintenancePlan.CALL_HORIZON.eq("xyz"))
.select(MaintenancePlan.TO_CALL_HISTORY)
.execute(erpConfig);
您可以通过嵌套选择进一步扩展或减少投影:
List<MaintenancePlan> result =
new DefaultZCUSTOMODATASRVService()
.getAllMaintenancePlan()
.filter(MaintenancePlan.CALL_HORIZON.eq("xyz"))
.select(MaintenancePlan.TO_CALL_HISTORY
.select(MaintenancePlanCallHistory.INDICATOR,
MaintenancePlanCallHistory.MAINTENANCE_PLAN
)
)
.execute(erpConfig);
作者:黑洞官方问答小能手
链接:http://www.javaheidong.com/blog/article/254442/b41d5249bfe797176822/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!