Search in sources :

Example 6 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class MSNSession method updateContact.

/**
     * @see net.sf.kraken.session.TransportSession#updateContact(net.sf.kraken.roster.TransportBuddy)
     */
@Override
public void updateContact(MSNBuddy contact) {
    Email email = Email.parseStr(getTransport().convertJIDToID(contact.getJID()));
    if (email == null) {
        Log.debug("MSN: Unable to update illegal contact " + contact.getJID());
        return;
    }
    String nickname = getTransport().convertJIDToID(contact.getJID());
    if (contact.getNickname() != null && !contact.getNickname().equals("")) {
        nickname = contact.getNickname();
    }
    try {
        MSNBuddy msnBuddy = getBuddyManager().getBuddy(contact.getJID());
        if (msnBuddy.msnContact == null) {
            MsnContact msnContact = msnMessenger.getContactList().getContactByEmail(email);
            if (msnContact == null) {
                Log.debug("MSN: Contact updated but doesn't exist?  Adding.");
                addContact(contact.getJID(), nickname, (ArrayList<String>) contact.getGroups());
                return;
            } else {
                msnBuddy.setMsnContact(msnContact);
            }
        }
        if (!msnBuddy.msnContact.getFriendlyName().equals(nickname)) {
            msnMessenger.renameFriend(email, nickname);
        }
        syncContactGroups(email, (List<String>) contact.getGroups());
    } catch (NotFoundException e) {
        Log.debug("MSN: Newly added buddy not found in buddy manager: " + email.getEmailAddress());
    }
}
Also used : Email(net.sf.jml.Email) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) MsnContact(net.sf.jml.MsnContact)

Example 7 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class MSNSession method syncContactGroups.

/**
     * Given a legacy contact and a list of groups, makes sure that the list is in sync with
     * the actual group list.
     *
     * @param contact Email address of contact.
     * @param groups List of groups contact should be in.
     */
public void syncContactGroups(Email contact, List<String> groups) {
    MsnContact msnContact = null;
    try {
        MSNBuddy msnBuddy = getBuddyManager().getBuddy(getTransport().convertIDToJID(contact.getEmailAddress()));
        msnContact = msnBuddy.getMsnContact();
    } catch (NotFoundException e) {
        Log.debug("MSN: Buddy not found in buddy manager: " + contact.getEmailAddress());
    }
    if (msnContact == null) {
        return;
    }
    if (groups != null && !groups.isEmpty()) {
        // Create groups that do not currently exist.
        for (String group : groups) {
            if (!msnGroups.containsKey(group)) {
                Log.debug("MSN: Group " + group + " is a new group, creating.");
                msnMessenger.addGroup(group);
                // Ok, short circuit here, we need to wait for this group to be added.  We'll be back.
                storePendingGroup(group, contact);
                return;
            }
        }
        // Make sure contact belongs to groups that we want.
        for (String group : groups) {
            Log.debug("MSN: Found " + contact + " should belong to group " + group);
            MsnGroup msnGroup = msnGroups.get(group);
            if (msnGroup != null && !msnContact.belongGroup(msnGroup)) {
                Log.debug("MSN: " + contact + " does not belong to " + group + ", copying.");
                msnMessenger.copyFriend(contact, msnGroup.getGroupId());
            }
        }
        // Now we will clean up groups that we should no longer belong to.
        for (MsnGroup msnGroup : msnContact.getBelongGroups()) {
            Log.debug("MSN: Found " + contact + " belongs to group " + msnGroup.getGroupName());
            if (!groups.contains(msnGroup.getGroupName())) {
                Log.debug("MSN: " + contact + " should not belong to " + msnGroup.getGroupName() + ", removing.");
                msnMessenger.removeFriend(contact, msnGroup.getGroupId());
            }
        }
    }
}
Also used : NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) MsnContact(net.sf.jml.MsnContact) MsnGroup(net.sf.jml.MsnGroup)

Example 8 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class PseudoRoster method loadFromDb.

/**
     * Load pseudo roster from database.
     */
