Search in sources :

Example 11 with Workgroup

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

the class ChatSettingsCreator method createBotSettings.

/**
     * Adds the default bot settings to the database.
     *
     * @param workgroupJID - the JID of the workgroup to setup.
     */
private void createBotSettings(JID workgroupJID) {
    try {
        // Enable the workgroup chatbot by default
        Workgroup workgroup = WorkgroupManager.getInstance().getWorkgroup(workgroupJID);
        workgroup.chatbotEnabled(true);
        for (KeyEnum key : botMap.keySet()) {
            String value = botMap.get(key);
            createChatSetting(workgroupJID, key, ChatSettings.SettingType.bot_settings, value);
        }
    } catch (UserNotFoundException e) {
        Log.error(e.getMessage(), e);
    } catch (UnauthorizedException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup)

Example 12 with Workgroup

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

the class FastpathPlugin method workgroupManagerStart.

private void workgroupManagerStart() {
    workgroupManager = WorkgroupManager.getInstance();
    // Register Fastpath service
    try {
        ComponentManagerFactory.getComponentManager().addComponent("workgroup", workgroupManager);
    } catch (ComponentException e) {
        // Do nothing. Should never happen.
        Log.error(e.getMessage(), e);
    }
    // Register the provider of workgroup names
    UserNameManager.addUserNameProvider(workgroupManager.getAddress().toString(), new UserNameProvider() {

        public String getUserName(JID entity) {
            try {
                Workgroup workgroup = workgroupManager.getWorkgroup(entity);
                return workgroup.getDisplayName();
            } catch (UserNotFoundException e) {
                return entity.toString();
            }
        }
    });
    // Start the Fastpath module
    workgroupManager.start();
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) UserNameProvider(org.jivesoftware.openfire.user.UserNameProvider) JID(org.xmpp.packet.JID) ComponentException(org.xmpp.component.ComponentException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup)

Example 13 with Workgroup

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

the class SoundServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String workgroupName = request.getParameter("workgroup");
    String action = request.getParameter("action");
    Workgroup workgroup = null;
    try {
        workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (UserNotFoundException e) {
        Log.error(e.getMessage(), e);
    }
    try {
        response.setContentType("audio/wav");
        if (action != null) {
            if ("incoming".equals(action.trim())) {
                String incomingMessage = workgroup.getProperties().getProperty("incomingSound");
                byte[] incomingBytes = StringUtils.decodeBase64(incomingMessage);
                response.getOutputStream().write(incomingBytes);
            } else if ("outgoing".equals(action.trim())) {
                String outgoingMessage = workgroup.getProperties().getProperty("outgoingSound");
                String outgoingBytes = StringUtils.encodeBase64(outgoingMessage);
                response.getOutputStream().write(outgoingBytes.getBytes("UTF-8"));
            }
        }
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 14 with Workgroup

use of org.jivesoftware.xmpp.workgroup.Workgroup 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 15 with Workgroup

use of org.jivesoftware.xmpp.workgroup.Workgroup 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)

Aggregations

Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)25 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)19 JID (org.xmpp.packet.JID)15 SQLException (java.sql.SQLException)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)6 Element (org.dom4j.Element)4 AgentSession (org.jivesoftware.xmpp.workgroup.AgentSession)4 RequestQueue (org.jivesoftware.xmpp.workgroup.RequestQueue)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)3 UnauthorizedException (org.jivesoftware.xmpp.workgroup.UnauthorizedException)3 IQ (org.xmpp.packet.IQ)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AdHocCommand (org.jivesoftware.openfire.commands.AdHocCommand)2 AgentSessionList (org.jivesoftware.xmpp.workgroup.AgentSessionList)2