Search in sources :

Example 1 with DeleteWorkgroup

use of org.jivesoftware.openfire.fastpath.commands.DeleteWorkgroup in project Openfire by igniterealtime.

the class WorkgroupManager method createWorkgroup.

/**
     * Creates a workgroup with default settings.
     *
     * @param name the name of the workgroup.
     * @return the created workgroup
     * @throws UnauthorizedException      if not allowed to create the workgroup.
     * @throws UserAlreadyExistsException If the address is already in use
     */
public Workgroup createWorkgroup(String name) throws UserAlreadyExistsException, UnauthorizedException {
    if (workgroups.containsKey(name + "@" + serviceAddress.toBareJID())) {
        throw new UserAlreadyExistsException(name);
    }
    // Reserve the username - user ID from the jiveUserID table
    long id = -1;
    Workgroup workgroup = null;
    try {
        id = SequenceManager.nextID(FastpathConstants.WORKGROUP);
        boolean workgroupAdded = addWorkgroup(id, name);
        if (workgroupAdded) {
            workgroupLock.writeLock().lock();
            try {
                workgroup = new Workgroup(id, agentManager);
                workgroups.put(workgroup.getJID().toBareJID(), workgroup);
                workgroupOpenStatus.put(workgroup.getID(), workgroup.getStatus());
            } finally {
                workgroupLock.writeLock().unlock();
            }
            // Create a chat room for this workgroup
            workgroup.createGroupChatRoom();
            // Trigger the event that a workgroup has been created
            WorkgroupEventDispatcher.workgroupCreated(workgroup);
        } else {
            throw new UnauthorizedException("Could not insert workgroup in database");
        }
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
        if (id != -1) {
            try {
                if (workgroup != null) {
                    workgroups.remove(workgroup.getJID().toBareJID());
                    workgroupOpenStatus.remove(workgroup.getID());
                    deleteWorkgroup(id);
                }
            } catch (Exception e1) {
                Log.error(e1.getMessage(), e1);
            }
        }
        if (e instanceof UserAlreadyExistsException) {
            throw (UserAlreadyExistsException) e;
        } else {
            throw new UnauthorizedException();
        }
    }
    return workgroup;
}
Also used : CreateWorkgroup(org.jivesoftware.openfire.fastpath.commands.CreateWorkgroup) DeleteWorkgroup(org.jivesoftware.openfire.fastpath.commands.DeleteWorkgroup) ComponentException(org.xmpp.component.ComponentException) SQLException(java.sql.SQLException) IOException(java.io.IOException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 2 with DeleteWorkgroup

use of org.jivesoftware.openfire.fastpath.commands.DeleteWorkgroup in project Openfire by igniterealtime.

the class WorkgroupManager method start.

public void start() {
    // anonymous login doesn't have to be enabled for the whole server.
    if (!JiveSharedSecretSaslServer.isSharedSecretAllowed()) {
        JiveSharedSecretSaslServer.setSharedSecretAllowed(true);
    }
    // disco stuff
    if (!JiveGlobals.getBooleanProperty("fastpath.database.setup")) {
        boolean createUser = createDemoUser();
        if (createUser) {
            createDemoWorkgroup();
        }
        JiveGlobals.setProperty("fastpath.database.setup", "true");
    }
    // Register ad-hoc commands
    commandManager.addCommand(new CreateWorkgroup());
    commandManager.addCommand(new DeleteWorkgroup());
}
Also used : DeleteWorkgroup(org.jivesoftware.openfire.fastpath.commands.DeleteWorkgroup) CreateWorkgroup(org.jivesoftware.openfire.fastpath.commands.CreateWorkgroup)

Aggregations

CreateWorkgroup (org.jivesoftware.openfire.fastpath.commands.CreateWorkgroup)2 DeleteWorkgroup (org.jivesoftware.openfire.fastpath.commands.DeleteWorkgroup)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 ComponentException (org.xmpp.component.ComponentException)1