use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class FilePersister method deleteUserData.
/**
* Delete all qti data dirs for certain user.
* Includes : /qtiser/<REPO_ID>/<COURSE_ID>/<USER_NAME>,
* /qtiser/<USER_NAME>
* /resreporting/<USER_NAME>
* @param identity
*/
public static void deleteUserData(Identity identity) {
try {
// 1. Delete temp file qti.ser @ /qtiser/<REPO_ID>/<COURSE_ID>/<USER_NAME>
// Loop over all repo-id-dirs and loop over all course-id-dirs and look for username
File qtiserBaseDir = new File(WebappHelper.getUserDataRoot() + File.separator + QTI_SER);
class OlatResidFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.matches("[0-9]*"));
}
}
File[] dirs = qtiserBaseDir.listFiles(new OlatResidFilter());
if (dirs != null) {
for (int i = 0; i < dirs.length; i++) {
File[] subDirs = dirs[i].listFiles(new OlatResidFilter());
for (int j = 0; j < subDirs.length; j++) {
File userDir = new File(subDirs[j], identity.getName());
if (userDir.exists()) {
FileUtils.deleteDirsAndFiles(userDir, true, true);
log.debug("Delete qti.ser Userdata dir=" + userDir.getAbsolutePath());
}
}
}
}
// 2. Delete temp file qti.ser @ /qtiser/<USER_NAME> (old <5.1 path)
File qtiserDir = new File(WebappHelper.getUserDataRoot() + File.separator + QTI_SER + File.separator + identity.getName());
if (qtiserDir != null) {
FileUtils.deleteDirsAndFiles(qtiserDir, true, true);
log.debug("Delete qti.ser Userdata dir=" + qtiserDir.getAbsolutePath());
}
// 3. Delete resreporting @ /resreporting/<USER_NAME>
File resReportingDir = new File(WebappHelper.getUserDataRoot() + File.separator + RES_REPORTING + File.separator + identity.getName());
if (resReportingDir != null) {
FileUtils.deleteDirsAndFiles(resReportingDir, true, true);
log.debug("Delete qti resreporting Userdata dir=" + qtiserDir.getAbsolutePath());
}
} catch (Exception e) {
throw new OLATRuntimeException(FilePersister.class, "could not delete QTI resreporting dir for identity=" + identity, e);
}
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class FilePersister method persist.
/**
* serialize the current test in case of a stop and later resume (e.g. the
* browser of the user crashes, and the user wants to resume the test or
* survey in a later session)
*
* @see org.olat.ims.qti.process.Persister#persist(Object, String)
*/
@Override
public void persist(Object o, String info) {
File fSerialDir = new File(getFullQtiPath());
OutputStream os = null;
try {
long start = -1;
boolean debugOn = log.isDebug();
if (debugOn) {
start = System.currentTimeMillis();
}
fSerialDir.mkdirs();
os = new FileOutputStream(new File(fSerialDir, QTI_FILE));
// big tests (>5MB) produce heavy load on the system without buffered output. 256K seem to be a performant value
// BufferedOutputStream bos = new BufferedOutputStream(os, 262144);
// above stmt. incorrect, big buffer does not mean faster storage
BufferedOutputStream bos = FileUtils.getBos(os);
ObjectOutputStream oostream = new ObjectOutputStream(bos);
oostream.writeObject(o);
oostream.close();
os.close();
if (debugOn) {
long stop = System.currentTimeMillis();
log.debug("time in ms to save ims qti ser file:" + (stop - start));
}
} catch (Exception e) {
try {
if (os != null)
os.close();
} catch (IOException e1) {
throw new OLATRuntimeException(this.getClass(), "Error while closing file stream: ", e1);
}
throw new OLATRuntimeException(this.getClass(), "user " + subjectName + " stream could not be saved to path:" + getFullQtiPath(), e);
}
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class QTIExportFormatterCSVType3 method closeReport.
public void closeReport() {
if (qtiItemObjectList == null) {
throw new OLATRuntimeException(null, "Can not format report when qtiItemObjectList is null", null);
}
String legend = translator.translate("legend");
sb.append(car + car);
sb.append(legend);
sb.append(car + car);
int y = 1;
for (Iterator<QTIItemObject> iter = qtiItemObjectList.iterator(); iter.hasNext(); ) {
QTIItemObject element = iter.next();
sb.append(element.getItemIdent());
sb.append(sep);
sb.append(emb);
sb.append(escape(element.getItemTitle()));
sb.append(emb);
sb.append(car);
// CELFI#107
sb.append(sep + sep + sep + sep);
String question = element.getQuestionText();
if (tagless) {
question = FilterFactory.getXSSFilter(-1).filter(question);
question = FilterFactory.getHtmlTagsFilter().filter(question);
}
question = StringEscapeUtils.unescapeHtml(question);
sb.append(question);
sb.append(car);
// CELFI#107 END
List<String> responseLabelMaterials = element.getResponseLabelMaterials();
for (int i = 0; i < element.getResponseIdentifier().size(); i++) {
sb.append(sep + sep);
sb.append(y);
sb.append("_");
sb.append(element.getItemType());
sb.append(i + 1);
sb.append(sep);
sb.append(element.getResponseIdentifier().get(i));
sb.append(sep);
if (responseLabelMaterials != null) {
String s = responseLabelMaterials.get(i);
s = StringEscapeUtils.unescapeHtml(s);
if (tagless) {
s = s.replaceAll("\\<.*?\\>", "");
}
sb.append(Formatter.stripTabsAndReturns(s));
}
sb.append(car);
}
y++;
}
sb.append(car + car);
sb.append("SCQ");
sb.append(sep);
sb.append("Single Choice Question");
sb.append(car);
sb.append("MCQ");
sb.append(sep);
sb.append("Multiple Choice Question");
sb.append(car);
sb.append("FIB");
sb.append(sep);
sb.append("Fill in the blank");
sb.append(car);
sb.append("ESS");
sb.append(sep);
sb.append("Essay");
sb.append(car);
sb.append("KPR");
sb.append(sep);
sb.append("Kprim (K-Type)");
sb.append(car + car);
sb.append("R:");
sb.append(sep);
sb.append("Radio button (SCQ)");
sb.append(car);
sb.append("C:");
sb.append(sep);
sb.append("Check box (MCQ or KPR)");
sb.append(car);
sb.append("B:");
sb.append(sep);
sb.append("Blank (FIB)");
sb.append(car);
sb.append("A:");
sb.append(sep);
sb.append("Area (ESS)");
sb.append(car + car);
sb.append("x_Ry");
sb.append(sep);
sb.append("Radio Button y of SCQ x, e.g. 1_R1");
sb.append(car);
sb.append("x_Cy");
sb.append(sep);
sb.append("Check Box y of MCQ x or two Radio Buttons y of KPR x, e.g. 3_C2");
sb.append(car);
sb.append("x_By");
sb.append(sep);
sb.append("Blank y of FIB x, e.g. 17_B2");
sb.append(car);
sb.append("x_Ay");
sb.append(sep);
sb.append("Area y of ESS x, e.g. 4_A1");
sb.append(car + car);
sb.append("Kprim:");
sb.append(sep);
sb.append("'+' = yes");
sb.append(sep);
sb.append("'-' = no");
sb.append(sep);
sb.append("'.' = no answer");
sb.append(sep);
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class BGAreaManagerImpl method findBGArea.
/**
* @see org.olat.group.area.BGAreaManager#findBGArea(java.lang.String,
* org.olat.group.context.BGContext)
*/
public BGArea findBGArea(String areaName, OLATResource resource) {
StringBuilder sb = new StringBuilder();
sb.append("select area from ").append(BGAreaImpl.class.getName()).append(" area ").append(" where area.name=:areaName and area.resource.key=:resourceKey");
List<BGArea> areas = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BGArea.class).setParameter("areaName", areaName).setParameter("resourceKey", resource.getKey()).getResultList();
if (areas.isEmpty()) {
return null;
} else if (areas.size() > 1) {
throw new OLATRuntimeException(BGAreaManagerImpl.class, "findBGArea(" + areaName + ") returned more than one row for BGContext with key " + resource.getKey(), null);
}
return areas.get(0);
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class FileResourceManager method getAsDownloadeableMediaResource.
/**
* @param res
* @return File resource as downloadeable media resource.
*/
public MediaResource getAsDownloadeableMediaResource(OLATResourceable res) {
FileResource fr = getAsGenericFileResource(res);
File f = getFile(fr);
if (// folder not existing or no file in it
f == null)
throw new OLATRuntimeException(FileResourceManager.class, "could not get File for OLATResourceable " + res.getResourceableId() + ":" + res.getResourceableTypeName(), null);
return new DownloadeableMediaResource(f);
}
Aggregations