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);
}
}
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);
}
}
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";
}
}
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;
}
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);
}
}
Aggregations