コード例 #1
0
ファイル: ArchiveAction.java プロジェクト: yllyx/sakai
  /**
   * doImport called when "eventSubmit_doBatch_Archive" is in the request parameters to archive a
   * bunch of sites that match the criteria NOTE. This performs exactly as per a normal archive. Ie
   * if you archive a site twice, you get two copies of the resources. A change needs to be made to
   * the archive service to clean out the archives before each run.
   */
  public void doBatch_Archive(RunData data, Context context) {

    SessionState state =
        ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    if (!securityService.isSuperUser()) {
      addAlert(state, rb.getString("archive.batch.auth"));
      return;
    }

    final String selectedTerm = (String) state.getAttribute("selectedTerm");
    final List<SparseSite> sites = (List<SparseSite>) state.getAttribute("sites");
    final Session currentSession =
        sessionManager.getCurrentSession(); // need to pass this into the new thread
    final User currentUser =
        userDirectoryService.getCurrentUser(); // need to pass this into the new thread

    // do the archive in a new thread
    Runnable backgroundRunner =
        new Runnable() {
          public void run() {
            try {
              archiveSites(sites, selectedTerm, currentSession, currentUser);
            } catch (IllegalStateException e) {
              throw e;
            } catch (Exception e) {
              log.error("Batch Archive background runner thread died: " + e, e);
            }
          }
        };
    Thread backgroundThread = new Thread(backgroundRunner);
    backgroundThread.setDaemon(true);
    backgroundThread.start();

    state.setAttribute(STATE_MODE, BATCH_MODE);
  }