简体   繁体   English

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

[英]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) ZCUSTOMODATASRVServiceMaintenancePlan是生成的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.

相关问题 如何告诉wsimport在生成的类中使用httpproxy - How to tell wsimport to use an httpproxy into generated classes 在 SQL 内省生成的 Hibernate 类上使用 Liquibase - Use Liquibase on SQL introspection generated Hibernate classes 在处理器生成的类中使用库 - Use a Library in the processor's generated classes 无法更改生成的类的SOAP客户端请求参数 - Can't change SOAP-Client Request parameters of generated classes 为什么wsimport生成的类需要JAXBElement <ClassName>参数? - Why classes generated by wsimport requires JAXBElement<ClassName> parameters? 在 SAP Cloud SDK 中使用 Java 为 SFSF 生成 VDM:生成的 URI 是错误的 - Generate VDM for SFSF using Java in SAP Cloud SDK: Generated URI is wrong 如何使用Eclipse生成的webservice-client类? - How to use the webservice-client classes generated with Eclipse? 需要使用自定义类而不是在Web服务中生成(通过wsimport) - need to use custom classes instead of generated (by wsimport) in web-services 如何对从WSDL生成的类使用JAXB自动继承? - How to use JAXB autoInheritance for generated classes from WSDL? 有没有办法在 Java 8 运行时中使用 flatc 生成的类? - Is there a way to use flatc generated classes within a Java 8 runtime?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM