I am trying to put an AND condition in xpath match on query parameters, however it's not working.
I am creating multiple stubs, wherein uniqueId could contain likewise digits 00000 or 11111 but serviceName will be different. e.g.In first request, uniqueId is 1000001 and serviceName='ABC', in Second request, uniqueId is again 1000001 and serviceName is 'XYZ'. For both response will be different. I have created three stubs one for service ABC, 2nd for service XYZ and third is default without and xpath match.
When I call service with queryparameter contains uniqueId 1000001 and serviceName ABC or XYZ, everytime I get response of default stub.
Passing xml in query parameter
"queryParameters":{
"xmlreqdoc": {
"matchesXPath" : "//*[[local-name()='uniqueId'][text()[contains(.,'00000')]] AND //*[local-name()='serviceName'][text() = 'ABCDEFGH']]"
}
}
I have created stubs with priority given.. and seems like everytime default one gets returned. Following is the request xml
<?xml version="1.0" encoding="UTF-8"?>
<service>
<serviceHeader>
<userId>XXXX</userId>
<password>XXXXX</password>
<serviceName>ABCDEFGH</serviceName>
</serviceHeader>
<serviceBody>
<subServiceName>add</subServiceName>
<uniqueId>00000</uniqueId>
</serviceBody>
</service>
Below is the stub mapping I have created
{
"priority" : 1,
"request": {
"urlPath": "/testMappings",
"method": "GET",
"headers": {
"Content-Type": {
"equalTo": "application/xml"
},
"Accept": {
"equalTo": "application/xml"
}
},
"queryParameters":{
"xmlreqdoc": {
"matchesXPath" : "//*[//[local-name()='uniqueId'][text()[contains(.,'00000')]] AND //*[local-name()='serviceName'][text() = 'ABCDEFGH']]"
}
}
},
"response": {
"status": 400,
"headers": {
"Content-Type" : "application/xml"
},
"fixedDelayMilliseconds": 500,
"bodyFileName": "ERROR.xml"
}
}
Any help or pointers will be highly appreciated. Thanks in advance!!
You've told us the incorrect syntax that you've tried, but you haven't told us what you're trying to achieve, so we can tell you what you did wrong, but we can't tell you how to make it right.
"//*[//[local-name()='uniqueId'][text()[contains(.,'00000')]] AND //*[local-name()='serviceName'][text() = 'ABCDEFGH']]"
Things that are obviously wrong here:
// followed immediately by a predicate
Unnecessary matching on local-name() when there are no namespaces involved
Unnecessary use of text()
Unnecessary use of contains() when you could use =
AND should be and
Perhaps you want //uniqueId = '00000' and //serviceName = 'ABCDEFGH'
//*[uniqueId[contains(text(),'00000')] and //serviceName='ABCDEFGH']
worked for me.
Related
I have a C# REST API that uses the Hl7.Fhir.R4 library (3.7.0) with a POST method that receives an object of type Hl7.Fhir.Model.Patient:
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[HttpPost()]
public async Task<IActionResult> Post(Patient patient)
{
IActionResult status = NotFound();
...
}
The Patient object has a list of extensions:
"extension": [
{
"url": "http://example.com/fhir/extension/patient/origin",
"valueString": "test"
},
{
"url": "http://example.com/fhir/extension/patient/domainId",
"valueInt" : "10"
}...
When receiving the JSON as a parameter in the POST function, all the fields have a better value than those of type 'Hl7.Fhir.Model.DataType':
Extension[0]
Children: {Hl7.Fhir.Model.Extension.<get_Children>d__17}
ElementId: null
NamedChildren: {Hl7.Fhir.Model.Extension.<get_NamedChildren>d__19}
Extension: Count = 0
TypeName: "Extension"
Url: "http://example.com/fhir/extension/patient/origin"
Value: null
Am I missing some decorator or attribute or simply can't the object be directly deserialized?
Did you use the FhirJsonParser from the library to parse the data? You cannot use a regular JSON parser, because it will not be able to handle the FHIR model correctly.
ETA:
As you now mention in your question, the object cannot be directly deserialized, see first part of my response.
Maybe you can take a look at this project to see how it's done there: https://github.com/brianpos/fhir-net-web-api
I got this type of query
query {
searchRandom (param : MyObjectClass){
city
}
}
How may I set param with the type of MyObjectClass and pass it in the query? To be able to test here?
Use the following query.
query getData($param: MyObjectClass){
searchRandom(param: $param)
city
}
And then go to query variables tab in Graphiql and pass the variable data like this. You have not mention the data types included in MyObjectClass. So use this as an example:
{
"param": {"country": "England", "population": "High" }
}
Then the data should be returned as expected.
--- Additionally ---
If you are running the server, make sure you have set the followings.
You need to create a input object in the GraphQL schema.
input MyObjectClass {
country: String
population: String
}
Then in the resolver you have to pass the object as the argument. (Assuming you are using JavaScript)
const resolvers = {
Query: {
searchRandom: (parent, { param }) => {
var query_data = param
...//your code
return city_name;
},
},
I am not sure whether this addresses your question or not. I hope this answer helps though.
I am trying to use Wiremock to do request matching.\
This matchXPath is correct when i set the value = 1
"bodyPatterns": [{
"matchesXPath" : "//ipgapi:IPGApiOrderRequest[./v1:Transaction=1]",
"xPathNamespaces": {
"ipgapi": "http://ipg/ipgapi",
"v1": "http://ipg/v1"
}
This is the XML
<ipgapi:IPGApiOrderRequest
xmlns:v1="http://ipg/v1"
xmlns:ipgapi="http://ipg/ipgapi">
<v1:Transaction>1</v1:Transaction>
</ipgapi:IPGApiOrderRequest>
But when i wish to change the value from 1 to abc it return not match.
"bodyPatterns": [{
"matchesXPath" : "//ipgapi:IPGApiOrderRequest[./v1:Transaction='abc']",
"xPathNamespaces": {
"ipgapi": "http://ipg/ipgapi",
"v1": "http://ipg/v1"
}
This is the XML
<ipgapi:IPGApiOrderRequest
xmlns:v1="http://ipg/v1"
xmlns:ipgapi="http://ipg/ipgapi">
<v1:Transaction>abc</v1:Transaction>
</ipgapi:IPGApiOrderRequest>
May i know what mistake i made when trying to do abc matching ? Thanks for helping !
I am trying to work Ember with Parse.com using
ember-model-parse-adapter by samharnack.
I add added a function to make multiple work search(like search engine) for which I have defined a function on cloud using Parse.Cloud.define and run from client.
The problem is the Array that my cloud response returns is not compatible with Ember Model because of two attributes they are __type and className. how can I modify the response to get response similar to that i get when I run a find query from client. i.e without __type and className
Example responses
for App.List.find() = {
"results":[
{
"text":"zzz",
"words":[
"zzz"
],
"createdAt":"2013-06-25T16:19:04.120Z",
"updatedAt":"2013-06-25T16:19:04.120Z",
"objectId":"L1X55krC8x"
}
]
}
for App.List.cloudFunction("sliptSearch",{"text" : this.get("searchText")})
{
"results":[
{
"text":"zzz",
"words":[
"zzz"
],
"createdAt":"2013-06-25T16:19:04.120Z",
"updatedAt":"2013-06-25T16:19:04.120Z",
"objectId":"L1X55krC8x",
"__type" : Object, //undesired
"className" : "Lists" //undesired
}
]
}
Thanks Vlad something like this worked for me for array
resultobj = [];
searchListQuery.find({
success: function(results) {
for( var i=0, l=results.length; i<l; i++ ) {
temp = results.pop();
resultobj.push({
text: temp.get("text"),
createdAt: temp.createdAt,
updatedAt: temp.updatedAt,
objectId: temp.id,
words: "",
hashtags: ""
});
}
In your cloud code before you make any response, create and object and extract from it the attributes/members you need and then response it. like so:
//lets say result is some Parse.User or any other Parse.Object
function(result)
{
var responseObj = {};
responseObj.name = responseObj.get("name");
responseObj.age = responseObj.get("age");
responseObj.id = responseObj.id;
response.success(responseObj);
}
on the response side you will get {"result": {"name": "jhon", "age": "26", "id": "zxc123s21"}}
Hope this would help you
how do I pass a 2-dimensional array from javascript to ruby, please? I have this on client side:
function send_data() {
var testdata = {
"1": {
"name": "client_1",
"note": "bigboy"
},
"2": {
"name": "client_2",
"note": "smallboy"
}
}
console.log(testdata);
$.ajax({
type: 'POST',
url: 'test',
dataType: 'json',
data: testdata
});
}
and this on server side:
post '/test' do p params end
but I can't get it right. The best I could get on server side is something like
{"1"=>"[object Object]", "2"=>"[object Object]"}
I tried to add JSON.stringify on client side and JSON.parse on server side, but the first resulted in
{"{\"1\":{\"name\":\"client_1\",\"note\":\"bigboy\"},\"2\":{\"name\":\"client_2\",\"note\":\"smallboy\"}}"=>nil}
while the latter has thrown a TypeError - can't convert Hash into String.
Could anyone help, or maybe post a short snippet of correct code, please? Thank you
You may want to build up the JSON manually, on the javascript side:
[[{'object':'name1'},{'object':'name2'}],[...],[...]]
This will build an array of arrays with objects.
It may look like this:
testdata = [[{
"1": {
"name": "client_1",
"note": "bigboy"
}],
[{"2": {
"name": "client_2",
"note": "smallboy"
}]
}]
I may have something off here, but this should be close to what it would look like.
I'm not sure if this will help but I've got two thoughts: serialize fields and/ or iterate the array.
I managed to get a json array into activerecord objects by setting serializing the fields which had to store sub-arrays:
class MyModel < ActiveRecord::Base
serialize :tags
end
and using an iterator to process the json array:
f = File.read("myarrayof.json")
jarray = JSON.load(f)
jarray.each { |j| MyModel.create.from_json(j.to_json).save }
The conversion back-and-forth seems a bit cumbersome but I found it the most obvious way to handle the array.