How do I access a mapping parameter ($$myvariable) from a Java Transformation in Informatica Powercenter?
What I want to do is to make a Java transformation reusable by making a part of it configurable, and a variable seemed suitable for that, however I haven't been able to access (read) a variable from the Java code.
I see three options
use an expression transformation with a variable port that passes
the variable into an input port defined in the java transformation
Use shell variables and get them with the Java 'System.getenv' call for example:
final String myconfig = System.getenv("MYCONFIG");
use a Java expression to get to the variable
Integer getEmpID() throws SDKException
{
return (Integer)invokeJExpression("SETCOUNTVARIABLE($$MyVar)", new Object [] {} );
}
Related
Context
I am developing a custom JMeter plugin which generates test data dynamically from a tree like structure.
The editor for the tree generates GUI input fields as needed, and therefore I have no set of defined configuration properties which are set in the respective TestElement. Instead, I serialize the tree as a whole in the GUI class, set the result as one property and deserialize it in the config element where it is processed further during test execution.
Problem
This works just fine, except that JMeter variable/function expressions like ${foo} or ${_bar(..)} in the dynamic input fields are not evaluated. As far as I understand the JMeter source code, the evaluation is triggered somehow if the respective property setters in org.apache.jmeter.testelement.TestElement are used which is not possible for my plugin.
Unfortunately, I was not able to find a proper implementation which can be used in my config element to evaluate such expressions explicitly after deserialization.
Question
I need a pointer to JMeter source code or documentation for evaluating variable/function expressions explicitly.
After I manages to setup the JMeter-Project properly in my IDE, I found org.apache.jmeter.engine.util.CompoundVariable which can be used like this:
CompoundVariable compoundVariable = new CompoundVariable();
compoundVariable.setParameters("${foo}");
// returns the value of the expression in the current context
compoundVariable.execute();
I've an instance variable the value of which should be set by looking up a dynamic property name.
Class Test {
#Value("#{T(java.lang.String).format('filter.%s.disable', getClass().getSimpleName())}")
private boolean disable;
}
disable should evaluate to true when filter.Test.disable = true and false otherwise. I also want to set a default value false if the property is not defined, which is usually done using the following syntax, but I'm not sure in this case.
#Value("${property:default}")
I'm getting the error:
Caused by: java.lang.IllegalArgumentException: Invalid boolean value
[filter.BeanExpressionContext.disable]
Also tried #Value("${'dcs.cloud.filter.'#{getClass().getSimpleName()}'.disable'}") and some other combinations of # and $ to no avail.
The SPEL doc shows useless parser.parseExpression calls to evaluate expressions, which uses a different syntax, and no one does in reality. Looks like they picked out code from the unit tests instead of real examples.
You can't access the class in which the expression is declared that way. getClass() there acts on the root object for the expression evaluation (the BeanExpressionContext in this case).
It's not clear why you can't just use filter.Test.disable here (unless, perhaps you are trying to get the actual class when Test is subclassed).
You can't do that.
It might be easier to implement EnvironmentAware and set the boolean by getting the property from the environment.
Updating my question to be more specific.
My entity is a Map<String, String>
I build generic queries using reflection. For all other types, I can build a path (PathBuilder) and then evaluate appropriately (equals, contains, startswith, etc).
For string types I can then get the StringExpression by invoking path.getString(fieldName). I can then use the startsWith, endsWith, etc methods to evaluate.
I don't see how to handle this with a Map.
I have a MapPath...is there way to resolve this to a StringExpression so that I can evaluate if the value startsWith or endsWith a particular value.
Any suggestions on how to make this work?
You can resolve a Map path only via a join to a String path
query.join(entity.mapPath, stringPath)
I have the following in a Spring bean:
#Value("${myValue}")
private String value;
The value is correctly injected. However, the variable needs to be optional, it is passed in as a command line parameter (which is then added to the Spring context using a SimpleCommandLinePropertySource), and this argument will not always exist.
I have tried both the following in order to provide a default value:
#Value("${myValue:}")
#Value("${myValue:DEFAULT}")
but in each case, the default argument after the colon is injected even when there is an actual value - this appears override what Spring should inject.
What is the correct way to specify that #Value is not required?
Thanks
What is the correct way to specify that #Value is not required?
Working on the assumption that by 'not required' you mean null then...
You have correctly noted that you can supply a default value to the right of a : character. Your example was #Value("${myValue:DEFAULT}").
You are not limited to plain strings as default values. You can use SPEL expressions, and a simple SPEL expression to return null is:
#Value("${myValue:#{null}}")
If you are using Java 8, you can take advantage of its java.util.Optional class.
You just have to declare the variable following this way:
#Value("${myValue:#{null}}")
private Optional<String> value;
Then, you can check whether the value is defined or not in a nicer way:
if (value.isPresent()) {
// do something cool
}
Hope it helps!
If you want to make the configuration property optional just pass an empty string like this:
#Value("${app.optional.value:}")
I guess you are you using multiple context:property-placeholder/ declarations?
If so, this is a known issue since 2012, but not fixed, apparently due to both lack of interest and no clean way of fixing it. See https://github.com/spring-projects/spring-framework/issues/14623 for discussion and some ways to work around it. It's explained in an understandable way by http://www.michelschudel.nl/wp/2017/01/25/beware-of-multiple-spring-propertyplaceholderconfigurers-and-default-values/
I've known that a writable object can be passed to mapper using something like:
DefaultStringifier.store(conf, object ,"key");
object = DefaultStringifier.load(conf, "key", Class );
My question is:
In a mapper I read out the object then change the value of this object,
for example: object=another .
How to do to make sure that the change of the object's value
could be known by the next time of mapper task?
Is there any better way to pass parameter to mapper?
Use the file system instead. Write the value in HDFS, and replace the file with a different content. Neither config nor DistributedCache are not appropiate for mutable state.