Oozie String wf:errorCode(String node) how to check empty? - hadoop

I have an action node named 'CW', after that I placed a Decision Node to check if 'CW' returns error or not.... how should I write the predicate?
I tried:
${ wf:errorCode('CW') eq '' } then go to Y
${ wf:errorCode('CW') != '' } then go to N
Although it return empty string (no error), but it always goes to N. Any advise? Thanks!!

Try
${not empty wf:errorCode('CW')}
to detect failures

This is the only method for checking an empty string that worked for me.
<decision name='decision-action'>
<switch>
<case to='success-action'>${firstNotNull(wf:lastErrorNode(), 'no error') eq 'no error'}</case>
<default to='failed-action' />
</switch>
</decision>
So, to relate this answer directly to the question, this conditional
${firstNotNull(wf:errorCode('CW'), 'no error') eq 'no error}
should map to Y.

Can't you just use the ok and error action transitions to do this?
<action name="CW">
<!--
....
-->
<ok to="Y"/>
<error to="N"/>
<\action>

${ wf:errorCode('CW') == null }
You can also check if CW exits with error like:
${ wf:lastErrorNode()=='CW' }
right after CW completion.

${ wf:errorCode('CW') eq null } then go to Y
${ wf:errorCode('CW') != null } then go to N
Worked for me

${wf:lastErrorNode() eq wf:errorMessage(wf:lastErrorNode())} --> consider this condition as success, these two values are blank when job fails
${wf:lastErrorNode() != wf:errorMessage(wf:lastErrorNode())} --> consider this condition as failure, when jobs fails, these values do not match
it worked for me, hope this helps

Related

Checking complex multiple values (and) in a node in Xpath

hello i find many explample with xpath, unfortunatly i can't do what i would like to do :(
I need to control a xml script, a i want to alert if 2 sub elements are correct.
here a part of my xml file
<node componentName="printinput" componentVersion="0.102" offsetLabelX="0" >
<elementParameter field="TEXT" name="UNIQUE_NAME" value="name1" show="false"/>
<elementParameter field="CHECK" name="TCK_HELP" value="true"/>
<elementParameter field="TEXT" name="CO_ON" value="10000" show="false"/>
</node>
i would like to check if TCK_HELP=true AND CO_ON=10000 . With or, no pb, but i don't know hox to do this with 'and'. i understand why it'is not working, but i don't know how to do .. Thank a lot for your help
one of my tries :
/*[local-name() = 'ProcessType']
/*[local-name() = 'node']
[
#componentName='printinput'
]
/*[local-name() = 'elementParameter']
[#name='TCK_HELP' and #value!='true'
and
#name='CO_ON' and #value='10000'
]
What about:
//node[#componentName="printinput"][elementParameter[#name="TCK_HELP"][#value="true"]][elementParameter[#name="CO_ON"][#value="10000"]]

how to use golang mongodb driver query $or with $and?

1.judge field label_status is exists, if exists is true find one record.
2.if field label_status exist is false. find one record label_status eq 1 and author
eq sample
i use the code:
bson.D{
{"$or", bson.D{{"label_status", bson.D{{"$exists", false}}}}},
{"$and", bson.A{bson.M{"label_status": Labeling}, bson.M{"annotator": "sample"}}},
}
err := collection.FindOne(context.Background(), bson.D{
{"$or", bson.D{{"label_status", bson.D{{"$exists", false}}}}},
{"$and", bson.A{bson.M{"label_status": Labeling}, bson.M{"annotator": "sample"}}},
}).Decode(&result)

xslt/xquery for checking values of two attributes in if conditions

I am stuck at a place in my xquery. In the response i want to get back the phone numbers for each Type i.e. HOME and CELL , but only the ones which have highest sequence number .If there are two rows with PhoneType="HOME" , I want back the phone which has highest sequence of two i.e in my case Sequence="3".
With my xquery I am able to get back a phoneType="HOME" and the first row with type HOME. i am not able to add a condition to check the Sequence as well. Where and how can i add it. Please suggest. Thanks in advance
Part of my Xquery:
<acc:phones>
{
for $PersonPhonesRow in $PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[#PhoneType="HOME"][1]
return
if(fn:data($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow/#PhoneType="HOME"[1]))
then
<com:phone>
<com:type>{'HOME'}</com:type>
<com:phoneNumber>{fn:data($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[#PhoneType="HOME"][1]/#PhoneNumber)}</com:phoneNumber>
<com:carrier>{fn:data($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[#PhoneType="HOME"][1]/#Extension)}</com:carrier>
</com:phone>
else
()
}
</acc:phones>
Request:
<CMPerson xmlns="http://splwg.com/CMPerson.xsd">
<CMPersonService>
<CMPersonDetails>
<PersonPhones>
<PersonPhonesHeader PersonID="1234567890" LastSequenceNumber="9"/>
<PersonPhonesRow PersonID="1234567890" Sequence="1" PhoneType="HOME" IntlPrefix="" PhoneNumber="(850) 123-0000" Extension="" Version="12" PhoneAlgorithmParamValue="(999) 999-9999"/>
<PersonPhonesRow PersonID="1234567890" Sequence="2" PhoneType="CELL" IntlPrefix="" PhoneNumber="(850) 000-0000" Extension="" Version="3" PhoneAlgorithmParamValue="(999) 999-9999"/>
<PersonPhonesRow PersonID="1234567890" Sequence="3" PhoneType="HOME" IntlPrefix="" PhoneNumber="(850) 123-1111" Extension="ATT" Version="1" PhoneAlgorithmParamValue="(999) 999-9999"/>
<PersonPhonesRow PersonID="1234567890" Sequence="4" PhoneType="BUSN" IntlPrefix="" PhoneNumber="(904) 111-1111" Extension="" Version="3" PhoneAlgorithmParamValue="(999) 999-9999"/>
</PersonPhones>
</CMPersonDetails>
</CMPersonService>
</CMPerson>
Response required:
<acc:phones>
<com:phone xmlns:com="******">
<com:type>HOME</com:type>
<com:phoneNumber>(850) 123-1111</com:phoneNumber>
<com:carrier>ATT</com:carrier>
</com:phone>
<com:phone xmlns:com="******">
<com:type>CELL</com:type>
<com:phoneNumber>(904) 111-1111</com:phoneNumber>
<com:carrier></com:carrier>
</com:phone>
</acc:phones>
Query to be used:
let $PersonMaintenanceResponse := 'Your request'
let $uniqPhoneType :=distinct-values($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow/#PhoneType)
for $each at $i in $uniqPhoneType
return
<acc:phones>
{
let $seq := $PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[(#PhoneType = $each)]
let $maxValue := max($seq/#Sequence)
let $maxrow := $seq[#Sequence eq $maxValue]
return
<com:phone xmlns:com="*******">
<com:type>{$each}</com:type>
<com:phoneNumber>{$maxrow/#PhoneNumber}</com:phoneNumber>
<com:carrier>{$maxrow/#Extension}</com:carrier>
</com:phone>
}</acc:phones>

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 Java 8

ABC abc = eMsg.getAbcCont().stream()
.filter(cnt -> (option.geiID().equals(cnt.getId()) && option.getIdVersion() == cnt.getIdVersion()))
.collect(Collectors.toList()).get(0);
delEmsg.getAbcCont().remove(abc);
Above code is giving me en exception as
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:657)
at java.util.ArrayList.get(ArrayList.java:433)
getAbcCont method will return the List of ABC objects.Currently my eMsg contains two object with the getAbcCont. When control reach to the .collect(Collectors.toList()).get(0); its giving the above mentioned exception. Any help suggestion must be appricaited.
This means that the result after the filter is zero elements, so you cannot do get(0).
A quick solution for this would be to first get the list of elements back, and then check if there is atleast one element.
List<ABC> list = ABC abc = eMsg.getAbcCont().stream()
.filter(cnt -> (option.geiID().equals(cnt.getId()) && option.getIdVersion() == cnt.getIdVersion()))
.collect(Collectors.toList());
if(list.size() > 0){
ABC abc = list.get(0);
}
Obviously there is a shorter way also using lambdas such as:
ABC abc = eMsg.getAbcCont().stream()
.filter(cnt -> (option.geiID().equals(cnt.getId()) && option.getIdVersion() == cnt.getIdVersion()))
.collect(Collectors.toList()).findFirst().orElse(null)
Reference: https://stackoverflow.com/a/26126636/1688441
But as User nullpointer , you might need to check if an element is found before you try to call remove() using object abc. I suspect trying to remove null from a collection might not do anything, but you could check to be sure!
if(abc != null){
delEmsg.getAbcCont().remove(abc);
}
You should do !list.isEmpty() rather than list.size() as per sonar

Subreport order sorting

In my report there are currently 2 subreports, let's call them A and B.
The A lists Cash positions, and the B lists Stocks.
I run this report from a web based Java environment, the JasperReports's report reads from a sql database.
I want to pass an argument to the JR report that tells it in what order to arrange the subreports, in this case for e.g. (B first, then A or vice versa).
Is there a way to accomplish this?
You should send a parameter of boolean type. while generating report. on the basis of that parameter you should define the path of subreport.
Here is jrxml code for subrepor path.e.g.
For first subreport:
<subreport>
<reportElement uuid="8dba7f58-0466-4504-9d51-7484786450d2" positionType="Float" x="0" y="16" width="315" height="16"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listOfObject})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{swap} == true ? "/path/to/first/subreport" : /path/to/second/subreport]]></subreportExpression>
</subreport>
And for second subreport:
<subreport>
<reportElement uuid="8dba7f58-0466-4504-9d51-7484786450d2" positionType="Float" x="0" y="16" width="315" height="16"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listOfObject})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{swap} == true ? "/path/to/second/subreport" : /path/to/first/subreport]]></subreportExpression>
</subreport>
And vice-versa in other case.I have not tested. Please have a look.
Enjoy.
You could use a more complex subreportExpression and "Print When Expression".
In first subreport set print when to something like
$P{NUM_OF_SUBS} <= 1 ? true : false
in second
$P{NUM_OF_SUBS} <= 2 ? true : false
etc...
And for subreportExpression in first subreport something like:
$P{SUBS}.split(",")[1] == "A"
? "repo:subA.jrxml"
: $P{SUBS}.split(",")[1] == "B"
? "repo:subB.jrxml"
: $P{SUBS}.split(",")[1] == "C"
? "repo:subC.jrxml"
: "repo:subD.jrxml"
and in second:
$P{SUBS}.split(",")[2] == "A"
? "repo:subA.jrxml"
: $P{SUBS}.split(",")[2] == "B"
? "repo:subB.jrxml"
: $P{SUBS}.split(",")[2] == "C"
? "repo:subC.jrxml"
: "repo:subD.jrxml"
etc...

Resources