Search in sources :

Example 11 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class UserProperties method populateResponseFields.

private void populateResponseFields(DataForm form, List<String> accounts) {
    FormField jidField = form.addField();
    jidField.setVariable("accountjids");
    FormField emailField = form.addField();
    emailField.setVariable("email");
    FormField nameField = form.addField();
    nameField.setVariable("name");
    UserManager manager = UserManager.getInstance();
    for (String account : accounts) {
        User user;
        try {
            JID jid = new JID(account);
            user = manager.getUser(jid.getNode());
        } catch (Exception ex) {
            continue;
        }
        jidField.addValue(account);
        emailField.addValue(user.getEmail());
        nameField.addValue(user.getName());
    }
}
Also used : User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) UserManager(org.jivesoftware.openfire.user.UserManager) FormField(org.xmpp.forms.FormField)

Example 12 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class WebManager method getPageProperty.

public int getPageProperty(String pageName, String property, int defaultValue) {
    User user = getUser();
    if (user != null) {
        String values = user.getProperties().get(property);
        if (values != null) {
            StringTokenizer tokens = new StringTokenizer(values, ",=");
            while (tokens.hasMoreTokens()) {
                String page = tokens.nextToken().trim();
                String rows = tokens.nextToken().trim();
                if (pageName.equals(page)) {
                    try {
                        return Integer.parseInt(rows);
                    } catch (NumberFormatException e) {
                        return defaultValue;
                    }
                }
            }
        }
    }
    return defaultValue;
}
Also used : StringTokenizer(java.util.StringTokenizer) User(org.jivesoftware.openfire.user.User)

Example 13 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class IQvCardHandler method handleIQ.

