use of org.olat.ims.qti.editor.beecom.objects.FIBResponse in project openolat by klemens.
the class FIBItemController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Component source, Event event) {
if (source == main) {
// olat::: as: improve easy fix since almost all operations change the main vc.
main.setDirty(true);
String cmd = event.getCommand();
String sPosid = ureq.getParameter("posid");
int posid = 0;
if (sPosid != null)
posid = Integer.parseInt(sPosid);
if (cmd.equals("up")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid > 0 && posid < item.getQuestion().getResponses().size()) {
Response obj = elements.remove(posid);
elements.add(posid - 1, obj);
} else {
logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
}
} else if (cmd.equals("down")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid >= 0 && posid < elements.size() - 1) {
Response obj = elements.remove(posid);
elements.add(posid + 1, obj);
} else {
logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
}
} else if (cmd.equals("editq")) {
editQuestion = item.getQuestion().getQuestion();
displayMaterialFormController(ureq, editQuestion, restrictedEdit);
} else if (cmd.equals("editr")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid >= 0 && posid < elements.size()) {
editResponse = elements.get(posid);
Material responseMat = elements.get(posid).getContent();
displayMaterialFormController(ureq, responseMat, restrictedEdit);
} else {
logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
}
} else if (cmd.equals("addtext")) {
FIBQuestion fib = (FIBQuestion) item.getQuestion();
FIBResponse response = new FIBResponse();
response.setType(FIBResponse.TYPE_CONTENT);
Material mat = new Material();
mat.add(new Mattext(translate("newtextelement")));
response.setContent(mat);
fib.getResponses().add(response);
} else if (cmd.equals("addblank")) {
FIBQuestion fib = (FIBQuestion) item.getQuestion();
FIBResponse response = new FIBResponse();
response.setType(FIBResponse.TYPE_BLANK);
response.setCorrectBlank("");
// default value
response.setPoints(1f);
fib.getResponses().add(response);
} else if (cmd.equals("del")) {
delYesNoCtrl = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), null, translate("confirm.delete.element"));
listenTo(delYesNoCtrl);
delYesNoCtrl.setUserObject(new Integer(posid));
delYesNoCtrl.activate();
} else if (cmd.equals("sfib")) {
// submit fib
FIBQuestion question = (FIBQuestion) item.getQuestion();
// Survey specific variables
if (surveyMode) {
List<Response> responses = question.getResponses();
for (int i = 0; i < responses.size(); i++) {
FIBResponse response = (FIBResponse) responses.get(i);
if (FIBResponse.TYPE_BLANK.equals(response.getType())) {
// Set size of input field
String size = ureq.getParameter("size_q" + i);
if (size != null)
response.setSizeFromString(size);
String maxLength = ureq.getParameter("maxl_q" + i);
if (maxLength != null)
response.setMaxLengthFromString(maxLength);
}
}
} else {
// set min/max values before single_correct !!
if (!restrictedEdit) {
// only in full edit mode the following fields are available:
// min_value, max_value, valuation_method
question.setMinValue(ureq.getParameter("min_value"));
question.setMaxValue(ureq.getParameter("max_value"));
question.setSingleCorrect("single".equals(ureq.getParameter("valuation_method")));
if (question.isSingleCorrect()) {
question.setSingleCorrectScore(ureq.getParameter("single_score"));
} else {
question.setSingleCorrectScore(0.0f);
}
}
NodeBeforeChangeEvent nce = new NodeBeforeChangeEvent();
nce.setItemIdent(item.getIdent());
List<Response> responses = question.getResponses();
for (int i = 0; i < responses.size(); i++) {
FIBResponse response = (FIBResponse) responses.get(i);
nce.setResponseIdent(response.getIdent());
fireEvent(ureq, nce);
response.setPoints(ureq.getParameter("points_q" + i));
if (FIBResponse.TYPE_BLANK.equals(response.getType())) {
response.setCorrectBlank(ureq.getParameter("content_q" + i));
// Set case sensitiveness
String caseSensitive = ureq.getParameter("case_q" + i);
if (caseSensitive == null)
caseSensitive = "No";
response.setCaseSensitive(caseSensitive);
// Set size of input field
String size = ureq.getParameter("size_q" + i);
if (size != null)
response.setSizeFromString(size);
String maxLength = ureq.getParameter("maxl_q" + i);
if (maxLength != null)
response.setMaxLengthFromString(maxLength);
// find longest correct blank in all synonyms of
// correct answers, fix max lenght if a longer value
// is found
String[] allCorrect = response.getCorrectBlank().split(";");
int longestCorrect = 0;
for (int j = 0; j < allCorrect.length; j++) {
String singleCorrect = allCorrect[j];
if (singleCorrect.length() > longestCorrect) {
longestCorrect = singleCorrect.length();
}
}
if (longestCorrect > response.getMaxLength())
response.setMaxLength(longestCorrect);
}
}
}
}
qtiPackage.serializeQTIDocument();
}
}
use of org.olat.ims.qti.editor.beecom.objects.FIBResponse in project openolat by klemens.
the class ItemNode method createMemento.
public Memento createMemento() {
Question question = item.getQuestion();
// special case switches as question types are encoded into integers!!
boolean isFIB = question.getType() == Question.TYPE_FIB;
boolean isESSAY = question.getType() == Question.TYPE_ESSAY;
// Item metadata
QtiNodeMemento qnm = new QtiNodeMemento();
Map<String, Object> qtiState = new HashMap<>();
qtiState.put("ID", item.getIdent());
qtiState.put("TITLE", item.getTitle());
qtiState.put("OBJECTIVES", item.getObjectives());
// question and responses
qtiState.put("QUESTION.ID", question.getIdent());
qtiState.put("QUESTION.HINTTEXT", question.getHintText());
Material questMaterial = question.getQuestion();
qtiState.put("QUESTION.MATERIAL.ASTEXT", questMaterial.renderAsText());
List<String> ids = new ArrayList<String>();
List<String> asTexts = new ArrayList<String>();
List<String> feedbacks = new ArrayList<String>();
List<Response> responses = question.getResponses();
for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
Response resp = iter.next();
if (isFIB) {
if (FIBResponse.TYPE_BLANK.equals(((FIBResponse) resp).getType())) {
asTexts.add(formatFIBResponseAsText((FIBResponse) resp));
ids.add(resp.getIdent());
feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
}
} else if (isESSAY) {
asTexts.add(formatESSAYResponseAsText((EssayResponse) resp));
ids.add(resp.getIdent());
feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
} else {
// not a FIB or ESSAY response
asTexts.add(resp.getContent().renderAsText());
ids.add(resp.getIdent());
feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
}
}
qtiState.put("QUESTION.RESPONSES.IDS", ids);
qtiState.put("QUESTION.RESPONSES.ASTEXT", asTexts);
qtiState.put("QUESTION.RESPONSES.FEEDBACK", feedbacks);
// feedback
qtiState.put("FEEDBACK.MASTERY", QTIEditHelper.getFeedbackMasteryText(item));
qtiState.put("FEEDBACK.FAIL", QTIEditHelper.getFeedbackFailText(item));
Control control = QTIEditHelper.getControl(item);
qtiState.put("FEEDBACK.ENABLED", control.getFeedback() == 1 ? Boolean.TRUE : Boolean.FALSE);
//
qnm.setQtiState(qtiState);
//
return qnm;
}
use of org.olat.ims.qti.editor.beecom.objects.FIBResponse in project openolat by klemens.
the class ItemNode method createChangeMessage.
public String createChangeMessage(Memento mem) {
String retVal = null;
if (mem instanceof QtiNodeMemento) {
QtiNodeMemento qnm = (QtiNodeMemento) mem;
Map<String, Object> qtiState = qnm.getQtiState();
//
String oldTitle = (String) qtiState.get("TITLE");
String newTitle = item.getTitle();
String titleChange = null;
//
String oldObjectives = (String) qtiState.get("OBJECTIVES");
String newObjectives = item.getObjectives();
String objectChange = null;
//
Question question = item.getQuestion();
boolean isFIB = question.getType() == Question.TYPE_FIB;
boolean isESSAY = question.getType() == Question.TYPE_ESSAY;
String oldHinttext = (String) qtiState.get("QUESTION.HINTTEXT");
String newHinttext = question.getHintText();
String hinttextChange = null;
//
String oldQuestion = (String) qtiState.get("QUESTION.MATERIAL.ASTEXT");
String newQuestion = question.getQuestion().renderAsText();
String questionChange = null;
// feedback
String feedbackChanges = "";
String oldFeedbackMastery = (String) qtiState.get("FEEDBACK.MASTERY");
String newFeedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
String oldFeedbackFail = (String) qtiState.get("FEEDBACK.FAIL");
String newFeedbackFail = QTIEditHelper.getFeedbackFailText(item);
Control control = QTIEditHelper.getControl(item);
Boolean oldHasFeedback = (Boolean) qtiState.get("FEEDBACK.ENABLED");
Boolean newHasFeedback = control != null ? new Boolean(control.getFeedback() == 1) : null;
//
List asTexts = (List) qtiState.get("QUESTION.RESPONSES.ASTEXT");
List feedbacks = (List) qtiState.get("QUESTION.RESPONSES.FEEDBACK");
String oldResp = null;
String newResp = null;
String oldFeedback = null;
String newFeedback = null;
String responsesChanges = "";
List<Response> responses = question.getResponses();
int i = 0;
boolean nothingToDo = false;
for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
nothingToDo = false;
Response resp = iter.next();
if (isFIB) {
if (FIBResponse.TYPE_BLANK.equals(((FIBResponse) resp).getType())) {
newResp = formatFIBResponseAsText((FIBResponse) resp);
} else {
// skip
nothingToDo = true;
}
} else if (isESSAY) {
newResp = formatESSAYResponseAsText((EssayResponse) resp);
} else {
newResp = resp.getContent().renderAsText();
}
// if NOT nothingToDO
if (!nothingToDo) {
oldResp = (String) asTexts.get(i);
if ((oldResp != null && !oldResp.equals(newResp)) || (newResp != null && !newResp.equals(oldResp))) {
if (isFIB) {
responsesChanges += "\nBlank changed:";
responsesChanges += "\nold blank: \n\t" + formatVariable(oldResp) + "\n\nnew blank: \n\t" + formatVariable(newResp);
} else {
responsesChanges += "\nResponse changed:";
responsesChanges += "\nold response: \n\t" + formatVariable(oldResp) + "\n\nnew response: \n\t" + formatVariable(newResp);
}
}
// feedback to response changed?
newFeedback = QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent());
oldFeedback = (String) feedbacks.get(i);
if ((oldFeedback != null && !oldFeedback.equals(newFeedback)) || (newFeedback != null && !newFeedback.equals(oldFeedback))) {
feedbackChanges += "\nFeedback changed:";
feedbackChanges += "\nold feedback: \n\t" + formatVariable(oldFeedback) + "\n\nnew feedback: \n\t" + formatVariable(newFeedback);
}
i++;
}
}
//
retVal = "\n---+++ Item changes [" + oldTitle + "]:";
if ((oldTitle != null && !oldTitle.equals(newTitle)) || (newTitle != null && !newTitle.equals(oldTitle))) {
titleChange = "\n\nold title: \n\t" + formatVariable(oldTitle) + "\n\nnew title: \n\t" + formatVariable(newTitle);
}
if ((oldObjectives != null && !oldObjectives.equals(newObjectives)) || (newObjectives != null && !newObjectives.equals(oldObjectives))) {
objectChange = "\n\nold objectives: \n\t" + formatVariable(oldObjectives) + "\n\nnew objectives: \n\t" + formatVariable(newObjectives);
}
if (titleChange != null || objectChange != null) {
retVal += "\nMetadata changed:";
if (titleChange != null)
retVal += titleChange;
if (objectChange != null)
retVal += objectChange;
}
//
if ((oldHinttext != null && !oldHinttext.equals(newHinttext)) || (newHinttext != null && !newHinttext.equals(oldHinttext))) {
hinttextChange = "\n---+++ old hinttext: \n\t" + formatVariable(oldHinttext) + "\n\nnew hinttext: \n\t" + formatVariable(newHinttext);
retVal += hinttextChange;
}
if ((oldQuestion != null && !oldQuestion.equals(newQuestion)) || (newQuestion != null && !newQuestion.equals(oldQuestion))) {
questionChange = "\n---+++ old question: \n\t" + formatVariable(oldQuestion) + "\n\nnew question: \n\t" + formatVariable(newQuestion);
retVal += questionChange;
}
if (!responsesChanges.equals("")) {
retVal += responsesChanges;
}
if ((oldFeedbackMastery != null && !oldFeedbackMastery.equals(newFeedbackMastery)) || (newFeedbackMastery != null && !newFeedbackMastery.equals(oldFeedbackMastery))) {
String tmp = "\n---+++ old master feedback: \n\t" + formatVariable(oldFeedbackMastery) + "\n\nnew master feedback: \n\t" + formatVariable(newFeedbackMastery);
feedbackChanges = tmp + feedbackChanges;
}
if ((oldFeedbackFail != null && !oldFeedbackFail.equals(newFeedbackFail)) || (newFeedbackFail != null && !newFeedbackFail.equals(oldFeedbackFail))) {
String tmp = "\n---+++ old fail feedback: \n\t" + formatVariable(oldFeedbackFail) + "\n\nnew fail feedback: \n\t" + formatVariable(newFeedbackFail);
feedbackChanges = tmp + feedbackChanges;
}
if ((oldHasFeedback != null && newHasFeedback != null && oldHasFeedback != newHasFeedback)) {
String oldF = oldHasFeedback.booleanValue() ? "enabled" : "disabled";
String newF = newHasFeedback.booleanValue() ? "enabled" : "disabled";
feedbackChanges = "\n---+++ feedback was : \n\t" + oldF + "\n\n feedback is now: \n\t" + newF + feedbackChanges;
}
if (!feedbackChanges.equals("")) {
retVal += feedbackChanges;
}
return retVal;
}
return "undefined";
}
use of org.olat.ims.qti.editor.beecom.objects.FIBResponse in project OpenOLAT by OpenOLAT.
the class CSVToQuestionConverterTest method importFillInBlanck_en_metadata.
@Test
public void importFillInBlanck_en_metadata() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_fib_en_metadata.txt");
Assert.assertNotNull(importTxtUrl);
File importTxt = new File(importTxtUrl.toURI());
String input = FileUtils.readFileToString(importTxt, "UTF-8");
Translator translator = new KeyTranslator(Locale.ENGLISH);
ImportOptions options = new ImportOptions();
options.setShuffle(true);
CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
converter.parse(input);
List<ItemAndMetadata> items = converter.getItems();
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
ItemAndMetadata importedItem = items.get(0);
Item item = importedItem.getItem();
Assert.assertNotNull(item);
Assert.assertEquals(Question.TYPE_FIB, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof FIBQuestion);
FIBQuestion question = (FIBQuestion) item.getQuestion();
List<Response> responses = question.getResponses();
Assert.assertNotNull(responses);
Assert.assertEquals(2, responses.size());
// check java type
for (Response response : responses) {
Assert.assertTrue(response instanceof FIBResponse);
}
// check type
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(0)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(1)).getType());
// check size
Assert.assertEquals(20, ((FIBResponse) responses.get(1)).getSize());
// check max length
Assert.assertEquals(50, ((FIBResponse) responses.get(1)).getMaxLength());
}
use of org.olat.ims.qti.editor.beecom.objects.FIBResponse in project OpenOLAT by OpenOLAT.
the class CSVToQuestionConverterTest method importFillInBlanck.
@Test
public void importFillInBlanck() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_fib.txt");
Assert.assertNotNull(importTxtUrl);
File importTxt = new File(importTxtUrl.toURI());
String input = FileUtils.readFileToString(importTxt, "UTF-8");
Translator translator = new KeyTranslator(Locale.ENGLISH);
ImportOptions options = new ImportOptions();
options.setShuffle(true);
CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
converter.parse(input);
List<ItemAndMetadata> items = converter.getItems();
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
ItemAndMetadata importedItem = items.get(0);
Item item = importedItem.getItem();
Assert.assertNotNull(item);
Assert.assertEquals(Question.TYPE_FIB, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof FIBQuestion);
FIBQuestion question = (FIBQuestion) item.getQuestion();
List<Response> responses = question.getResponses();
Assert.assertNotNull(responses);
Assert.assertEquals(7, responses.size());
// check java type
for (Response response : responses) {
Assert.assertTrue(response instanceof FIBResponse);
}
// check type
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(0)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(1)).getType());
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(2)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(3)).getType());
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(4)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(5)).getType());
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(6)).getType());
// check size
Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getSize());
Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getSize());
Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getSize());
// check max length
Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getMaxLength());
Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getMaxLength());
Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getMaxLength());
}
Aggregations