use of org.olat.fileresource.types.ImsQTI21Resource in project OpenOLAT by OpenOLAT.
the class QTI21AssessmentTestHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
ImsQTI21Resource ores = new ImsQTI21Resource();
OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(ores);
File fResourceFileroot = FileResourceManager.getInstance().getFileResourceRoot(resource);
File zipDir = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
copyResource(file, filename, zipDir);
File optionsFile = new File(zipDir, QTI21Service.PACKAGE_CONFIG_FILE_NAME);
if (optionsFile.exists()) {
try {
// move the options to the root directory
File target = new File(fResourceFileroot, QTI21Service.PACKAGE_CONFIG_FILE_NAME);
Files.move(optionsFile.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
log.error("", e);
}
}
RepositoryEntry re = CoreSpringFactory.getImpl(RepositoryService.class).create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
DBFactory.getInstance().commit();
return re;
}
use of org.olat.fileresource.types.ImsQTI21Resource in project OpenOLAT by OpenOLAT.
the class QTI21AssessmentTestHandler method createResource.
@Override
public RepositoryEntry createResource(Identity initialAuthor, String displayname, String description, Object createObject, Locale locale) {
ImsQTI21Resource ores = new ImsQTI21Resource();
OLATResource resource = OLATResourceManager.getInstance().findOrPersistResourceable(ores);
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
dbInstance.commit();
File repositoryDir = new File(FileResourceManager.getInstance().getFileResourceRoot(re.getOlatResource()), FileResourceManager.ZIPDIR);
if (!repositoryDir.exists()) {
repositoryDir.mkdirs();
}
if (createObject instanceof QItemList) {
QItemList itemToImport = (QItemList) createObject;
qpoolServiceProvider.exportToEditorPackage(repositoryDir, itemToImport.getItems(), locale);
} else if (createObject instanceof QTIEditorPackage) {
QTIEditorPackage testToConvert = (QTIEditorPackage) createObject;
QTI21DeliveryOptions options = qtiService.getDeliveryOptions(re);
qpoolServiceProvider.convertFromEditorPackage(testToConvert, repositoryDir, locale, options);
qtiService.setDeliveryOptions(re, options);
} else if (createObject instanceof OLATResource) {
// convert a Onyx test in QTI 2.1
OLATResource onyxResource = (OLATResource) createObject;
RepositoryEntry onyxRe = CoreSpringFactory.getImpl(RepositoryService.class).loadByResourceKey(onyxResource.getKey());
if (OnyxModule.isOnyxTest((OLATResource) createObject)) {
copyOnyxResources(onyxResource, repositoryDir);
} else {
QTI21DeliveryOptions options = qtiService.getDeliveryOptions(re);
QTIEditorPackage testToConvert = TestFileResource.getQTIEditorPackageReader(onyxResource);
qpoolServiceProvider.convertFromEditorPackage(testToConvert, repositoryDir, locale, options);
qtiService.setDeliveryOptions(re, options);
}
copyMetadata(onyxRe, re, repositoryDir);
} else {
createMinimalAssessmentTest(displayname, repositoryDir, locale);
}
return re;
}
use of org.olat.fileresource.types.ImsQTI21Resource in project openolat by klemens.
the class QTI21AssessmentTestHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
ImsQTI21Resource ores = new ImsQTI21Resource();
OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(ores);
File fResourceFileroot = FileResourceManager.getInstance().getFileResourceRoot(resource);
File zipDir = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
copyResource(file, filename, zipDir);
File optionsFile = new File(zipDir, QTI21Service.PACKAGE_CONFIG_FILE_NAME);
if (optionsFile.exists()) {
try {
// move the options to the root directory
File target = new File(fResourceFileroot, QTI21Service.PACKAGE_CONFIG_FILE_NAME);
Files.move(optionsFile.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
log.error("", e);
}
}
RepositoryEntry re = CoreSpringFactory.getImpl(RepositoryService.class).create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
DBFactory.getInstance().commit();
return re;
}
use of org.olat.fileresource.types.ImsQTI21Resource in project openolat by klemens.
the class QTI21AssessmentTestHandler method createResource.
@Override
public RepositoryEntry createResource(Identity initialAuthor, String displayname, String description, Object createObject, Locale locale) {
ImsQTI21Resource ores = new ImsQTI21Resource();
OLATResource resource = OLATResourceManager.getInstance().findOrPersistResourceable(ores);
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
dbInstance.commit();
File repositoryDir = new File(FileResourceManager.getInstance().getFileResourceRoot(re.getOlatResource()), FileResourceManager.ZIPDIR);
if (!repositoryDir.exists()) {
repositoryDir.mkdirs();
}
if (createObject instanceof QItemList) {
QItemList itemToImport = (QItemList) createObject;
qpoolServiceProvider.exportToEditorPackage(repositoryDir, itemToImport.getItems(), locale);
} else if (createObject instanceof QTIEditorPackage) {
QTIEditorPackage testToConvert = (QTIEditorPackage) createObject;
QTI21DeliveryOptions options = qtiService.getDeliveryOptions(re);
qpoolServiceProvider.convertFromEditorPackage(testToConvert, repositoryDir, locale, options);
qtiService.setDeliveryOptions(re, options);
} else if (createObject instanceof OLATResource) {
// convert a Onyx test in QTI 2.1
OLATResource onyxResource = (OLATResource) createObject;
RepositoryEntry onyxRe = CoreSpringFactory.getImpl(RepositoryService.class).loadByResourceKey(onyxResource.getKey());
if (OnyxModule.isOnyxTest((OLATResource) createObject)) {
copyOnyxResources(onyxResource, repositoryDir);
} else {
QTI21DeliveryOptions options = qtiService.getDeliveryOptions(re);
QTIEditorPackage testToConvert = TestFileResource.getQTIEditorPackageReader(onyxResource);
qpoolServiceProvider.convertFromEditorPackage(testToConvert, repositoryDir, locale, options);
qtiService.setDeliveryOptions(re, options);
}
copyMetadata(onyxRe, re, repositoryDir);
} else {
createMinimalAssessmentTest(displayname, repositoryDir, locale);
}
return re;
}
Aggregations