groovy script issue

jiyoung kim June 8, 2012

this days i tested about jira upgrade from ver 4.4.5(standalon, redhat) to 5.0.5(war, open suse, vm enviroment)

there is a groovy script issue.

this script is work well at jira version 4.4.5. but make a issue at jira version 5.0.5

//===========================================================

import com.atlassian.jira.user.util.UserUtilImpl

//import com.atlassian.core.user.GroupUtils

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.DefaultGroupManager

import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext

//log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
//log.debug ("test " + "test")
//log.error "error"

def allowGroupStr = "crowd-project"
def addUsers = "User to grant"
def addGroups = "Group to add"
String commentValue = ""

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

CustomField customFieldaddUsers = customFieldManager.getCustomFieldObjectByName( addUsers )
println "***" + customFieldaddUsers +"***"
addUsersFieldVal = issue.getCustomFieldValue( customFieldaddUsers )
println "***" + addUsersFieldVal + "***"
CustomField customFieldaddGroups = customFieldManager.getCustomFieldObjectByName( addGroups )
addGroupsFieldVal = issue.getCustomFieldValue( customFieldaddGroups )

//IssueFactory issueFactory = componentManager.getIssueFactory()
//MutableIssue issue = issueFactory.getIssue()
//User currentUser = componentManager.getJiraAuthenticationContext().getUser()
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

println "*** test code ****"
User userToAdd1 = UserUtils.getUser( "test11" )

println "***test" + userToAdd1 +" **test**"

===========================================================//

from this script

fail to getCustomFieldValue and getUser.

the error log is

//============================================================

***User to grant***
***[com.atlassian.crowd.embedded.ofbiz.OfBizUser@ab3680ae]***
*** test code ****
***testcom.atlassian.crowd.embedded.ofbiz.OfBizUser@ab3680ae **test**

=============================================================//

I don't know why this error message is printed.

do you know the solution?

plz help me :)

2 answers

0 votes
Dieter
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.
June 8, 2012

Hi Jiyoung,

I have made some changes in your code to make it run on Jira 5

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.crowd.embedded.api.User;


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.GroupManager;

import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext


import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.issue.Issue;



 

//log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
//log.debug ("test " + "test")
//log.error "error"


def allowGroupStr = "crowd-project"
def addUsers = "User to grant"
def addGroups = "Group to add"
String commentValue = ""

// get all managers if possible using ComponentAccessor
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

// please use this in Jira 5
GroupManager groupManager = ComponentAccessor.getGroupManager()

CustomField customFieldaddUsers = customFieldManager.getCustomFieldObjectByName( addUsers )
println "***" + customFieldaddUsers +"***"
List addUsersFieldVal = issue.getCustomFieldValue( customFieldaddUsers )
addUsersFieldVal.each() {println "*** " + it.getName()}

println "***" + addUsersFieldVal + "***"
CustomField customFieldaddGroups = customFieldManager.getCustomFieldObjectByName( addGroups )
addGroupsFieldVal = issue.getCustomFieldValue( customFieldaddGroups )

//IssueFactory issueFactory = componentManager.getIssueFactory()
//MutableIssue issue = issueFactory.getIssue()
//User currentUser = componentManager.getJiraAuthenticationContext().getUser()

User currentUserObject = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

println "*** test code ****"
User userToAdd1 = ComponentAccessor.getUserUtil().getUserObject("test11" )

// use getName(). toString() is not implemented anymore for crowd user objects
println "***test" + userToAdd1.getName() +" **test**"
println "***current user" + currentUserObject.getName() +" **current user**"

jiyoung kim July 2, 2012

thanks so much. I solve that issue ^^

0 votes
Mizan
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.
June 8, 2012

There are some API changes in 5.0 onwards . Have a look at this .

You will have to update your script accordingly to the updated API

Suggest an answer

Log in or Sign up to answer