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

Highlighted
Six Stars

[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: 


Accepted Solutions
Highlighted
Six Stars

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

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!!! 

View solution in original post


All Replies
Highlighted
Six Stars

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

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!!! 

View solution in original post

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog