package isrp.viewbeans;

import isrp.hibernate.model.businessobject.Answer;
import isrp.hibernate.model.businessobject.Question;
import isrp.model.service.QuestionService;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

/**
 * Komponent wsparcia dla wyświetlania szczególów recenzji.
 *
 */
public class ReviewDetailsBean implements Serializable{

	private static final long serialVersionUID = 1L;
	private VisitBean visitBean;
	private List<Question> questions;
	private UtilBean utilBean;
	
	public UtilBean getUtilBean() {
		return utilBean;
	}
	public void setUtilBean(UtilBean utilBean) {
		this.utilBean = utilBean;
	}
	public VisitBean getVisitBean() {
		return visitBean;
	}
	public void setVisitBean(VisitBean visitBean) {
		this.visitBean = visitBean;
	}
	@SuppressWarnings("unchecked")
	public List<Question> getQuestions() {
		if (questions==null){
			//questions asnwers from review
			QuestionService qSer = utilBean.getServiceLocator().getQuestionService();
			questions = qSer.findAll();		
			Answer ans;
			Iterator it;
			it = visitBean.getCurrentReview().getSelectedAnswers().iterator();
			while (it.hasNext()){
				ans = (Answer) it.next();
				for (int i=0;i<questions.size();i++){
					if (questions.get(i).getId()==ans.getQuestionId()){
						questions.get(i).getSelectedAnswersList().add(ans);
					}
				}
			}			
			//questions = new ArrayList<Question>(visitBean.getCurrentReview().getQuestions());
		}
		return questions;
	}
	public void setQuestions(List<Question> questions) {
		this.questions = questions;
	}

	
	
	
	
}