private void loadFromDb() {
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GET_ALL_USER_ROSTER_ITEMS);
        pstmt.setLong(1, registrationID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String username = rs.getString(1);
            try {
                pseudoRosterItems.put(username, new PseudoRosterItem(registrationID, username));
            } catch (NotFoundException e) {
                Log.error("Could not find pseudo roster item after already having found it.", e);
            }
        }
    } catch (SQLException sqle) {
        Log.error(sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NotFoundException(org.jivesoftware.util.NotFoundException) PreparedStatement(java.sql.PreparedStatement)

Example 9 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class RegistrationHandler method addNewRegistration.

/**
     * Adds a registration with this transport, or updates an existing one.
     *
     * @param jid          JID of user to add registration to.
     * @param username     Legacy username of registration.
     * @param password     Legacy password of registration.
     * @param nickname     Legacy nickname of registration.
     * @param noRosterItem True if the transport is not to show up in the user's roster.
     * @throws UserNotFoundException    if registration or roster not found.
     * @throws IllegalAccessException   if jid is not from this server.
     * @throws IllegalArgumentException if username is not valid for this transport type.
     */
public void addNewRegistration(JID jid, String username, String password, String nickname, Boolean noRosterItem) throws UserNotFoundException, IllegalAccessException {
    Log.debug("Adding or updating registration for : " + jid.toString() + " / " + username);
    if (!XMPPServer.getInstance().isLocal(jid)) {
        throw new IllegalAccessException("Domain of jid registering does not match domain of server.");
    }
    if (!parent.isUsernameValid(username)) {
        throw new IllegalArgumentException("Username specified is not valid for this transport type.");
    }
    final Collection<Registration> registrations = RegistrationManager.getInstance().getRegistrations(jid, parent.transportType);
    boolean foundReg = false;
    boolean triggerRestart = false;
    for (final Registration registration : registrations) {
        if (!registration.getUsername().equals(username)) {
            Log.debug("Deleting existing registration before" + " creating a new one: " + registration);
            RegistrationManager.getInstance().deleteRegistration(registration);
        } else {
            Log.debug("Existing registration found that can be updated: " + registration);
            if ((registration.getPassword() != null && password == null) || (registration.getPassword() == null && password != null) || (registration.getPassword() != null && password != null && !registration.getPassword().equals(password))) {
                Log.debug("Updating password for existing registration: " + registration);
                registration.setPassword(password);
                triggerRestart = true;
            }
            if ((registration.getNickname() != null && nickname == null) || (registration.getNickname() == null && nickname != null) || (registration.getNickname() != null && nickname != null && !registration.getNickname().equals(nickname))) {
                Log.debug("Updating nickname for existing registration: " + registration);
                registration.setNickname(nickname);
                triggerRestart = true;
            }
            foundReg = true;
        }
        // if a change was made to the registration, restart it.
        if (triggerRestart) {
            try {
                Log.debug("An existing registration was " + "updated. Restarting the related session: " + registration);
                final TransportSession relatedSession = parent.sessionManager.getSession(registration.getJID().getNode());
                parent.registrationLoggedOut(relatedSession);
            } catch (NotFoundException e) {
            // No worries, move on.
            }
        }
    }
    if (!foundReg) {
        RegistrationManager.getInstance().createRegistration(jid, parent.transportType, username, password, nickname);
        triggerRestart = true;
    }
    if (triggerRestart) {
        Log.debug("Clean up any leftover roster items " + "from other transports for: " + jid);
        try {
            parent.cleanUpRoster(jid, !noRosterItem);
        } catch (UserNotFoundException ee) {
            throw new UserNotFoundException("Unable to find roster.");
        }
    }
    if (!noRosterItem) {
        try {
            Log.debug("Adding Transport roster item to the roster of: " + jid);
            parent.addOrUpdateRosterItem(jid, parent.getJID(), parent.getDescription(), "Transports");
        } catch (UserNotFoundException e) {
            throw new UserNotFoundException("User not registered with server.");
        }
    } else {
        Log.debug("Not adding Transport roster item to the roster of: " + jid + " (as this was explicitly requested).");
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) TransportSession(net.sf.kraken.session.TransportSession)

Example 10 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class Conversation method loadFromDb.

private void loadFromDb() throws NotFoundException {
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(LOAD_CONVERSATION);
        pstmt.setLong(1, conversationID);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new NotFoundException("Conversation not found: " + conversationID);
        }
        this.room = rs.getString(1) == null ? null : new JID(rs.getString(1));
        this.external = rs.getInt(2) == 1;
        this.startDate = new Date(rs.getLong(3));
        this.lastActivity = new Date(rs.getLong(4));
        this.messageCount = rs.getInt(5);
        rs.close();
        pstmt.close();
        this.participants = new ConcurrentHashMap<String, UserParticipations>();
        pstmt = con.prepareStatement(LOAD_PARTICIPANTS);
        pstmt.setLong(1, conversationID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            // Rebuild full JID of participant
            String baredJID = rs.getString(1);
            String resource = rs.getString(2);
            JID fullJID = new JID("".equals(resource) ? baredJID : baredJID + "/" + resource);
            // Rebuild joined and left time
            ConversationParticipation participation = new ConversationParticipation(new Date(rs.getLong(4)), rs.getString(3));
            if (rs.getLong(5) > 0) {
                participation.participationEnded(new Date(rs.getLong(5)));
            }
            // Store participation data
            UserParticipations userParticipations = participants.get(fullJID.toString());
            if (userParticipations == null) {
                userParticipations = new UserParticipations(room != null);
                participants.put(fullJID.toString(), userParticipations);
            }
            userParticipations.addParticipation(participation);
        }
    } catch (SQLException sqle) {
        Log.error(sqle.getMessage(), sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
}
Also used : JID(org.xmpp.packet.JID) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date)

Aggregations

NotFoundException (org.jivesoftware.util.NotFoundException)67 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)29 Element (org.dom4j.Element)17 JID (org.xmpp.packet.JID)15 ArrayList (java.util.ArrayList)10 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)8 ResultSet (java.sql.ResultSet)7 TransportSession (net.sf.kraken.session.TransportSession)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 Avatar (net.sf.kraken.avatars.Avatar)5 TransportBuddy (net.sf.kraken.roster.TransportBuddy)5 Packet (org.xmpp.packet.Packet)5 Date (java.util.Date)4 MultiUserChatServiceImpl (org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl)4 UserRequest (org.jivesoftware.xmpp.workgroup.request.UserRequest)4 KrakenPlugin (net.sf.kraken.KrakenPlugin)3 Registration (net.sf.kraken.registration.Registration)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3