Search in sources :

Example 1 with WorkgroupManager

use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.

the class ImageServlet method getImage.

/**
     * Returns the image bytes of the encoded image.
     *
     * @param imageName the name of the image.
     * @param workgroupName the name of the workgroup.
     * @return the image bytes found, otherwise null.
     */
public byte[] getImage(String imageName, String workgroupName) {
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    JID workgroupJID = new JID(workgroupName);
    Workgroup workgroup;
    try {
        workgroup = workgroupManager.getWorkgroup(workgroupJID);
    } catch (UserNotFoundException e) {
        Log.error(e.getMessage(), e);
        return null;
    }
    ChatSettings chatSettings = chatSettingsManager.getChatSettings(workgroup);
    ChatSetting setting = chatSettings.getChatSetting(imageName);
    String encodedValue = setting.getValue();
    if (encodedValue == null) {
        return null;
    }
    return StringUtils.decodeBase64(encodedValue);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) ChatSettings(org.jivesoftware.openfire.fastpath.settings.chat.ChatSettings) JID(org.xmpp.packet.JID) ChatSetting(org.jivesoftware.openfire.fastpath.settings.chat.ChatSetting) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Example 2 with WorkgroupManager

use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.

the class DeleteWorkgroup method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Get requested group
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    // Load the workgroup
    try {
        Workgroup workgroup = workgroupManager.getWorkgroup(new JID(data.getData().get("workgroup").get(0)));
        workgroupManager.deleteWorkgroup(workgroup);
    } catch (UserNotFoundException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Workgroup not found");
        return;
    } catch (Exception e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Error executing the command");
        return;
    }
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 3 with WorkgroupManager

use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.

the class WorkgroupUtils method addAgents.

/**
     * Adds agents to a request queue.
     *
     * @param queue  the <code>RequestQueue</code> to add agents to.
     * @param agents a comma-delimited list of agents.
     */
public static void addAgents(RequestQueue queue, String agents) {
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    AgentManager agentManager = workgroupManager.getAgentManager();
    // loop thru all params
    StringTokenizer tokenizer = new StringTokenizer(agents, ", \t\n\r\f");
    while (tokenizer.hasMoreTokens()) {
        String usernameToken = tokenizer.nextToken();
        if (usernameToken.indexOf('@') != -1) {
            usernameToken = JID.escapeNode(usernameToken);
        }
        try {
            // See if they are a user in the system.
            UserManager.getInstance().getUser(usernameToken);
            usernameToken += ("@" + ComponentManagerFactory.getComponentManager().getServerName());
            JID address = new JID(usernameToken.trim());
            Agent agent;
            if (agentManager.hasAgent(address)) {
                agent = agentManager.getAgent(address);
            } else {
                agent = agentManager.createAgent(address);
            }
            queue.addMember(agent);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
}
Also used : Agent(org.jivesoftware.xmpp.workgroup.Agent) AgentManager(org.jivesoftware.xmpp.workgroup.AgentManager) StringTokenizer(java.util.StringTokenizer) JID(org.xmpp.packet.JID) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) StringprepException(gnu.inet.encoding.StringprepException) UserAlreadyExistsException(org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 4 with WorkgroupManager

use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.

the class WorkgroupUtils method updateWorkgroup.

public static String updateWorkgroup(String workgroupName, String displayName, String description, int maxSize, int minSize, long requestTimeout, long offerTimeout) {
    final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    Workgroup workgroup;
    try {
        workgroup = workgroupManager.getWorkgroup(new JID(workgroupName));
    } catch (UserNotFoundException e) {
        return getUpdateMessage(false, "The JID specified is invalid.");
    }
    workgroup.setDisplayName(displayName);
    workgroup.setDescription(description);
    if (maxSize < minSize) {
        return getUpdateMessage(false, "Max size must be greater or equal to min size.");
    }
    workgroup.setMaxChats(maxSize);
    workgroup.setMinChats(minSize);
    workgroup.setRequestTimeout(requestTimeout);
    workgroup.setOfferTimeout(offerTimeout);
    return getUpdateMessage(true, "Workgroup has been updated");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Example 5 with WorkgroupManager

use of org.jivesoftware.xmpp.workgroup.WorkgroupManager in project Openfire by igniterealtime.

the class MonitorProvider method executeSet.

public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply = null;
    Element iq = packet.getChildElement();
    try {
        JID from = packet.getFrom();
        String bareJID = from.toBareJID();
        if (!isOwner(bareJID, workgroup)) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.forbidden));
            workgroup.send(reply);
            return;
        }
        // Verify that an agent is requesting this information.
        WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
        if (iq.element("makeOwner") != null) {
            String sessionID = iq.element("makeOwner").attributeValue("sessionID");
            final String serviceName = workgroupManager.getMUCServiceName();
            final String roomName = sessionID + "@" + serviceName;
            // final String roomJID = roomName + "/" + workgroup.getJID().getNode();
            IQ iqPacket = new IQ(IQ.Type.set);
            iqPacket.setTo(roomName);
            iqPacket.setFrom(workgroup.getFullJID());
            Element query = iqPacket.setChildElement("query", "http://jabber.org/protocol/muc#admin");
            Element item = query.addElement("item");
            item.addAttribute("affiliation", "owner");
            item.addAttribute("jid", packet.getFrom().toBareJID());
            workgroup.send(iqPacket);
        }
        reply = IQ.createResultIQ(packet);
    } catch (Exception e) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
    }
    workgroup.send(reply);
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Aggregations

WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)10 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)6 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)6 JID (org.xmpp.packet.JID)6 Element (org.dom4j.Element)4 IQ (org.xmpp.packet.IQ)3 PacketError (org.xmpp.packet.PacketError)3 StringprepException (gnu.inet.encoding.StringprepException)2 HashMap (java.util.HashMap)2 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)2 UserAlreadyExistsException (org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException)2 XStream (com.thoughtworks.xstream.XStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Properties (java.util.Properties)1 StringTokenizer (java.util.StringTokenizer)1 FormManager (org.jivesoftware.openfire.fastpath.dataforms.FormManager)1 ChatSetting (org.jivesoftware.openfire.fastpath.settings.chat.ChatSetting)1