request.setAttribute("addition", "&forDocuments");
}
buildingObjectManager.savePreparedDocumentationQuestions(new Integer(objectId));
BuildingObject buildingObject =
buildingObjectManager.getBuildingObjectForList(new Integer(objectId));
//checking if the objectanswer list is not empty. Otherwise filling it by the documenttation questions containig in the base
// if (buildingObject.getDocumentationQuestions().size() == 0) {
// //filling the list from the database
// List objectAnswerList = buildingObjectManager.getDocumentationQuestions();
// for (int i = 0; i < objectAnswerList.size(); i++) {
// Question question = (Question) objectAnswerList.get(i);
// question = questionManager.getQuestion(question.getQuestionId().toString());
// ObjectAnswer objectAnswer = new ObjectAnswer();
// objectAnswer.setObjectConstruction(null);
// objectAnswer.setQuestion(question);
// if (!question.isFewAnswers()) {
// Answer answer = new Answer();
// answer.setAnswerId(new Integer(-1));
// objectAnswer.getAnswers().add(answer);
// } else {
// for (int j = 0; j < question.getAnswers().size(); j++) {
// Answer answer = new Answer();
// answer.setAnswerId(new Integer(-1));
// objectAnswer.getAnswers().add(answer);
// }
// }
// objectAnswer.setObjectConstruction(null);
// objectAnswer.setBuildingObject(buildingObject);
// buildingObject.getDocumentationQuestions().add(objectAnswer);
// }
// buildingObjectManager.saveBuildingObject(buildingObject);
// }
int num = 0;
String questionId = request.getParameter("questionId");
Integer currentQuestionId = null;
if (questionId != null && !questionId.equals("null")) {
//trying to retrieve the current answer from url
currentQuestionId = new Integer(questionId);
}
//getting the number of question in the list with the current ID to be asked the first in the current list
int currentPosition = 0;
if (currentQuestionId != null) {
for (int i = 0; i < buildingObject.getDocumentationQuestions().size(); i++) {
ObjectAnswer o = (ObjectAnswer) buildingObject.getDocumentationQuestions().get(i);
if (o.getQuestion().getQuestionId().equals(currentQuestionId)) {
currentPosition = i;
break;
}
}
}
//putting all current questions to the list
for (int i = currentPosition; i < buildingObject.getDocumentationQuestions().size(); i++) {
ObjectAnswer o = (ObjectAnswer) buildingObject.getDocumentationQuestions().get(i);
if ((!o.getQuestion().isForObjectStructure() && forDocuments) || (o.getQuestion().isForObjectStructure() && !forDocuments)) {
//getting the hint for the question if it exists
o.setHasHint(questionManager.hasHint(o.getQuestion().getQuestionId().toString()));
buildingObject.getCurrentDocumentationQuestions().add(o);
num++;
if (num == buildingObject.getQuestionNumber()) {
break;
}
}
}
//getting previous and next questions
List currentAnswerList = buildingObject.getCurrentDocumentationQuestions();
Integer lastQuestionId = null;
Integer firstQuestionId = null;
if (currentAnswerList.size() != 0) {
lastQuestionId = ((ObjectAnswer) currentAnswerList.get(currentAnswerList.size() - 1)).getQuestion().getQuestionId();
firstQuestionId = ((ObjectAnswer) currentAnswerList.get(0)).getQuestion().getQuestionId();
}
if (lastQuestionId != null) {
ObjectAnswer nextObjectAnswer = (buildingObjectManager.getNextQestion(buildingObject.getObjectId(), lastQuestionId, !forDocuments));
if (nextObjectAnswer != null) {
request.setAttribute("nextId", nextObjectAnswer.getQuestion().getQuestionId());
buildingObject.setNextId(nextObjectAnswer.getQuestion().getQuestionId());
}
}
if (firstQuestionId != null) {
ObjectAnswer prevObjectAnswer = (buildingObjectManager.getPrevQestion(buildingObject.getObjectId(), firstQuestionId, !forDocuments));
if (prevObjectAnswer != null) {
request.setAttribute("prevId", prevObjectAnswer.getQuestion().getQuestionId());
buildingObject.setPrevId(prevObjectAnswer.getQuestion().getQuestionId());
}
}
if (buildingObject.getDocumentationQuestions().size() == 0) {
request.setAttribute("noQuestions", "true");
}
if (currentQuestionId == null || currentQuestionId.equals(new Integer(0))) {
request.setAttribute("theFirst", "true");
}
buildingObject.setNoValidation(false);
// buildingObjectManager.evict(buildingObject);
return buildingObject;
}
return super.formBackingObject(request);
}