How to create (shared) groups in plugin?

I’‘m currently developing a plugin for user administration (adding, changing, deleting), based on the registration plugin. I want to keep all the functionality in the plugin, rather than in the jsp. I’'m using NetBeans and JDK 5.

I don’‘t know how to create a shared group though. I know about group.getProperties(), but I don’'t know how to deal with the Map…

Any help regarding all the properties pertaining to shared groups is appreciated.

In a related issue: if the plugin does extensive adding and removing, are there any concurrency problems to expect? If so, how should I proceed?

Message was edited by:

Op3racional

I would suggest checking out the group editing JSP to see the logic for creeating and editing shared groups – just copy that logic and you should be good.

In terms of concurrency, you can generally assume that the Wildfire API is thread safe. How many add/remove operations are you talking about?

Regards,

Matt

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.jivesoftware.util.ParamUtils;

import org.jivesoftware.wildfire.group.Group;

import org.jivesoftware.wildfire.group.GroupAlreadyExistsException;

import org.jivesoftware.wildfire.group.GroupManager;

import org.jivesoftware.wildfire.plugin.click2show.id.IdentifierGenerator;

import org.jivesoftware.wildfire.plugin.click2show.id.UUIDHexGenerator;

public class AddShareGroupHandler implements IHandler {

public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

String description = ParamUtils.getParameter(request,“description”);

String displayname = ParamUtils.getParameter(request,“displayname”);

String showtype = ParamUtils.getParameter(request,“showtype”);

response.setContentType(“text/xml”);

PrintWriter out = response.getWriter();

String groupname = createShareGroup( description, displayname, showtype);

out.write(groupname);

}

private String createShareGroup(String description,

String displayname, String showtype)

throws GroupAlreadyExistsException {

IdentifierGenerator idGenerator = new UUIDHexGenerator(); //generator group id

String groupname = (String) idGenerator.generate();

Group newGroup = GroupManager.getInstance().createGroup(groupname);

if (newGroup == null) return “-1”; // occur error , return -1

if (description != null) {

newGroup.setDescription(description);

}

if ((!"".equals(showtype)) && (showtype != null) ){

if (“spefgroups”.equals(showtype)) {

newGroup.getProperties().put("sharedRoster.showInRoster ",

“onlyGroup”);

}

}

else {

newGroup.getProperties().put(“sharedRoster.showInRoster”, “nobody”);

}

if (displayname != null) {

newGroup.getProperties().put(“sharedRoster.displayName”,

displayname);

}

newGroup.getProperties().put(“sharedRoster.groupList”, “”);

return groupname;

}

}

/code

-zhuam

zhuam,

Very nice! Thanks for posting a code example!

-Matt

Thanks Matt for clearing the concurrency issue up (and the hint to the group editing jsp)!

Matt: Basically, this is to automate user adminsitration. It should occur at night, when noone is using the system. Initially, it will be a lot of creation (200 users to add)… Later on, we expect to mainly do changes to “full name” and “email”, since the user name is linked to our authentication token.

Thanks zhuam for the code! Very helpful!

Message was edited by:

Op3racional