Reputation: 823
I am trying to use the datamapper. I am trying to modify the script to my liking but I keep getting an error even though in the graphical visualisation it seems to be working I can see the string separated.
Here's my script
String streetnumaddress = input.streetAddress;
String[] parts = streetnumaddress.split(",");
String streetnumber = parts[0];
String streetaddress = parts[1];
output.blabla= "Hello";
output.telephone = input.telephoneNumber;
output.lastname= input.sn;
output.firstname= input.givenName;
output.email = input.mail;
output.city= input.l;
output.province = input.st;
output.codepostal = input.postalCode;
output.country= "CA";
output.telephoneinternet = input.telephoneNumber;
output.immeubleetsuffixe = streetnumber;
output.odonyme = streetaddress;
Basically the problem is the split. When I affect a String directly like output.blabla= "Hello"; This works. But the split and affectation doesn't work. Any idea how to fix it and if it's even possible in the first place to do this?
Here is my error.
Exception while trying to execute your data mapping.
Check:
• All the required libraries are declared on the classpath.
• No errors are shown on the mapping.
• If using groovy script, check your script is valid.
Cause By:
Component [Foreach 'array' -> 'array':FOREACH_ARRAY_ARRAY] finished with status ERROR.
org.jetel.exception.JetelRuntimeException: Component [Foreach 'array' -> 'array':FOREACH_ARRAY_ARRAY] finished with status ERROR.
at org.jetel.graph.Node.createNodeException(Node.java:543)
at org.jetel.graph.Node.run(Node.java:522)
at org.jetel.graph.runtime.SingleThreadWatchDog.executePhase(SingleThreadWatchDog.java:88)
at org.jetel.graph.runtime.WatchDog.call(WatchDog.java:266)
at com.mulesoft.mule.module.datamapper.clover.impl.CloverEngineImpl.execute(CloverEngineImpl.java:92)
at com.mulesoft.mule.module.datamapper.clover.impl.CloverEngineImpl.execute(CloverEngineImpl.java:151)
at com.mulesoft.mule.module.datamapper.clover.impl.CloverEngineImpl.execute(CloverEngineImpl.java:37)
at com.mulesoft.mule.module.datamapper.impl.DefaultGraphExecutor.execute(DefaultGraphExecutor.java:85)
at com.mulesoft.mule.module.datamapper.api.DataMapperHelper.execute(DataMapperHelper.java:38)
at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mulesoft.mule.datamapper.ui.graph.service.impl.SingleGraphLauncher.launch(SingleGraphLauncher.java:82)
at com.mulesoft.mule.datamapper.ui.utils.RunGraphJob.run(RunGraphJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.jetel.exception.TransformException: Message: Transform failed!
at org.jetel.component.DataRecordTransform.transformOnError(DataRecordTransform.java:132)
at org.jetel.component.Reformat.execute(Reformat.java:273)
at org.jetel.graph.Node.run(Node.java:493)
... 13 more
Caused by: org.mule.api.expression.ExpressionRuntimeException: Execution of the expression "//MEL
//START -> DO NOT REMOVE
output.__id = str2long(input.__id);
//END -> DO NOT REMOVE
String streetnumaddress = input.streetAddress;
String[] parts = streetnumaddress.split(",");
String streetnumber = parts[0];
String streetaddress = parts[1];
output.blabla= "Hello";
output.telephone = input.telephoneNumber;
output.lastname= input.sn;
output.firstname= input.givenName;
output.email = input.mail;
output.city= input.l;
output.province = input.st;
output.codepostal = input.postalCode;
output.country= "CA";
output.telephoneinternet = input.telephoneNumber;
output.immeubleetsuffixe = streetnumber;
output.odonyme = streetaddress;" failed.
at org.mule.el.mvel.DataMapperExpressionLanguage.evaluate(DataMapperExpressionLanguage.java:71)
at com.mulesoft.datamapper.transform.MelRecordTransform.transform(MelRecordTransform.java:53)
at org.jetel.component.Reformat.execute(Reformat.java:271)
... 14 more
Caused by: java.lang.RuntimeException: cannot invoke method: split
at org.mule.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:63)
at org.mule.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:37)
at org.mule.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
at org.mule.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)
at org.mule.mvel2.ast.TypedVarNode.getReducedValueAccelerated(TypedVarNode.java:70)
at org.mule.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
at org.mule.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mule.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mule.mvel2.MVEL.executeExpression(MVEL.java:943)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:72)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:35)
at org.mule.el.mvel.DataMapperExpressionLanguage.evaluate(DataMapperExpressionLanguage.java:67)
... 16 more
Caused by: java.lang.NullPointerException
at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mule.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)
... 27 more
Upvotes: 2
Views: 681
Reputation: 823
I changed it for a Groovy script instead as such :
String acronymeministere = "YOOOO;"
String pays = "CA;"
String finalString = ""
payload.each { p ->
String telephoneinternet = ";";
String telephone = ";";
String telecopieur = ";"
String nomdefamille = ";";
String prenom = ";";
String initale =";"
String qualificateurdegen = ";"
String email = ";";
String immeubleetsuffixe = ";"
String odonyme = ";"
String ville = ";";
String province = ";";
String codepostal = ";";
String casepostale = ";"
String bureau = ";"
String etage = ";"
String localisation = ";"
String edifice = ";"
String autres =";"
if(p.streetAddress != null){
String streetnumaddress = p.streetAddress;
String[] parts = streetnumaddress.split(",");
immeubleetsuffixe = parts[0].trim() + immeubleetsuffixe
odonyme = parts[1].trim() + odonyme
}
telephoneinternet = p.telephoneNumber.toString().trim() + telephoneinternet
telephone = p.telephoneNumber.toString().trim() + telephone
nomdefamille = p.sn.toString().trim() + nomdefamille
prenom = p.givenName.toString().trim() + prenom
email = p.mail.toString().trim() + email
ville = p.l.toString().trim() + ville
province = p.st.toString().trim() + province
codepostal = p.postalCode.toString().trim() + codepostal
finalString += ('"' + acronymeministere+telephoneinternet+telephone+telecopieur+nomdefamille
+prenom+initale+qualificateurdegen+email+immeubleetsuffixe
+odonyme+ville+province+codepostal+casepostale+pays+bureau+
etage+localisation+edifice+autres+ '"'+'\n')
}
return finalString
Upvotes: 2
Reputation: 1
It is possible to split the string and assign the values to out put values in data mapper like you are trying to do.
You are getting a null pointer exception, which means your "input.streetAddress" could be null. can you please check you input street address data is present.
-Vinay
Upvotes: 0