use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseTransport method syncLegacyRoster.
/**
* Sync a user's roster with their legacy contact list.
*
* Given a collection of transport buddies, syncs up the user's
* roster by fixing any nicknames, group assignments, adding and removing
* roster items, and generally trying to make the jabber roster list
* assigned to the transport's JID look at much like the legacy buddy
* list as possible. This is a very extensive operation. You do not
* want to do this very often. Typically once right after the person
* has logged into the legacy service.
*
* @param userjid JID of user who's roster we are syncing with.
* @param legacyitems List of TransportBuddy's to be synced.
* @throws UserNotFoundException if userjid not found.
*/
public void syncLegacyRoster(JID userjid, Collection<B> legacyitems) throws UserNotFoundException {
Log.debug("Syncing Legacy Roster: " + legacyitems);
try {
Roster roster = rosterManager.getRoster(userjid.getNode());
// Lets lock down the roster from update notifications if there's an active session.
try {
TransportSession<B> session = sessionManager.getSession(userjid.getNode());
session.lockRoster();
} catch (NotFoundException e) {
// No active session? Then no problem.
}
// First thing first, we want to build ourselves an easy mapping.
Map<JID, TransportBuddy> legacymap = new HashMap<JID, TransportBuddy>();
for (TransportBuddy buddy : legacyitems) {
// Log.debug("ROSTERSYNC: Mapping "+buddy.getName());
legacymap.put(buddy.getJID(), buddy);
}
// Now, lets go through the roster and see what matches up.
for (RosterItem ri : roster.getRosterItems()) {
if (!ri.getJid().getDomain().equals(this.jid.getDomain())) {
// Not our contact to care about.
continue;
}
if (ri.getJid().getNode() == null) {
// This is a transport instance, lets leave it alone.
continue;
}
JID jid = new JID(ri.getJid().toBareJID());
if (legacymap.containsKey(jid)) {
Log.debug("ROSTERSYNC: We found, updating " + jid.toString());
// Ok, matched a legacy to jabber roster item
// Lets update if there are differences
TransportBuddy buddy = legacymap.get(jid);
try {
if (buddy.getAskType() != null && buddy.getSubType() != null) {
this.addOrUpdateRosterItem(userjid, buddy.getName(), buddy.getNickname(), buddy.getGroups(), buddy.getSubType(), buddy.getAskType());
} else {
this.addOrUpdateRosterItem(userjid, buddy.getName(), buddy.getNickname(), buddy.getGroups());
}
} catch (UserNotFoundException e) {
Log.debug("Failed updating roster item", e);
}
legacymap.remove(jid);
} else {
Log.debug("ROSTERSYNC: We did not find, removing " + jid.toString());
// This person is apparantly no longer in the legacy roster.
try {
this.removeFromRoster(userjid, jid);
} catch (UserNotFoundException e) {
Log.debug("Failed removing roster item", e);
}
}
}
// Ok, we should now have only new items from the legacy roster
for (TransportBuddy buddy : legacymap.values()) {
Log.debug("ROSTERSYNC: We have new, adding " + buddy.getName());
try {
this.addOrUpdateRosterItem(userjid, buddy.getName(), buddy.getNickname(), buddy.getGroups());
} catch (UserNotFoundException e) {
Log.debug("Failed adding new roster item", e);
}
}
// All done, lets unlock the roster.
try {
TransportSession<B> session = sessionManager.getSession(userjid.getNode());
session.unlockRoster();
} catch (NotFoundException e) {
// No active session? Then no problem.
}
} catch (UserNotFoundException e) {
throw new UserNotFoundException("Could not find roster for " + userjid.toString());
}
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class Avatar method getImageData.
/**
* Retrieves the actual image data for this avatar.
*
* @return The base64 encoded image data for the avatar.
* @throws NotFoundException if avatar entry was not found in database.
*/
public String getImageData() throws NotFoundException {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String imageData = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(RETRIEVE_IMAGE);
pstmt.setString(1, jid.toString());
rs = pstmt.executeQuery();
if (!rs.next()) {
throw new NotFoundException("Avatar not found for " + jid);
}
imageData = rs.getString(1);
} catch (SQLException sqle) {
Log.error(sqle);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return imageData;
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseMUCTransport method handleMUCAdmin.
/**
* Handle MUC admin requests.
*
* @param packet An IQ packet in the MUC admin namespace.
* @return A list of IQ packets to be returned to the user.
*/
private List<Packet> handleMUCAdmin(IQ packet) {
List<Packet> reply = new ArrayList<Packet>();
JID from = packet.getFrom();
JID to = packet.getTo();
Element query = (packet).getChildElement();
Element item = query.element("item");
String nick = item.attribute("nick").getText();
String role = item.attribute("role").getText();
try {
TransportSession<B> session = getTransport().getSessionManager().getSession(from);
if (session.isLoggedIn()) {
try {
MUCTransportSession mucSession = session.getMUCSessionManager().getSession(to.getNode());
if (packet.getTo().getNode() == null) {
// Targeted at a room.
} else {
// Targeted at a specific user.
if (nick != null && role != null) {
if (role.equals("none")) {
// This is a kick
String reason = "";
Element reasonElem = item.element("reason");
if (reasonElem != null) {
reason = reasonElem.getText();
}
mucSession.kickUser(nick, reason);
}
}
}
} catch (NotFoundException e) {
// Not found? No active session then.
}
}
} catch (NotFoundException e) {
// Not found? No active session then.
}
return reply;
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseMUCTransport method handleDiscoItems.
/**
* Handle service discovery items request.
*
* @param packet An IQ packet in the disco items namespace.
* @return A list of IQ packets to be returned to the user.
*/
private List<Packet> handleDiscoItems(IQ packet) {
List<Packet> reply = new ArrayList<Packet>();
JID from = packet.getFrom();
JID to = packet.getTo();
if (packet.getTo().getNode() == null) {
// A request for a list of rooms
IQ result = IQ.createResultIQ(packet);
if (JiveGlobals.getBooleanProperty("plugin.gateway." + getTransport().getType() + ".roomlist", false)) {
try {
TransportSession<B> session = getTransport().getSessionManager().getSession(from);
if (session.isLoggedIn()) {
storePendingRequest(packet);
session.getRooms();
}
} catch (NotFoundException e) {
// Not found? No active session then.
result.setError(PacketError.Condition.forbidden);
reply.add(result);
}
} else {
// Time to lie and tell them we have no rooms
sendRooms(from, new ArrayList<MUCTransportRoom>());
}
} else {
// Ah, a request for members of a room.
IQ result = IQ.createResultIQ(packet);
try {
TransportSession<B> session = getTransport().getSessionManager().getSession(from);
if (session.isLoggedIn()) {
storePendingRequest(packet);
session.getRoomMembers(getTransport().convertJIDToID(to));
} else {
// Not logged in? Not logged in then.
result.setError(PacketError.Condition.forbidden);
reply.add(result);
}
} catch (NotFoundException e) {
// Not found? No active session then.
result.setError(PacketError.Condition.forbidden);
reply.add(result);
}
}
return reply;
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class VCardManager method setVCard.
/**
* Sets the user's vCard information. The new vCard information will be persistent. Advanced
* user systems can use vCard information to link to user directory information or store
* other relevant user information.
*
* @param username The username of the user to set his new vCard.
* @param vCardElement The DOM element sent by the user as his new vCard.
* @throws Exception if an error occurred while storing the new vCard.
*/
public void setVCard(String username, Element vCardElement) throws Exception {
boolean created = false;
boolean updated = false;
if (provider.isReadOnly()) {
throw new UnsupportedOperationException("VCard provider is read-only.");
}
Element oldVCard = getOrLoadVCard(username);
Element newvCard = null;
// See if we need to update the vCard or insert a new one.
if (oldVCard != null) {
// Only update the vCard in the database if the vCard has changed.
if (!oldVCard.equals(vCardElement)) {
try {
newvCard = provider.updateVCard(username, vCardElement);
vcardCache.put(username, (DefaultElement) newvCard);
updated = true;
} catch (NotFoundException e) {
Log.warn("Tried to update a vCard that does not exist", e);
newvCard = provider.createVCard(username, vCardElement);
vcardCache.put(username, (DefaultElement) newvCard);
created = true;
}
}
} else {
try {
newvCard = provider.createVCard(username, vCardElement);
vcardCache.put(username, (DefaultElement) newvCard);
created = true;
} catch (AlreadyExistsException e) {
Log.warn("Tried to create a vCard when one already exist", e);
newvCard = provider.updateVCard(username, vCardElement);
vcardCache.put(username, (DefaultElement) newvCard);
updated = true;
}
}
// Dispatch vCard events
if (created) {
// Alert listeners that a new vCard has been created
VCardEventDispatcher.dispatchVCardCreated(username, newvCard);
} else if (updated) {
// Alert listeners that a vCard has been updated
VCardEventDispatcher.dispatchVCardUpdated(username, newvCard);
}
}
Aggregations