I am trying to write a customer specific plugin to set home pages for users depending on the groups they are in. My approach is that
1 - Get list of groups
2 - Get list of users in each group
3 - Set home page for each user of every group.
I have been successful step 1 and 2 but not able to acheieve thrid. This is what I am doing for it
UserAccessor userAccessor = (UserAccessor)ContainerManager.getInstance().getContainerContext().getComponent("userAccessor");
private UserSettingsServiceuserSettingsService = new ConfluenceUserSettingsService(userAccessor);
But I get an exection that no class defenition was found for ConfluenceUserSettingsService. Whereas the class is very much in the buildpath of the project and cimpiles fine
If Has anyone done anything such please let me know. Any approach is fine, be it a plugin or code change.
Hi,
I've seen that you can also use UserManager for doing so...
Pom.xml
<dependency> <groupId>com.atlassian.sal</groupId> <artifactId>sal-api</artifactId> <version>${sal.api.version}</version> <scope>provided</scope> </dependency>
I'm using version 2.8.0
In your atlassian-plugin.xml
<component-import key="userManager" interface="com.atlassian.sal.api.user.UserManager" />
And finally, inject the component in your java class
public YourClass(UserManager userManager){ this.userManager= userManager; } void method(){ profile = userManager.getUserProfile(username); profile.setHomepage(homepage); }
Gorka
Thanksa ton for all your help so far Gorka, but I am not able to use the <component-import> statement. I have some errors in my pom.xml and they very original problem of "no class def found" also seems be due the same issue that dependecies. I have 17 erros on my pom.xml and they say this:-
Plugin execution not covered by lifecycle configuration:com.atlassian.maven.plugins:maven-confluence-plugin:5.0.4:compress resources(execution:default-compress-resources, phase process-resources)
I did some research on it and someone was talking abt a file "lifecycle-mapping-metadata.xml". I wasnt able to find any such file at the specified place. Is it possible that my atlassian sdk is not properly installed.
Please advise if you can. And Apologies for too much bugging.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you upload both, pom.xml and atlassian-plugin.xml to see what's going on.
Regards,
Gorka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Gorka Puente Apologies for not eplying to you sooner, this site was down for maintenance. I dont see any provision to upload the files. Can you please send me a test mail on simratpal.singh@glintech.com. I shall email you the files. Any help is greatly appreciated as I am very close to my delivery.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Why don't you upload those files to a public repository (e.g., http://www.filesnack.com/ or any other) and post the links here? So anyone in the forum can have a look! Regards, Gorka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Gorka, I am able to get an object of UserManager after injecting it the way you advised above/ However userManager.getUserProfile(username); This gets me an object of Userprofile but it does not have any provision to get or set the home page. In fact it does not have any setter method. The UserProfile you pointed me in your response above seems to be from a different API. Do I need ot use some other api instead of sal-api?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi SimratPal,
If you want to get all groups and the users in each group, you can inject in your class the groupManager:
public YourClass(GroupManager groupManager){ this.groupManager = groupManager; }
Then, retrieve all groups
Pager<Group> groups = groupManager.getGroups();
And finally, get the members of each group
for(Group group: groups){
Pager<String> membersOfGroup = groupManager.getMemberNames(group); }
Hope this helps,
Gorka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Gorkha, getting groups and its memebrs was never a problem, the issue how to set home page specific to each member. Which property of each user has to be set with home pahe url and how to do it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi SimratPal,
I've not done it ever, but it seems that you need the method UserProfile.setHomepage(java.lang.String homepage
);
https://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/it/user/UserProfile.html
And the UserProfile maybe with ConfluenceUserManager
https://docs.atlassian.com/atlassian-confluence/5.4.4/com/atlassian/sal/confluence/user/ConfluenceUserManager.html
Give it a try!
Gorka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi SimratPal, If you are using confluence 5.x+ , I dont think you need to put anything in the pom for UserManager. Simple inject it via the constructor and your IDE will take care of the imports.
public YourClass { private UserManager userManager; public YourClass(UserManager userManager){ this.userManager= userManager; } //other methods ... }
Try doing this before going into other complexities.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Gorka Puente [Comalatech] - I'm posting on Simrat's behalf as he is having technical difficulties.
Here's what he has to say:
I am able to get an object of UserManager after injecting it the way you advised above/ However userManager.getUserProfile(username); This gets me an object of Userprofile but it does not have any provision to get or set the home page. In fact it does not have any setter method. The UserProfile you pointed me in your response above seems to be from a different API. Do I need ot use some other api instead of sal-api?
There seems to be two UserProfile classes from different APIs
1- com.atlassian.sal.api.user.UserProfile
2 - com.atlassian.confluence.it.user.UserProfile
Number 2 has setHomePage option but i have no way to get object of this userprofile class
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Gorka and Simrat also uploaded files for you to have a look atlassian-plugin.xml -> http://snk.to/f-cdxpy9px pom.xml-> http://snk.to/f-ctc3g83c
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Sorry for that, my mistake. You are right, it's a different class. I've been looking for a setHomepage and I've only found it in the API for spaces. For users, It's not in the public API. Maybe someone from Atlassian can help. Gorka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Gorka, now getting back to the very original question, did you get a chance to look into my pom.xml. I am having build errors and getting No class def found for ConfluenceUserSettingsService. This class has a method "updateusersettings". I want to try that as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Gorka Puente [Comalatech] please see my comment above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.