Current Groovy class with getUser method

Leos Junek
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.
December 17, 2013

Hello to all!

I have upgraded JIRA 4.4.4 to JIRA 6.1.3. The last thing to do was to make plugin Behaviours running. One behaviour, defined long time ago, fills field "Tester" with name of current logged user.

However, it uses class com.opensymphony.com.User, that is not currently available. Due to it I cannot compile script and use method getUser().

I have tried a lot to find alternative class in various discussion forums, but without success. Here are classes I tried and results of their usage:

import com.opensymphony.user.User; (cannot be compiled)
import com.atlassian.crowd.embedded.api.User; (error @ exec)
import com.atlassian.jira.user.UserUtils; (cannot be compiled)
import com.atlassian.jira.user.UserKeyService; (cannot be compiled)

All I need is the name of the class to import to be able to use method getUser(), or the way to find username.

Current script (with no changes described above) is attached.

My JIRA runs as WAR in Tomcat 7.0.29, linux x64.

Could you help me, please?

Leos

2 answers

1 accepted

1 vote
Answer accepted
RambanamP
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.
December 18, 2013

you need to try like this

import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;


FormField formTester = getFieldByName("Tester");
ApplicationUser appUser = ComponentAccessor.getJiraAuthenticationContext().getUser();
User user = appUser.getDirectoryUser();
String currUserFullName = user.getDisplayName();
String currUserName = user.getName();		
		 
log.error (currUserFullName);
log.error (currUserName);
		 
if(formTester.getFormValue() == ""){
	formTester.setFormValue(currUserName);
}

Leos Junek
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.
December 18, 2013

Hello Rambanam!

Thanks a lot! There's no error in my Tomcat log yet. Moreover, script is working, verified by end-users. Thanks!

As I notice, you changed names of imported classes and one line in source code below import commands. Although I don't understand how did you do that, I don't need to know it by hook or crook. I am happy with working code :-)

Regards,

Leoš

RambanamP
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.
December 18, 2013

glad to here it worked!!

you have to change the api's as per the jira version, you can check the jira 6.1 public api here

https://docs.atlassian.com/jira/6.1/allclasses-noframe.html

2 votes
RambanamP
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.
December 17, 2013

import com.opensymphony.user.User ----> it is deprecated

import com.atlassian.crowd.embedded.api.User; -----------> it should work, error will be related to other code

import com.atlassian.jira.user.UserUtils ------> should be work, check this

https://docs.atlassian.com/jira/6.1/com/atlassian/jira/user/UserUtils.html

if it is possible can you share your code here?

Leos Junek
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.
December 17, 2013

Thanks!

My code

import com.opensymphony.user.User;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.ComponentManager;

FormField formTester = getFieldByName("Tester");

ComponentManager componentManager=ComponentManager.getInstance();
User user = componentManager.getJiraAuthenticationContext().getUser();
String currUserFullName = user.getFullName();
String currUserName = user.getName();String currUserName = user.getName();

log.error (currUserFullName);
log.error (currUserName);

if(formTester.getFormValue() == ""){
  formTester.setFormValue(currUserName);
}

Suggest an answer

Log in or Sign up to answer