use of org.olat.fileresource.FileResourceManager in project openolat by klemens.
the class RepositoryEntryResource method replaceFileResource.
private RepositoryEntry replaceFileResource(Identity identity, RepositoryEntry re, File fResource) {
if (re == null)
throw new NullPointerException("RepositoryEntry cannot be null");
FileResourceManager frm = FileResourceManager.getInstance();
File currentResource = frm.getFileResource(re.getOlatResource());
if (currentResource == null || !currentResource.exists()) {
log.debug("Current resource file doesn't exist");
return null;
}
String typeName = re.getOlatResource().getResourceableTypeName();
if (typeName.equals(ImsCPFileResource.TYPE_NAME)) {
if (currentResource.delete()) {
FileUtils.copyFileToFile(fResource, currentResource, false);
String repositoryHome = FolderConfig.getCanonicalRepositoryHome();
String relUnzipDir = frm.getUnzippedDirRel(re.getOlatResource());
File unzipDir = new File(repositoryHome, relUnzipDir);
if (unzipDir != null && unzipDir.exists()) {
FileUtils.deleteDirsAndFiles(unzipDir, true, true);
}
frm.unzipFileResource(re.getOlatResource());
}
log.audit("Resource: " + re.getOlatResource() + " replaced by " + identity.getName());
return re;
}
log.debug("Cannot replace a resource of the type: " + typeName);
return null;
}
use of org.olat.fileresource.FileResourceManager in project openolat by klemens.
the class QTI21ServiceImpl method getDeliveryOptions.
@Override
public QTI21DeliveryOptions getDeliveryOptions(RepositoryEntry testEntry) {
FileResourceManager frm = FileResourceManager.getInstance();
File reFolder = frm.getFileResourceRoot(testEntry.getOlatResource());
File configXml = new File(reFolder, PACKAGE_CONFIG_FILE_NAME);
QTI21DeliveryOptions config;
if (configXml.exists()) {
config = (QTI21DeliveryOptions) configXstream.fromXML(configXml);
} else {
// set default config
config = QTI21DeliveryOptions.defaultSettings();
setDeliveryOptions(testEntry, config);
}
return config;
}
use of org.olat.fileresource.FileResourceManager in project openolat by klemens.
the class QTI21ServiceImpl method needManualCorrection.
@Override
public boolean needManualCorrection(RepositoryEntry testEntry) {
FileResourceManager frm = FileResourceManager.getInstance();
File fUnzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
ResolvedAssessmentTest resolvedAssessmentTest = loadAndResolveAssessmentTest(fUnzippedDirRoot, false, false);
return AssessmentTestHelper.needManualCorrection(resolvedAssessmentTest);
}
use of org.olat.fileresource.FileResourceManager in project openolat by klemens.
the class QTI21ServiceImpl method setDeliveryOptions.
@Override
public void setDeliveryOptions(RepositoryEntry testEntry, QTI21DeliveryOptions options) {
FileResourceManager frm = FileResourceManager.getInstance();
File reFolder = frm.getFileResourceRoot(testEntry.getOlatResource());
File configXml = new File(reFolder, PACKAGE_CONFIG_FILE_NAME);
if (options == null) {
if (configXml.exists()) {
configXml.delete();
}
} else {
try (OutputStream out = new FileOutputStream(configXml)) {
configXstream.toXML(options, out);
} catch (IOException e) {
log.error("", e);
}
}
}
use of org.olat.fileresource.FileResourceManager in project openolat by klemens.
the class QTI21ArchiveFormat method exportCourseElement.
public MediaResource exportCourseElement() {
FileResourceManager frm = FileResourceManager.getInstance();
File unzippedDirRoot = frm.unzipFileResource(searchParams.getTestEntry().getOlatResource());
resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
ICourse course = CourseFactory.loadCourse(searchParams.getCourseEntry());
courseNode = course.getRunStructure().getNode(searchParams.getNodeIdent());
String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".xlsx";
if ("iqself".equals(courseNode.getType())) {
anonymizerCallback = course.getCourseEnvironment().getCoursePropertyManager();
}
// content
final List<AssessmentTestSession> sessions = testSessionDao.getTestSessionsOfResponse(searchParams);
final List<AssessmentResponse> responses = responseDao.getResponse(searchParams);
return new OpenXMLWorkbookResource(label) {
@Override
protected void generate(OutputStream out) {
try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
// headers
OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
exportSheet.setHeaderRows(2);
writeHeaders_1(exportSheet, workbook);
writeHeaders_2(exportSheet, workbook);
writeData(sessions, responses, exportSheet, workbook);
} catch (Exception e) {
log.error("", e);
}
}
};
}
Aggregations