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

在Bonita中使用Groovy时没有方法错误的签名,groovy,bonita,Groovy,Bonita,我用的是Bonita 7.7.4。Groovy脚本可以在Bonita中使用。 我写了下面的脚本,它工作了,但当“状态”字段不存在时,它就有错误 String status = apiAccessor.identityAPI.getCustomUserInfo(startedById, 0, 1000).stream().filter({ row -> "status" == row.getDefinition().getName() }).findFirst().orEl

我用的是Bonita 7.7.4。Groovy脚本可以在Bonita中使用。 我写了下面的脚本,它工作了,但当“状态”字段不存在时,它就有错误

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. ( )
问题就在这里

.findFirst().orElse("").getValue();
用这个代替

.findFirst().orElse("");
解释 对
流调用
findFirst()
,因此它返回一个
可选的
。如果流为空
。orElse(“”
确保返回空字符串,而不是流的第一个元素。显然,如果您希望在流为空时返回
null
,请使用以下命令

.findFirst().orElse(null);
问题就在这里

.findFirst().orElse("").getValue();
用这个代替

.findFirst().orElse("");
解释 对
流调用
findFirst()
,因此它返回一个
可选的
。如果流为空
。orElse(“”
确保返回空字符串,而不是流的第一个元素。显然,如果您希望在流为空时返回
null
,请使用以下命令

.findFirst().orElse(null);

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

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

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

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

方法java.lang.String.getValue()
…orElse(“”)处没有签名。getValue()
似乎是最有可能发生这种情况的地方。因为您有返回字符串的
.orElse(“”
)。字符串没有getValue()方法是的,你是对的,我更改了它,它可以工作:.orElse(null)?.getValue()<代码>没有方法的签名:java.lang.String.getValue()
…orElse(“”)处。getValue()
似乎是最有可能发生这种情况的地方。因为您有返回字符串的
.orElse(“”
)。字符串没有getValue()方法是的,你是对的,我更改了它,它可以工作:.orElse(null)?.getValue();