use of org.olat.ims.qti.QTIResultManager in project OpenOLAT by OpenOLAT.
the class QTIExportManager method selectAndExportResults.
public boolean selectAndExportResults(QTIExportFormatter qef, Long courseResId, String shortTitle, String olatResourceDetail, RepositoryEntry testRe, ZipOutputStream exportStream, Locale locale, String fileNameSuffix) throws IOException {
boolean resultsFoundAndExported = false;
QTIResultManager qrm = QTIResultManager.getInstance();
List<QTIResult> results = qrm.selectResults(courseResId, olatResourceDetail, testRe.getKey(), null, qef.getType());
if (results.size() > 0) {
List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(testRe);
qef.setQTIItemObjectList(qtiItemObjectList);
if (results.size() > 0) {
createContentOfExportFile(results, qtiItemObjectList, qef);
String targetFileName = getFilename(shortTitle, fileNameSuffix);
exportStream.putNextEntry(new ZipEntry(targetFileName));
IOUtils.write(qef.getReport(), exportStream);
exportStream.closeEntry();
resultsFoundAndExported = true;
}
} else {
String targetFileName = getFilename(shortTitle, fileNameSuffix);
exportStream.putNextEntry(new ZipEntry(targetFileName));
Translator translator = Util.createPackageTranslator(QTIExportFormatter.class, locale);
IOUtils.write(translator.translate("archive.noresults.short"), exportStream);
exportStream.closeEntry();
resultsFoundAndExported = true;
}
return resultsFoundAndExported;
}
use of org.olat.ims.qti.QTIResultManager in project openolat by klemens.
the class QTIStatisticsResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding(encoding);
} catch (Exception e) {
log.error("", e);
}
CourseNode courseNode = resourceResult.getTestCourseNode();
String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
hres.setHeader("Content-Description", urlEncodedLabel);
try {
// fields separated by
String sep = "\\t";
// fields embedded by
String emb = "\"";
// carriage return
String car = "\\r\\n";
sep = QTIArchiver.convert2CtrlChars(sep);
car = QTIArchiver.convert2CtrlChars(car);
int exportType = 1;
QTIExportFormatter formatter;
if (QTIType.test.equals(resourceResult.getType())) {
exportType = 1;
formatter = new QTIExportFormatterCSVType1(locale, sep, emb, car, true);
} else if (QTIType.survey.equals(resourceResult.getType())) {
exportType = 2;
formatter = new QTIExportFormatterCSVType3(locale, null, sep, emb, car, true);
} else {
return;
}
Long qtiRepoEntryKey = resourceResult.getQTIRepositoryEntry().getKey();
List<QTIItemObject> itemList = new QTIObjectTreeBuilder().getQTIItemObjectList(resourceResult.getResolver());
formatter.setMapWithExportItemConfigs(getQTIItemConfigs(itemList));
QTIResultManager qrm = QTIResultManager.getInstance();
QTIStatisticSearchParams params = resourceResult.getSearchParams();
List<Group> limitToGroups = params.isMayViewAllUsersAssessments() ? null : params.getLimitToGroups();
List<QTIResult> results = qrm.selectResults(resourceResult.getCourseOres().getResourceableId(), courseNode.getIdent(), qtiRepoEntryKey, limitToGroups, exportType);
QTIExportManager.getInstance().exportResults(formatter, results, itemList, hres.getOutputStream());
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.ims.qti.QTIResultManager in project openolat by klemens.
the class QTIExportManager method selectAndExportResults.
public boolean selectAndExportResults(QTIExportFormatter qef, Long courseResId, String shortTitle, String olatResourceDetail, RepositoryEntry testRe, ZipOutputStream exportStream, Locale locale, String fileNameSuffix) throws IOException {
boolean resultsFoundAndExported = false;
QTIResultManager qrm = QTIResultManager.getInstance();
List<QTIResult> results = qrm.selectResults(courseResId, olatResourceDetail, testRe.getKey(), null, qef.getType());
if (results.size() > 0) {
List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(testRe);
qef.setQTIItemObjectList(qtiItemObjectList);
if (results.size() > 0) {
createContentOfExportFile(results, qtiItemObjectList, qef);
String targetFileName = getFilename(shortTitle, fileNameSuffix);
exportStream.putNextEntry(new ZipEntry(targetFileName));
IOUtils.write(qef.getReport(), exportStream);
exportStream.closeEntry();
resultsFoundAndExported = true;
}
} else {
String targetFileName = getFilename(shortTitle, fileNameSuffix);
exportStream.putNextEntry(new ZipEntry(targetFileName));
Translator translator = Util.createPackageTranslator(QTIExportFormatter.class, locale);
IOUtils.write(translator.translate("archive.noresults.short"), exportStream);
exportStream.closeEntry();
resultsFoundAndExported = true;
}
return resultsFoundAndExported;
}
use of org.olat.ims.qti.QTIResultManager in project OpenOLAT by OpenOLAT.
the class QTIStatisticsResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding(encoding);
} catch (Exception e) {
log.error("", e);
}
CourseNode courseNode = resourceResult.getTestCourseNode();
String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
hres.setHeader("Content-Description", urlEncodedLabel);
try {
// fields separated by
String sep = "\\t";
// fields embedded by
String emb = "\"";
// carriage return
String car = "\\r\\n";
sep = QTIArchiver.convert2CtrlChars(sep);
car = QTIArchiver.convert2CtrlChars(car);
int exportType = 1;
QTIExportFormatter formatter;
if (QTIType.test.equals(resourceResult.getType())) {
exportType = 1;
formatter = new QTIExportFormatterCSVType1(locale, sep, emb, car, true);
} else if (QTIType.survey.equals(resourceResult.getType())) {
exportType = 2;
formatter = new QTIExportFormatterCSVType3(locale, null, sep, emb, car, true);
} else {
return;
}
Long qtiRepoEntryKey = resourceResult.getQTIRepositoryEntry().getKey();
List<QTIItemObject> itemList = new QTIObjectTreeBuilder().getQTIItemObjectList(resourceResult.getResolver());
formatter.setMapWithExportItemConfigs(getQTIItemConfigs(itemList));
QTIResultManager qrm = QTIResultManager.getInstance();
QTIStatisticSearchParams params = resourceResult.getSearchParams();
List<Group> limitToGroups = params.isMayViewAllUsersAssessments() ? null : params.getLimitToGroups();
List<QTIResult> results = qrm.selectResults(resourceResult.getCourseOres().getResourceableId(), courseNode.getIdent(), qtiRepoEntryKey, limitToGroups, exportType);
QTIExportManager.getInstance().exportResults(formatter, results, itemList, hres.getOutputStream());
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.ims.qti.QTIResultManager in project OpenOLAT by OpenOLAT.
the class QTIExportManager method selectAndExportResults.
/**
* @param locale
* @param olatResource
* @param shortTitle
* @param olatResourceDetail
* @param repositoryRef
* @param type
* @param exportDirectory
* @param anonymizerCallback callback that should be used to anonymize the user names or NULL if row counter
* should be used (only for type 2 and 3)
* @return
*/
public boolean selectAndExportResults(QTIExportFormatter qef, Long courseResId, String shortTitle, String olatResourceDetail, Long testReKey, File exportDirectory, String charset, String fileNameSuffix) {
boolean resultsFoundAndExported = false;
QTIResultManager qrm = QTIResultManager.getInstance();
List<QTIResult> results = qrm.selectResults(courseResId, olatResourceDetail, testReKey, null, qef.getType());
if (results.size() > 0) {
QTIResult res0 = results.get(0);
List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(new Long(res0.getResultSet().getRepositoryRef()));
qef.setQTIItemObjectList(qtiItemObjectList);
if (results.size() > 0) {
createContentOfExportFile(results, qtiItemObjectList, qef);
writeContentToFile(shortTitle, exportDirectory, charset, qef, fileNameSuffix);
resultsFoundAndExported = true;
}
}
return resultsFoundAndExported;
}
Aggregations