Hello All,
I am tring to import rosters from my exiting system to Openfire.
using following code:
public void importUserFromOldSystem(String username) throws UserNotFoundException {
XMPPServer server = XMPPServer.getInstance();
RosterManager rosterManager = server.getRosterManager();
Roster roster=rosterManager.getRoster(username)
List<String> friends = ServiceLocatorForMessenger.friendListService().friendResults(username));{color: #808000}// By this I get Friends name from other server
for (Iterator iter = friends.iterator(); iter.hasNext() {
String friend = (String) iter.next();
Roster recipientRoster = rosterManager.getRoster(friend);
try {
JID friendJid = server.createJID(friend, null);
if(roster.isRosterItem(friendJid))
continue;
RosterItem forFriend = roster.createRosterItem(friendJid, friend, Arrays.asList(“OldSystem Friends”), true, true);
RosterItem forUser = recipientRoster.createRosterItem(server.createJID(username, null), username, Arrays.asList(“OldSystem Friends”), true, true);
updateRosterItem(forFriend);
updateRosterItem(forUser);
roster.broadcast(forFriend, false);
recipientRoster.broadcast(forUser, false);
}
catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(“Roster imported…”);
}
private void updateRosterItem(RosterItem item) {
item.setAskStatus(RosterItem.ASK_NONE);
item.setRecvStatus(RosterItem.RECV_NONE);
item.setSubStatus(RosterItem.SUB_BOTH);
}
By using this code I am able to import friends. But after this method call I am able to see these friend in my friendlist but they are showed as Not authrized. But when I login again with this id. I can see online friend as online and offline as offline. What I can do in this code so that they can shown online and offline after this method calls.