使用参数 $filter 和 $expand 生成 VDM 类

Use parameters $filter and $expand with VDM generated classes

我使用 VDM 生成器为 S/4 中的自定义 OData 服务创建了客户端 classes。 我正在尝试使用生成的 *Service class 从实体集中获取信息,使用自定义 $filter$expand 参数,但似乎没有办法所以。 (FluentHelperRead class 没有任何定义自定义参数的方法,而 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;      
}

(ZCUSTOMODATASRVServiceMaintenancePlan 生成 VDM classes)

这是我想使用的(仅使用 VDM classes):

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);