Example usage for java.lang Thread getName

List of usage examples for java.lang Thread getName

Introduction

In this page you can find the example usage for java.lang Thread getName.

Prototype

public final String getName() 

Source Link

Document

Returns this thread's name.

Usage

From source file:org.sakaiproject.search.component.service.impl.SearchIndexBuilderWorkerImpl.java

/**
 * Main run target of the worker thread {@inheritDoc}
 *//*  w  w  w  .j  a va  2  s  .  com*/
public void run() {
    if (!enabled)
        return;

    int threadno = -1;
    Thread tt = Thread.currentThread();
    for (int i = 0; i < indexBuilderThread.length; i++) {
        if (indexBuilderThread[i] == tt) {
            threadno = i;
        }
    }

    String nodeID = getNodeID();

    org.sakaiproject.component.cover.ComponentManager.waitTillConfigured();

    try {

        while (runThreads) {
            log.debug("Run Processing Thread");
            org.sakaiproject.tool.api.Session s = null;
            if (s == null) {
                s = sessionManager.startSession();
                User u = userDirectoryService.getUser("admin");
                s.setUserId(u.getId());
            }

            while (runThreads) {
                sessionManager.setCurrentSession(s);

                //SAK-17117 before we do this clear threadLocal
                //get the security advisor stack otherwise later calls will fail
                Object obj = ThreadLocalManager.get("SakaiSecurity.advisor.stack");
                Object sess = ThreadLocalManager.get("org.sakaiproject.api.kernel.session.current");
                Object toolsess = ThreadLocalManager.get("org.sakaiproject.api.kernel.session.current.tool");

                ThreadLocalManager.clear();
                ThreadLocalManager.set("SakaiSecurity.advisor.stack", obj);
                ThreadLocalManager.set("org.sakaiproject.api.kernel.session.current", sess);
                ThreadLocalManager.set("org.sakaiproject.api.kernel.session.current.tool", toolsess);

                try {
                    int totalDocs = searchIndexBuilder.getPendingDocuments();
                    long lastEvent = getLastEventTime();
                    long now = System.currentTimeMillis();
                    long interval = now - lastEvent;
                    boolean process = false;
                    boolean createIndex = false;
                    if (!indexExists) {
                        if (!searchIndexBuilderWorkerDao.indexExists()) {
                            process = true;
                            createIndex = true;
                            log.debug("No cluster Index exists, creating for the first time");
                        } else {
                            indexExists = true;
                        }
                    } else {

                        // if activity == totalDocs and interval > 10
                        if (totalDocs > 200) {
                            loadFactor = 10L;
                        } else {
                            loadFactor = 1000L;
                        }
                        if (totalDocs == 0) {
                            process = false;
                        } else if (totalDocs < 20 && interval > (20 * loadFactor)) {
                            process = true;
                        } else if (totalDocs >= 20 && totalDocs < 50 && interval > (10 * loadFactor)) {
                            process = true;
                        } else if (totalDocs >= 50 && totalDocs < 90 && interval > (5 * loadFactor)) {
                            process = true;
                        } else if (totalDocs > ((90 * loadFactor) / 1000)) {
                            process = true;
                        }
                    }

                    // should this node consider taking the lock ?
                    long lastLockInterval = (System.currentTimeMillis() - lastLock);
                    long lastLockMetric = lastLockInterval * totalDocs;

                    // if we have 1000 docs, then indexing should happen
                    // after 10 seconds break
                    // 1000*10000 10000000
                    // 500 docs/ 20 seconds
                    //

                    // make certain that we are alive
                    log.debug("Activity " + (lastLockMetric > (10000L * loadFactor)) + " "
                            + (lastLockInterval > (60L * loadFactor)) + " " + createIndex);

                    if (lastLockMetric > (10000L * loadFactor) || lastLockInterval > (60L * loadFactor)
                            || createIndex) {
                        log.debug("===" + process + "=============PROCESSING ");
                        if (process && getLockTransaction(2L * 60L * 1000L, createIndex)) {

                            log.debug("===" + nodeID + "=============PROCESSING ");
                            if (lockedTo != null && lockedTo.equals(nodeID)) {
                                log.error("+++++++++++++++Local Lock Collision+++++++++++++");
                            }
                            lockedTo = nodeID;

                            lastLock = System.currentTimeMillis();

                            if (createIndex) {
                                log.info(
                                        "=======================Search Index being created for the first time");
                                searchIndexBuilderWorkerDao.createIndexTransaction(this);
                                indexExists = true;
                                log.info(
                                        "=======================Done creating Search Index for the first time");

                            } else {
                                int batchSize = 100;
                                if (totalDocs > 500) {
                                    batchSize = 200;
                                } else if (totalDocs > 1000) {
                                    batchSize = 500;
                                } else if (totalDocs > 10000) {
                                    batchSize = 1000;
                                }
                                searchIndexBuilderWorkerDao.processToDoListTransaction(this, batchSize);

                            }

                            lastLock = System.currentTimeMillis();

                            if (lockedTo.equals(nodeID)) {
                                lockedTo = null;
                            } else {
                                log.error("+++++++++++++++++++++++++++Lost Local Lock+++++++++++");
                            }
                            log.debug("===" + nodeID + "=============COMPLETED ");

                        } else {
                            break;
                        }
                    } else {
                        // make certain the node updates hearbeat
                        updateNodeLock(2L * 60L * 1000L);
                        log.debug("Not taking Lock, too much activity");
                        break;
                    }
                } finally {
                    clearLockTransaction();
                }
            }
            // this is here force cluster members
            // this will not reload the index on this node as
            if (indexExists) {
                try {
                    searchService.reload();
                } catch (Exception ex) {
                    log.info("No Search Segment exists at present, this is Ok on first start :"
                            + ex.getMessage());
                }
            }
            if (!runThreads) {
                break;
            }
            try {
                log.debug("Sleeping Processing Thread");
                synchronized (sem) {
                    log.debug("++++++WAITING " + nodeID);
                    sem.wait(sleepTime);

                    log.debug("+++++ALIVE " + nodeID);
                }
                log.debug("Wakey Wakey Processing Thread");

                if (org.sakaiproject.component.cover.ComponentManager.hasBeenClosed()) {
                    runThreads = false;
                    break;
                }
                if (soakTest && (searchService.getPendingDocs() == 0)) {
                    log.error("SOAK TEST---SOAK TEST---SOAK TEST. Index Rebuild Started");
                    searchService.rebuildInstance();
                }
            } catch (InterruptedException e) {
                log.debug(" Exit From sleep " + e.getMessage());
                break;
            }
        }
    } catch (Throwable t) {

        log.warn("Failed in IndexBuilder when indexing document: " + getNowIndexing(), t);
    } finally {

        log.debug("IndexBuilder run exit " + tt.getName());
        if (threadno != -1) {
            indexBuilderThread[threadno] = null;
        }
    }
}

