Websphere Commerce: Sorting results of <wcf:getData ...> - java

Is there a way to get the IBM Websphere Commerce Foundation framework (WCF) sort data?
E.g. this snippet from a Websphere Commerce JSP file:
<wcf:getData type="com.ibm.commerce.store.facade.datatypes.GeoNodeType[]"
var="geoNodes" varException="geoNodeException" expressionBuilder="findChildGeoNodesByGeoNodeUniqueID">
<wcf:param name="accessProfile" value="IBM_Store_All" />
<wcf:param name="parentUniqueId" value="${provinceId}" />
</wcf:getData>
How would I get this to sort the data by a given data field in GeoNodeType? Can I add something like <wcf:param name="sortBy" value="Description" /> ?

ExpressionBuilder "findChildGeoNodesByGeoNodeUniqueID" from your example is declared in /Stores/WebContent/WEB_INF/config/com.ibm.commerce.store/get-data-config.xml as follows:
<expression-builder>
<name>findChildGeoNodesByGeoNodeUniqueID</name>
<data-type-name>GeoNode</data-type-name>
<expression-template>{_wcf.ap=$accessProfile$}/GeoNode[ParentGeoNodeIdentifier[UniqueID='$parentUniqueId$']]</expression-template>
<param>
<name>accessProfile</name>
<value>IBM_Store_All</value>
</param>
<param>
<name>parentUniqueId</name>
<value></value>
</param>
</expression-builder>
According to expression-builder tag docs, if expression-language is not specified inside expression-builder tag - XPath language is used by default. Unfortunately XPath does not support ordering.
I imagine that you can still implement your own ExpressionBuilder class (I haven't done that), implement any kind of sorting inside this new class, and then specify it in get-data-config.xml

Related

How to split xml to header and items using smooks?

I have a xml file roughly like this:
<batch>
<header>
<headerStuff />
</header>
<contents>
<timestamp />
<invoices>
<invoice>
<invoiceStuff />
</invoice>
<!-- Insert 1000 invoice elements here -->
</invoices>
</contents>
</batch>
I would like to split that file to 1000 files with the same headerStuff and only one invoice. Smooks documentation is very proud of the possibilities of transformations, but unfortunately I don't want to do those.
The only way I've figured how to do this is to repeat the whole structure in freemarker. But that feels like repeating the structure unnecessarily. The header has like 30 different tags so there would be lots of work involved also.
What I currently have is this:
<?xml version="1.0" encoding="UTF-8"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:calc="http://www.milyn.org/xsd/smooks/calc-1.1.xsd"
xmlns:frag="http://www.milyn.org/xsd/smooks/fragment-routing-1.2.xsd"
xmlns:file="http://www.milyn.org/xsd/smooks/file-routing-1.1.xsd">
<params>
<param name="stream.filter.type">SAX</param>
</params>
<frag:serialize fragment="INVOICE" bindTo="invoiceBean" />
<calc:counter countOnElement="INVOICE" beanId="split_calc" start="1" />
<file:outputStream openOnElement="INVOICE" resourceName="invoiceSplitStream">
<file:fileNamePattern>invoice-${split_calc}.xml</file:fileNamePattern>
<file:destinationDirectoryPattern>target/invoices</file:destinationDirectoryPattern>
<file:highWaterMark mark="10"/>
</file:outputStream>
<resource-config selector="INVOICE">
<resource>org.milyn.routing.io.OutputStreamRouter</resource>
<param name="beanId">invoiceBean</param>
<param name="resourceName">invoiceSplitStream</param>
<param name="visitAfter">true</param>
</resource-config>
</smooks-resource-list>
That creates files for each invoice tag, but I don't know how to continue from there to get the header also in the file.
EDIT:
The solution has to use Smooks. We use it in an application as a generic splitter and just create different smooks configuration files for different types of input files.
I just started with Smooks myself. However... your problem sounds identical to this: http://www.smooks.org/mediawiki/index.php?title=V1.5:Smooks_v1.5_User_Guide#Routing_to_File
You will have to provide the output FTL format in whole, that's the downside of using a general purpose tool I guess. Data mapping often includes a lot of what feels like redundancy, one way around this is to leverage convention but that has to be built into the framework.
I don't know smooks, but the simplest solution (with poor performance) would be (to create the Nth file):
copy the whole xml structure
delete all the invoice tags but the Nth one
I don't know how to do that in smooks, that only an idea. In this case you don't need to duplicate the structure of the xml in a freemarker template.

XML Parsing - DOM or SAX - Complex xml with attributes as conditions to access hierarchy in java

<playingTestCodeDetails classCode="ENT" determinerCode="INSTANCE" >
<realmCode code="QD" />
<id assigningAuthorityName="PRMORDCODE" extension="16494" />
<id assigningAuthorityName="TESTNUMINBOOK" extension="16494" />
<code code="16494" codeSystemName="QTIM" displayName="SureSwab Candidiasis" />
<name use=""></name>
<asSeeAlsoCode classCode="ROL" > <!-- Have repeated Seealsocode section for multiple see also codes and stripped names -->
<realmCode code="QD" />
<code code="7600" displayName="Sample See Also Name" ></code>
</asSeeAlsoCode>
<asSeeAlsoCode classCode="ROL" >
<realmCode code="QD" />
<code code="6496" displayName="Sample See Also Name" ></code>
</asSeeAlsoCode>
</playingTestCodeDetails>
<subjectOf typeCode="SBJ">
<realmCode code="QD" />
<order classCode="OBS" moodCode="EVN" >
<realmCode code="QD" />
<performer nullFlavor="" typeCode="PRF"><!-- Have added this to accomodate the UnitCode-->
<performingLocatedEntity classCode="LOCE" nullFlavor="">
<locatedPerformingSite classCode="ORG" determinerCode="INSTANCE">
<id assigningAuthorityName="ASORDERED" extension="16494" />
</locatedPerformingSite>
</performingLocatedEntity>
</performer>
<origin nullFlavor="" typeCode="ORG"> <!-- Have added this to accomodate the Ordering Lab Code-->
<orderingLocatedEntity classCode="LOCE" >
<locatedOrderingSite classCode="ORG" determinerCode="INSTANCE">
<id assigningAuthorityName="PRMORDCODE" extension="16494"/>
<code code="SJC" codeSystemName="QTIM" codeSystem="ORDERINGLABCODE"/>
</locatedOrderingSite>
</orderingLocatedEntity>
</origin>
<pertinentInformation1 typeCode="PERT">
<realmCode code="QD" />
<clinicalInfo classCode="ACT" moodCode="EVN">
<realmCode code="QD" />
<title>Specialitysample1</title>
<text>Conditionsample1</text>
</clinicalInfo>
</pertinentInformation1>
<subjectOf typeCode="SUBJ">
<realmCode code="QD" />
<annotation classCode="ACT" moodCode="EVN" >
<realmCode code="QD" />
<code code="DOSCATNAME"></code>
<text><![CDATA[SureSwab<sup>®</sup>, <em>Candidiasis</em>, PCR]]></text>
</annotation>
</subjectOf>
</subjectOf>
I have a xml looking like above. I want to parse it; what is the best way to parse it?? DOM, SAX ( i have heard of JAXB, XSLT,.... not sure of this two); Can we have a combination of DOM & SAX to parse a XML??
A simple scenario to attain a tag value using attribute access as "code"
like when code=DOSCATNAME in tag then we need to take up data for corresponding tag.
Other scenario is to access tag and get the hierarchy and access extension attribute of when assigningAuthorityName attribute has value PRMORDCODE.
Can the above two scenarios can be achievable using a Parser??
I am a newbie, please understand what i need to parse & suggest me a thought... thanks in advance...
Use JAXB. Create class model and annotate your classes appropriately. The environment will do the rest.
For example you should create class PlayingTestCodeDetails with properties classCode, determinerCode etc.
I will tell you more: you can kindly ask JAXB to generate the classes for you. Start learning from this article: http://www.roseindia.net/jaxb/r/jaxb.shtml
It will take a couple of hours to start but than you will be done in 15 minutes. If you are using DOM you can start in 15 minutes of learning and the coding a couple of days to parse your XML.
It depends on your need which to use.
Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation.
SAX
• Parses node by node
• Doesn’t store the XML in memory
• We cant insert or delete a node
• SAX is an event based parser
• SAX is a Simple API for XML
• doesn’t preserve comments
• SAX generally runs a little faster than DOM
DOM
• Stores the entire XML document into memory before processing
• Occupies more memory
• We can insert or delete nodes
• Traverse in any direction.
• DOM is a tree model parser
• Document Object Model (DOM) API
• Preserves comments
• SAX generally runs a little faster than DOM
If we need to find a node and doesn’t need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory.
These are few parsers:-
woodstox
dom4j
In addition to SAX and DOM there is STaX parsing available using XMLStreamReader which is an xml pull parser.

How would I make custom atom links using RESTEasy?

I'm wondering if (and if so, how) it's possible to make RESTEasy return an object with custom atom links, such as links to next/previous page when paginating, particularly what I want to get is something akin to the following:
<collection>
<start>4</start>
<values>4</values>
<total>20</total>
<item>...</item>
<item>...</item>
<item>...</item>
<item>...</item>
<atom:link rel="next" href="...?page=3"/>
<atom:link rel="previous" href="...?page=1"/>
<atom:link rel="first" href="...?page=1"/>
<atom:link rel="last" href="...?page=5"/>
</collection>
I've worked out how to give links for discovery, but making custom links like this appears to be more complicated, if at all possible.
In the end I've ended up using the <any/> element and creating my own Elements to insert in to the any field of the JAXB objects. That seems to have its own problems, but at least it's a step further.

how to validate dynamic map elements

i have a map and i want to validate in struts 2 validation framework by using expression validation how can i access the elements of the map dynamically?
if Map myMap; how can i validate the map with dynamic key? if mymap has static key like "Salary", i could validate like
<field
name="myMap['Salary']">
<field-validator
type="regex">
<param
name="expression">[0-9]+[.][0-9]+</param>
<message>${getText("errors.validation.number")}</message>
</field-validator>
</field>
thanks,
Helen
There are two ways you can use the myApp in declarative validation.
By using myMap.salary
By using myMap['salary']
You will need to use one of the above notations which is based on how you have your input form fields defined.
For example, if your input form looks something like below then you need to use the . operator as you are using the . operator while defining the name of input field.
<s:form action="sayHello">
<s:textfield name="myMap.salary" label="Salary">
<s:submit/>
</s:form>
If you use [] opertaor for defining the name of input field then use the [] operator to access the property in validator.
So, your validation code above is correct, you just need to define your input field at input form correctly with [] operator.
Hope this helps
Hibernate Validator Framework has a recursive validation feature.
And there is a plugin for Struts2 that uses this:
Full Hibernate Plugin: http://cwiki.apache.org/S2PLUGINS/full-hibernate-plugin.html
I don't think you can do this in the declarative validation. I'd suggest dropping down to the validation method for this, or doing the validation in javascript if you're using the javascript validation that is generated by the framework.

Multiple <application> tags in faces-config.xml

It's a very simple question: can faces-config.xml file have multiple tags (more like SHOULD they have)? I'm working in a JSF project and the faces-config.xml file has something like this:
<application>
<el-resolver>org.jboss.seam.el.SeamELResolver</el-resolver>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<message-bundle>customMessages</message-bundle>
</application>
<application>
<view-handler>org.rivetlogic.crafter.core.jsf.CrafterFacesViewHandlerImpl</view-handler>
<el-resolver>org.jboss.seam.ioc.spring.SpringELResolver</el-resolver>
</application>
But I've never seen another JSF application with multiple <application> tags, and maybe this could be one of the causes of my problems (I kind of think the multpiple view handlers are involved).
From the JSF 1.2 schema:
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="application"
type="javaee:faces-config-applicationType"/>
Multiple application elements should be OK, but there aren't any restrictions on the number of view-handler elements within an application element either.
The ViewHandler is pretty fundamental to how JSF works. The ViewHandlers may not be compatible (check their documentation) or they may be sensitive to load order (I don't think it is specified within a faces-config.xml). In the latter case, you can put them in separate documents and use the javax.faces.CONFIG_FILES init parameter to specify processing order (see spec).

Categories

Resources