Set confluence home page specific to user groups
Asked by SimratPal Singh:

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.


Answers:
author: Gorka Puente _Appfire_
body: Hi,

I've seen that you can also use UserManager for doing so...

Pom.xml

```
&lt;dependency&gt;            &lt;groupId&gt;com.atlassian.sal&lt;/groupId&gt;            &lt;artifactId&gt;sal-api&lt;/artifactId&gt;            &lt;version&gt;${sal.api.version}&lt;/version&gt;            &lt;scope&gt;provided&lt;/scope&gt;        &lt;/dependency&gt;
```

I'm using version 2.8.0

In your atlassian-plugin.xml

```
&lt;component-import key="userManager" interface="com.atlassian.sal.api.user.UserManager" /&gt;
```

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

comments: author: SimratPal Singh
body: 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.


author: Gorka Puente _Appfire_
body: Could you upload both, pom.xml and atlassian-plugin.xml to see what's going on.

Regards,

Gorka


author: SimratPal Singh
body: 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.


author: Gorka Puente _Appfire_
body: 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


author: SimratPal Singh
body: 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?


author: Gorka Puente _Appfire_
body: 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&lt;Group&gt; 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

comments: author: SimratPal Singh
body: 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?


author: Gorka Puente _Appfire_
body: 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)<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)<https://docs.atlassian.com/atlassian-confluence/5.4.4/com/atlassian/sal/confluence/user/ConfluenceUserManager.html>

Give it a try!

Gorka


author: SimratPal Singh
body: I am new to confluence development so found its constructor arguments too unfamiliar.


author: SimratPal Singh
body: That looks like a very promising solution Girls. But any idea how do I get instance of ConfluenceUserManager


author: SimratPal Singh
body: hat looks like a very promising solution Gorka. But any idea how do I get instance of ConfluenceUserManager


author: Yagnesh Bhat
body: 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.


author: Theophil Xavier
body: @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](http://com.atlassian.confluence.it/).user.UserProfile**   

**Number 2 has setHomePage option but i have no way to get object of this userprofile class**

comments: author: Theophil Xavier
body: Gorka and Simrat also uploaded files for you to have a lookatlassian-plugin.xml -\> <http://snk.to/f-cdxpy9px>pom.xml-\> <http://snk.to/f-ctc3g83c>


author: Gorka Puente _Appfire_
body: 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


author: SimratPal Singh
body: 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.


author: SimratPal Singh
body: @Gorka Puente \[Comalatech\] please see my comment above.