Can we use parameters in oozie decision node? - java

I am trying to execute a decision control node in oozie 3.3.2 but getting javax.servlet.jsp.el.ELException
Encountered "{"
<decision name="decision-wf">
<switch>
<case to="another_wf">
${fs:fileSize(${OutputDir}/000000_0) gt 100 }
</case>
<default to="fail-wf"/>
</switch>
How should I pass the parameter in String format as the above mentioned FS method expects String input ?

From the document it appears,
You need to pass hardcoded i.e. enclosed in ' like in ${fs:fileSize('/usr/foo/myinputdir'/1000) gt 10 }
or
just the parameter name ${fs:fileSize(OutputDir/1000) gt 10 }
This OutputDir might be specified in the <config> sections of the workflow OR the .properties file OR passed at time of submitting the job using -D

Yes you can. In fact you can combine multiple parameters with the concat function (which, I think, would help with the original poster's question).
For example if ${location} and ${date} are two params defined in your config file:
<decision name="check-directory-exists">
<switch>
<case to="load-directory">
<!-- check if the directory at this location for this date exists -->
${fs:exists(concat(location, date))}
</case>
<!-- The directory doesn't exist, there is nothing to do -->
<default to="end" />
</switch>
</decision>
and if location and date need a '/' between them, you have to do this:
${fs:exists(concat(concat(location, "/"), date))}

Related

Search query in XML file from java

My Project Manager told me to move all the queries in a xml file (he even made for me), so when the user (via jsp) select the description: "Flusso VLT mensile" he has 2 options, click search, update or download, (the download it works now but I need to get the name of filename), he told me to work with jaxb but I don't think is necessary
<flow-monitor>
<menu1>
<item id="7" type="simple">
<connection name="VALSAP" />
<description value="Flusso VLT mensile" />
<filename value="flussoVltmensile" />
<select><![CDATA[
SELECT * FROM vlt_sap WHERE stato=7
]]>
</select>
<update>
<![CDATA[update vlt_sap set stato = 0 where stato =7]]>
</update>
</item>
<item id="11" type="simple">
<connection name="VALSAP" />
<description value="Flusso REPNORM BERSANI" />
<filename value="flussoRepnormBersani" />
<select><![CDATA[
select * from repnorm_bersani_sap where stato = 99
]]>
</select>
<update>
<![CDATA[update repnorm_bersani_sap set stato=0 where stato = 99]]>
</update>
</item>
</menu1>
</flow-monitor>
On java I should read this xml and depending on <description value=> I should execute the query inside them, any way to easily read the value inside without make a lot of if statement
Anybody knows a good and easy way to achieve all this?
Thanks
There are a few ways to read the XML file and extract the information you need without using a lot of if statements. One approach is to use an XML parsing library such as JAXB or SAX, and create Java classes to represent the XML elements.
In JAXB, you can use the javax.xml.bind.Unmarshaller class to unmarshal the XML file into a Java object, which you can then traverse to extract the information you need.
You should start creating a Java classes based on the XML structure, like FlowMonitor, Menu1, Item, Connection etc. , and use annotation to map the xml elements to the fields.
Then, you can use the unmarshaller.unmarshal() method to parse the XML file and create an instance of the FlowMonitor class, which will contain all the information from the XML file.
Once you have the FlowMonitor object you can loop through the items, and get the description and filename by calling getDescriptionValue() and getFilenameValue() of the item object....

Language.properties file in Liferay

I want to support multiple languages for my portlet application. So I:
Created content package in src folder.
Created Language.properties file with string Book-Name=Book Name
Paste this line
<supported-locale>es</supported-locale>
<resource-bundle>content/Language</resource-bundle>
in portlet.xml file.
So could you please tell me why I still have Book-Name here?!
<liferay-ui:search-container>
<liferay-ui:search-container-results results="${bookListArray}" />
<liferay-ui:search-container-row className="com.softwerke.model.Book" modelVar="aBook">
<liferay-ui:search-container-column-text property="bookName" name="Book-Name"/>
<liferay-ui:search-container-column-text property="bookDescription" name="Description"/>
<liferay-ui:search-container-column-jsp path="/html/action.jsp" align="right" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
UPDATE
This:
<liferay-ui:search-container-column-text property="bookName" name="${bookName}" />
....
<c:set var="bookName"> <liferay-ui:message key="book-Name" /> </c:set>
does NOT work too
You are not using it at all.
The name="Book-Name" in this line
<liferay-ui:search-container-column-text property="bookName" name="Book-Name"/>
adds name property to this html component with valye defined inside the quotation marks to make this value the one defined in the properties file you have to use <liferay-ui:message /> tag in your case it would be:
:
<liferay-ui:search-container-column-text property="bookName" name="<liferay-ui:message key="Book-Name" />"/>
Also it is not relevant but a dev practice that the language key is all lower case.

How to check whether the input is not blank in Ant Input Task?

I have a ant script that requires user inputs. I would like to ensure the correct input type has been entered by the user and if not, prompt them to enter something that is correct.
<input message="secure-input:" addproperty="the.password" >
</input>
I have to check if the input is blank then i will prompt them to reenter.
Is it possible in ant input task?
Most of the conditional clauses allow you at best to fail the script if some condition is not met. I am imagining that you are gathering some inputs from the user, so failing if the user supplies an empty password might not be the best usability experience, since he would have to input everything all over again...
Furthermore, just testing for an empty string seems like a poor validation, what if the user submits a bunch of spaces?
My (admittedly hackish) suggestion is the following:
<target name="askPassword">
<local name="passwordToValidate"/>
<input message="secure-input:" addproperty="passwordToValidate"/>
<script language="javascript">
<![CDATA[
passwordToValidate = project.getProperty("passwordToValidate");
//You can add more validations here...
if(passwordToValidate.isEmpty()){
println("The password cannot be empty.");
project.executeTarget('askPassword');
}
]]>
</script>
<property name="the.password" value="${passwordToValidate}"/>
</target>
So the highlights:
Use the local task to set a local scope for the "passwordToValidate" property (remember that once you set a property on a ant script most tasks don't allow you to rewrite it, so the recursion would be problematic)
Test your input with a script (maybe add some more validations)
If the test fails, call the target again
If the test succeeds, assign the local scoped property to the global scoped one
My 2 cents.
You can use condition task to check if input is not empty but you can also use antcontrib to add if/else and show user appropriate message:
<if>
<not>
<length string="${the.password}" trim="true" when="greater" length="0" />
</not>
</if>
<then>
<echo>Your password is empty!</echo>
</then>
Take a look at Conditions - for condition task.

ant string manipulation : extracting characters from a string

I have an ant property which has value of the type 1.0.0.123
I want to extract the value after the last dot, in this case that would be '123'.
Which ant task should i use and how?
With native ant task
If not wanting to use external libs nor scripting, I found in an answer to a similar question the best option (credit him for this answer). Here you'll be using a ReplaceRegex:
<loadresource property="index">
<propertyresource name="build.number"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replaceregex pattern=".*\.)" replace="" />
</tokenfilter>
</filterchain>
</loadresource>
(I have used the same variable names as you in your solution. Of course, this is still missing the increment part of your answer, but that was not in your question.)
This script loads in index the result of deleting the regex .*\.) from build.number, that is, if build.number = 1.0.0.123 then index = 123.
Example
build.xml:
<project name="ParseBuildNumber" default="parse" basedir=".">
<property name="build.number" value="1.0.0.123"/>
<target name="parse">
<loadresource property="index">
<propertyresource name="build.number"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replaceregex pattern=".*\." replace="" />
</tokenfilter>
</filterchain>
</loadresource>
<echo message="build.number=${build.number}; index=${index}"/>
</target>
</project>
$ ant
Buildfile: /tmp/build.xml
parse:
[echo] build.number=1.0.0.123; index=123
BUILD SUCCESSFUL
Total time: 0 seconds
I suspect the easiest approach may be to use the ant-contrib PropertyRegex task.
Something like this - completely untested:
<propertyregex property="output"
input="input"
regexp=".*([^\.]*)"
select="\1" />
Ok i have found the answer myself and this is tested.
you just gotta use a bit of javascript.
<target name="get build ctr">
<script language="javascript">
<![CDATA[
// getting the value
buildnumber = myproj.getProperty("build.number");
index = buildnumber.lastIndexOf(".");
counter = buildnumber.substring(index+1);
myproj.setProperty("buildctr",counter);
]]>
</script>
</target>
<propertyregex property="xtractedvalue"
input="${foobar}"
regexp="(.*)\.(.*)$"
select="\2" />
Here's a solution using flaka without scripting =
<project xmlns:fl="antlib:it.haefelinger.flaka">
<property name="foobar" value="1.0.0.123"/>
<target name="main">
<!-- simple echo -->
<fl:echo>xtractedvalue => #{split('${foobar}','\.')[3]}</fl:echo>
<!-- create property for further processing.. -->
<fl:let>
xtractedvalue := split('${foobar}','\.')[3]
</fl:let>
<echo>$${xtractedvalue} => ${xtractedvalue}</echo>
</target>
</project>
I would also use the ant-contrib PropertyRegex task.
The following snippet only works if the input string follows the convention you used in your description and you can also use it to extract the other numbers by changing the value entered in the select tag.
<propertyregex property="output"
input="input"
regexp="(\d)\.(\d)\.(\d)\.(\d{3})"
select="\4" />
You can also use the issest task on the output string to print out an error message if the input string does not follow the convention, because the output property will not be set.

Escapse url GET parameters in URL with Java/ICEFaces

I have a JAVA with JSF/ICEFaces application. I need to pass parameters from one page to another so I user something like:
<f:param name="eventName" value="#{item.event_name}" />
And then get it in the constructor using:
eventName = request.getParameter("eventName");
While works fine unless there is a '/' character in the string submitted, it doesn't get parsed properly. I believe I need to escape the '/' parameter with %2F and then parse it back.
Two things:
1- How to do this in ICEFaces or JSF
2- Are there other parameter I have to escape?
Thanks,
Tam
<h:outputLink value="http://google.com">click
<f:param name="eventName" value="#{param.eventName}" />
</h:outputLink>
works for me - the browser takes care of url-encoding.
Note that you can get request parameters directly in your page, using #{param.paramName}

Categories