use of org.olat.ims.qti.editor.QTIEditorPackage in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_11_0_0 method checkEssay.
private boolean checkEssay(RepositoryEntry testEntry) {
if (qtiEssayMap.containsKey(testEntry.getKey())) {
return qtiEssayMap.get(testEntry.getKey()).booleanValue();
}
TestFileResource fr = new TestFileResource();
fr.overrideResourceableId(testEntry.getOlatResource().getResourceableId());
TransientIdentity pseudoIdentity = new TransientIdentity();
pseudoIdentity.setName("transient");
Translator translator = Util.createPackageTranslator(QTIModule.class, Locale.ENGLISH);
try {
QTIEditorPackage qtiPackage = new QTIEditorPackageImpl(pseudoIdentity, fr, null, translator);
if (qtiPackage.getQTIDocument() != null && qtiPackage.getQTIDocument().getAssessment() != null) {
Assessment ass = qtiPackage.getQTIDocument().getAssessment();
// Sections with their Items
List<Section> sections = ass.getSections();
for (Section section : sections) {
List<Item> items = section.getItems();
for (Item item : items) {
String ident = item.getIdent();
if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
qtiEssayMap.put(testEntry.getKey(), Boolean.TRUE);
return true;
}
}
}
}
} catch (OLATRuntimeException e) {
log.warn("QTI without content in repository entry: " + testEntry.getKey(), e);
}
qtiEssayMap.put(testEntry.getKey(), Boolean.FALSE);
return false;
}
use of org.olat.ims.qti.editor.QTIEditorPackage 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.ims.qti.editor.QTIEditorPackage 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;
}
use of org.olat.ims.qti.editor.QTIEditorPackage in project openolat by klemens.
the class OLATUpgrade_11_0_0 method checkEssay.
private boolean checkEssay(RepositoryEntry testEntry) {
if (qtiEssayMap.containsKey(testEntry.getKey())) {
return qtiEssayMap.get(testEntry.getKey()).booleanValue();
}
TestFileResource fr = new TestFileResource();
fr.overrideResourceableId(testEntry.getOlatResource().getResourceableId());
TransientIdentity pseudoIdentity = new TransientIdentity();
pseudoIdentity.setName("transient");
Translator translator = Util.createPackageTranslator(QTIModule.class, Locale.ENGLISH);
try {
QTIEditorPackage qtiPackage = new QTIEditorPackageImpl(pseudoIdentity, fr, null, translator);
if (qtiPackage.getQTIDocument() != null && qtiPackage.getQTIDocument().getAssessment() != null) {
Assessment ass = qtiPackage.getQTIDocument().getAssessment();
// Sections with their Items
List<Section> sections = ass.getSections();
for (Section section : sections) {
List<Item> items = section.getItems();
for (Item item : items) {
String ident = item.getIdent();
if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
qtiEssayMap.put(testEntry.getKey(), Boolean.TRUE);
return true;
}
}
}
}
} catch (OLATRuntimeException e) {
log.warn("QTI without content in repository entry: " + testEntry.getKey(), e);
}
qtiEssayMap.put(testEntry.getKey(), Boolean.FALSE);
return false;
}
Aggregations