Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get user Id programmically?

Zawistowski Grzegorz November 18, 2015

I run in compilator this code, 

com.atlassian.jira.user.util.UserManager userManager = ComponentAccessor.getUserManager();
        ApplicationUser user = userManager.getUserByName(leadDispayName);
        String userId=user.getId().toString();
        
        params.put("userId", userId);

And it shows this error:

  Unable to run plugin code because of 'java.lang.NoSuchMethodError - com.atlassian.jira.user.ApplicationUser.getId()Ljava/lang/Long;

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
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.
November 18, 2015

My best guess is that you've compiled your code against one version of JIRA and then installed the add-on in a version where the user management has changed.  Later versions of JIRA don't have a getID, they use getKey() for a start.

 

Zawistowski Grzegorz November 18, 2015

But if I put getKey() it shown me the name admin on the parameter. Not number.

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.
November 18, 2015

But that's the key you need, the numbers aren't there any more.

Zawistowski Grzegorz November 18, 2015

But how could I get avatar of user ? If I get img i must put avatarid of user: <img alt="admin" src="http://gzawistowskilp2:2990/jira/secure/useravatar?size=small&ownerId=admin&avatarId=10400">;

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.
November 18, 2015

Ah, that would have helped earlier in the conversation. AvatarService.getAvatar expects you to give it a *user*, not an ID, so I've no idea why you were looking for the user ID. And, from memory, it can return the absolute URL with a different get function.

Zawistowski Grzegorz November 18, 2015

Oh thank You Nic :)

Zawistowski Grzegorz November 18, 2015

But in Avatar I have got still: 9ud fe80:0:0:0:e97c:5225:d756:dce7%16 /projects/TEST [com.atlassian.ozymandias.SafePluginPointAccess] A LinkageError indicates that plugin code was compiled with outdated versions. Unable to run plugin code because of 'java.lang.NoSuchMethodError - com.atlassian.jira.avatar.AvatarService.getAvatarURL(Lcom/atlassian/jira/user/ApplicationUser;Ljava/lang/String;)Ljava/net/URI;

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.
November 18, 2015

Ok, that goes back to "you've compiled for one version of JIRA and run it on another". Try compiling it on the same version that you're targeting.

Zawistowski Grzegorz November 18, 2015

How could I choose of compilance Version of Jira ? maybe atlas-clean command ?

Zawistowski Grzegorz November 18, 2015

How choose a compilance of version ? in POM I set: <jira.version>6.4.11</jira.version> <amps.version>5.1.16</amps.version> <plugin.testrunner.version>1.2.3</plugin.testrunner.version> <atlassian.spring.scanner.version>1.2.6</atlassian.spring.scanner.version> <!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. --> <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key> <!-- TestKit version 6.x for JIRA 6.x --> <testkit.version>6.3.11</testkit.version>

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.
November 18, 2015
Zawistowski Grzegorz November 18, 2015

Yes I know this link, but how change compiled for one version of Jira and run in another?

Zawistowski Grzegorz November 18, 2015

I have a problem to understand difference.

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.
November 18, 2015

It looks like you are compiling it for version X, and installing in Y. That's all I can tell you from the information here, I don't know how you're managing to do that. Although the answer given a couple of days ago is a possibility.

Zawistowski Grzegorz November 18, 2015

But now in footer I have got: Atlassian JIRA Project Management Software (v6.4.11#64026-sha1:78f6ec4) like in my POM file: <properties> <jira.version>6.4.11</jira.version> <amps.version>5.1.16</amps.version> <plugin.testrunner.version>1.2.3</plugin.testrunner.version> <atlassian.spring.scanner.version>1.2.6</atlassian.spring.scanner.version> <!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. --> <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key> <!-- TestKit version 6.x for JIRA 6.x --> <testkit.version>6.3.11</testkit.version> </properties>

Zawistowski Grzegorz November 18, 2015

After atlas-clean it helped. Thank You Nic :)

0 votes
Volodymyr Krupach
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.
November 18, 2015

ApplicationUser.getId() appeared only since version 7.0.0 and you are probably compiling against previous JIRA.

Anyway I guess that what you need is userKey: user.getKey() and not id. JIRA DB (at least till 7.0.0) uses userKey varchar(255) as key for the user.

Zawistowski Grzegorz November 18, 2015

Byt then it write me user name - admin. I want to take user avatar.

0 votes
Mario Günter
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.
November 18, 2015

Hi Zawistowski Grzegorz, 

please try user.getKey() instead of Id. The ID of a user is equal to his/her key.

For documentation please refer to: 

https://docs.atlassian.com/jira/6.4.1/com/atlassian/jira/user/ApplicationUser.html

Hope this helps.

Cheers,
Mario

TAGS
AUG Leaders

Atlassian Community Events