@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
    IQ result = IQ.createResultIQ(packet);
    IQ.Type type = packet.getType();
    if (type.equals(IQ.Type.set)) {
        try {
            User user = userManager.getUser(packet.getFrom().getNode());
            Element vcard = packet.getChildElement();
            if (vcard != null) {
                VCardManager.getInstance().setVCard(user.getUsername(), vcard);
            }
        } catch (UserNotFoundException e) {
            result = IQ.createResultIQ(packet);
            result.setChildElement(packet.getChildElement().createCopy());
            result.setError(PacketError.Condition.item_not_found);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
            result.setError(PacketError.Condition.internal_server_error);
        }
    } else if (type.equals(IQ.Type.get)) {
        JID recipient = packet.getTo();
        // If no TO was specified then get the vCard of the sender of the packet
        if (recipient == null) {
            recipient = packet.getFrom();
        }
        // By default return an empty vCard
        result.setChildElement("vCard", "vcard-temp");
        // Only try to get the vCard values of non-anonymous users
        if (recipient != null) {
            if (recipient.getNode() != null && server.isLocal(recipient)) {
                VCardManager vManager = VCardManager.getInstance();
                Element userVCard = vManager.getVCard(recipient.getNode());
                if (userVCard != null) {
                    // Check if the requester wants to ignore some vCard's fields
                    Element filter = packet.getChildElement().element(QName.get("filter", "vcard-temp-filter"));
                    if (filter != null) {
                        // Create a copy so we don't modify the original vCard
                        userVCard = userVCard.createCopy();
                        // Ignore fields requested by the user
                        for (Iterator toFilter = filter.elementIterator(); toFilter.hasNext(); ) {
                            Element field = (Element) toFilter.next();
                            Element fieldToRemove = userVCard.element(field.getName());
                            if (fieldToRemove != null) {
                                fieldToRemove.detach();
                            }
                        }
                    }
                    result.setChildElement(userVCard);
                }
            } else {
                result = IQ.createResultIQ(packet);
                result.setChildElement(packet.getChildElement().createCopy());
                result.setError(PacketError.Condition.item_not_found);
            }
        } else {
            result = IQ.createResultIQ(packet);
            result.setChildElement(packet.getChildElement().createCopy());
            result.setError(PacketError.Condition.item_not_found);
        }
    } else {
        result.setChildElement(packet.getChildElement().createCopy());
        result.setError(PacketError.Condition.not_acceptable);
    }
    return result;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Iterator(java.util.Iterator) VCardManager(org.jivesoftware.openfire.vcard.VCardManager) PacketException(org.jivesoftware.openfire.PacketException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 14 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class EmailTranscriptEvent method chatSupportFinished.

public void chatSupportFinished(Workgroup workgroup, String sessionID) {
    Log.debug("Chat Support Finished, sending transcripts");
    final EmailService emailService = EmailService.getInstance();
    String property = JiveGlobals.getProperty("mail.configured");
    if (!ModelUtil.hasLength(property)) {
        Log.debug("Mail settings are not configured, transcripts will not be sent.");
        return;
    }
    final ChatSession chatSession = ChatTranscriptManager.getChatSession(sessionID);
    if (chatSession == null || chatSession.getFirstSession() == null) {
        return;
    }
    final StringBuilder builder = new StringBuilder();
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyy hh:mm a");
    // Get duration of conversation
    Date date = new Date(chatSession.getFirstSession().getStartTime());
    int duration = getChatDuration(date, chatSession);
    TreeMap<String, List<String>> map = new TreeMap<String, List<String>>(chatSession.getMetadata());
    String body = JiveGlobals.getProperty("chat.transcript.body");
    if (ModelUtil.hasLength(body)) {
        builder.append(body).append("\n\n");
    }
    builder.append("formname=chat transcript\n");
    extractAndDisplay(builder, "question", map);
    display(builder, "fullname", chatSession.getCustomerName());
    extractAndDisplay(builder, "email", map);
    extractAndDisplay(builder, "Location", map);
    extractAndDisplay(builder, "userID", map);
    extractAndDisplay(builder, "username", map);
    extractAndDisplay(builder, "workgroup", map);
    display(builder, "chatduration", String.valueOf(duration));
    display(builder, "chatdate", formatter.format(date));
    if (chatSession.getFirstSession() != null && chatSession.getFirstSession().getAgentJID() != null) {
        try {
            display(builder, "agent", new JID(chatSession.getFirstSession().getAgentJID()).toBareJID());
        } catch (Exception e) {
            Log.debug("Could not display agent in transcript.", e);
        }
    }
    for (Iterator<Map.Entry<String, List<String>>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<String, List<String>> entry = iterator.next();
        display(builder, entry.getKey(), getListItem(entry.getValue()));
    }
    builder.append("ctranscript=\n");
    builder.append(ChatTranscriptManager.getTextTranscriptFromSessionID(sessionID));
    String subject = JiveGlobals.getProperty("chat.transcript.subject");
    String from = JiveGlobals.getProperty("chat.transcript.from");
    String to = JiveGlobals.getProperty("chat.transcript.to");
    if (!ModelUtil.hasLength(subject) || !ModelUtil.hasLength(from)) {
        Log.debug("Transcript settings (chat.transcript.subject, chat.transcript.from) are not configured, " + "transcripts will not be sent.");
        return;
    }
    if (ModelUtil.hasLength(to)) {
        emailService.sendMessage("Chat Transcript", to, "Chat Transcript", from, subject, builder.toString(), null);
        Log.debug("Transcript sent to " + to);
    }
    // NOTE: Do not sent to the customer. They will receive a prompt for a seperate chat transcript
    // that does not contain agent information.
    // Send to Agents
    UserManager um = UserManager.getInstance();
    for (Iterator<AgentChatSession> iterator = chatSession.getAgents(); iterator.hasNext(); ) {
        AgentChatSession agentSession = iterator.next();
        try {
            User user = um.getUser(new JID(agentSession.getAgentJID()).getNode());
            emailService.sendMessage("Chat Transcript", user.getEmail(), "Chat Transcript", from, subject, builder.toString(), null);
            Log.debug("Transcript sent to agent " + agentSession.getAgentJID());
        } catch (UserNotFoundException e) {
            Log.error("Email Transcript Not Sent:" + "Could not load agent user object for jid " + agentSession.getAgentJID());
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) TreeMap(java.util.TreeMap) ChatSession(org.jivesoftware.openfire.fastpath.history.ChatSession) AgentChatSession(org.jivesoftware.openfire.fastpath.history.AgentChatSession) Date(java.util.Date) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) AgentChatSession(org.jivesoftware.openfire.fastpath.history.AgentChatSession) UserManager(org.jivesoftware.openfire.user.UserManager) List(java.util.List) EmailService(org.jivesoftware.util.EmailService) SimpleDateFormat(java.text.SimpleDateFormat) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 15 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class BookmarkInterceptor method addBookmarkElement.

/**
     * Adds a Bookmark to the users defined list of bookmarks.
     *
     * @param jid      the users jid.
     * @param bookmark the bookmark to be added.
     * @param element  the storage element to append to.
     */
private void addBookmarkElement(JID jid, Bookmark bookmark, Element element) {
    final UserManager userManager = UserManager.getInstance();
    try {
        userManager.getUser(jid.getNode());
    } catch (UserNotFoundException e) {
        return;
    }
    // do not add duplicate bookmarks.
    if (bookmark.getType() == Bookmark.Type.url) {
        Element urlBookmarkElement = urlExists(element, bookmark.getValue());
        if (urlBookmarkElement == null) {
            urlBookmarkElement = element.addElement("url");
            urlBookmarkElement.addAttribute("name", bookmark.getName());
            urlBookmarkElement.addAttribute("url", bookmark.getValue());
            // Add an RSS attribute to the bookmark if it's defined. RSS isn't an
            // official part of the Bookmark JEP, but we define it as a logical
            // extension.
            boolean rss = Boolean.valueOf(bookmark.getProperty("rss"));
            if (rss) {
                urlBookmarkElement.addAttribute("rss", Boolean.toString(rss));
            }
        }
        appendSharedElement(urlBookmarkElement);
    } else // Otherwise it's a conference bookmark.
    {
        try {
            Element conferenceElement = conferenceExists(element, bookmark.getValue());
            // reply.
            if (conferenceElement == null) {
                conferenceElement = element.addElement("conference");
                conferenceElement.addAttribute("name", bookmark.getName());
                boolean autojoin = Boolean.valueOf(bookmark.getProperty("autojoin"));
                conferenceElement.addAttribute("autojoin", Boolean.toString(autojoin));
                conferenceElement.addAttribute("jid", bookmark.getValue());
                boolean nameasnick = Boolean.valueOf(bookmark.getProperty("nameasnick"));
                if (nameasnick) {
                    User currentUser = userManager.getUser(jid.getNode());
                    Element nick = conferenceElement.addElement("nick");
                    nick.addText(currentUser.getName());
                }
            }
            appendSharedElement(conferenceElement);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) UserManager(org.jivesoftware.openfire.user.UserManager) Element(org.dom4j.Element) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Aggregations

User (org.jivesoftware.openfire.user.User)58 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)26 Element (org.dom4j.Element)17 JID (org.xmpp.packet.JID)17 UserManager (org.jivesoftware.openfire.user.UserManager)10 ArrayList (java.util.ArrayList)9 Group (org.jivesoftware.openfire.group.Group)9 IQ (org.xmpp.packet.IQ)7 List (java.util.List)6 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)6 RosterItem (org.jivesoftware.openfire.roster.RosterItem)5 Date (java.util.Date)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)4 Message (org.xmpp.packet.Message)4 Presence (org.xmpp.packet.Presence)4 HashSet (java.util.HashSet)3 StringTokenizer (java.util.StringTokenizer)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2