How can we compare two #Rest\RequestParam? - api

I am trying to compare two input values, provided to the request body via API.
Is there a way via Annonations to compare two request params?
i.e.,
* #Rest\RequestParam(
* name="abc",
* strict=true,
* nullable=false
* )
* #Rest\RequestParam(
* name="xyz",
* strict=true,
* nullable=false
* requirements={
* #Assert\EqualTo(
* value="abc"
* )
* }
* )
But above logic will not work because here "xyz" is trying to compare with string "abc" not the request body value provided.

Related

Spring Data JPA Native Query - How to use Postgres ARRAY type as a parameter

I have a native postgresql query (opts - jsonb array):
select * from table users jsonb_exists_any(opts, ARRAY['CASH', 'CARD']);
it works fine in my database console and I'm getting a result:
user1, ['CASH','CARD']
user2, ['CASH']
user3, ['CARD']
but when I want to use it in my spring data jpa application as:
#Query(value = "select * from users where jsonb_exists_any(opts, ARRAY[?1])", nativeQuery = true)
List<Users> findUsers(Set<String> opts);
I'm getting an error:
h.e.j.s.SqlExceptionHelper - SQL Error: 0, SQLState: 42883
h.e.j.s.SqlExceptionHelper - ERROR: function jsonb_exists_any(jsonb,
record[]) does not exist
because that query converts to:
select
*
from
users
where
jsonb_exists_any(opts, ARRAY[(?, ?)])
Is there a way to pass parameters as an array? i.e. without brackets around ?, ?
can you try this :
#Query(value = "select * from users where jsonb_exists_any(opts, string_to_array(?1, ','))", nativeQuery = true)
List<Users> findUsers(String listStringSeparatedByComma);
Notice you have to replace the Set parameter by a String.
this will work:
#Query(value = "with array_query as (select array_agg(value) as array_value from (select (json_each_text(row_to_json(row_values))).value from (values ?1) row_values) col_values)"+
" select * from users where jsonb_exists_any(opts, (select array_value from array_query))", nativeQuery = true)
List<Users> findUsers(Set<String> opts);

Send a second request nb of times as nb of items returned for first request using Karate

I need to send 2 requests in a Scenario Outline. Ex:
Background:
* url 'someurl'
Scenario Outline:
* path <owner_id>, 'cats'
* method get
* status 200
here I need to get ids of cats from response as {"cats": [{"cat_id": "xx"}, {"cat_id": "yy"}...]}
* path <owner_id>, <cat_id>, 'kittens'
* method get
* status 200
Examples:
|owner_id|
|bill_id |
|kate_id | and so on
Is it possible to send the second request (kittens' retrieving) for each cat_id from the first request and this for each owner_id?
I tried another way:
Background:
* url 'someurl'
Scenario Outline:
* def cats = call read('GetCats.feature')
then store cat_ids as here:
* def catsIds = cats.c[*].id (I get an error "javascript evaluation failed: cats.c[*]id, <eval>:1:6 Expected an operand but found *")
OR
* def catsIds = karate.mapWithKey(cats.c[*].id, 'cat_id')
* path <owner_id>, <cat_id>, 'kittens'
* method get
* status 200
Examples:
|owner_id|
|bill_id |
|kate_id | ...
And here is GetCats.feature
Scenario:
* url 'someurl'
* path 'cats'
* method get
* status 200
* def c = response
I was thinking about karate.repeat but can we use it for this case?
Anything is possible, you can call other features, all data is in scope etc.
You made a mistake here, note the $:
* def catsIds = $cats.c[*].id
Refer: https://github.com/intuit/karate#get

Which documentation system uses this format?

#pragma region INFO
/*
* # FUNCTION: GetSubStrBetween
*
* # PARAMETER(s):
* [1st] std::string &in_Str = This paramter takes in a std::string, which
* is the string that contains the unknown sub-string.
*
* [2nd] std::string in_A = This parameter takes in a std::string, which
* will be the beginning point of the unknown sub-string.
*
* [3rd] std::string in_B = This parameter takes in a std::string, which
* happens to be the ending point of the unknown sub-string.
*
* [4th] std::string in_out_SubStr = This parameter takes in a std::string,
* which will contain the unknown sub-string.
*
* [5th] bool in_opt_Append = This optional* parameter takes in either a true
* or false value. If in_opt_Append = true, in_out_SubStr (see 4th
* param.) will append the unknown sub-str. Else, in_out_SubStr will be
* equal to the unknown sub-str. Note: The default value is false.
*
* # RETURN VALUE(s):
* false = This function returns a false value because...
* - The length of in_Str/in_A/in_B is equal to 0.
* - The length of in_A/in_B is greater than or equal to the length
* of in_Str.
* - The length of in_Str is smaller than length of in_A + the length
* of in_B.
* - Unable to find in_A/in_B.
* true = Successfully found and return the unknown sub-str to in_out_SubStr.
*/
#pragma endregion INFO
It's clean and seems like very useful format.
#pragma region <region_name>
#pragma endregion <region_comment>
is simply the collapsible region stuff in Visual Studio, allowing you to collapse or expand blocks when looking at your source in outline mode.
The text inside it is largely irrelevant to Visual Studio and doesn't match the usual suspects like Doxygen, Ghost Doc or the built-in Visual Studio stuff.
Failing notification from the author of that code (unfortunately, they haven't been seen here since May 2013), you may just have to accept they were fastidious about their comments, unless someone comes along who knows the format off the top of their head.

Drupal 7 db_select ORDER BY

I am trying to work out how to convert the order by code bellow that I am currently using in db_query to db_select.
The query sorts users by how well the match the current logged in user. I am also using some WHERE statements to remove users that are totally incompatible before running the rest through the order by calculation to speed up the query, so I don't want to run it as a select expression.
ORDER BY (10*(s.field_smoker_value * :field_smoker_pref_value) +
10*(sp.field_smoker_pref_value * :field_smoker_value) +
15*(p.field_pet_value * :field_pet_pref_value) +
15*(pp.field_pet_pref_value * :field_pet_value) +
5*(c.field_couple_value * :field_couple_pref_value) +
5*(cp.field_couple_pref_value * :field_couple_value))ASC

how to do a select * in jython and get the result

how to do a select * from table in jython and get the result for each row into a list or string.
i know how to do for select counmn_name1 ,column_name2 from table1 but not able to figure out for select *
Please suggest .thanks
If you use JDBC then you can use JDBC ResultSetMetaData interface:
rs = c.executeQuery("SELECT * FROM a_tmp_table")
while (rs.next()):
rsmd = rs.getMetaData()
print('columnCnt: %d' % (rsmd.getColumnCount()))
for i in range(rsmd.getColumnCount()):
print(rs.getString(i + 1))
If you use zxJDBC (comes with Jython) then you can follow the cross-implementation DB-API protocol to execute queries and retrieve results.