Search in sources :

Example 6 with WorkgroupManager

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

the class SearchProvider method executeGet.

public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    // Retrieve the web chat setting.
    String kbURL = workgroup.getProperties().getProperty("kb");
    String forumURL = workgroup.getProperties().getProperty("forums");
    // Check that the sender of this IQ is an agent
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    try {
        workgroupManager.getAgentManager().getAgent(packet.getFrom());
    } catch (AgentNotFoundException e) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    Element searchSetting = reply.setChildElement("search-settings", "http://jivesoftware.com/protocol/workgroup");
    if (forumURL != null) {
        searchSetting.addElement("forums").setText(forumURL);
    }
    if (kbURL != null) {
        searchSetting.addElement("kb").setText(kbURL);
    }
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Example 7 with WorkgroupManager

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

the class FormManager method loadWebForms.

private void loadWebForms() {
    final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    for (Workgroup workgroup : workgroupManager.getWorkgroups()) {
        DbProperties props = workgroup.getProperties();
        String context = "jive.webform.wg";
        String form = props.getProperty(context);
        if (form != null) {
            XStream xstream = new XStream();
            xstream.setClassLoader(this.getClass().getClassLoader());
            try {
                Object object = xstream.fromXML(form);
                WorkgroupForm workgroupForm = (WorkgroupForm) object;
                if (workgroupForm != null) {
                    addWorkgroupForm(workgroup, workgroupForm);
                }
            } catch (Exception e) {
                Log.error(e.getMessage(), e);
            }
        } else {
            // Create a default Web Form
            createGenericForm(workgroup);
        }
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException)

Example 8 with WorkgroupManager

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

the class WorkgroupUtils method createWorkgroup.

/**
     * Create a new Workgroup.
     *
     * @param workgroupName the name of the workgroup.
     * @param description the description of the workgroup.
     * @param agents the agents, in a comma delimited string.
     * @return a map of errors (if any)
     */
public static Map<String, String> createWorkgroup(String workgroupName, String description, String agents) {
    Map<String, String> errors = new HashMap<String, String>();
    // Get a workgroup manager
    WorkgroupManager wgManager = WorkgroupManager.getInstance();
    if (wgManager == null) {
        errors.put("general_error", "The server is down");
        return errors;
    }
    String defaultQueueName = "Default Queue";
    // Validate
    if (workgroupName == null) {
        errors.put("wgName", "");
    } else {
        try {
            workgroupName = workgroupName.trim().toLowerCase();
            workgroupName = Stringprep.nodeprep(workgroupName);
        } catch (StringprepException se) {
            errors.put("wgName", "");
        }
    }
    // do a create if there were no errors
    RequestQueue queue = null;
    if (errors.size() == 0) {
        try {
            // Create new workgroup
            Workgroup workgroup = wgManager.createWorkgroup(workgroupName);
            workgroup.setDescription(description);
            // Create a default workgroup queue
            queue = workgroup.createRequestQueue(defaultQueueName);
            //workgroup.setMaxChats(maxChats);
            //workgroup.setMinChats(minChats);
            // Make the workgroup ready by default:
            workgroup.setStatus(Workgroup.Status.READY);
            // Create default messages and images for the new workgroup
            ChatSettingsCreator.getInstance().createDefaultSettings(workgroup.getJID());
            // Add generic web form
            FormManager formManager = FormManager.getInstance();
            formManager.createGenericForm(workgroup);
        } catch (UserAlreadyExistsException uaee) {
            errors.put("exists", "");
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
            errors.put("general", "");
        }
    }
    if (ModelUtil.hasLength(agents)) {
        addAgents(queue, agents);
    }
    return errors;
}
Also used : StringprepException(gnu.inet.encoding.StringprepException) HashMap(java.util.HashMap) FormManager(org.jivesoftware.openfire.fastpath.dataforms.FormManager) RequestQueue(org.jivesoftware.xmpp.workgroup.RequestQueue) UserAlreadyExistsException(org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) StringprepException(gnu.inet.encoding.StringprepException) UserAlreadyExistsException(org.jivesoftware.xmpp.workgroup.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 9 with WorkgroupManager

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

the class MetadataProvider method executeGet.

/**
     * Executed if #handleGet returned true. This is responsible for sending
     * information back to the client.
     *
     * @param packet    the IQ GET packet sent to the server.
     * @param workgroup the Workgroup the packet was sent to.
     */
public void executeGet(IQ packet, Workgroup workgroup) {
    // Create the generic reply packet.
    IQ reply = IQ.createResultIQ(packet);
    // Check that the sender of this IQ is an agent. If so
    // we throw an item not found exception.
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    try {
        workgroupManager.getAgentManager().getAgent(packet.getFrom());
    } catch (AgentNotFoundException e) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
        workgroup.send(reply);
        return;
    }
    // If the sender of the packet is an agent, send back name-value pairs
    // of all properties files specified.
    final Map<String, String> map = new HashMap<String, String>();
    final List<String> configFiles = JiveGlobals.getProperties("config");
    for (String fileName : configFiles) {
        File file = new File(fileName);
        if (file.exists()) {
            // load properties file.
            Properties props = new Properties();
            try {
                props.load(new FileInputStream(file));
                Enumeration<?> properties = props.propertyNames();
                while (properties.hasMoreElements()) {
                    String key = (String) properties.nextElement();
                    String value = props.getProperty(key);
                    map.put(key, value);
                }
            } catch (IOException e) {
                Log.error(e.getMessage(), e);
            }
        }
    }
    //  It is VERY IMPORTANT that you use the same name and namespace as the sending packet. Otherwise,
    //  it would never be mapped correctly.
    final Element genericSetting = reply.setChildElement("generic-metadata", "http://jivesoftware.com/protocol/workgroup");
    for (Map.Entry<String, String> entry : map.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        // Create a name-value element
        Element element = genericSetting.addElement("entry");
        element.addElement("name").setText(key);
        element.addElement("value").setText(value);
    }
    // Send back new packet with requested information.
    workgroup.send(reply);
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) IOException(java.io.IOException) Properties(java.util.Properties) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) FileInputStream(java.io.FileInputStream) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with WorkgroupManager

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

the class WorkgroupUtils method toggleStatus.

public static void toggleStatus(String workgroupName) {
    final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    Workgroup workgroup;
    try {
        workgroup = workgroupManager.getWorkgroup(new JID(workgroupName));
    } catch (UserNotFoundException e) {
        return;
    }
    Workgroup.Status status = workgroup.getStatus();
    if (status == Workgroup.Status.READY) {
        workgroup.setStatus(Workgroup.Status.CLOSED);
    } else {
        workgroup.setStatus(Workgroup.Status.READY);
    }
}
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)

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