Use parameters $filter and $expand with VDM generated classes










3















I used the VDM generator to create client classes for a custom OData service in S/4.
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.
(The FluentHelperRead class doesn't have any method for defining custom parameters, like the ODataQueryBuilder has).



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)



This is what I would like to use (using only the VDM classes):



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?










share|improve this question
























  • Could you share the Metadata of your OData service?

    – Sander Wozniak
    Nov 14 '18 at 7:08















3















I used the VDM generator to create client classes for a custom OData service in S/4.
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.
(The FluentHelperRead class doesn't have any method for defining custom parameters, like the ODataQueryBuilder has).



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)



This is what I would like to use (using only the VDM classes):



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?










share|improve this question
























  • Could you share the Metadata of your OData service?

    – Sander Wozniak
    Nov 14 '18 at 7:08













3












3








3








I used the VDM generator to create client classes for a custom OData service in S/4.
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.
(The FluentHelperRead class doesn't have any method for defining custom parameters, like the ODataQueryBuilder has).



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)



This is what I would like to use (using only the VDM classes):



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?










share|improve this question
















I used the VDM generator to create client classes for a custom OData service in S/4.
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.
(The FluentHelperRead class doesn't have any method for defining custom parameters, like the ODataQueryBuilder has).



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)



This is what I would like to use (using only the VDM classes):



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?







java s4sdk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 7:23









Sander Wozniak

953312




953312










asked Nov 13 '18 at 21:56









Guilherme MaedaGuilherme Maeda

833




833












  • Could you share the Metadata of your OData service?

    – Sander Wozniak
    Nov 14 '18 at 7:08

















  • Could you share the Metadata of your OData service?

    – Sander Wozniak
    Nov 14 '18 at 7:08
















Could you share the Metadata of your OData service?

– Sander Wozniak
Nov 14 '18 at 7:08





Could you share the Metadata of your OData service?

– Sander Wozniak
Nov 14 '18 at 7:08












1 Answer
1






active

oldest

votes


















1














Given your metadata, your VDM call could look like this:



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





share|improve this answer

























  • Here's my service metadata: pastebin.com/8YxpjWwy In my scenario this solution would work if I could do several individual reads (one for each Id I need) in a $batch request, but I also don't know it that's possible with VDM.

    – Guilherme Maeda
    Nov 16 '18 at 2:47












  • Thanks. I've changed my answer based on your concrete metadata. This is how you can retrieve multiple MaintenancePlans at a time. What do you mean by one for each id in a batch request? Do you mean instead of writing a query, you would like to retrieve simply multiple MaintenancePlans by ID in one batch?

    – Philipp Herzig
    Nov 16 '18 at 6:59











  • Thanks for that, it's good to know how I can do multi-level selects with VDM. Answering your question: Yes, I have several MaintenancePlan IDs I need to read. If I have let's say 100 IDs, it's not practical to create a filter tree that deep and send it in a query (I might even have problems with URLs being cropped). Ideally it would be a $batch request with 100 individual reads inside.

    – Guilherme Maeda
    Nov 16 '18 at 16:19











  • Please watch the release notes for updates on this matter. If the other answer was helpful, kindly ask you to accept the answer.

    – Philipp Herzig
    Nov 16 '18 at 19:49











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290124%2fuse-parameters-filter-and-expand-with-vdm-generated-classes%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Given your metadata, your VDM call could look like this:



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





share|improve this answer

























  • Here's my service metadata: pastebin.com/8YxpjWwy In my scenario this solution would work if I could do several individual reads (one for each Id I need) in a $batch request, but I also don't know it that's possible with VDM.

    – Guilherme Maeda
    Nov 16 '18 at 2:47












  • Thanks. I've changed my answer based on your concrete metadata. This is how you can retrieve multiple MaintenancePlans at a time. What do you mean by one for each id in a batch request? Do you mean instead of writing a query, you would like to retrieve simply multiple MaintenancePlans by ID in one batch?

    – Philipp Herzig
    Nov 16 '18 at 6:59











  • Thanks for that, it's good to know how I can do multi-level selects with VDM. Answering your question: Yes, I have several MaintenancePlan IDs I need to read. If I have let's say 100 IDs, it's not practical to create a filter tree that deep and send it in a query (I might even have problems with URLs being cropped). Ideally it would be a $batch request with 100 individual reads inside.

    – Guilherme Maeda
    Nov 16 '18 at 16:19











  • Please watch the release notes for updates on this matter. If the other answer was helpful, kindly ask you to accept the answer.

    – Philipp Herzig
    Nov 16 '18 at 19:49
















1














Given your metadata, your VDM call could look like this:



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





share|improve this answer

























  • Here's my service metadata: pastebin.com/8YxpjWwy In my scenario this solution would work if I could do several individual reads (one for each Id I need) in a $batch request, but I also don't know it that's possible with VDM.

    – Guilherme Maeda
    Nov 16 '18 at 2:47












  • Thanks. I've changed my answer based on your concrete metadata. This is how you can retrieve multiple MaintenancePlans at a time. What do you mean by one for each id in a batch request? Do you mean instead of writing a query, you would like to retrieve simply multiple MaintenancePlans by ID in one batch?

    – Philipp Herzig
    Nov 16 '18 at 6:59











  • Thanks for that, it's good to know how I can do multi-level selects with VDM. Answering your question: Yes, I have several MaintenancePlan IDs I need to read. If I have let's say 100 IDs, it's not practical to create a filter tree that deep and send it in a query (I might even have problems with URLs being cropped). Ideally it would be a $batch request with 100 individual reads inside.

    – Guilherme Maeda
    Nov 16 '18 at 16:19











  • Please watch the release notes for updates on this matter. If the other answer was helpful, kindly ask you to accept the answer.

    – Philipp Herzig
    Nov 16 '18 at 19:49














