AnsweredAssumed Answered

JDOM setAttribute on GroovyScript

Question asked by errol.cristales404236 on Mar 27, 2018
Latest reply on Mar 29, 2018 by sterling.papp008063

Hi Everyone,

 

I am currently trying to use the setAttribute method from object org.jdom.Element,

I find it odd though that I'm encountering the error: No signature of method: org.jdom.Element.setAttribue() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [SEGMENT, 1, ] , when I'm passing 2 strings   myElement.setAttribue("SEGMENT", "1"); as needed from the JDOM api document. Has someone encountered the same error and how did you resolve it?

the following are snippet of the error and the re-purposed script I found here on the forums.

 

 

 

   com.boomi.process.ProcessException: Error executing data process
    at com.boomi.process.shape.BaseFiberShape.prepareFiberThrown(BaseFiberShape.java:259)
    at com.boomi.process.shape.CatchErrorsShape.executeInitial(CatchErrorsShape.java:255)
    at com.boomi.process.shape.BaseFiberShape.execute(BaseFiberShape.java:77)
    at com.boomi.process.shape.CatchErrorsShape.execute(CatchErrorsShape.java:123)
    at com.boomi.process.graph.ProcessShape.executeShape(ProcessShape.java:559)
    at com.boomi.process.graph.ProcessGraph.executeShape(ProcessGraph.java:489)
    at com.boomi.process.graph.ProcessGraph.executeNextShapes(ProcessGraph.java:573)
    at com.boomi.process.graph.ProcessGraph.executeShape(ProcessGraph.java:510)
    at com.boomi.process.graph.ProcessGraph.executeNextShapes(ProcessGraph.java:573)
    at com.boomi.process.graph.ProcessGraph.execute(ProcessGraph.java:308)
    at com.boomi.process.ProcessExecution.call(ProcessExecution.java:812)
    at com.boomi.execution.ExecutionTask.call(ExecutionTask.java:935)
    at com.boomi.execution.ExecutionTask.call(ExecutionTask.java:61)
    at com.boomi.util.concurrent.CancellableFutureTask.run(CancellableFutureTask.java:160)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.boomi.process.ProcessException: Error executing data process
    at com.boomi.process.shape.DataProcessShape.execute(DataProcessShape.java:52)
    at com.boomi.process.graph.ProcessShape.executeShape(ProcessShape.java:559)
    at com.boomi.process.graph.ProcessGraph.executeShape(ProcessGraph.java:489)
    at com.boomi.process.graph.ProcessGraph.executeNextShapes(ProcessGraph.java:573)
    at com.boomi.process.graph.ProcessGraph.executeShape(ProcessGraph.java:510)
    at com.boomi.process.graph.ProcessGraph.executeNextShapes(ProcessGraph.java:573)
    at com.boomi.process.graph.ProcessGraph.executeShape(ProcessGraph.java:510)
    at com.boomi.process.graph.ProcessGraph.executeNextShapes(ProcessGraph.java:573)
    at com.boomi.process.graph.ProcessGraph.execute(ProcessGraph.java:308)
    at com.boomi.process.ProcessExecution.call(ProcessExecution.java:812)
    at com.boomi.execution.ExecutionTask.call(ExecutionTask.java:935)
    at com.boomi.execution.ExecutionTask.call(ExecutionTask.java:61)
    at com.boomi.util.concurrent.CancellableFutureTask.run(CancellableFutureTask.java:160)
    at com.boomi.execution.NestedExecutionForker$NestedSynchronousExecutionFuture.runSynchronous(NestedExecutionForker.java:203)
    at com.boomi.execution.NestedExecutionForker$NestedSynchronousExecutionFuture.get(NestedExecutionForker.java:171)
    at com.boomi.execution.NestedExecutionForker$NestedSynchronousExecutionFuture.get(NestedExecutionForker.java:150)
    at com.boomi.execution.ExecutionTask.getChildResult(ExecutionTask.java:1307)
    at com.boomi.execution.ExecutionTask.getChildResult(ExecutionTask.java:1293)
    at com.boomi.process.shape.ChildInvokerShape.getChildResult(ChildInvokerShape.java:41)
    at com.boomi.process.shape.CatchErrorsShape.executeInitial(CatchErrorsShape.java:250)
    ... 15 more
