在Bonita中使用Groovy时没有方法错误的签名

时间:2019-05-15 06:03:51

标签: groovy bonita

我正在使用Bonita 7.7.4。 Groovy脚本可以在Bonita中使用。 我在下面的脚本中编写了该脚本,并且可以正常工作,但是当“ status”字段没有退出时,就会出错。

String status = apiAccessor.identityAPI.getCustomUserInfo(startedById, 0, 1000).stream().filter({ row ->
        "status" == row.getDefinition().getName() 
}).findFirst().orElse("").getValue();

错误:

Possible solutions: getClass(), getAt(int), getAt(groovy.lang.Range), getAt(java.lang.String), getAt(groovy.lang.Range), getAt(java.util.Collection) ( ). ( )
at org.bonitasoft.engine.execution.ProcessExecutorImpl.start(ProcessExecutorImpl.java:839)
at org.bonitasoft.engine.execution.ProcessExecutorImpl.start(ProcessExecutorImpl.java:782)
at org.bonitasoft.engine.api.impl.ProcessStarter.start(ProcessStarter.java:132)
at org.bonitasoft.engine.api.impl.ProcessStarter.start(ProcessStarter.java:103)
at ... 44 more. ( )
at  Caused by: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException.: groovy.lang.MissingMethodException: No signature of method: java.lang.String.getValue() is applicable for argument types: () values: []
 Possible solutions: getClass(), getAt(int), getAt(groovy.lang.Range), getAt(java.lang.String), getAt(groovy.lang.Range), getAt(java.util.Collection) ( ). ( )
at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:147)
at org.bonitasoft.engine.expression.impl.ExpressionServiceImpl.evaluate(ExpressionServiceImpl.java:86)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionWithResolvedDependencies(ExpressionResolverServiceImpl.java:213)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionsFlatten(ExpressionResolverServiceImpl.java:120)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluate(ExpressionResolverServiceImpl.java:83)
at org.bonitasoft.engine.execution.ProcessExecutorImpl.initializeSingleBusinessData(ProcessExecutorImpl.java:448)
at org.bonitasoft.engine.execution.ProcessExecutorImpl.initializeBusinessData(ProcessExecutorImpl.java:435)
at org.bonitasoft.engine.execution.ProcessExecutorImpl.initialize(ProcessExecutorImpl.java:387)
at org.bonitasoft.engine.execution.ProcessExecutorImpl.start(ProcessExecutorImpl.java:824)
at ... 47 more. ( )
at  Caused by: groovy.lang.MissingMethodException.: No signature of method: java.lang.String.getValue() is applicable for argument types: () values: []
  Possible solutions: getClass(), getAt(int), getAt(groovy.lang.Range),   getAt(java.lang.String), getAt(groovy.lang.Range), getAt(java.util.Collection) ( ). ( )
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at BScript83.run(BScript83.groovy:47)
at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:141)
at ... 55 more. ( )

2 个答案:

答案 0 :(得分:0)

问题在这里

.findFirst().orElse("").getValue();

改为使用此

.findFirst().orElse("");

说明

findFirst()上调用

Stream<String>,因此它返回一个Optional<String>。如果流为空,.orElse("")确保返回一个空字符串,而不是流的第一个元素。显然,如果您宁愿在流为空时返回null,请使用以下

.findFirst().orElse(null);

答案 1 :(得分:0)

您正在编写Java 8代码,可以选择Groovy语法:

def status = apiAccessor.identityAPI
                 .getCustomUserInfo(startedById, 0, 1000)
                 .find { "status" == it.getDefinition().getName() }
                 ?.getValue()