1












1








1







Given your metadata, your VDM call could look like this:



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





share|improve this answer















Given your metadata, your VDM call could look like this:



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






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 8:54

























answered Nov 15 '18 at 19:56









Philipp HerzigPhilipp Herzig

68048




68048












  • Here's my service metadata: pastebin.com/8YxpjWwy In my scenario this solution would work if I could do several individual reads (one for each Id I need) in a $batch request, but I also don't know it that's possible with VDM.

    – Guilherme Maeda
    Nov 16 '18 at 2:47












  • Thanks. I've changed my answer based on your concrete metadata. This is how you can retrieve multiple MaintenancePlans at a time. What do you mean by one for each id in a batch request? Do you mean instead of writing a query, you would like to retrieve simply multiple MaintenancePlans by ID in one batch?

    – Philipp Herzig
    Nov 16 '18 at 6:59











  • Thanks for that, it's good to know how I can do multi-level selects with VDM. Answering your question: Yes, I have several MaintenancePlan IDs I need to read. If I have let's say 100 IDs, it's not practical to create a filter tree that deep and send it in a query (I might even have problems with URLs being cropped). Ideally it would be a $batch request with 100 individual reads inside.

    – Guilherme Maeda
    Nov 16 '18 at 16:19











  • Please watch the release notes for updates on this matter. If the other answer was helpful, kindly ask you to accept the answer.

    – Philipp Herzig
    Nov 16 '18 at 19:49


















  • Here's my service metadata: pastebin.com/8YxpjWwy In my scenario this solution would work if I could do several individual reads (one for each Id I need) in a $batch request, but I also don't know it that's possible with VDM.

    – Guilherme Maeda
    Nov 16 '18 at 2:47












  • Thanks. I've changed my answer based on your concrete metadata. This is how you can retrieve multiple MaintenancePlans at a time. What do you mean by one for each id in a batch request? Do you mean instead of writing a query, you would like to retrieve simply multiple MaintenancePlans by ID in one batch?

    – Philipp Herzig
    Nov 16 '18 at 6:59











  • Thanks for that, it's good to know how I can do multi-level selects with VDM. Answering your question: Yes, I have several MaintenancePlan IDs I need to read. If I have let's say 100 IDs, it's not practical to create a filter tree that deep and send it in a query (I might even have problems with URLs being cropped). Ideally it would be a $batch request with 100 individual reads inside.

    – Guilherme Maeda
    Nov 16 '18 at 16:19











  • Please watch the release notes for updates on this matter. If the other answer was helpful, kindly ask you to accept the answer.

    – Philipp Herzig
    Nov 16 '18 at 19:49

















Here's my service metadata: pastebin.com/8YxpjWwy In my scenario this solution would work if I could do several individual reads (one for each Id I need) in a $batch request, but I also don't know it that's possible with VDM.

– Guilherme Maeda
Nov 16 '18 at 2:47






Here's my service metadata: pastebin.com/8YxpjWwy In my scenario this solution would work if I could do several individual reads (one for each Id I need) in a $batch request, but I also don't know it that's possible with VDM.

– Guilherme Maeda
Nov 16 '18 at 2:47














Thanks. I've changed my answer based on your concrete metadata. This is how you can retrieve multiple MaintenancePlans at a time. What do you mean by one for each id in a batch request? Do you mean instead of writing a query, you would like to retrieve simply multiple MaintenancePlans by ID in one batch?

– Philipp Herzig
Nov 16 '18 at 6:59





Thanks. I've changed my answer based on your concrete metadata. This is how you can retrieve multiple MaintenancePlans at a time. What do you mean by one for each id in a batch request? Do you mean instead of writing a query, you would like to retrieve simply multiple MaintenancePlans by ID in one batch?

– Philipp Herzig
Nov 16 '18 at 6:59













Thanks for that, it's good to know how I can do multi-level selects with VDM. Answering your question: Yes, I have several MaintenancePlan IDs I need to read. If I have let's say 100 IDs, it's not practical to create a filter tree that deep and send it in a query (I might even have problems with URLs being cropped). Ideally it would be a $batch request with 100 individual reads inside.

– Guilherme Maeda
Nov 16 '18 at 16:19





Thanks for that, it's good to know how I can do multi-level selects with VDM. Answering your question: Yes, I have several MaintenancePlan IDs I need to read. If I have let's say 100 IDs, it's not practical to create a filter tree that deep and send it in a query (I might even have problems with URLs being cropped). Ideally it would be a $batch request with 100 individual reads inside.

– Guilherme Maeda
Nov 16 '18 at 16:19













Please watch the release notes for updates on this matter. If the other answer was helpful, kindly ask you to accept the answer.

– Philipp Herzig
Nov 16 '18 at 19:49






Please watch the release notes for updates on this matter. If the other answer was helpful, kindly ask you to accept the answer.

– Philipp Herzig
Nov 16 '18 at 19:49


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290124%2fuse-parameters-filter-and-expand-with-vdm-generated-classes%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto