[英]Use parameters $filter and $expand with VDM generated classes
I used the VDM generator to create client classes for a custom OData service in S/4. 我使用VDM生成器为S / 4中的自定义OData服务创建客户端类。 I'm trying to use the generated *Service class to get information from an Entity Set, using custom
$filter
and $expand
parameters, but there doesn't seem to be a way to do so. 我正在尝试使用生成的* Service类从实体集中获取信息,使用自定义
$filter
和$expand
参数,但似乎没有办法这样做。 (The FluentHelperRead
class doesn't have any method for defining custom parameters, like the ODataQueryBuilder
has). (
FluentHelperRead
类没有任何定义自定义参数的方法,如ODataQueryBuilder
具有的)。
Right now this is what I'm using (it works): 现在这就是我正在使用的(它的工作原理):
/**
* 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
and MaintenancePlan
are generated VDM classes) (
ZCUSTOMODATASRVService
和MaintenancePlan
是生成的VDM类)
This is what I would like to use (using only the VDM classes): 这就是我想要使用的(仅使用VDM类):
ZCUSTOMODATASRVService service = new DefaultZCUSTOMODATASRVService();
List<MaintenancePlan> result = service.getAllMaintenancePlan()
.param("$filter", filter)
.param("$expand", "to_CallHistory")
.execute(erpConfig);
Is there any way to do this? 有没有办法做到这一点?
Given your metadata, your VDM call could look like this: 根据您的元数据,您的VDM调用可能如下所示:
List<MaintenancePlan> =
new DefaultZCUSTOMODATASRVService()
.getAllMaintenancePlan()
.filter(MaintenancePlan.CALL_HORIZON.eq("xyz"))
.select(MaintenancePlan.TO_CALL_HISTORY)
.execute(erpConfig);
You could expand further or reduce the projection via nested selects: 您可以通过嵌套选择进一步扩展或缩小投影:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.