我使用 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);
有没有办法做到这一点?