Package org.olat.repository.handlers

Source Code of org.olat.repository.handlers.QTIHandler

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.repository.handlers;

import java.io.File;

import org.olat.core.commons.fullWebApp.LayoutMain3ColsController;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.generic.layout.MainLayoutController;
import org.olat.core.gui.translator.PackageTranslator;
import org.olat.core.gui.translator.Translator;
import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.util.FileUtils;
import org.olat.core.util.Util;
import org.olat.core.util.ZipUtil;
import org.olat.core.util.coordinate.CoordinatorManager;
import org.olat.core.util.coordinate.LockResult;
import org.olat.fileresource.FileResourceManager;
import org.olat.fileresource.types.FileResource;
import org.olat.fileresource.types.SurveyFileResource;
import org.olat.ims.qti.process.AssessmentInstance;
import org.olat.ims.qti.process.ImsRepositoryResolver;
import org.olat.ims.qti.process.Resolver;
import org.olat.modules.iq.IQManager;
import org.olat.modules.iq.IQPreviewSecurityCallback;
import org.olat.modules.iq.IQSecurityCallback;
import org.olat.repository.RepositoryManager;
import org.olat.resource.references.ReferenceManager;

/**
* Initial Date:  Apr 6, 2004
*
* @author Mike Stock
*
* Comment: 
*
*/
public abstract class QTIHandler extends FileHandler implements RepositoryHandler {

  private static final String PACKAGE = Util.getPackageName(RepositoryManager.class);

  /**
   * Comment for <code>PROCESS_UPLOAD</code>
   */
  public static final String PROCESS_UPLOAD = "pu";
  /**
   * Comment for <code>PROCESS_CREATENEW</code>
   */
  public static final String PROCESS_CREATENEW = "cn";


  /**
   * Default constructor.
   */
  public QTIHandler() {
    // Implemented by specific sub-class
  }

 
  /**
   * @see org.olat.repository.handlers.RepositoryHandler#getLaunchController(org.olat.core.id.OLATResourceable java.lang.String, org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl)
   */
  public MainLayoutController getLaunchController(OLATResourceable res, String initialViewIdentifier, UserRequest ureq, WindowControl wControl) {
    Resolver resolver = new ImsRepositoryResolver(res);
    IQSecurityCallback secCallback = new IQPreviewSecurityCallback();
    MainLayoutController runController = res.getResourceableTypeName().equals(SurveyFileResource.TYPE_NAME) ?
      IQManager.getInstance().createIQDisplayController(res, resolver, AssessmentInstance.QMD_ENTRY_TYPE_SURVEY, secCallback, ureq, wControl)
      IQManager.getInstance().createIQDisplayController(res, resolver, AssessmentInstance.QMD_ENTRY_TYPE_SELF, secCallback, ureq, wControl);
      // use on column layout
      LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(ureq, wControl, null, null, runController.getInitialComponent(), null);
      layoutCtr.addDisposableChildController(runController); // dispose content on layout dispose
      return layoutCtr;
  }

  /**
   * @see org.olat.repository.handlers.RepositoryHandler#readyToDelete(org.olat.core.id.OLATResourceable org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl)
   */
  public boolean readyToDelete(OLATResourceable res, UserRequest ureq, WindowControl wControl) {
    ReferenceManager refM = ReferenceManager.getInstance();
    String referencesSummary = refM.getReferencesToSummary(res, ureq.getLocale());
    if (referencesSummary != null) {
      Translator translator = new PackageTranslator(PACKAGE, ureq.getLocale());
      wControl.setError(translator.translate("details.delete.error.references",
          new String[] { referencesSummary }));
      return false;
    }
    if (CoordinatorManager.getCoordinator().getLocker().isLocked(res, null)) {
      Translator translator = new PackageTranslator(PACKAGE, ureq.getLocale());
      wControl.setError(translator.translate("details.delete.error.editor"));
      return false;
    }
    return true;
  }
 
  /**
   *
   * @see org.olat.repository.handlers.RepositoryHandler#acquireLock(org.olat.core.id.OLATResourceable, org.olat.core.id.Identity)
   */
  public LockResult acquireLock(OLATResourceable ores, Identity identity) {
    //nothing to do
    return null;
  }
 
  /**
   *
   * @see org.olat.repository.handlers.RepositoryHandler#releaseLock(org.olat.core.util.coordinate.LockResult)
   */
  public void releaseLock(LockResult lockResult) {
    //nothing to do since nothing locked
  }
 
  /**
   *
   * @see org.olat.repository.handlers.RepositoryHandler#isLocked(org.olat.core.id.OLATResourceable)
   */
  public boolean isLocked(OLATResourceable ores) {
    return false;
  }
 
  /**
   *
   * @see org.olat.repository.handlers.FileHandler#createCopy(org.olat.core.id.OLATResourceable, org.olat.core.gui.UserRequest)
   */
  public OLATResourceable createCopy(OLATResourceable res, UserRequest ureq) {
    OLATResourceable oLATResourceable = super.createCopy(res, ureq);
   
    File sourceFile = FileResourceManager.getInstance().getFileResource(oLATResourceable);
    //unzip sourceFile in a temp dir, delete changelog if any, zip back, delete temp dir
    FileResource tempFr = new FileResource();
    // move file to its new place
    File fResourceFileroot = FileResourceManager.getInstance().getFileResourceRoot(tempFr);
    if (!FileUtils.copyFileToDir(sourceFile, fResourceFileroot)) return null;
    File fUnzippedDir = FileResourceManager.getInstance().unzipFileResource(tempFr);
    File changeLogDir = new File(fUnzippedDir, "changelog");
    if(changeLogDir.exists()) {     
      boolean changeLogDeleted = FileUtils.deleteDirsAndFiles(changeLogDir, true, true);     
    }
    File targetZipFile = sourceFile;
    FileUtils.deleteDirsAndFiles(targetZipFile.getParentFile(), true, false);
    ZipUtil.zipAll(fUnzippedDir, targetZipFile);   
    FileResourceManager.getInstance().deleteFileResource(tempFr);
   
    return oLATResourceable;
  }
 
 
}
TOP

Related Classes of org.olat.repository.handlers.QTIHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.