So I created this quick job and strangely, even after getting confirmation that the variables have been loaded, I can't seem to read the variables using context.. What am I doing wrong?
The input file has just one variable 'temp_var' with value set to 'passed' (temp_var=passed). While loading the job, I also see the info in the talend log window (tContextLoad_2 set key "test_var" with value "passed"). Further, I can use the context.containsKey("test_var") construct and it yields 'true' in the Java Node. But the moment I try to run the following command, it fails:
System.out.println("Value of var test_var read from context " + context.test_var);
Kindly help.
So I saw the source code of another job with context variables and found that talend internally manages the context variables using the getProperty method. Used that information and it all worked fine.
System.out.println("Value of var test_var read from context " + (String) context.getProperty("test_var"));
Related
I wonder if there is any way how to access jEdit variables (like the buffer variable) from the beanshell inside SuperAbbrevs plugin template.
When I try to expand following template, the error Attempt to resolve method: getName() on undefined variable or class name: buffer appears int Activity log.
<#= buffer.getName() #>
When I try to run this code in the BeanShell console then it displays the current buffer name:
buffer.getName()
Is it possible to access buffer name from the SuperAbbrevs template?
As far as I can see from a quick look at that plugins sources, those variables are not forwarded to the templates. Only the variables you define in the options of the plugin and additionally filename and selection.
In your example filename is exactly what you want, so <#= filename #> works for inserting the name of the file. If you would need more, you would probably need to issue a plugin feature request.
I want to develop a Talend job parent job which will read a file. This file will have all the child job names.
So the parent job when run must go through each entry in the file (ie each child job name) and execute the child job.
Can anyone please guide me on this.
You can use the tRunJob dynamic job feature, I executed 3 sub jobs called a, b and c, and the order is specified in the file, see below :
First block is to load your file into context, you can use a properties file or delimited file.
I used properties file with this content :
jobs=a;c;b;a
You have to add a string typed context variable named jobs to put the propertie value into.
Now, our job list is stored in a context variable, we need to iterate through them using tJavaFlex and update a context variable called currentjob:
And finally, this is how to set tRunJob component:
Here you specify jobs to be executed, but the execution order is specified by the file !
You can do it like following scenario
This is the sample job which I tried out.
I have assumed your input from CSV file and the input file contain three job name which are
ChildJob1
ChildJob2
ChildJob3
I am getting the jobname and assigning it to a context variable like below
Then that context variable is used in tRunJob component.
Each child job has a single tjava component which displays the jobname
Hope this may help you out.
I've been trying to use raster calculation in ipython for a tif file I have uploaded, but I'm unable to find the whole code for the function. I keep finding examples such as below, but am unsure how to use this.
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
I then tried another process by assigning sections, however this still doesn't work (code below)
a = '/iPythonData/cstone/prec_7.tif'
outfile = '/iPythonData/cstone/prec_result.tif'
expr = 'A<125'
gdal_calc.py -A=a --outfile=outfile --calc='expr' --NoDataValue=0
It keeps coming up with can't assign to operator. Can someone please help with the whole code.
Looking at the source code for gdal_calc.py, the file is only about 300 lines. Here is a link to that file.
https://raw.githubusercontent.com/OSGeo/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py
The punchline is that they just create an OptionParser object in main and pass it to the doit() method (Line 63). You could generate the same OptionParser instance based on the same arguments you pass to it via the command-line and call their doit method directly.
That said, a system call is perfectly valid per #thomas-k. This is only if you really want to stay in the Python environment.
This is the first time I'm encountering GetLayoutObjectAttribute and I am having serious issues with it. My variable $web won't set. I think it's because PD_WebV isn't the right object name to refer to, but I don't know how to find the right object name. I can't find the objects name when I hit Edit Layout, so does anyone know how to find an layout objects name?
Loop
Pause/Resume Script [Duration (seconds): 1]
Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")]
If[$Web="done"]
#execute if statements
After Edit:
After some troubleshooting, I found out that PD_WebV is the right object name to refer and it's refered to correctly, so my new question is why doesn't the script go to the line If[$Web="done"] and how could I fix it? Ss my If statement not evaluating something it should be? Is my $web variable never set to done or is the issue something completely different? Would the problem possibly have to do with my WebDirect sharing settings? Any guidance would help. Thanks.
After, After Edit:
So now that my application is getting past Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")], the variable $web only equals <HTML></HTML>. Does anyone know a way, without using javascript, to test the inside of the html tags?
Also, I printed the bounds of the webViewer PD_WebV that I can't locate on the layout but am referring to in the script. The bounds that are printed are different each time I run the script. Is the usual or unusual? My source is also about:blank so it doesn't look like I'm sourcing from a URL
Is my $web variable never set to done or is the issue something
completely different?
If you're doing:
Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")]
then the only time
$Web="done"
will return true is when the web page loaded into your web viewer contains exactly the string "done" (in practical terms, that's never).
I have already suggested in a comment that you test for:
PatternCount ( $webpage ; "</html>" )
This is assuming you want the subsequent steps to execute only after the page has finished loading. The entire script would look something like this:
Loop
Pause/Resume Script [Duration (seconds): 1]
Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")]
Exit Loop If [ PatternCount ( $webpage ; "</html>" ) ]
End Loop
# execute statements
You might also want to add a counter to the loop and exit the script after n trials.
Ah, I reread your question.
To set the object name for your webviewer so that the GetLayoutObjectAttribute function works you need to set it in the Name field in the inspector when you have the webviewer selected.
e.g.:
After that your variable should populate.
Be aware
What it will populate with will be all of the html from the browser, i.e. not a boolean true/false liek your conditional suggests.
I'm not sure exactly what you're trying to accomplish, but to be able to determine a result from your web viewer you'll need to either parse the HTML to see if it's content contains what you're looking for or within the code you're setting the webviewer with, fire a javascript function that calls back to the FileMaker file using a FileMaker url.
I'm trying to debug a Groovy script in Eclipse from a JUnit test. The Groovy code is part of a larger Java application that runs in Tomcat. For various reasons our system is set up to use compiled JSR223 expressions. Here's the abbreviated code snippet:
GroovyScriptEngineImpl engine = new GroovyScriptEngineImpl();
Resource r =
new ClassPathResource("groovy/transformations/input/Foo.groovy");
String expression = IOUtils.toString(r.getInputStream());
CompiledScript script = engine.compile(expression);
String result = (String) script.eval(new SimpleBindings(bindings));
The test runs fine, but even though I have a breakpoint set in Foo.groovy, and the file is on the classpath, the breakpoint never gets hit when debugging. I'm guessing this doesn't work because there's no association between the expression in String format and the actual file that contains it. So is there a way of creating this association between the String and its corresponding file name? As mentioned, I need to use a CompiledScript. As a side note, I have been able to hit the breakpoint in the debugger with the same Groovy script when using this approach:
Resource r =
new ClassPathResource("groovy/transformations/input/Foo.groovy");
GroovyShell shell = new GroovyShell(new Binding(bindings));
String str = (String) shell.evaluate(r.getFile());
But of course, in this case the Groovy engine loads the file directly. Any hints as to how to get the first example to work are greatly appreciated. Thanks.
You are exactly right that this has to do with creating a class from a string. GroovyScriptEngineImpl likes to assign arbitrary names to the compiled script since it assumes everything comes from a string. The GroovyShell, however, generates the script name based off of the file that the script comes from, and this is the link that the debugger needs.
I'd perhaps recommend that you avoid using GroovyScriptEngineImpl and use GroovyShell.parse instead. And then, you can create a GroovyCompiledScript from the result of GroovyShell.parse and using a new GroovyScriptEngineImpl. Something like this:
File f = getScriptFile();
Script s = new GroovyShell().parse(f);
CompiledScript cs = new GroovyCompiledScript(new GroovyScriptEngineImpl(), s.getClass());
...
Note that I haven't tried this yet, but based on my experience, this should work.
If you are feeling really good-spirited, I'd raise a jira on the groovy issue tracker to ensure that you can pass in a proper name for scripts created using the GroovyScriptEngineImpl.