Caused by: com.boomi.process.ProcessException: No signature of method: org.jdom.Element.setAttribue() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [SEGMENT, 1, ]
Possible solutions: setAttribute(java.lang.String, java.lang.String), setAttribute(java.lang.String, java.lang.String, org.jdom.Namespace), getAttributes(), getAttribute(java.lang.String), getAttribute(java.lang.String, org.jdom.Namespace), setAttribute(org.jdom.Attribute) (in groovy2 script)
    at com.boomi.process.graph.ProcessShape.failProcess(ProcessShape.java:772)
    at com.boomi.process.graph.ProcessShape.notifyDocumentStatus(ProcessShape.java:630)
    at com.boomi.document.util.DocumentUtil.failProcess(DocumentUtil.java:122)
    at com.boomi.document.impl.OutboundDocumentGroupImpl.failRemainingDocuments(OutboundDocumentGroupImpl.java:125)
    at com.boomi.document.handler.DocumentMultiProcessExecutor.invoke(DocumentMultiProcessExecutor.java:36)
    at com.boomi.document.util.DataProcessExecutor.executeStep(DataProcessExecutor.java:111)
    at com.boomi.document.util.DataProcessExecutor.executeDataProcess(DataProcessExecutor.java:65)
    at com.boomi.process.shape.DataProcessShape.execute(DataProcessShape.java:50)
    ... 34 more
Caused by: com.boomi.execution.ExecutionException: No signature of method: org.jdom.Element.setAttribue() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [SEGMENT, 1, ]
Possible solutions: setAttribute(java.lang.String, java.lang.String), setAttribute(java.lang.String, java.lang.String, org.jdom.Namespace), getAttributes(), getAttribute(java.lang.String), getAttribute(java.lang.String, org.jdom.Namespace), setAttribute(org.jdom.Attribute) (in groovy2 script)
    at com.boomi.execution.ScriptExecutorManager$SimpleScriptExecutor.execute(ScriptExecutorManager.java:371)
    at com.boomi.document.scripting.ScriptingDocumentHandler.execute(ScriptingDocumentHandler.java:80)
    at com.boomi.document.handler.DocumentMultiProcessExecutor.invoke(DocumentMultiProcessExecutor.java:33)
    ... 37 more
Caused by: groovy.lang.MissingMethodException: No signature of method: org.jdom.Element.setAttribue() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [SEGMENT, 1, ]
Possible solutions: setAttribute(java.lang.String, java.lang.String), setAttribute(java.lang.String, java.lang.String, org.jdom.Namespace), getAttributes(), getAttribute(java.lang.String), getAttribute(java.lang.String, org.jdom.Namespace), setAttribute(org.jdom.Attribute)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
    at org.codehaus.groovy.vmplugin.v7.IndyGuardsFiltersAndSignatures.unwrap(IndyGuardsFiltersAndSignatures.java:177)
    at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
    at Script7.run(Script7.groovy:32)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
    at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72)
    at javax.script.CompiledScript.eval(CompiledScript.java:106)
    at com.boomi.execution.ScriptExecutorManager$SimpleScriptExecutor.execute(ScriptExecutorManager.java:341)
    ... 39 more
    
    

 

    
    import org.jdom.input.SAXBuilder;  
    import org.jdom.Document; 

    import org.jdom.Element;
    import org.jdom.xpath.XPath;  
    import org.jdom.output.XMLOutputter;  
    
    // Set the full path to the XML element containing the values to split.  
    String[] segmentsToCheck = ["/xpath1", "/xpath2", "/xpath3", "/xpath4"];  
 
      
    // Loop through the Process Documents  
    for (int i = 0; i < dataContext.getDataCount(); i++) {  
     InputStream is = dataContext.getStream(i);  
     Properties props = dataContext.getProperties(i);  
      
     // Build XML Document  
     SAXBuilder builder = new SAXBuilder();  
     Document doc = builder.build(is);  
     

 

     for (int k = 0; k < segmentsToCheck.length; k++) {  
      XPath x = XPath.newInstance(segmentsToCheck[k]);  
      
      // Select multiple nodes and loop through them  
      myElements = x.selectNodes(doc);  
      
      if (myElements != null) {
      
        for (Element myElement: myElements) {
          
           myElement.setAttribue("SEGMENT", "1");
      
        }
      }  
      
     }  
      
     XMLOutputter outputter = new XMLOutputter();  
     is = new ByteArrayInputStream(outputter.outputString(doc).getBytes("UTF-8"));  
     dataContext.storeStream(is, props);  
      
    }  

Outcomes