From source file:org.sakaiproject.site.tool.SiteAction.java

/**
 * /* Actions for vm templates under the "chef_site" root. This method is
 * called by doContinue. Each template has a hidden field with the value of
 * template-index that becomes the value of index for the switch statement
 * here. Some cases not implemented./*from w w w  .j a v a  2  s.  c o  m*/
 */
private void actionForTemplate(String direction, int index, ParameterParser params, final SessionState state,
        RunData data) {
    // Continue - make any permanent changes, Back - keep any data entered
    // on the form
    boolean forward = "continue".equals(direction) ? true : false;

    SiteInfo siteInfo = new SiteInfo();
    // SAK-16600 change to new template for tool editing
    if (index == 3) {
        index = 4;
    }

    switch (index) {
    case 0:
        /*
         * actionForTemplate chef_site-list.vm
         * 
         */
        break;
    case 1:
        /*
         * actionForTemplate chef_site-type.vm
         * 
         */
        break;
    case 4:
        /*
         * actionForTemplate chef_site-editFeatures.vm
         * actionForTemplate chef_site-editToolGroupFeatures.vm
         * 
         */
        if (forward) {
            // editing existing site or creating a new one?
            Site site = getStateSite(state);
            getFeatures(params, state, site == null ? "18" : "15");
        }
        break;

    case 8:
        /*
         * actionForTemplate chef_site-siteDeleteConfirm.vm
         * 
         */
        break;
    case 10:
        /*
         * actionForTemplate chef_site-newSiteConfirm.vm
         * 
         */
        if (!forward) {
        }
        break;
    case 12:
        /*
         * actionForTemplate chef_site_siteInfo-list.vm
         * 
         */
        break;
    case 13:
        /*
         * actionForTemplate chef_site_siteInfo-editInfo.vm
         * 
         */
        if (forward) {
            if (getStateSite(state) == null) {
                // alerts after clicking Continue but not Back
                if (!forward) {
                    // removing previously selected template site
                    state.removeAttribute(STATE_TEMPLATE_SITE);
                }

                updateSiteAttributes(state);
            }

            updateSiteInfo(params, state);
        }
        break;
    case 14:
        /*
         * actionForTemplate chef_site_siteInfo-editInfoConfirm.vm
         * 
         */
        break;
    case 15:
        /*
         * actionForTemplate chef_site_siteInfo-addRemoveFeatureConfirm.vm
         * 
         */
        break;
    case 18:
        /*
         * actionForTemplate chef_siteInfo-editAccess.vm
         * 
         */
        if (!forward) {
        }
        break;
    case 24:
        /*
         * actionForTemplate
         * chef_site-siteInfo-editAccess-globalAccess-confirm.vm
         * 
         */
        break;
    case 26:
        /*
         * actionForTemplate chef_site-modifyENW.vm
         * 
         */
        updateSelectedToolList(state, params, true);
        break;
    case 27:
        /*
         * actionForTemplate chef_site-importSites.vm
         * 
         * This is called after the tools have been selected on the import page (merge) and the finish button is clicked
         * and is also called in the new site workflow when importing from an existing site
         */
        if (forward) {
            Site existingSite = getStateSite(state);
            if (existingSite != null) {
                // revising a existing site's tool
                if (select_import_tools(params, state)) {
                    String threadName = "SiteImportThread" + existingSite.getId();
                    boolean found = false;
                    //check all running threads for our named thread
                    //this isn't cluster safe, but this check it more targeted towards
                    //a single user re-importing multiple times during a slow import (which would be on the same server)
                    for (Thread t : Thread.getAllStackTraces().keySet()) {
                        if (threadName.equals(t.getName())) {
                            found = true;
                            break;
                        }
                    }
                    if (found) {
                        //an existing thread is running for this site import, throw warning
                        addAlert(state, rb.getString("java.import.existing"));
                    } else {

                        // list of tools that were selected for import
                        final Hashtable importTools = (Hashtable) state.getAttribute(STATE_IMPORT_SITE_TOOL);

                        //list of existing tools in the destination site
                        final List existingTools = originalToolIds(
                                (List<String>) state.getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST),
                                state);

                        final String userEmail = UserDirectoryService.getCurrentUser().getEmail();
                        final Session session = SessionManager.getCurrentSession();
                        final ToolSession toolSession = SessionManager.getCurrentToolSession();
                        final String siteId = existingSite.getId();
                        Thread siteImportThread = new Thread() {
                            public void run() {
                                Site existingSite;
                                try {
                                    existingSite = SiteService.getSite(siteId);
                                    SessionManager.setCurrentSession(session);
                                    SessionManager.setCurrentToolSession(toolSession);
                                    EventTrackingService.post(
                                            EventTrackingService.newEvent(SiteService.EVENT_SITE_IMPORT_START,
                                                    existingSite.getReference(), false));
                                    importToolIntoSite(existingTools, importTools, existingSite);
                                    if (ServerConfigurationService.getBoolean(SAK_PROP_IMPORT_NOTIFICATION,
                                            true)) {
                                        userNotificationProvider.notifySiteImportCompleted(userEmail,
                                                existingSite.getId(), existingSite.getTitle());
                                    }
                                    EventTrackingService.post(
                                            EventTrackingService.newEvent(SiteService.EVENT_SITE_IMPORT_END,
                                                    existingSite.getReference(), false));
                                } catch (IdUnusedException e) {
                                    M_log.error(e.getMessage(), e);
                                }
                            }
                        };
                        siteImportThread.setName(threadName);
                        siteImportThread.start();
                        state.setAttribute(IMPORT_QUEUED, rb.get("importQueued"));
                        state.removeAttribute(STATE_IMPORT_SITE_TOOL);
                        state.removeAttribute(STATE_IMPORT_SITES);
                    }
                } else {
                    // show alert and remain in current page
                    addAlert(state, rb.getString("java.toimporttool"));
                }
            } else {
                // new site
                select_import_tools(params, state);
            }
        } else {
            // read form input about import tools
            select_import_tools(params, state);
        }
        break;
    case 60:
        /*
         * actionForTemplate chef_site-importSitesMigrate.vm
         * 
         * This is called after the tools have been selected on the import page (replace) and the finish button is clicked
         *
         */
        if (forward) {
            Site existingSite = getStateSite(state);
            if (existingSite != null) {
                // revising a existing site's tool
                if (select_import_tools(params, state)) {
                    String threadName = "SiteImportThread" + existingSite.getId();
                    boolean found = false;
                    //check all running threads for our named thread
                    //this isn't cluster safe, but this check it more targeted towards
                    //a single user re-importing multiple times during a slow import (which would be on the same server)
                    for (Thread t : Thread.getAllStackTraces().keySet()) {
                        if (threadName.equals(t.getName())) {
                            found = true;
                            break;
                        }
                    }
                    if (found) {
                        //an existing thread is running for this site import, throw warning
                        addAlert(state, rb.getString("java.import.existing"));
                    } else {

                        // list of tools that were selected for import
                        final Hashtable importTools = (Hashtable) state.getAttribute(STATE_IMPORT_SITE_TOOL);

                        //list of existing tools in the destination site
                        final List existingTools = originalToolIds(
                                (List<String>) state.getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST),
                                state);

                        final String userEmail = UserDirectoryService.getCurrentUser().getEmail();
                        final Session session = SessionManager.getCurrentSession();
                        final ToolSession toolSession = SessionManager.getCurrentToolSession();
                        final String siteId = existingSite.getId();
                        Thread siteImportThread = new Thread() {
                            public void run() {
                                Site existingSite;
                                try {
                                    existingSite = SiteService.getSite(siteId);
                                    SessionManager.setCurrentSession(session);
                                    SessionManager.setCurrentToolSession(toolSession);
                                    EventTrackingService.post(
                                            EventTrackingService.newEvent(SiteService.EVENT_SITE_IMPORT_START,
                                                    existingSite.getReference(), false));
                                    // Remove all old contents before importing contents from new site
                                    importToolIntoSiteMigrate(existingTools, importTools, existingSite);
                                    if (ServerConfigurationService.getBoolean(SAK_PROP_IMPORT_NOTIFICATION,
                                            true)) {
                                        userNotificationProvider.notifySiteImportCompleted(userEmail,
                                                existingSite.getId(), existingSite.getTitle());
                                    }
                                    EventTrackingService.post(
                                            EventTrackingService.newEvent(SiteService.EVENT_SITE_IMPORT_END,
                                                    existingSite.getReference(), false));
                                } catch (IdUnusedException e) {
                                    M_log.error(e.getMessage(), e);
                                }
                            }
                        };
                        siteImportThread.setName(threadName);
                        siteImportThread.start();
                        state.setAttribute(IMPORT_QUEUED, rb.get("importQueued"));
                        state.removeAttribute(STATE_IMPORT_SITE_TOOL);
                        state.removeAttribute(STATE_IMPORT_SITES);
                    }
                } else {
                    // show alert and remain in current page
                    addAlert(state, rb.getString("java.toimporttool"));
                }
            } else {
                // new site
                select_import_tools(params, state);
            }
        } else {
            // read form input about import tools
            select_import_tools(params, state);
        }
        break;
    case 28:
        /*
         * actionForTemplate chef_siteinfo-import.vm
         * 
         * This is called after the sites to import from have been selected on the import page and the next button is clicked
         * 
         */
        if (forward) {
            if (params.getStrings("importSites") == null) {
                addAlert(state, rb.getString("java.toimport") + " ");
                state.removeAttribute(STATE_IMPORT_SITES);
            } else {
                List importSites = new ArrayList(Arrays.asList(params.getStrings("importSites")));
                Hashtable sites = new Hashtable();
                for (index = 0; index < importSites.size(); index++) {
                    try {
                        Site s = SiteService.getSite((String) importSites.get(index));
                        sites.put(s, new Vector());
                    } catch (IdUnusedException e) {
                    }
                }
                state.setAttribute(STATE_IMPORT_SITES, sites);
            }
        }
        break;
    case 58:
        /*
         * actionForTemplate chef_siteinfo-importSelection.vm
         * 
         */
        break;
    case 59:
        /*
         * actionForTemplate chef_siteinfo-import.vm
         * 
         */
        if (forward) {
            if (params.getStrings("importSites") == null) {
                addAlert(state, rb.getString("java.toimport") + " ");
                state.removeAttribute(STATE_IMPORT_SITES);
            } else {
                List importSites = new ArrayList(Arrays.asList(params.getStrings("importSites")));
                Hashtable sites = new Hashtable();
                for (index = 0; index < importSites.size(); index++) {
                    try {
                        Site s = SiteService.getSite((String) importSites.get(index));
                        sites.put(s, new Vector());
                    } catch (IdUnusedException e) {
                    }
                }
                state.setAttribute(STATE_IMPORT_SITES, sites);
            }

        }
        break;
    case 29:
        /*
         * actionForTemplate chef_siteinfo-duplicate.vm
         * 
         */
        if (forward) {
            if (state.getAttribute(SITE_DUPLICATED) == null) {
                if (StringUtils.trimToNull(params.getString("title")) == null) {
                    addAlert(state, rb.getString("java.dupli") + " ");
                } else {
                    String title = params.getString("title");
                    state.setAttribute(SITE_DUPLICATED_NAME, title);

                    String newSiteId = IdManager.createUuid();
                    try {
                        String oldSiteId = (String) state.getAttribute(STATE_SITE_INSTANCE_ID);

                        // Retrieve the source site reference to be used in the EventTrackingService
                        // notification of the start/end of a site duplication.
                        String sourceSiteRef = null;
                        try {
                            Site sourceSite = SiteService.getSite(oldSiteId);
                            sourceSiteRef = sourceSite.getReference();

                        } catch (IdUnusedException e) {
                            M_log.warn(
                                    this + ".actionForTemplate; case29: invalid source siteId: " + oldSiteId);
                            return;
                        }

                        // SAK-20797
                        long oldSiteQuota = this.getSiteSpecificQuota(oldSiteId);

                        Site site = SiteService.addSite(newSiteId, getStateSite(state));

                        // An event for starting the "duplicate site" action
                        EventTrackingService
                                .post(EventTrackingService.newEvent(SiteService.EVENT_SITE_DUPLICATE_START,
                                        sourceSiteRef, site.getId(), false, NotificationService.NOTI_OPTIONAL));

                        // get the new site icon url
                        if (site.getIconUrl() != null) {
                            site.setIconUrl(transferSiteResource(oldSiteId, newSiteId, site.getIconUrl()));
                        }

                        // set title
                        site.setTitle(title);

                        // SAK-20797 alter quota if required
                        boolean duplicateQuota = params.getString("dupequota") != null
                                ? params.getBoolean("dupequota")
                                : false;
                        if (duplicateQuota == true) {

                            if (oldSiteQuota > 0) {
                                M_log.info("Saving quota");
                                try {
                                    String collId = m_contentHostingService.getSiteCollection(site.getId());

                                    ContentCollectionEdit col = m_contentHostingService.editCollection(collId);

                                    ResourcePropertiesEdit resourceProperties = col.getPropertiesEdit();
                                    resourceProperties.addProperty(
                                            ResourceProperties.PROP_COLLECTION_BODY_QUOTA,
                                            new Long(oldSiteQuota).toString());
                                    m_contentHostingService.commitCollection(col);

                                } catch (Exception ignore) {
                                    M_log.warn("saveQuota: unable to duplicate site-specific quota for site : "
                                            + site.getId() + " : " + ignore);
                                }
                            }
                        }

                        try {
                            SiteService.save(site);

                            // import tool content
                            importToolContent(oldSiteId, site, false);

                            String siteType = site.getType();
                            if (SiteTypeUtil.isCourseSite(siteType)) {
                                // for course site, need to
                                // read in the input for
                                // term information
                                String termId = StringUtils.trimToNull(params.getString("selectTerm"));
                                if (termId != null) {
                                    AcademicSession term = cms.getAcademicSession(termId);
                                    if (term != null) {
                                        ResourcePropertiesEdit rp = site.getPropertiesEdit();
                                        rp.addProperty(Site.PROP_SITE_TERM, term.getTitle());
                                        rp.addProperty(Site.PROP_SITE_TERM_EID, term.getEid());
                                    } else {
                                        M_log.warn("termId=" + termId + " not found");
                                    }
                                }
                            }

                            // save again
                            SiteService.save(site);

                            String realm = SiteService.siteReference(site.getId());
                            try {
                                AuthzGroup realmEdit = authzGroupService.getAuthzGroup(realm);
                                if (SiteTypeUtil.isCourseSite(siteType)) {
                                    // also remove the provider id attribute if any
                                    realmEdit.setProviderGroupId(null);
                                }

                                // add current user as the maintainer
                                realmEdit.addMember(UserDirectoryService.getCurrentUser().getId(),
                                        site.getMaintainRole(), true, false);

                                authzGroupService.save(realmEdit);
                            } catch (GroupNotDefinedException e) {
                                M_log.error(this
                                        + ".actionForTemplate chef_siteinfo-duplicate: IdUnusedException, not found, or not an AuthzGroup object "
                                        + realm, e);
                                addAlert(state, rb.getString("java.realm"));
                            } catch (AuthzPermissionException e) {
                                addAlert(state, this + rb.getString("java.notaccess"));
                                M_log.error(this + ".actionForTemplate chef_siteinfo-duplicate: "
                                        + rb.getString("java.notaccess"), e);
                            }

                        } catch (IdUnusedException e) {
                            M_log.warn(this
                                    + " actionForTemplate chef_siteinfo-duplicate:: IdUnusedException when saving "
                                    + newSiteId);
                        } catch (PermissionException e) {
                            M_log.warn(this
                                    + " actionForTemplate chef_siteinfo-duplicate:: PermissionException when saving "
                                    + newSiteId);
                        }

                        // TODO: hard coding this frame id
                        // is fragile, portal dependent, and
                        // needs to be fixed -ggolden
                        // schedulePeerFrameRefresh("sitenav");
                        scheduleTopRefresh();

                        // send site notification
                        sendSiteNotification(state, site, null);

                        state.setAttribute(SITE_DUPLICATED, Boolean.TRUE);

                        // An event for ending the "duplicate site" action
                        EventTrackingService
                                .post(EventTrackingService.newEvent(SiteService.EVENT_SITE_DUPLICATE_END,
                                        sourceSiteRef, site.getId(), false, NotificationService.NOTI_OPTIONAL));

                    } catch (IdInvalidException e) {
                        addAlert(state, rb.getString("java.siteinval"));
                        M_log.error(this + ".actionForTemplate chef_siteinfo-duplicate: "
                                + rb.getString("java.siteinval") + " site id = " + newSiteId, e);
                    } catch (IdUsedException e) {
                        addAlert(state, rb.getString("java.sitebeenused"));
                        M_log.error(this + ".actionForTemplate chef_siteinfo-duplicate: "
                                + rb.getString("java.sitebeenused") + " site id = " + newSiteId, e);
                    } catch (PermissionException e) {
                        addAlert(state, rb.getString("java.allowcreate"));
                        M_log.error(this + ".actionForTemplate chef_siteinfo-duplicate: "
                                + rb.getString("java.allowcreate") + " site id = " + newSiteId, e);
                    }
                }
            }

            if (state.getAttribute(STATE_MESSAGE) == null) {
                // site duplication confirmed
                state.removeAttribute(SITE_DUPLICATED);
                state.removeAttribute(SITE_DUPLICATED_NAME);

                // return to the list view
                state.setAttribute(STATE_TEMPLATE_INDEX, "12");
            }
        }
        break;
    case 33:
        break;
    case 36:
        /*
         * actionForTemplate chef_site-newSiteCourse.vm
         */
        if (forward) {
            List providerChosenList = new Vector();
            List providerDescriptionChosenList = new Vector();

            if (params.getStrings("providerCourseAdd") == null) {
                state.removeAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
                state.removeAttribute(STATE_ADD_CLASS_PROVIDER_DESCRIPTION_CHOSEN);
                if (params.getString("manualAdds") == null) {
                    addAlert(state, rb.getString("java.manual") + " ");
                }
            }
            if (state.getAttribute(STATE_MESSAGE) == null) {
                // The list of courses selected from provider listing
                if (params.getStrings("providerCourseAdd") != null) {
                    providerChosenList = new ArrayList(Arrays.asList(params.getStrings("providerCourseAdd"))); // list of
                    // description choices
                    if (params.getStrings("providerCourseAddDescription") != null) {
                        providerDescriptionChosenList = new ArrayList(
                                Arrays.asList(params.getStrings("providerCourseAddDescription"))); // list of
                        state.setAttribute(STATE_ADD_CLASS_PROVIDER_DESCRIPTION_CHOSEN,
                                providerDescriptionChosenList);
                    }
                    // course
                    // ids
                    String userId = (String) state.getAttribute(STATE_INSTRUCTOR_SELECTED);
                    String currentUserId = (String) state.getAttribute(STATE_CM_CURRENT_USERID);

                    if (userId == null || (userId != null && userId.equals(currentUserId))) {
                        state.setAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN, providerChosenList);
                        state.removeAttribute(STATE_CM_AUTHORIZER_SECTIONS);
                        state.removeAttribute(FORM_ADDITIONAL);
                        state.removeAttribute(STATE_CM_AUTHORIZER_LIST);
                    } else {
                        // STATE_CM_AUTHORIZER_SECTIONS are SectionObject,
                        // so need to prepare it
                        // also in this page, u can pick either section from
                        // current user OR
                        // sections from another users but not both. -
                        // daisy's note 1 for now
                        // till we are ready to add more complexity
                        List sectionObjectList = prepareSectionObject(providerChosenList, userId);
                        state.setAttribute(STATE_CM_AUTHORIZER_SECTIONS, sectionObjectList);
                        state.removeAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
                        // set special instruction & we will keep
                        // STATE_CM_AUTHORIZER_LIST
                        String additional = StringUtils.trimToEmpty(params.getString("additional"));
                        state.setAttribute(FORM_ADDITIONAL, additional);
                    }
                }
                collectNewSiteInfo(state, params, providerChosenList);

                String find_course = params.getString("find_course");
                if (state.getAttribute(STATE_TEMPLATE_SITE) != null
                        && (find_course == null || !"true".equals(find_course))) {
                    // creating based on template
                    doFinish(data);
                }
            }
        }
        break;
    case 38:
        break;
    case 39:
        break;
    case 42:
        /*
         * actionForTemplate chef_site-type-confirm.vm
         * 
         */
        break;
    case 43:
        /*
         * actionForTemplate chef_site-editClass.vm
         * 
         */
        if (forward) {
            if (params.getStrings("providerClassDeletes") == null
                    && params.getStrings("manualClassDeletes") == null
                    && params.getStrings("cmRequestedClassDeletes") == null && !"back".equals(direction)) {
                addAlert(state, rb.getString("java.classes"));
            }

            if (params.getStrings("providerClassDeletes") != null) {
                // build the deletions list
                List providerCourseList = (List) state.getAttribute(SITE_PROVIDER_COURSE_LIST);
                List providerCourseDeleteList = new ArrayList(
                        Arrays.asList(params.getStrings("providerClassDeletes")));
                for (ListIterator i = providerCourseDeleteList.listIterator(); i.hasNext();) {
                    providerCourseList.remove((String) i.next());
                }

                //Track provider deletes, seems like the only place to do it. If a confirmation is ever added somewhere, don't do this.
                trackRosterChanges(org.sakaiproject.site.api.SiteService.EVENT_SITE_ROSTER_REMOVE,
                        providerCourseDeleteList);
                state.setAttribute(SITE_PROVIDER_COURSE_LIST, providerCourseList);
            }
            if (params.getStrings("manualClassDeletes") != null) {
                // build the deletions list
                List manualCourseList = (List) state.getAttribute(SITE_MANUAL_COURSE_LIST);
                List manualCourseDeleteList = new ArrayList(
                        Arrays.asList(params.getStrings("manualClassDeletes")));
                for (ListIterator i = manualCourseDeleteList.listIterator(); i.hasNext();) {
                    manualCourseList.remove((String) i.next());
                }
                state.setAttribute(SITE_MANUAL_COURSE_LIST, manualCourseList);
            }

            if (params.getStrings("cmRequestedClassDeletes") != null) {
                // build the deletions list
                List<SectionObject> cmRequestedCourseList = (List) state
                        .getAttribute(STATE_CM_REQUESTED_SECTIONS);
                List<String> cmRequestedCourseDeleteList = new ArrayList(
                        Arrays.asList(params.getStrings("cmRequestedClassDeletes")));
                for (ListIterator i = cmRequestedCourseDeleteList.listIterator(); i.hasNext();) {
                    String sectionId = (String) i.next();
                    try {
                        SectionObject so = new SectionObject(cms.getSection(sectionId));
                        SectionObject soFound = null;
                        for (Iterator j = cmRequestedCourseList.iterator(); soFound == null && j.hasNext();) {
                            SectionObject k = (SectionObject) j.next();
                            if (k.eid.equals(sectionId)) {
                                soFound = k;
                            }
                        }
                        if (soFound != null)
                            cmRequestedCourseList.remove(soFound);
                    } catch (IdNotFoundException e) {
                        M_log.warn("actionForTemplate 43 editClass: Cannot find section " + sectionId);
                    }
                }
                state.setAttribute(STATE_CM_REQUESTED_SECTIONS, cmRequestedCourseList);
            }

            updateCourseClasses(state, new Vector(), new Vector());
        }
        break;
    case 44:
        if (forward) {
            AcademicSession a = (AcademicSession) state.getAttribute(STATE_TERM_SELECTED);
            Site site = getStateSite(state);
            ResourcePropertiesEdit pEdit = site.getPropertiesEdit();

            // update the course site property and realm based on the selection
            updateCourseSiteSections(state, site.getId(), pEdit, a);
            try {
                SiteService.save(site);
            } catch (Exception e) {
                M_log.error(this + ".actionForTemplate chef_siteinfo-addCourseConfirm: " + e.getMessage()
                        + site.getId(), e);
            }

            removeAddClassContext(state);
        }

        break;
    case 54:
        if (forward) {

            // store answers to site setup questions
            if (getAnswersToSetupQuestions(params, state)) {
                state.setAttribute(STATE_TEMPLATE_INDEX,
                        state.getAttribute(STATE_SITE_SETUP_QUESTION_NEXT_TEMPLATE));
            }
        }
        break;
    case 61:
        // import users
        if (forward) {
            if (params.getStrings("importSites") == null) {
                addAlert(state, rb.getString("java.toimport") + " ");
            } else {
                importSitesUsers(params, state);
            }
        }
        break;
    }

}