what is the best way to specify default value for a date parameter in ireport - jasper-reports

I have created a parameter in iReport Value_DT with Date data type.
If I'm using expression "new java.util.Date("01-SEP-14") as default value it works fine but this is hard code.
I'd like to use user defined function from Oracle DB, i.e. it might be similar to "new java.util.Date(new java.util.Date($F{GETACCOUNTINGDATE})) where GETACCOUNTINGDATE is oracle function.
With such syntax I have an error "The constructor Date(Timestamp) is undefined".
What should be changed in order to use function from DB in default parameter?

I'm not sure of any way to do this directly in the default value expression without writing custom code. I believe you would need to write a custom class with a static method which connects to your database, calls GETACCOUNTINGDATE, and returns the date. You could then, bundle this as a JAR, put it in your classpath and call this method in your Default Value Expression.
That's quite a bit of work though, so alternatively you may be able to 'recreate' the date using Java Date Function libraries.
We've used apache dateUtils:
org.apache.commons.lang.time.DateUtils.addMonths(new Date(),0))
I know a colleague has used jchronic to use strings and create dates.

Related

Anylogic: can you type a probability distribution into an edit box?

In the simulation window, before the run, I'd like to change some probability distributions (e.g. delay time) by typing, for example, "triangular(5, 20, 15)" into a specific editbox linked to a variable.
I know how to do this with static values, but I couldn't figure out how to do the same with probability distributions.
AnyLogic offers a built-in functionality for that with com.anylogic.engine.database.CodeValue.
It is originally meant that a distribution function stored as text in the internal database can be parsed to java code and executed, but it actually also works without the database and for any kind of code. It is the same idea as in Benjamin's answer, just that you do not need to add any external java library.
Use it like this:
CodeValue myCode = new CodeValue(this,"....java code to be executed");
myCode.execute();
And in your specific case, assuming you have a variable named variableA and an editbox named editbox, use the following to evaluate the expression, get a value and set it for the variable:
CodeValue myCode = new CodeValue(this,"variableA = "+editbox.getText());
myCode.execute();
Obviously, allowing the user to type any command there and running it without a check or error treatment is a bad idea, be aware of that.
This is a Java issue. You need to convert a String (your editbox content) to executable code. Not straight-forward but also not impossible, see Convert String to Code and similar posts.

How to import and use StringUtils in tMap using Talend 3.6

I understand the library http://commons.apache.org/proper/commons-lang/javadocs/api-3.4/index.html provides a number of string functions including StringUtils.capitalize
In Talend OpenStudio 6.3 I have added the tLibraryLoad and in basic settings selected commons-lang3-3.4.jar In advanced settings I have import org.apache.commons.lang3.StringUtils.*;
in my tMap I have StringUtils.Capitalize(row20.Forename) assigned to a variable but I get the error The method Capitalize(String) is undefined for the type StringUtils
On TalendExchange there is a StringUtils available but its only for 6.2 and lower.
Whats the best and most reliable way to get access to additional string handling tools like Capitalize which converts a string like MONKEY to Monkey
It seems that talend uses its own StringUtils library (routines.system), then when specifying "StringUtils", Talend does not recognize your importn and still uses its own class.
In tMap, try org.apache.commons.lang3.StringUtils.capitalize(row20.Forename) instead
You almost got the correct set-up in your tLibraryload but you may try to configure it as illustrated below:
tLibraryload set-up
Tmap
Result
I think you should try StringUtils.Capitalize(row20.Forename)
You can use StringHandling.UPCASE(row20.Forename) to convert to uppercase.
In tMap, click on "..." just where you place the expression to fill the output fields. It oppens the expression builder. Search for "StringHandling" in the categories column, then click on UPCASE and complete the expression proposed as an example by TOS.

Access to Bind Parameters in MyBatis Interceptor

How do I read the bind parameters inside a MyBatis Interceptor? I'm trying to extract those information so I can write them to a log table.
The guide (http://www.mybatis.org/mybatis-3/configuration.html) didn't mention how to get them, and the JavaDoc (http://www.mybatis.org/mybatis-3/es/apidocs/org/apache/ibatis/mapping/BoundSql.html) does not have a single line of comment. I saw an example on SO about constructing a new BoundSql but that isn't what I needed.
I tried to test what contents are stored in BoundSql.getParameterMappings() and BoundSql.getParameterObject(), but it seems to be pretty complex. There's JavaType and JdbcType, and if there's only one parameter the ParameterObject isn't a Map object.
What is the proper way to get the bind parameters from BoundSql?
After going through MyBatis source code (where comment is an endangered species), I found out how MyBatis processes the bind parameters. However, that requires access to the JDBC Statement object, which is simply not available inside an Interceptor.
Then I did some testing and settled on this:
If there is only a single parameter, BindSql.getParameterObject() will give you the parameter itself. By using BindSql.getParameterMappings() and ParameterMapping.getJavaType() I can tell which Java class the parameter is.
If there are more than one parameter, BindSql.getParameterObject() will return an instance of org.apache.ibatis.binding.MapperMethod.ParamMap, which extends HashMap, or it will be an instance of the DTO you used. Using .getProperty() from ParameterMapping as key or as getter name, you can process the bind parameters one by one.
If anyone has a better way to do this, I'm all ears.

Jasper Reports Custom global or built in parameter

In my application I have a setting that can be configured by the user called Date Format. There are a list of formats they can use and when they choose one, all dates in the application and in the reports use that format.
Every time I create a new report I have to create the parameter and link the input control. I just added a new setting, for formatting numbers. I have about 50 reports that I need to apply this to. After going through the monotonous task of adding the parameter and input control to every report I was wondering if there is an easier way.
Is it possible to create a custom global parameter that is automatically available to all reports (Similar to the built in parameters)?
Furthermore, is there a way to tell jasper if a field is of a certain type to automatically do something with it, on a global level. For example if my field type is 'decimal' apply the number format?
Every report has a REPORT_FORMAT_FACTORY parameter that is an instance of net.sf.jasperreports.engine.util.FormatFactory. You should be able to create your class that implements FormatFactory and in the constructor takes what ever you need to determine the correct format. Then add it to the parameters when exporting your report.
You will probably need to play with it, as I am not sure what it passes in for pattern when a value is/isn't set. And if you always ignore the pattern, then when you need to explicitly set it to be the same in all reports it will cause problems.
If I get time tonight, I will try to create an example and see how it works and update my answer, or if you beat me to it, you could post a comment letting us know how it works.

Issue: Action redirect do not include parameter as complex objects in Struts2?

I have tried an example in which i have inserted a user using insert method of UserAction class.
On insert I have redirected the success to loadAdd method of UserAction.
During redirect I have passed the parameter as
${user}
In struts 2.0.14 this gives an ognl exception.
whereas when I pass
${user.id}
it works.
My observation says this is a bug in struts or ognl that it does parse composite objects while it parses simple data types.
Any work-around please suggest.
Or
Is there any way by which I can forward the complete action context or value stack in the redirected action
It's not a bug.
Struts2 uses a type conversion system to convert between Strings (native HTTP) and other objects. It has default type converters for all of the standard primitives, boxed primitives, collections, maps, etc. If you want to allow Struts2 to automatically convert between a string and your User class, you need to create a type converter for it. Otherwise, you can use ${user.id}, which is a primitive or boxed primitive.
http://struts.apache.org/2.2.3/docs/type-conversion.html
Also, the ValueStack is per-request, so when you redirect and create a new request, the previous requests ValueStack is no longer available.