Hey guys I'm trying to write a macro that will need to retrieve the Confluence user's profile picture when it is given the user name as a parameter. I can't figure out how to access the profile picture of a user.
I saw a similar thread where someone mentioned:
https://answers.atlassian.com/questions/196629/access-users-profile-picture
By using the DefaultUserAccessor it's possible.
1
2
3
|
ProfilePictureInfo pic = defaultUserAccessor.getUserProfilePicture(accountName); String pathToImage = pic.getDownloadPath() |
My Problem is that I can't figure out how to instantiate DefaultUserAccesor
I have no idea what to pass to the constructor.
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor( ????);
Community moderators have prevented the ability to post new answers.
Hi Jason,
You should not construct instances of "accessor" and "manager" classes yourself. You should expect that Confluence will handle the construction of these objects internally, and then provide access to these via a design pattern called "dependency injection" or "inversion of control".
You may find it beneficial to read up general documentation about these design patterns. Alternatively, here is a document that describes how this pattern is applied to Confluence in practice: https://developer.atlassian.com/display/CONFDEV/Spring+IoC+in+Confluence
If you just want the quick answer, then it's here: https://developer.atlassian.com/display/CONFDEV/Accessing+Confluence+Components+from+Plugin+Modules
To summarize, you need to write your code like this:
public class MyClassThatDoesStuff { private UserAccessor theThingIWantToUse; public MyClassThatDoesStuff(UserAccessor confluenceGivesMeTheThingIWantToUse) { this.theThingIWantToUse = confluenceGivesMeTheThingIWantToUse; } public void doStuff() { // In here you can access the UserAccessor } }
In order for this to work, Confluence also needs to be responsible for calling the constructor of your class. You can achieve this by making your class a "component module", which means you'll need to add something like this to your atlassian-plugin.xml:
<component key="myComponent" name="My Component" class="com.example.plugin.MyClassThatDoesStuff"> <description>This is my component in my plugin</description> </component>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh wow, thanks for your help. I finally got it to work. I'm new to dependency injection so this is pretty nifty.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(repositoryAccessor);
Tried this. Note that I'm using bucket.user.DefaultUserAccessor
I get 'DefaultUserAccessor' is abstract; cannot be instantiatiated.
I found another DefaultUserAccessor: com.atlassian.confluence.user.DefaultUserAccessor
This one requires a LOT more arguments though, which I'm not sure how to obtain. Hopefully there's an easier way to do this
public DefaultUserAccessor(com.atlassian.user.configuration.RepositoryAccessor repositoryAccessor, com.atlassian.confluence.security.SpacePermissionManager spacePermissionManager, com.atlassian.confluence.core.ContentEntityManager contentEntityManager, com.atlassian.confluence.mail.notification.NotificationManager notificationManager, com.atlassian.confluence.user.PersonalInformationManager personalInformationManager, com.atlassian.confluence.util.UserChecker userChecker, com.atlassian.confluence.pages.AttachmentManager attachmentManager, com.atlassian.event.EventManager eventManager, com.atlassian.confluence.core.ContentPermissionManager contentPermissionManager, com.atlassian.confluence.security.PermissionManager permissionManager, com.atlassian.confluence.userstatus.UserStatusManager userStatusManager, com.atlassian.confluence.follow.FollowManager followManager, com.atlassian.crowd.embedded.api.CrowdService crowdService, com.atlassian.confluence.user.DisabledUserManager disabledUserManager, com.atlassian.confluence.core.persistence.hibernate.HibernateSessionManager sessionManager, com.atlassian.confluence.user.persistence.dao.ConfluenceUserDao confluenceUserDao, com.atlassian.user.UserManager backingUserManager, com.atlassian.confluence.setup.settings.SettingsManager settingsManager) { /* compiled code */ }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes I saw that but how do I get an instance of RepositoryAccessor?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this what you are looking for?
<th align="left" colspan="2">
protected |
DefaultUserAccessor(com.atlassian.user.configuration.RepositoryAccessor repositoryAccessor) |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.