I’m currently using the IS 4.6. I have a record list in my flow service that I need to sort so that the output will be in the correct order. I will have records in the list that have the same key value(ShipUnit). I’m not a JAVA developer but I am very good with the building of flow services. There are no built in functions for sorting in webMethods. Any suggestions?
// pipeline
pipelineCursor = pipeline.getCursor();
IDataUtil.put( pipelineCursor, “sorted”, sortedItemList==null ? “false” : “true”);
pipelineCursor.destroy();[/highlight]
IDataUtil is a class defined in the API. You can look at the javadoc for it in the IS API stuff.
The only tricky part is the COMPARE_TYPE_*. I couldn’t get anything other than COMPARE_TYPE_COLLATION to work. The fourth parm to sortIDataArrayByKey is documented to be “pattern - A String specifying the pattern to sort by.” but I can’t for the life of me figure out what patterns are expected. Thus, this service only does string-based sorting. Numeric sorting won’t work right.
Can anyone please explain what the compareType in the method sortIDataArrayByKey of class IDataUtil means particularly the IDataUtil.COMPARE_TYPE_EQUALS and IDataUtil.COMPARE_TYPE_COLLATION types. Also what pattern strings should be used for compareType NUMERIC and EQUALS. So far I can only get it to work on types IDataUtil.COMPARE_TYPE_COLLATION an IDataUtil.COMPARE_TYPE_TIME. Thanks.
Here’s an explanation I received from tech support.
I received an explanation on this from our
development team:
dataArray
the IData Array to be sorted.
key
the key to sort by
compareType
supports String and Date comparation. Supported
values: IDataUtil.COMPARE_TYPE_COLLATION and
IDataUtil.COMPARE_TYPE_TIME. Not supported are
IDataUtil.COMPARE_TYPE_EQUALS and
IDataUtil.COMPARE_TYPE_NUMERIC
pattern
The pattern of the date format (used for
COMPARE_TYPE_TIME). Default pattern if pattern is
null is “MM/dd/yyyy hh:mm:ss a”. Pattern is used
to turn the dates into longs, then the longs are
turned into strings so that in a COMPARE_TYPE_TIME
sort the sort is truely by time and not by the
formatted representation of time.
That’s right, the input list is sorted in place, per the comments:
itemList; record list to be sorted in-place
To create a new list, you’ll need to create a deep clone of your list. Depending on the version of IS you have, I believe there is a deep clone method somewhere but not sure where.
Hello,
Did try to add the Cloning, but ended with null pointer exception when running the service. The java code is getting compiled without errors. I am working on Version 4.6.
Has anyone seen peculiar behavior sorting record lists using a double as the key field?
In some testing today, I have seen inconsistent instances in which the array element with the max key value is sorted first in the list. The rest of the sorted array appears to be correct.
I suppose this could be an example of unsupported compare types since the only supported types appear to be String and Time.
Has anyone attempted to extend an IData to implement the java Comparator interface so that you could simply sort an IData array?
Has anyone implemented a record list sort that sorts on more than one key?
About the sorting, if you want to sort Documents in a meaningful way, try to create a Comparator and Comparable class as a inner class in a Java service. This is a fast & stable manner to sort in Java. Takes a little coding (see the Java tutorial on how to use Comparable/Comparator).
About the cloning, the deepClone is doing not too well on performance. The easiest way to clone a document is to convert it to an XML string (thus removing the reference to the original object) & reconvert it back to Document (which results in a new Object). You don’t even need Java for that
Java is great but you should also consider other people working with you on projects. There are still lots of wm users who do not manage Java as well as others. Regarding maintainability, you should always weigh the performance of Java against the maintainability of flows.
I’ve thought about using the comparator/comparable approach in the past, but haven’t had the time to spend sorting this out (pun intended). Do you have any examples of doing this for Values/IData?
Well, that is a bit of an issue. I do have an implementation but if I place that on wMUsers I’m violating Intellectual Property regulations as everything I write is automatically owned by my employer. As this implementation is part of our products & services, it is a bit tricky to give it out.
I do however can give you a number of tips:
Create a class extending Comparable to enclose the Document object.
Create a class extending Comparator to match the Comparable objects.
Make sure that there are no ‘equals’, so == will mean <or>.
Put both classes as inner classes in the ‘shared’ section.
Well, the Values object is more or less deprecated in IS 601, so I have used IData objects.
The Comparable is an object that holds an IData object as one of its attributes. It has a number of getter methods for retrieving the values of the fields you are sorting on.
The Comparator is the functional part. It handles the matching of 2 Comparable objects and decides whether or not object 1 preceeds object 2.
Here Outbound process i am using document in that whenever i am running this its is giving this exception
$errorDump com.wm.lang.flow.FlowException:[ISS.0085.9159] Invalid input. ‘document’ is a required parameter of type IData
$error [ISS.0085.9159] Invalid input. ‘document’ is a required parameter of type IData
$localizedError [ISS.0085.9159] Invalid input. ‘document’ is a required parameter of type IData
$errorType com.wm.lang.flow.FlowException
$service wm.PartnerMgr.flows.MD1070.SAP_WM_LYNX_MD1070:Z_ERP2_MM_EDIDC_SOX_COMPLIANCE
$user skaturi
$time 2005-04-21 13:42:23 EDT
$pipeline Severity 1
PU009_LYNX_CMDC_Publish_v1.ExceptionHandler.docs:PublishError SourceSystem CMDC
InterfacePoint GDS - pubSOxReportRequest
ReferenceID PU009_TBICanonicals_v1.docs.UDMDocuments:RequestDocument
Severity 1
Timestamp 2005/04/21 13:42:21.719
InitiatingDocument Name GDS SOx Report Data Request
Data
Errors Type com.wm.app.b2b.server.ServiceException
SystemCode
Message [ISS.0085.9159] Invalid input. ‘document’ is a required parameter of type IData
SourceSystem Cornerstone
strLastError [ISS.0085.9159] Invalid input. ‘document’ is a required parameter of type IData
tranService wm.PartnerMgr.gateway.transport.B2ButboundProcess
transportParams serverAlias (local)
valueScope SESSION
servicePath PU009_LYNX_GDS_ERP2Subscribe_v1.IDOCReconciliation
service pubIDOCReconRequest
InitiatingDocumentName GDS SOx Report Data Request