Search in sources :

Example 71 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class RepositoryEntryImportExport method exportDoExportProperties.

/**
 * Export metadata of a repository entry to a file.
 * Only one repository entry's metadata may be exported into a directory. The
 * file name of the properties file will be the same for all repository entries!
 */
public void exportDoExportProperties() {
    // save repository entry properties
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(new File(baseDirectory, PROPERTIES_FILE));
        XStream xstream = getXStream();
        RepositoryEntryImport imp = new RepositoryEntryImport(re);
        RepositoryManager rm = RepositoryManager.getInstance();
        VFSLeaf image = rm.getImage(re);
        if (image instanceof LocalFileImpl) {
            imp.setImageName(image.getName());
            FileUtils.copyFileToDir(((LocalFileImpl) image).getBasefile(), baseDirectory, "");
        }
        RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
        VFSLeaf movie = repositoryService.getIntroductionMovie(re);
        if (movie instanceof LocalFileImpl) {
            imp.setMovieName(movie.getName());
            FileUtils.copyFileToDir(((LocalFileImpl) movie).getBasefile(), baseDirectory, "");
        }
        addLicenseInformations(imp, re);
        xstream.toXML(imp, fOut);
    } catch (IOException ioe) {
        throw new OLATRuntimeException("Error writing repo properties.", ioe);
    } finally {
        FileUtils.closeSafely(fOut);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) IOException(java.io.IOException) File(java.io.File)

Example 72 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class RepositoryEntryImportExport method loadConfiguration.

/**
 * Read previousely exported Propertiesproperties
 */
private void loadConfiguration() {
    FileSystem fs = null;
    try {
        if (baseDirectory.exists()) {
            if (baseDirectory.getName().endsWith(".zip")) {
                fs = FileSystems.newFileSystem(baseDirectory.toPath(), null);
                Path fPath = fs.getPath("/");
                Path manifestPath = fPath.resolve("export").resolve(PROPERTIES_FILE);
                try (InputStream inputFile = Files.newInputStream(manifestPath, StandardOpenOption.READ)) {
                    XStream xstream = getXStream();
                    repositoryProperties = (RepositoryEntryImport) xstream.fromXML(inputFile);
                } catch (Exception e) {
                    log.error("Cannot read repo.xml im zip", e);
                }
            } else {
                File inputFile = new File(baseDirectory, PROPERTIES_FILE);
                if (inputFile.exists()) {
                    XStream xstream = getXStream();
                    repositoryProperties = (RepositoryEntryImport) xstream.fromXML(inputFile);
                } else {
                    repositoryProperties = new RepositoryEntryImport();
                }
            }
        } else {
            repositoryProperties = new RepositoryEntryImport();
        }
        propertiesLoaded = true;
    } catch (Exception ce) {
        throw new OLATRuntimeException("Error importing repository entry properties.", ce);
    } finally {
        IOUtils.closeQuietly(fs);
    }
}
Also used : Path(java.nio.file.Path) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XStream(com.thoughtworks.xstream.XStream) FileSystem(java.nio.file.FileSystem) File(java.io.File) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException)

Example 73 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class OLATApiAdapter method olatCommit.

/**
 * @param isACommit true, if the call comes from a lmscommit, false if it comes from a lmsfinish
 * @return
 */
