How to perform Sorting using flow steps in WebMethods (Software AG)? - sorting

I am new to this Middleware and I tried my level best to perform sorting using the flow steps in designer but couldn't make it.Can anybody help me out by giving me direction for how to complete my work?(like the flow steps in order and where i can put the conditions and all)
Thanks.

No need to over-complicate it - use the utilities - pub.document:sortDocuments is what you are looking for.
If you receive stringList as input - convert this into a documentList. This can be done using pub.list:stringListToDocumentList (set the key to 'value')
Use pub.document:sortDocuments to sort the documentList. Remember to specify the key as 'value' once again and compareStringAs as 'numeric'. The order can also be set (ascending/descending)

What do you want to Sort? For Document-Lists you will find a built-in services in the WmPublic Folder.
For String-Lists i would use a Java-Service for Sorting.

Logic behind Sorting in webMethods is same as all other languages. You need LOOP to iterate every string in stringList, BRANCH to compare the two number and then map to the compare result to new StringList.

What format do you have the numbers in? Are they in a flat file or in a string list etc.

Related

How to ignore "stop words" while sorting in MarkLogic?

Is there any way to ignore "stop words" while sorting.
For example:
I have words like
dixit
singla
the marklogic
On sorting in descending order the result should be
singla, the marklogic, dixit
As in the above example the is ignored.
Any way to achieve this?
Update:
Stop word can occur at any place.
for example
the MarkLogic
MarkLogic is the best
the MarkLogic is awesome
while sorting should not consider any stop word in the text.
Above is just a small example to describe the problem.
In actual I am using search:search API.
For sorting, I am using sort-order search options.
The element on which I have to perform sorting is dynamic. There are approx 30-35 elements.
Is there any way to customize the collation at this level like to configure some words (stop words) which will be ignored while sorting.
There is no standard collation URI that is going to do this for you (at least none that I've ever seen). You can do it dynamically, of course, by sorting on the result of a function invocation, but if you want it done efficiently at scale (and available to search:search), then you need to materialize the sortable string into your document. I've often done this as an attribute on the element:
<title sortable="Great Gatsby, The">The Great Gatsby</title>
Then you put a range index on the title/#sortable attribute.
You can also use the "envelope pattern" where materialized metadata like this is maintained in its own section of the document with the original kept in its own section. For things like this, I think it's a bit more elegant to decorate the elements directly, to keep the context.
If I understand your question correctly you're trying to get rid of the definite article when sorting your result-set.
In order to do this you need to use some additional functions and create a 'sort' criteria. My solution would look like this (I'm also including some sample documents so that you can test this just by copy-pasting):
(:
xdmp:document-insert("/peter.xml", <person><firstName>Peter</firstName><lastName>O'Toole</lastName><age>60</age></person>);
xdmp:document-insert("/john.xml", <person><firstName>John</firstName><lastName>Adams</lastName><age>18</age></person>);
xdmp:document-insert("/simon.xml", <person><firstName>Simon</firstName><lastName>Petrov</lastName><age>22</age></person>);
xdmp:document-insert("/mark.xml", <person><firstName>Mark</firstName><lastName>the Lord</lastName><age>25</age></person>);
:)
for $person in /person
let $sort := fn:reverse(fn:tokenize($person/lastName, ' '))[1]
order by $sort
(: return $person :)
return $person/lastName/text()
Notice that now the sort order is going to be
- Adams
- the Lord
- O'Toole
- Petrov
I hope this will help.

Correlating multiple dynamic values

How can I get the value of important id and ValueType?
I have tried using web_save_param_regexp (but unfortunately I don't fully understand how the function works).
I have also tried using web_save_param (with the help of offset and length).
unfortunately once again I cannot get the accurate value some values change in length specially when the total amount values dynamically changes per run.
<important id=\"insertsomevalueshere\" record=\"1\" nucTotal=\"NUC609.40\"><total amount=\"68.75\" currency=\"USD\"/><total amount=\"609.40\" currency=\"USD\"/><out avgsomecost=\"540.65\" ValueType=\"insertsomevalueshere\" containsawesomeness=\"1\" Score=\"-97961\" somedatatype=\"1\" typeofData=\"VAL\" web=\"1\">
Put these lines of code before the line of code which does your web request:
web_reg_save_param_regexp("ParamName=importantid","Regexp=<important id=\\\"(.*?)\\\"",LAST);
web_reg_save_param_regexp("ParamName=ValueType","Regexp= ValueType=\\\"(.*?)\\\"",LAST);
You will then have two stored parameters 'importantid' and 'ValueType'
Dynamic number of elements to correlate? Your path for resubmission is through web_custom_request(). You will need to build the string you need dynamically with the name:value pairs for all of the data which needs to be included.
This path will place a premium on your string manipulation skills in the language of the tool. The default path is through C, but you have other language options if your skills are more refined in another language.

Mockaroo Formulas for random date range using Ruby

I am trying to create a data field using Mockaroo and they say they have Ruby support but I know nothing about Ruby so I am trying to find out how to do a field that will randomly choose between the 3 options.
now() or
now()+days(-1) or
now()+days(-2) or
now()+days(-3)
Idea 1
I was initially thinking something using random like now()+days(this.rand(-3))
Idea 2
I also thought of using or logic like now() or now()+days(-3) or etc...
This answer may end up being different than a typical ruby solution since Mockaroo has their own little API to use too... Appreciate any help that can be given.
Turns out I had to use the random function first and pass in min and max date parameters.
random(now()+days(2), now()+days(-3))

XSLT/ Xpath how to accumulate / get total of a node based on a condition in another node

I need to get two totals CreditCardTotal and CashTotal and have to display them in another tag AccountCost, as shown below.
Basically, I need get the expense amount and check to see if it is a credit card or cash and then add it to the respective total variable. Or if there is a more elegant way please let me know.
I am completely stumped and new to Xpath. Thanks, and will truly appreciate your time and effort.
<ExpenseCatDetail>
<Expense>500</Expense>
<PaymentMethod>CreditCard</PaymentMethod>
<AccountCost>700</AccountCost>
</ExpenseCatDetail>
<ExpenseCatDetail>
<Expense>100</Expense>
<PaymentMethod>Cash</PaymentMethod>
<AccountCost>400</AccountCost>
</ExpenseCatDetail>
<ExpenseCatDetail>
<Expense>200</Expense>
<PaymentMethod>CreditCard</PaymentMethod>
<AccountCost>700</AccountCost>
</ExpenseCatDetail>
<ExpenseCatDetail>
<Expense>300</Expense>
<PaymentMethod>Cash</PaymentMethod>
<AccountCost>400</AccountCost>
</ExpenseCatDetail>
Element construction is not possible with XPath, you would require XQuery for that.
To fetch a single sum, use
sum(//ExpenseCatDetail[PaymentMethod="Cash"]/AccountCost)
and replace "Cash" as needed.
Using XPath 2.0, you could at least calculate both sums in one statement and return a sequence of both values (is usually mapped to an array or similar construct in other programming languages):
(
sum(//ExpenseCatDetail[PaymentMethod="Cash"]/AccountCost),
sum(//ExpenseCatDetail[PaymentMethod="CreditCard"]/AccountCost)
)

data structure to support lookup based on full key or part of key

I need to be able to lookup based on the full key or part of the key..
e.g. I might store keys like 10,20,30,40 11,12,30,40, 12,20,30,40
I want to be able to search for 10,20,30,40 or 20,30,40
What is the best data structure for achieving this..best for time.
our programming language is Java..any pointers for open source projects will be appreciated..
Thanks in advance..
If those were the actual numbers I'd be working with, I'd use an array where a given index contains an array of all records that contain the index. If the actual numbers were larger, I'd use a hash table employed the same way.
So the structure would look like (empty indexes elided, in the case of the array implementation):
10 => ((10,20,30,40)),
11 => ((11,12,30,40)),
12 => ((11,12,30,40), (12,20,30,40)),
20 => ((10,20,30,40), (12,20,30,40)),
30 => ((10,20,30,40), (11,12,30,40), (12,20,30,40)),
40 => ((10,20,30,40), (11,12,30,40), (12,20,30,40)),
It's not clear to me whether your searches are inclusive (OR-based) or exclusive (AND-based), but either way you look up the record groups for each element of the search set; for the inclusive search you find their union, and for the exclusive search you find their intersection.
Since you seen to care about retrieval time over other concerns (such as space), I suggest you use a hashtable and you enter your items several times, once per subkey. So you'd put("10,20,30,40",mydata), then put("20,30,40",mydata) and so on (of course this would be a method, you're not going to manually call put so many times).
Use a tree structure. Here is an open source project that might help ... written in Java :-)
http://suggesttree.sourceforge.net/

Resources