Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everybody,
i would like pass data from tJava into tMap, is ther anybody who knows how to do it ? Please
My tJava code look like that :
package routines;
import java.io.*;
import java.util.Arrays;
public class ClearCodeFab {
//RETOURNE UN STRING CONCATENE
public static String clear(String csvFile) throws IOException {
String splitBy = ";";
String line="";
String result=null;
BufferedReader br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine())!=null){
String[] tabFab = line.split(splitBy);
String codeFab=tabFab[4];
if (tabFab[5]!=null) {
String nomFab=tabFab[5].replaceAll(" [(][A-Z][A-Z][A-Z][0-9][0-9][)]|[(][A-Z][A-Z][A-Z][A-Z][0-9][0-9][)]|[(] [A-Z][A-Z][A-Z][0-9][0-9][)]|[(][(][A-Z][A-Z][A-Z][0-9][0-9][)]|[(][A-Z][A-Z][0-9][0-9][0-9][)]|[\\[][A-Z][A-Z][A-Z][0-9][0-9][)]|[(][A-Z][A-Z][A-Z][0-9][0-9][\\]]", "");
//for(int i=0; i<tabFab.length; i++) {
result += codeFab.substring(1, 6)+";"+nomFab+"\n";
//}
}
}
return result;
}
}
I tried with Array of String in return but it didn't work too.
My job structure :
My error message :
Exécution en erreur :Erreurs de compilation du Job
Au moins le Job "recupCodeFabricantBac" a des erreurs de compilation, réparez et réexportez.
Ligne en erreur: 794
Message détaillé: Type mismatch: cannot convert from String[] to String
Il peut y avoir d'autres erreurs causées par la compatibilité avec la JVM. Vérifiez que les paramètres de votre JVM sont les mêmes que dans le studio.
Job recupCodeFabricantBac terminé à 17:18 29/09/2020. [Code sortie=0]
My tMap structure :
Thanks in advance.
Hi Gadje,
you wrote, that you tried with array of string, but your code tells, that return type is String. Error tells, that your return type is an array of string. What is the truth? What error you are getting when you are using code pasted in your post?
Hi Pakapi, i tried with both. I just posted String issues report.
I'll give you the real mmessage tomorrow.
Seems like some sort of array pattern in tabFab[5] is this a string which is actualy an array or a list ? provide some line examples please.
And for the love of God, please cleanup your regex in replaceAll looks horrible. In addition to your code an example .... I've added blanks to ( and ) indicate grouping just to make it more readable.
( \\[+|\\(+ ) ( [A-Z]{3,4}[0-9]{2}|[A-Z]{2}[0-9]{3} ) ( \\]+|\\)+ )
[\\[] which is the same as \\[
In between brackets is a list of characters and range of characters [] and [^] not like
For regex study in dept : grouping and specials like ? or + or * or {} or [] or ( ?<= ) lookahead lookbehind ... group repetitions
You will improve your dataprepping skills.
Hi,
A sample of my input file csv :
CODE_0;LIBELLE_NIVEAU_0;CODE_1;LIBELLE_NIVEAU_1;CODE_2;LIBELLE_NIVEAU_2;CODE_3;LIBELLE_NIVEAU_3;CODE_4;LIBELLE_NIVEAU_4;CODE_5;LIBELLE_NIVEAU_5;CODE_6;LIBELLE_NIVEAU_6;CODE_7;LIBELLE_NIVEAU_7
F00F;Fournisseurs;F00123;Fournisseur 1-99;FMMM01;3M BRICOLAGE (MMM01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FABS01;AB SOLUTIONS (ABS01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FABB01;ABB (ABB01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FACO01;ACOVA (ACO01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FACT03;ACTION PIN (ACT03);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FACT01;ACTIS (ACT01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FACT02;ACTON (ACT02);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAFY01;AFY (AFY01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAGI01;AGI ROBUR (AGI01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAGL01;AGL (AGL01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAIR02;AIRCALO (AIR02);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAIR03;AIR-FIX (AIR03);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAKW01;AKW (AKW01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALC01;ALCAD (ALC01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALD01;ALDES (ALD01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALF01;ALFERCAT RACORDS (ALF01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALG01;ALGIMOUSS (ALG01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALI01;ALIAXIS (ALI01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALL02;ALLO SOINS (ALL02);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALP01;ALPATEC (ALP01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALP03;ALPENWOOD (ALP03);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALP02;ALPHA INNOTEC (ALP02);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FALS01;ALSAFIX (ALS01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAMA01;AMACO (AMA01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAMB01;AMBIANCE BAIN (AMB01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAMP01;AMPACK (AMP01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FANJ01;ANJOS (ANJ01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FANQ01;ANQUIER (ANQ01);;;;;;;;;;
F00F;Fournisseurs;F00FAB;Fournisseurs A-B;FAOS01;AO SMITH (AOS01);;;;;;;;;;
The regex / replaceAll is use for remove (xxxxx).
My routine code with 2 methods :
package routines;
import java.io.*;
import java.util.Arrays;
public class ClearCodeFab {
//RETOURNE UN STRING CONCATENE
/*public static String clear(String csvFile) throws IOException {
String splitBy = ";";
String line="";
String result=null;
String regexp ="\\s?[(\\[\\\\]+\\s?+[A-Z]{1,6}[0-9]{1,6}+\\s?+[)\\]\\\\]+";
BufferedReader br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine())!=null){
String[] tabFab = line.split(splitBy);
String codeFab=tabFab[4];
if (tabFab[5]!=null) {
String nomFab=tabFab[5].replaceAll(regexp, "");
//for(int i=0; i<tabFab.length; i++) {
result += codeFab.substring(1, 6)+";"+nomFab+"\n";
//}
}
}
return result;
}*/
// RETOURNE UN TABLEAU DE STRING
public static String[] clear(String csvFile) throws IOException {
String splitBy = ";";
String line="";
String regexp ="\\s?[(\\[\\\\]+\\s?+[A-Z]{1,6}[0-9]{1,6}+\\s?+[)\\]\\\\]+";
String[] result={};
BufferedReader br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine())!=null){
String[] tabFab = line.split(splitBy);
String codeFab=tabFab[4];
if (tabFab[5]!=null) {
String nomFab=tabFab[5].replaceAll(regexp, "");
result=Arrays.copyOf(result, result.length+1);
result[result.length-1]=codeFab.substring(1,6)+";"+nomFab;
}
}
return result;
}
}
one is returning a String an the other is returning a array of String (just for test).
My tJava code that instancied my class ClearCodeFab:
String[] codeFab = ClearCodeFab.clear("C:/Talend/Jobs_Talend/EXPORT_BDD_COPAB_ORCAB/IN/codeFabBac.csv");
//String res="";
for (int i=0;i<codeFab.length;i++){
System.out.println(codeFab[i]);
//res=codeFab[i].toString();
//System.out.println(codeFab);
}
I switch by uncommenting if String or array of String for test.
This is what i want in output :
MMM01;3M BRICOLAGE
ABS01;AB SOLUTIONS
ABB01;ABB
ACO01;ACOVA
ACT03;ACTION PIN
ACT01;ACTIS
ACT02;ACTON
AFY01;AFY
AGI01;AGI ROBUR
AGL01;AGL
AIR02;AIRCALO
AIR03;AIR-FIX
AKW01;AKW
ALC01;ALCAD
ALD01;ALDES
ALF01;ALFERCAT RACORDS
ALG01;ALGIMOUSS
ALI01;ALIAXIS
ALL02;ALLO SOINS
ALP01;ALPATEC
ALP03;ALPENWOOD
ALP02;ALPHA INNOTEC
ALS01;ALSAFIX
AMA01;AMACO
AMB01;AMBIANCE BAIN
AMP01;AMPACK
ANJ01;ANJOS
ANQ01;ANQUIER
AOS01;AO SMITH
AQU02;AQUA+
AQU01;AQUARINE
GROUP;ATLANTIC ...
That's my issue message when i return a String or array of String :
Exécution en erreur :Erreurs de compilation du Job
Au moins le Job "recupCodeFabricantBac" a des erreurs de compilation, réparez et réexportez.
Ligne en erreur: 793
Message détaillé: Type mismatch: cannot convert from String[] to String
Il peut y avoir d'autres erreurs causées par la compatibilité avec la JVM. Vérifiez que les paramètres de votre JVM sont les mêmes que dans le studio.
Job recupCodeFabricantBac terminé à 08:43 30/09/2020. [Code sortie=0]
I didn't see String[] in tMap types.
@Jesperrekuh :
I changed my regex by this "\\s?[(\\[\\\\]+\\s?+[A-Z]{1,6}[0-9]{1,6}+\\s?+[)\\]\\\\]+" for more readability.
Any ideas ?
Thanks.
Hi Gadje,
what about below approach. Is it good for you? If yes, remember about error handlanding, it's just a sample 😉
Hi pakapi,
thanks for your reply and sorry for the delay of mine.
I would like to learn how to do it (catch data from Array of String in tMap), just for improve my Talend skills.
for the rest, i succeeded to do what i needed.
If somebody knows how catch data from an java method in tMap, it will be great.
Thanks in advance.
Hi Gadje,
you should convert Array to String if you would like to use it in tMap. Read about it f.g here: https://www.baeldung.com/java-array-to-string
Hi Pakapi,
I made this class:
public class ClearCodeFab {
public static String codeFab(String pathFile) throws IOException{
String line="";
String[] tabVal=null;
String splitter=";";
String result="";
BufferedReader br = new BufferedReader(new FileReader(pathFile));
while((line = br.readLine())!=null){
tabVal=line.split(splitter);
String codeFab=tabVal[0];
String nomFab=tabVal[1];
result=codeFab+" - "+nomFab;
System.out.println(result);
}
return result;
}
}
And i instancied it in tJava like that :
ClearCodeFab.main("C:/Talend/Jobs_Talend/EXPORT_BDD_COPAB_ORCAB/OUT/codeNomFab.csv");
I can see the lines in console with System.out but i don't catch anything in my tFilOutpuDelimited
First, add br.close(); before return result in your code.
As far as I know, tJava dosen't return flow, so you should use f.g tFixedFlowInput, and just call your method with parameter inside: