Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Configure a tJavaFlex to generate e-mail addresses

Hello Guys!

I have encountered this exercise from the internet(Advanced Talend Exercise 13: Call an existing jar from within a job) and one of its task is to generate 3 email addresses("training@talend.com", "test.talend.com", "support@talend.com") by using a tJavaflex component. Now I'm not sure if the code that I made is right...so Im just gonna show you guys my code below:
// start part of your Java code
String [] emailArray = {"training@talend.com", "test@talend.com", "support@talend.com"};
for(int j=0;j<emailArray.length;j++) {

// here is the main part of the component,
// a piece of code executed in the row
// loop
System.out.println(emailArray)

// end of the component, outside/closing the loop

and I want to know if this is correct? or Am I missing something important here? Because after generating the email addresses, you will have to link the tJavaflex to a tMap so that when the job runs, the the email generated will be outputted and the tMap  will test if it has the right email pattern or not...anyways, Any kind of help would be gladly appreciated thank you and God Bless to all and here is the screenshot of the exercise below: 

0683p000009MGox.jpg

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Oh I actually solved it!! Anyways...in how I generated the java code for the email address I might just as well document it in here for the sake of ALL THE BEGINNERS out there like me on how I solved the whole exercise...for the exercise task, there is a picture attached below:

Step 1: Create a routine called "MyRoutines" that will validate email address. As for me, my routine looked like this:

package routines;

import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;

public class MyRoutines {

public static boolean isValidEmail(String email) {
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
Pattern pattern;

try {
pattern = compiler.compile("^[\\w_.-]+@[\\w_.-]+\\.[\\w]+$");
if(!matcher.matches(email, pattern)) {
return false;
}
} catch (MalformedPatternException e) {
throw new RuntimeException(e);

return true;
}


this routine needs to have a jakarta-oro-2.0.8.jar in order for this to work, so just (Download jakarta-oro-2.0.8 > right-click My Routines > Edit Routine Libraries > New > Browse Library File > Select jakarta-oro-2.0.8 )

Step 2: Create a Job, put tJavaflex, tMap and tLogrow

Step 3: Configure tJavaflex to generate 3 email address: ("talend@talend.com", "test.talend.com", "support@talend.com")

The code in the tJavaflex is actually very simple: 

// start part of your Java code
String [] emailArray = {"training@talend.com", "test.talend.com", "support@talend.com"};
for(int j=0;j<emailArray.length;j++) {

//main
row1.mail = emailArray<J>;

// end of the component, outside/closing the loop
}

Step 4: In the edit schema button of the tJavaFlex component, create a column and name it "mail" and connect the tjavaflex to the tMap component and connect the tMap compnent to the tLogRow component(you can choose the output name)

Step 5: Double click the tMap component and drag the row1.mail to the output side of the tMap

Step 6: In the output side, add another column and name it "test" and set its type to Boolean

Step 7: In the output expression part of the tMap, just below the row1.mail(output) and right beside the "test" column put this expression ------> MyRoutines.isValidEmail(row1.mail) ------> this will call the routine and will validate the email address generated by the tJavaflex

Step 8: That's it your done and run the Job!!

Thank you guys for bearing with me!! hahaha!! XD peace y'all!!! 

0683p000009MGiu.jpg 0683p000009MGox.jpg

View solution in original post

1 Reply
Anonymous
Not applicable
Author

Oh I actually solved it!! Anyways...in how I generated the java code for the email address I might just as well document it in here for the sake of ALL THE BEGINNERS out there like me on how I solved the whole exercise...for the exercise task, there is a picture attached below:

Step 1: Create a routine called "MyRoutines" that will validate email address. As for me, my routine looked like this:

package routines;

import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;

public class MyRoutines {

public static boolean isValidEmail(String email) {
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
Pattern pattern;

try {
pattern = compiler.compile("^[\\w_.-]+@[\\w_.-]+\\.[\\w]+$");
if(!matcher.matches(email, pattern)) {
return false;
}
} catch (MalformedPatternException e) {
throw new RuntimeException(e);

return true;
}


this routine needs to have a jakarta-oro-2.0.8.jar in order for this to work, so just (Download jakarta-oro-2.0.8 > right-click My Routines > Edit Routine Libraries > New > Browse Library File > Select jakarta-oro-2.0.8 )

Step 2: Create a Job, put tJavaflex, tMap and tLogrow

Step 3: Configure tJavaflex to generate 3 email address: ("talend@talend.com", "test.talend.com", "support@talend.com")

The code in the tJavaflex is actually very simple: 

// start part of your Java code
String [] emailArray = {"training@talend.com", "test.talend.com", "support@talend.com"};
for(int j=0;j<emailArray.length;j++) {

//main
row1.mail = emailArray<J>;

// end of the component, outside/closing the loop
}

Step 4: In the edit schema button of the tJavaFlex component, create a column and name it "mail" and connect the tjavaflex to the tMap component and connect the tMap compnent to the tLogRow component(you can choose the output name)

Step 5: Double click the tMap component and drag the row1.mail to the output side of the tMap

Step 6: In the output side, add another column and name it "test" and set its type to Boolean

Step 7: In the output expression part of the tMap, just below the row1.mail(output) and right beside the "test" column put this expression ------> MyRoutines.isValidEmail(row1.mail) ------> this will call the routine and will validate the email address generated by the tJavaflex

Step 8: That's it your done and run the Job!!

Thank you guys for bearing with me!! hahaha!! XD peace y'all!!! 

0683p000009MGiu.jpg 0683p000009MGox.jpg