0

This is my groovy script:

def map = ["curr_dept":codes.get("ICU_DEPT").value];
def list = getActLists(visit,"TRAN",map,[]);
boolean flag = false;
if(null!=list && list.size()>=1){
    return true;
}
return false;

This is my java code for executing script, in class "SingleDiseaseAction" method "testConfig()":

GroovyClassLoader loader = new GroovyClassLoader();
Map<String, Class<?>> totalMap = new HashMap<String, Class<?>>();
Class<?> newClazz = loader.parseClass(hsdqTargetConfig.getTarget_compute());
totalMap.put(hsdqTargetConfig.getTarget_compute(), newClazz);
Object obj = newClazz.newInstance();
Script script = (Script) obj;
Object[] paramters = new Object[] { script, getTestVisit(), hsdqRecord, map };
GroovyUtils.newInstance().invokeMethod("initScript", paramters);
value = script.run();

In above code, my groovy script can be getted by the code "hsdqTargetConfig.getTarget_compute()".

The "initScript" method is just for import some util class:

def initScript(Script dslScript,Object obj,Object record,Map codes){
    dslScript.setProperty('codes', codes);
    def rootName =  obj.getClass().getSimpleName();
    def recordName = record.getClass().getSimpleName();
    dslScript.setProperty(rootName.substring(0,1).toLowerCase() + rootName.substring(1), obj);
    dslScript.setProperty(recordName.substring(0,1).toLowerCase() + recordName.substring(1), record);
    dslScript.setProperty('HLRUtils', HLRUtils);
    dslScript.setProperty('DateUtils', DateUtils);
    dslScript.setProperty('EnumUtils', EnumUtils);
}

Thank you for read this. Sorry for my bad English.
Here is the error report :

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script1440555137250324574603.groovy: 4: expecting ')', found ';' @ line 4, column 32.
if(null!=list && list.size()&gt;=1){
                              ^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:359)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:142)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:108)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:162)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:912)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:574)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:550)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:527)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:202)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:212)
at com.goodwill.hdeap.web.console.record.singleDisease.SingleDiseaseAction.testConfig(SingleDiseaseAction.java:699)

My groovy jar is "groovy-all-2.1.6.jar".
I have check groovy's Syntax. Groovy should support the ">" operator.
But now I don't know why it is error.
Is it because of the convert operate from ">" to "&gt;" ? If sure, what I can do for this problem?

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Rocky Yu
  • 23
  • 4

1 Answers1

0

Wow, that is weird. It looks like an HTML encoding error, but that doesn't make sense.

Try the safe dereference operator:

def map = ["curr_dept":codes.get("ICU_DEPT").value];
def list = getActLists(visit,"TRAN",map,[]);
boolean flag = false;
return list?.size() != 0
Emmanuel Rosa
  • 9,697
  • 2
  • 14
  • 20
  • Thanks for your answer ! I write the groovy script code on one web page. I think perhaps the reason is about HTML encoding . I will check it. – Rocky Yu Aug 26 '15 at 04:14
  • Thank you for your prompt. I write the groovy code in web page's form. I check my MySQL database.When i write a ``">"`` in form, it is converted to ``">"``in database field. Now i think i must write groogy code directly in SQL. – Rocky Yu Aug 26 '15 at 04:27
  • Ahhh. Now it makes sense. It sounds like your back end is getting encoded data from your html form. That's a good thing. You can just decode it prior to saving it in mysql. – Emmanuel Rosa Aug 26 '15 at 04:32
  • I will try it. Very thanks for your advice. I will try to decode it prior to saving it in mysql. – Rocky Yu Aug 26 '15 at 04:44