powered by Jive Software

Mass User Create - Import a CSV of users with just one CLICK!

Hi, I need to create several users at once, so I developed a JSP to import a CSV of users. I fill up even the virtual card!

You just put this jsp in the web dir and is ready to USE!

Since I didn’'t create a plugin there will be no menu acess, you will have do acess directly the JSP in the address bar.

When the page open there is a TextArea to paste the CSV file, and a button to submit. The layout is exactly like the rest of the application.

The format of the CSV is : username;nome;password;email;group;full name;city;Company Unit;Tel.;company;URL of company;country

I don’'t have time to make a plugin, but I think this code will help a lot.

Feel free to enjoy it.

I can’'t post files? Well, I put the code here, if somebody wants the original file just send me a email.


mass-user-create.jsp[/b]

<%-- mass-user-create.jsp --%>

<%@ page import="org.jivesoftware.util.*,

org.jivesoftware.wildfire.user.*,

java.net.URLEncoder,

java.util.*,

org.jivesoftware.stringprep.Stringprep,

org.jivesoftware.stringprep.StringprepException,

org.jivesoftware.wildfire.group.Group,

org.jivesoftware.wildfire.group.GroupManager,

org.jivesoftware.wildfire.vcard.*,

org.dom4j.Element,

org.dom4j.io.SAXReader"

errorPage=“error.jsp”

%>

<%@ page import=“java.util.Map”%>

<%@ page import=“java.util.HashMap”%>

<%@ taglib uri=“http://java.sun.com/jstl/core_rt” prefix=“c” %>

<%@ taglib uri=“http://java.sun.com/jstl/fmt_rt” prefix=“fmt” %>

<jsp:useBean id=“webManager” class=“org.jivesoftware.util.WebManager” />

<% webManager.init(request, response, session, application, out ); %>

<% // Get parameters //

boolean another = request.getParameter(“another”) != null;

boolean create = another || request.getParameter(“create”) != null;

boolean cancel = request.getParameter(“cancel”) != null;

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

GroupManager groupManager = webManager.getGroupManager();

VCardProvider vcardProv = new DefaultVCardProvider();

SAXReader xmlReader = new SAXReader();

Map errors = new HashMap();

// Handle a cancel

if (cancel) {

response.sendRedirect(“user-summary.jsp”);

return;

}

// Handle a request to create a user:

if (create) {

// Validate

if (usernames == null) {

errors.put(“username”,"");

}

else {

String[] linhas = usernames.split(“
s**\n
s**”);

try {

for(int i=0; i<linhas.length; i++) {

System.out.println(“linhas[“i”]=”+ linhas[i]);

String s[] = linhas[i].split(“
s**;
s**”);

String username = s[0];

String name = s[1];

String password = s[2];

String email = s[3];

String groupName = s[4];

String fullName = s[5];

String city = s[6];

String orgUnit = s[7];

String phone = s[8];

String company = s[9];

String companyURL = s[10];

String country = s[11];

try {

//Cria usuario

User newUser = webManager.getUserManager().createUser(username, password, name, email);

//Adiciona no grupo

Group group = groupManager.getGroup(groupName);

group.getMembers().add((Object)webManager.getXMPPServer().createJID(username, null));

//Adiciona informações no VCard

String vCardXml = "“fullName”“fullName”“company”“orgUnit”“companyURL”“fullName”“email”“phone”“city”“country

<%<c:set var=“submit” value="${param.create}"/>%>

<%<c:set var=“errors” value="$"/>%>

  • <fmt:message key=“user.create.requied” />

document.f.username.focus();

Cool, thanks for the post! If you do have time to create a plugin at some point later, we’'d definitely appreciate the contribution.

Regards,

Matt