private final String olatCommit(boolean isACommit) {
    if (olatScoId == null)
        return "false";
    core.transEnd();
    @SuppressWarnings("unchecked") Hashtable<String, String> ins = core.getTransNew();
    @SuppressWarnings("unchecked") Hashtable<String, String> mod = core.getTransMod();
    core.transBegin();
    LMSDataFormBean lmsDataBean = new LMSDataFormBean();
    lmsDataBean.setItemID(olatScoId);
    // TODO:gs pass the dataBean for use, and do not get it a second time
    lmsDataBean.setNextAction("5");
    lmsDataBean.setLmsAction("update");
    Map<String, String> cmiData = new HashMap<String, String>();
    // TODO:gs:c make it possible only to update the changed cmi data.
    if (ins.size() > 0) {
        Set<String> set = ins.keySet();
        for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
            String cmi = it.next();
            olatScoCmi.remove(cmi);
            olatScoCmi.put(cmi, ins.get(cmi));
        }
    }
    if (mod.size() > 0) {
        Set<String> set = mod.keySet();
        for (Iterator<String> it = set.iterator(); it.hasNext(); ) {
            String cmi = it.next();
            olatScoCmi.remove(cmi);
            olatScoCmi.put(cmi, mod.get(cmi));
        }
    }
    cmiData.putAll(olatScoCmi);
    // work around for missing cmi's (needed by reload code, but not used in ilias code)
    if (cmiData.get("cmi.interactions._count") != null && cmiData.get("cmi.interactions._count") != "0") {
        int count = Integer.parseInt(cmiData.get("cmi.interactions._count"));
        for (int i = 0; i < count; i++) {
            // OLAT-4271: check first if cmi.interactions.n.objectives._count exist before putting a default one
            String objectivesCount = cmiData.get("cmi.interactions." + i + ".objectives._count");
            if (!StringHelper.containsNonWhitespace(objectivesCount)) {
                cmiData.put("cmi.interactions." + i + ".objectives._count", "0");
            }
        }
    }
    if (isACommit) {
        String rawScore = cmiData.get(SCORE_IDENT);
        String lessonStatus = cmiData.get(LESSON_STATUS_IDENT);
        if (StringHelper.containsNonWhitespace(rawScore) || StringHelper.containsNonWhitespace(lessonStatus)) {
            // to prevent problems with bad xmlhttprequest timings
            synchronized (this) {
                // o_clusterOK by:fj: instance is spawned by the ScormAPIandDisplayController
                if (StringHelper.containsNonWhitespace(rawScore)) {
                    scoresProp.put(olatScoId, rawScore);
                    OutputStream os = null;
                    try {
                        os = new BufferedOutputStream(new FileOutputStream(scorePropsFile));
                        scoresProp.store(os, null);
                    } catch (IOException e) {
                        throw new OLATRuntimeException(this.getClass(), "could not save scorm-properties-file: " + scorePropsFile.getAbsolutePath(), e);
                    } finally {
                        FileUtils.closeSafely(os);
                    }
                }
                if (StringHelper.containsNonWhitespace(lessonStatus)) {
                    lessonStatusProp.put(olatScoId, lessonStatus);
                    OutputStream os = null;
                    try {
                        os = new BufferedOutputStream(new FileOutputStream(lessonStatusPropsFile));
                        lessonStatusProp.store(os, null);
                    } catch (IOException e) {
                        throw new OLATRuntimeException(this.getClass(), "could not save scorm-properties-file: " + scorePropsFile.getAbsolutePath(), e);
                    } finally {
                        FileUtils.closeSafely(os);
                    }
                }
                // notify
                if (!apiCallbacks.isEmpty()) {
                    for (ScormAPICallback apiCallback : apiCallbacks) {
                        apiCallback.lmsCommit(olatScoId, scoresProp, lessonStatusProp);
                    }
                }
            }
        }
    // <OLATCE-289>
    } else {
        // if "isACommit" is false, this is a lmsFinish and the apiCallback shall save the points an passed information
        if (!apiCallbacks.isEmpty()) {
            String rawScore = cmiData.get(SCORE_IDENT);
            if (rawScore != null && !rawScore.equals("")) {
                scoresProp.put(olatScoId, rawScore);
            }
            String lessonStatus = cmiData.get(LESSON_STATUS_IDENT);
            if (StringHelper.containsNonWhitespace(lessonStatus)) {
                lessonStatusProp.put(olatScoId, lessonStatus);
            }
            for (ScormAPICallback apiCallback : apiCallbacks) {
                apiCallback.lmsFinish(olatScoId, scoresProp, lessonStatusProp);
            }
        }
    // </OLATCE-289>
    }
    try {
        lmsDataBean.setDataAsMap(cmiData);
        odatahandler = new LMSDataHandler(scormManager, lmsDataBean, scormSettingsHandler);
        odatahandler.updateCMIData(olatScoId);
        return "true";
    } catch (Exception e) {
        logError("Error during commit", e);
        return "false";
    }
}
Also used : HashMap(java.util.HashMap) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) LMSDataHandler(org.olat.modules.scorm.server.beans.LMSDataHandler) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) LMSDataFormBean(org.olat.modules.scorm.server.beans.LMSDataFormBean)

Example 74 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class ScormAssessmentManager method getSequencerModel.

/**
 * Load the SequencerModel
 * @param username
 * @param courseEnv
 * @param node
 * @return can be null if the user hasn't visited the course
 */
public SequencerModel getSequencerModel(String username, CourseEnvironment courseEnv, ScormCourseNode node) {
    VFSContainer scoDirectory = ScormDirectoryHelper.getScoDirectory(username, courseEnv, node);
    if (scoDirectory == null)
        return null;
    VFSItem reloadSettingsFile = scoDirectory.resolve(RELOAD_SETTINGS_FILE);
    if (reloadSettingsFile instanceof LocalFileImpl) {
        LocalFileImpl fileImpl = (LocalFileImpl) reloadSettingsFile;
        return new SequencerModel(fileImpl.getBasefile(), null);
    } else if (reloadSettingsFile != null) {
        throw new OLATRuntimeException(this.getClass(), "Programming error, SCORM results must be file based", null);
    }
    return null;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) SequencerModel(org.olat.modules.scorm.server.servermodels.SequencerModel) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 75 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class NavigationViewer method updateDefaultOrg.

/**
 * Method to change the default organization in the navigation file
 *
 * @param index
 */
public void updateDefaultOrg(int index) {
    Element[] orgs = getOrganizationList();
    String newDefault = orgs[index].getAttributeValue(SCORM12_Core.IDENTIFIER);
    _sequencerModel.setDefaultOrg(newDefault);
    try {
        _sequencerModel.saveDocument();
    } catch (IOException ex) {
        throw new OLATRuntimeException(this.getClass(), "Could not save changes to default organization. ", ex);
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Element(org.jdom.Element) IOException(java.io.IOException)

Aggregations

OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)268 IOException (java.io.IOException)104 File (java.io.File)50 ModuleConfiguration (org.olat.modules.ModuleConfiguration)26 ArrayList (java.util.ArrayList)22 AssertException (org.olat.core.logging.AssertException)22 FileOutputStream (java.io.FileOutputStream)20 OutputStream (java.io.OutputStream)20 Properties (java.util.Properties)20 FileInputStream (java.io.FileInputStream)18 HashMap (java.util.HashMap)18 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)18 QTIItemObject (org.olat.ims.qti.export.helper.QTIItemObject)18 DefaultElement (org.dom4j.tree.DefaultElement)16 Element (org.jdom.Element)16 InputStream (java.io.InputStream)14 BufferedInputStream (java.io.BufferedInputStream)12 List (java.util.List)12 Document (org.dom4j.Document)12 CPItem (org.olat.ims.cp.objects.CPItem)12