Can't get isUserMemberOfRole() to work

Stefan Johansson July 2, 2014

Im in need of the functionallity of the isUserMemberOfRole. When I use it in my validator script an exception is thrown saying there is "No Signature of method" that is applicable for argumnent types String.

I have tried to find any documentation of it but only found it in various examples where it is used directly with a String as input. Is there any page with documentation of such Script runner closures?

2 answers

1 accepted

5 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2014

Those functions are only available in the condition block and the additional actions block of built-in scripts. You can just copy the impl to your script:

Closure isUserMemberOfRole = {String role ->
            ProjectManager projectManager = componentManager.getProjectManager()

            ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class)
            ProjectRoleActors projectRoleActors =
                projectRoleManager.getProjectRoleActors(projectRoleManager.getProjectRole(role), issue.getProjectObject())
            projectRoleActors.getUsers().contains(currentUser)
        }

where currentUser might be:

ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 2, 2014

That error means you're passing the wrong thing into the function. This may well not really be a script-runner problem, it's to do with the API in Jira.

How are you using isUserMemberOfRole? (I mean, the full use, is it from a manager object of some sort?)

Stefan Johansson July 2, 2014

I actually only use it in an if statement such as:

if (isUserMemberOfRole("Project Manager")){
   something
}else {
   somethingelse
}

From what Ive seen on other posts I presumed it is something script-runner provides during runtime. In my IDE, calling the function show there is no linkage to anything in my API. Is there an import or something I should use?

During the exception it says it tried to link it to something in the "org.codehaus.groovy.jsr223.GroovyScriptEngineImpl", probably because it couldnt find any match.

Thanks for your quick reply!

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 2, 2014

Yup, I see what you mean. Could you give us a bit more of the error message?

There's usually a bit after that error saying something like "can't do this, try flibble.impl.jira.string[Role: blada][fungus]" (Sorry, that's a string of rubbish, I can't remember a typical error message - the important bit is that it tries to tell us somethign about what the function is expecting, with a "try" in the middle of the block)

Stefan Johansson July 2, 2014

Unfortuenately i get two "... 180 more" lines message that dont show in catalina.out. Is there a way to expand the error message and get it all written to the log? I tried it in the script-runner consol also but it resulted in the same with to many traces.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 2, 2014

Yeah, java stack traces - helpful for developers, gives the rest of us nightmares trying to unpick them

Could you look for a line that says "Possible solutions" - it should happen almost immediately after the "no signature of method" line - include both of those lines here!

Stefan Johansson July 2, 2014

Ive seen those possible solutions other times when i have made an error but this time there isn't any entry with possible solutions.

2014-07-03 12:45:28,919 http-8080-2 ERROR stefanj 765x19739x1 86higu 10.10.2.58,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.isUserMemberOfRole() is applicable for argument types: (java.lang.String) values: [Project Manager]
2014-07-03 12:45:28,920 http-8080-2 ERROR stefanj 765x19739x1 86higu 10.10.2.58,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyValidator] Script validator failed on SES-766: /srv/jira-home/scripts/validators/CheckIfCurrentUserIsInRole.groovy
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.isUserMemberOfRole() is applicable for argument types: (java.lang.String) values: [Project Manager]
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:195)
        at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
	...

Maybe it cant connect or relate the method call to anything in the vicinity.

Ive been thinking about that it says "org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.isUserMemberOfRole()" - this must be something connected to the usual groovy, shouldn't it be something connected to script runner?

Where should it look for that method? Ive read that Jamie calls the method an "closure defined in the script runner plugin", do you know what that means or where I can read about such methods?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 2, 2014

Hmm, there's no suggestions coming out there, not sure why I'm getting them.

It really doesn't seem to like the string you're passing in. I wonder if feeding it a "role" object would work.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2014

You are using it in the right way IIRC. I think the issue is it's not available in the script binding for some reason. This is in the script for a "simple scripted validator", or is it your own script? A screenshot might help.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 2, 2014

Ah, ok, I've not used that function, thanks for the correction before my suggestion sent Stefan off down the wrong route!

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2014

No worries, thanks for helping.

Stefan Johansson July 2, 2014

Its my own script. Its very basic because i just wanted to confirm that I used the isUserMemberOfRole method correctly.


import org.apache.log4j.Category

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)

	if(isUserMemberOfRole("Project Manager")){
				
		log.debug "User is in Role Project Manager"
	}else {		
		log.debug "User is not in Role Project Manager"	
	}

Or did you mean a screenshot of the stack trace?
Appreciate the help from you both!

Stefan Johansson July 3, 2014

This worked great, thanks for taking the time! Can I just accept your post as the answer in someway?

If I had any karma to give, you would get it!

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2014

I converted it to an answer, you can accept that. Thanks!

Suggest an answer

Log in or Sign up to answer