我使用 VDM 生成器为 S/4 中的自定义 OData 服务创建客户端类。
我正在尝试使用生成的 *Service 类从实体集中获取信息,使用自定义 $filter
和 $expand
参数,但似乎没有这样做的一种方法。
(FluentHelperRead
类没有任何定义自定义参数的方法,而 ODataQueryBuilder
有)。
现在这就是我正在使用的(有效):
/**
* 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);
关于java - 将参数 $filter 和 $expand 与 VDM 生成的类一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53290124/