powered by Jive Software

Automatic creation of users and user usergroup relationship in jive database

Hi There,

I am using jive messenger 2.1.4 as the messenger server and i am using the smack 1.5 libraries in my own system project.

I want to automatically create a user as well as add that user to a specific user group in jive messenger database when i create a user in my own system.

I have managed to create a user in the jive database by doing the following:

AccountManager accountManager = new AccountManager(Session.getInstance().getConnection());

String user = “testuser”;

Map<String, String> theMap = new HashMap<String, String>();

theMap.put(“name”, “Test User”);
theMap.put(“first”, “Test”);
theMap.put(“last”, “User”);
theMap.put(“email”, "test.user@gmail.com");

accountManager.createAccount(user, “password”, theMap);

Session.getInstance().getConnection().getRoster().reload();

The above code creates a row in the jiveuser table successfully.

I am forced to now use the admin web application to add this user to a specific group and then once i have restarted the jive server i can then see the new user in my buddies listing in my own system view.

I have tried getting all entries as well as unfiled entries from the roster to get a RosterEntry object which i could put into the following line below:

Roster theRoster = Session.getInstance().getConnection().getRoster();

RosterGroup rosterGroup = theRoster.getGroup(“My Contacts”);

rosterEntry = * tried many different ways to get this object but have failed *

rosterGroup.addEntry(rosterEntry);

Ofcourse i cannot create a new RosterEntry object with my newly created user information as there is no constructor for it and i know that that cannot be the right way of doing it. My assumption was that if i create a user then it should at least be in the unfiled entries listing on the roster. I assumed then i could get that unfiled RosterEntry object by the newly created username and put that into the addEntry method as the object parameter but when i retrieve the unfiled entries listing it is empty.

I would really like an example or a link to documentation of the way to add this newly created user to a user group automatically from my java code and then without having to restart the jive server have the user reflected in the buddies list as well.

I have already added data to the user and usergroup tables and then restarted the jive server just as a test and it worked. So i am pretty confident that i only need 2 rows in the jive database for a user to be registered and filed under a usergroup. I also assume, once again, that if i call the reload method on the roster after doing whatever i have to do to add the user to the usergroup that i won’t have to restart the jive server. Is this correct?

Thanks and Regards

Sean

accountManager.createAccount(user, “password”, theMap);

At this point you have added the user to the users database table, not to your roster.

Session.getInstance().getConnection().getRoster().reload();

If you want to add the user to your roster you would need to do the following:

Session.getInstance().getConnection().getRoster().createEntry("user@host.com", “user”, null);

Be sure the group exists. If it doesn’t then add the Group.

RosterGroup rosterGroup = Session.getInstance().getConnection().getRoster().getGroup(“My Contacts”);

if(rosterGroup == null) {

rosterGroup = Session.getInstance().getConnection().getRoster().createGroup(“My Contacts”);

}

This is how you should then be able to add to your groups

rosterGroup.addEntry("user@host.com");

//TBD - This is what you are supposed to be able to do to add the Entry to your roster and groups tables. But, I can not get it to work.

Session.getInstance().getConnectiontion().getRoster().createEntry("user@host.com", “user”, new String[] = {“Group1”, “Group2”});

Check your groups database table after the addEntry command. Do you get any kind of “500” “WAIT” error back if you try to add another user to that same group? If so, I think this may be a Smack and/or XMPP issue.

Hi Dave,

Thanks for your advice it did give me a few more things to try but i am still unable to get a row into the jivegroupuser table.

accountManager.createAccount(user, “password”, theMap);

This does indeed create a user row in the jiveuser table.

theRoster.createEntry(fullUsername, user, null );

This creates a row in the jiveroster **table
**

RosterGroup rosterGroup = theRoster.getGroup(usergroup);

Iterator entries = Session.getInstance().getConnection().getRoster().getEntries();

while(entries.hasNext()){
RosterEntry aRosterEntry = (RosterEntry)entries.next();
if(aRosterEntry.getUser().equals(fullUsername)){
rosterGroup.addEntry(aRosterEntry);
}
}

The above code finds the newly created entry by its full user name (user@host.com) and adds it to the usergroup found earlier on above

“Check your groups database table after the addEntry command. Do you get any kind of “500” “WAIT” error back if you try to add another user to that same group? If so, I think this may be a Smack and/or XMPP issue.”

After calling addEntry command i still have no added data in the jivegroupuser table only a new row in the jiveroster table.

I am not receiving any error code when i’ve run through my code. I did receive a code 406 when i tried to call the following:

theRoster.createEntry(fullUsername, user, groupStringArray );

So basically i get the error 406 when i try create an entry on the roster with attached string array of groupnames but i do not get any errors when i create an entry on the roster, then go find the roster group by its name and finally attach the entry to the roster group object with the addEntry method.

I just don’t understand why it is so hard to just get a row into the jivegroupuser table.

When i use the admin web application for jive messenger and i add a user it creates a row in the jiveuser table and then when i add the user to the group it creates a row in the jivegroupuser table. Thats all i want to do from the code.

I did notice something about subscriptions or entry.getType(). The users i created through the admin web appplication all print out “both” but the user created through code prints out as “none”.

Javadoc of the RosterEntry.getType()

Returns the roster subscription type of the entry.

When the type is RosterPacket.ItemType.NONE, the subscription request is pending.

Do you think that this may have anything to do with it? I did change the value to both whilst in denug mode just before the addEntry() was called but it still made no difference.

Have you had any luck getting this right?

Regards

Sean

Subscriptions have nothing to do with updating the tables. All that does is help XCP know how or if to route presence messages.

Subscription -

None = Do not route presence to either the user (you) or their contact

To = Only route presence to the user (you) from their contact (I think of this as Receive presences from your contact)

From = Only route presence from the user (yout) to their contact (Transmit)

Both = Both the user and contact will get presence from each other.

I still have problems with this. I am trying to determine if this is a Jabber XCP issue or Smack/Jive. I am using a copy of MOMENTIM to test this idea. Jabber has given me a copy to use. It is too bad they do not have a Solaris version as I need to connect a Microsoft PC to my solaris box.

Have you tried to do something like this?

RosterGroup rosterGroup = theRoster.getGroup(“My Contact”);

if (rosterGroup == null) {

theRoster.createGroup(“My Contact”).addEntry(RosterEntry);

} else {

rosterGroup.addEntry(RosterEntry);

}

I know there is some stipulation that if the RosterGroup is not added the first time with something attached to it, it will not work.

Let me know if this helps.

Dave