powered by Jive Software

Is it required to restart a server after importing users?

This is my first post on the forum and so I wanted to say hello to everyone:

hello everyone!

And now about my problem: I am trying to write a plugin that connects

to a remote database, gets user data and imports it to openfire

database. I am using that code to add user to a roster:

rosterItem = new RosterItem(userJID,RosterItem.SUB_BOTH, RosterItem.ASK_NONE,RosterItem.RECV_NONE , userToUpdate.getName(), userGroupList);

rosterItemProvider.createItem(username,rosterItem);

The plugin compiles, it starts, it imports users BUT without a server restart there are no changes visible in user’s rosters. After the restart everything is OK, all the users have their rosters updated. Is that restart required or am I missing something?

Thank you for your answers!

You should not use the RosterProvider directly.

This is the code from my Server-Bot Helga:

CommandRoster.java, line 640

CommandRoster#RosterImporter#importContacts()

Roster roster;
try {
     roster = rosterManager.getRoster(userJID.getNode());
}
catch (UserNotFoundException e) {
     Log.error(e);
     return;
} // check if contact is already von contacts roster, if not create new RosterItem
RosterItem item;
try {
     item = roster.getRosterItem(contactJID);
     exists = true;
}
catch (UserNotFoundException e) {
     exists = false;
     try {
          item = roster.createRosterItem(contactJID, false, true);
     }
     catch (UserAlreadyExistsException f) {
          /* ...handle error... */
     }
     catch (SharedGroupException f) {
          /* ...handle error... */
     }
} if (!exists) {
     // set state to "From + Pending Out"
     item.setSubStatus(RosterItem.SUB_FROM);
     item.setAskStatus(RosterItem.ASK_SUBSCRIBE);
} // set nickname
if (nickname != null) {
     item.setNickname(nickname);
} // add roster groups
Iterator<String> itrGrp = item.getGroups().iterator();
while (itrGrp.hasNext()) {
     String groupname = itrGrp.next();
     if (!groups.contains(groupname)) {
          groups.add(groupname);
     }
}
try {
     int size = groups.size();
     item.setGroups(groups);
     if (item.getGroups().size() != size) {
          // one or more groups where deleted without an SharedGroupException was thrown...
          // (bug in RosterItem#setGroups, Openfire 3.3.2)
          
          /* ...handle error... */
     }
}
catch (SharedGroupException e) {
     /* ...handle error... */
} // update item in database and push it to all connected resources.
try {
     roster.updateRosterItem(item);
}
catch (UserNotFoundException e) {
     Log.error(e);
     return;
} if (!exists) {
     // fake subscribe from contacts client
     helgaUtil.sendPresence(contactJID, userJID, Presence.Type.subscribe);
     // fake subscribe from users client
     helgaUtil.sendPresence(userJID, contactJID, Presence.Type.subscribe);
     // fake subscribed from users client
     helgaUtil.sendPresence(userJID, contactJID, Presence.Type.subscribed);
}

Thank you for your answer Coolcat!

I’ve changed the code to:

RosterItem item = myUserRoster.createRosterItem(userToUpdateJID, userToUpdate.getName(), groupList, false, true);

item.setSubStatus(RosterItem.SUB_BOTH);

item.setAskStatus(RosterItem.ASK_NONE);

item.setRecvStatus(RosterItem.RECV_NONE);

myUserRoster.updateRosterItem(item);

and it works just fine. Plugin adds users, no restart is required nor subscription confirmation, and that was just what I wanted to achieve.

Still I wonder why restarting the server did the trick back then?

Thank you for your help again!

item.setSubStatus(RosterItem.SUB_BOTH);

item.setAskStatus(RosterItem.ASK_NONE);

item.setRecvStatus(RosterItem.RECV_NONE);

This may look on user side ok, but the user will not appear on contacts roster, as long as there is not running a similar plugin. Thats the reason why I’am faking the subscribe/subscribed messages.

Coolcat

On my server and ALL the users have ALL other users in their rosters, which is assured during the process of importing data. I have also disabled the possibility to create users, add new contacts to the rooster etc. other than IMPORTING data from remote database by admin. The point of that customization is to provide a stable user database where all people have all other people in their rosters and they cannot spoil anything nor chat with users not approved by admin.

On my server and ALL the users have ALL other users in their rosters

Wouldn’t it be easier to use a shared group for this? Create a group with all users and share it with everyone.