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.
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
add a comment |
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
Could you share the Metadata of your OData service?
– Sander Wozniak
Nov 14 '18 at 7:08
add a comment |
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
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
java s4sdk
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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);
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 byone 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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
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 byone 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
add a comment |
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);
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 byone 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
add a comment |
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);
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);
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 byone 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
add a comment |
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 byone 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Could you share the Metadata of your OData service?
– Sander Wozniak
Nov 14 '18 at 7:08