3

我使用 VDM 生成器为 S/4 中的自定义 OData 服务创建客户端类。我正在尝试使用生成的 *Service 类从实体集中获取信息,使用自定义$filter$expand参数,但似乎没有办法这样做。(FluentHelperRead该类没有任何用于定义自定义参数的方法,如ODataQueryBuilderhas)。

现在这就是我正在使用的(它有效):

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

有没有办法做到这一点?

4

1 回答 1

0

鉴于您的元数据,您的 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);
于 2018-11-15T19:56:39.910 回答