gt: 					quizzesMap.put(quizId, quizStringList.get(x + 1));
context: /**
   * File ./src/main/java/de/lemo/apps/pages/viz/PerformanceCumulative.java
   * Lemo-Application-Server for learning analytics.
   * Copyright (C) 2015
   * Leonard Kappe, Andreas Pursian, Sebastian Schwarzrock, Boris Wenzlaff
   * 
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * any later version.
   * 
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  **/
  
  package de.lemo.apps.pages.viz;
  
  import java.io.IOException;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  
  import org.apache.shiro.authz.annotation.RequiresAuthentication;
  import org.apache.tapestry5.PersistenceConstants;
  import org.apache.tapestry5.SelectModel;
  import org.apache.tapestry5.ValueEncoder;
  import org.apache.tapestry5.annotations.AfterRender;
  import org.apache.tapestry5.annotations.Component;
  import org.apache.tapestry5.annotations.Environmental;
  import org.apache.tapestry5.annotations.Import;
  import org.apache.tapestry5.annotations.InjectComponent;
  import org.apache.tapestry5.annotations.Persist;
  import org.apache.tapestry5.annotations.Property;
  import org.apache.tapestry5.corelib.components.DateField;
  import org.apache.tapestry5.corelib.components.Form;
  import org.apache.tapestry5.corelib.components.Zone;
  import org.apache.tapestry5.ioc.Messages;
  import org.apache.tapestry5.ioc.annotations.Inject;
  import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
  import org.apache.tapestry5.ioc.services.TypeCoercer;
  import org.apache.tapestry5.json.JSONArray;
  import org.apache.tapestry5.json.JSONLiteral;
  import org.apache.tapestry5.services.SelectModelFactory;
  import org.apache.tapestry5.services.javascript.JavaScriptSupport;
  import org.apache.tapestry5.util.EnumSelectModel;
  import org.apache.tapestry5.util.EnumValueEncoder;
  import org.codehaus.jackson.JsonNode;
  import org.codehaus.jackson.JsonProcessingException;
  import org.codehaus.jackson.map.ObjectMapper;
  import org.codehaus.jackson.type.TypeReference;
  import org.slf4j.Logger;
  
  import se.unbound.tapestry.breadcrumbs.BreadCrumb;
  import se.unbound.tapestry.breadcrumbs.BreadCrumbInfo;
  import de.lemo.apps.application.AnalysisWorker;
  import de.lemo.apps.application.DateWorker;
  import de.lemo.apps.application.UserWorker;
  import de.lemo.apps.application.VisualisationHelperWorker;
  import de.lemo.apps.application.config.ServerConfiguration;
  import de.lemo.apps.entities.Course;
  import de.lemo.apps.entities.GenderEnum;
  import de.lemo.apps.entities.LearningType;
  import de.lemo.apps.entities.Quiz;
  import de.lemo.apps.exceptions.RestServiceCommunicationException;
  import de.lemo.apps.integration.CourseDAO;
  import de.lemo.apps.pages.data.Explorer;
  import de.lemo.apps.restws.client.Analysis;
  import de.lemo.apps.restws.client.Initialisation;
  import de.lemo.apps.restws.entities.BoxPlot;
  import de.lemo.apps.restws.entities.ResultListStringObject;
  import de.lemo.apps.services.internal.CourseIdSelectModel;
  import de.lemo.apps.services.internal.CourseIdValueEncoder;
  import de.lemo.apps.services.internal.LearningTypeValueEncoder;
  import de.lemo.apps.services.internal.LongValueEncoder;
  import de.lemo.apps.services.internal.QuizValueEncoder;
  
  /**
   * Visualisation for the cumulative performance
   */
  @RequiresAuthentication
  @BreadCrumb(titleKey = "visPerformanceCumulative")
  @Import(library = { "../../js/d3/BoxPlot.js",
  		"../../js/d3/libs/d3.v2.js"
  })
  public class PerformanceCumulative {
  
  	private static final int THOU = 1000;
  	
  	@Environmental
  	private JavaScriptSupport javaScriptSupport;
  
  	@Inject
  	private Logger logger;
  
  	@Inject
  	private DateWorker dateWorker;
  
  	@Inject
  	private AnalysisWorker analysisWorker;
  	
  	@Inject
  	private VisualisationHelperWorker visWorker;
  
  	@Inject
  	private Initialisation init;
  
  	@Inject
  	private CourseIdValueEncoder courseValueEncoder;
  
  	@Inject
  	private Analysis analysis;
  
  	@Inject
  	private UserWorker userWorker;
  
  	@Inject
  	private CourseDAO courseDAO;
  
  	@Inject
  	private Locale currentlocale;
  
  	@Inject
  	private Messages messages;
  
  	@Inject
  	private TypeCoercer coercer;
  
  	@Property
  	private BreadCrumbInfo breadCrumb;
  
  	@InjectComponent
  	private Zone formZone;
  
  	@Component(id = "customizeForm")
  	private Form customizeForm;
  
  	@Property
  	@SuppressWarnings("unused")
  	private SelectModel courseModel;
  
  	@Property
  	@Persist
  	private Course course;
  
  	@Property
  	@Persist
  	private Long courseId;
  
  	@Component(id = "beginDate")
  	private DateField beginDateField;
  
  	@Component(id = "endDate")
  	private DateField endDateField;
  
  	@Persist
  	@Property
  	private Date beginDate;
  
  	@Persist
  	@Property
  	private Date endDate;
  	
  	@Persist
  	private Map<Long, Date> beginMem;
  
  	@Persist
  	private Map<Long, Date> endMem;
  
  	@Property
  	@Persist
  	Integer resolution;
  
  	@Property
  	@Persist
  	private List<Course> courses;
  
  	@Inject
  	@Property
  	private LearningTypeValueEncoder learningTypeEncoder;
  	
  	@Property
  	@Persist
  	private List<LearningType> selectedLearningTypes;
  	
  	@Property
  	private SelectModel learningTypeSelectModel;
  	// Value Encoder for gender multi-select component
  	@Property(write = false)
  	private final ValueEncoder<GenderEnum> genderEncoder = new EnumValueEncoder<GenderEnum>(this.coercer,
  					GenderEnum.class);
  		
  	// Select Model for gender multi-select component
  	@Property(write = false)
  	private final SelectModel genderModel = new EnumSelectModel(GenderEnum.class, this.messages);
  
  	@Property
  	@Persist
  	private List<GenderEnum> selectedGender;
  	
  	@Property
  	private SelectModel quizSelectModel;
  
  	@Inject
  	SelectModelFactory selectModelFactory;
  
  	@Inject
  	@Property
  	private QuizValueEncoder quizEncoder;
  
  
  	@Inject
  	@Property
  	private LongValueEncoder userIdEncoder;
  
  	@Property
  	@Persist
  	private List<Long> userIds, quizIds;
  
  	@Property
  	@Persist
  	private List<Long> selectedUsers;
  	
  	@Property
  	@Persist
  	private List<Quiz> selectedQuizzes;
  	
  	@Persist
  	@Property
  	private Boolean userOptionEnabled;
  
  	public List<Long> getUsers() {
  		final List<Long> courses = new ArrayList<Long>();
  		courses.add(this.course.getCourseId());
  		final List<Long> elements = this.analysis
  				.computeCourseUsers(courses, this.beginDate.getTime() / THOU, this.endDate.getTime() / THOU, this.visWorker.getGenderIds(this.selectedGender)).getElements();
  		return elements;
  	}
  
  	public Object onActivate(final Course course) {
  		this.logger.debug("--- Bin im ersten onActivate");
  		final List<Long> allowedCourses = this.userWorker.getCurrentUser().getMyCourseIds();
  		if ((allowedCourses != null) && (course != null) && (course.getCourseId() != null)
  				&& allowedCourses.contains(course.getCourseId())) {
  			this.courseId = course.getCourseId();
  			this.course = course;
  
  			return true;
  			} else {
  				return Explorer.class;
  			}
  		}
  
  		public Object onActivate() {
  			this.logger.debug(" No Course Id provided ...");
  			return Explorer.class;
  		}
  
  	public Course onPassivate() {
  		return this.course;
  	}
  
  	void cleanupRender() {
  		this.customizeForm.clearErrors();
  		// Clear the flash-persisted fields to prevent anomalies in onActivate
  		// when we hit refresh on page or browser
  		// button
  		this.courseId = null;
  		this.course = null;
  		this.selectedUsers = null;
  		this.selectedQuizzes = null;
  		this.selectedLearningTypes = null;
  		this.selectedGender = null;
  		this.beginDate = null;
  		this.endDate = null;
  	}
  
  	void onPrepareForRender() {
  		logger.debug("bin im onPrepareForRender");
  		final List<Course> courses = this.courseDAO.findAllByOwner(this.userWorker.getCurrentUser(), false);
  		this.courseModel = new CourseIdSelectModel(courses);
  		this.userIds = this.getUsers();
  		this.quizIds = new ArrayList<Long>();
  
  		final List<Long> courseList = new ArrayList<Long>();
  		courseList.add(this.courseId);
  		ResultListStringObject quizList = null;
  		try {
  			quizList = this.init.getRatedObjects(courseList);
  		} catch (RestServiceCommunicationException e) {
  			logger.error(e.getMessage());
  		}
  
  		final Map<Long, String> quizzesMap = CollectionFactory.newMap();
  		final List<String> quizzesTitles = new ArrayList<String>();
  		final List<Quiz> quizzesList = new ArrayList<Quiz>();
  
  		if ((quizList != null) && (quizList.getElements() != null)) {
  			this.logger.debug(quizList.getElements().toString());
  			final List<String> quizStringList = quizList.getElements();
  			for (Integer x = 0; x < quizStringList.size(); x = x + 2) {
  				final Long quizId = Long.parseLong(quizStringList.get(x));
  				quizzesList.add(new Quiz(quizStringList.get(x + 1),quizId));
  				quizzesMap.put(quizId, quizStringList.get(x + 1));
  				quizzesTitles.add(quizStringList.get(x + 1));
  				this.quizIds.add(quizId);
  				this.logger.debug("Quiz item:"+quizId+ " -- " + quizStringList.get(x + 1));
  			}
  			
  			this.quizEncoder.setUp(quizzesList);
  			
  			quizSelectModel = selectModelFactory.create(quizzesList, "name");
  			
  			this.logger.debug("Rated Objetcs found");
  		} else {
  			this.logger.debug("No rated Objetcs found");
  		}
  		
  		ResultListStringObject learningTypeList = null;
  		try {
  			learningTypeList = this.init.getLearningTypes(courseList);
  		} catch (Exception e) {
  			logger.error(e.getMessage());
  		}
  		final List<LearningType> learningTypes = new ArrayList<LearningType>();
  		
  		if ((learningTypeList != null) && (learningTypeList.getElements() != null)) {
  			this.logger.debug(learningTypeList.getElements().toString());
  			final List<String> learningStringList = learningTypeList.getElements();
  			for (Integer x = 0; x < learningStringList.size(); x = x + 2) {
  				final Long learningTypeId = Long.parseLong(learningStringList.get(x) );
  				learningTypes.add(new LearningType(learningStringList.get(x + 1),learningTypeId));
  			}
  			
  			this.learningTypeEncoder.setUp(learningTypes);
  
  			learningTypeSelectModel = selectModelFactory.create(learningTypes, "name");
  
  		} else {
  			this.logger.debug("No Learning Types found");
  		}
  	}
  
  	public final ValueEncoder<Course> getCourseValueEncoder() {
  		return this.courseValueEncoder.create(Course.class);
  	}
  
  	// returns datepicker params
  	public JSONLiteral getDatePickerParams() {
  		return this.dateWorker.getDatePickerParams(this.currentlocale);
  	}
  
  	public String getQuestionResult() {
  		if (this.courseId != null) {
  			Long endStamp = 0L;
  			Long beginStamp = 0L;
  			if (this.endDate != null) {
  				endStamp = new Long(this.endDate.getTime() / THOU);
  			}
  
  			if (this.beginDate != null) {
  				beginStamp = new Long(this.beginDate.getTime() / THOU);
  			}
  
  			if ((this.resolution == null) || (this.resolution < 10)) {
  				this.resolution = 30;
  			}
  			
  			final List<Long> courseList = new ArrayList<Long>();
  			courseList.add(this.courseId);
  
  			// calling dm-server
  			for (int i = 0; i < courseList.size(); i++) {
  				this.logger.debug("Courses: " + courseList.get(i));
  			}
  
  			List<Long> quizzesList = new ArrayList<Long>();
  
  			ResultListStringObject quizList = null;
  			try {
  				quizList = this.init.getRatedObjects(courseList);
  			} catch (RestServiceCommunicationException e1) {
  				logger.error(e1.getMessage());
  			}
  
  			final Map<Long, String> quizzesMap = CollectionFactory.newMap();
  			final List<String> quizzesTitles = new ArrayList<String>();
  
  			if ((quizList != null) && (quizList.getElements() != null)) {
  				this.logger.debug(quizList.getElements().toString());
  				final List<String> quizStringList = quizList.getElements();
  				for (Integer x = 0; x < quizStringList.size(); x = x + 2) {
  					final Long quizId = Long.parseLong(quizStringList.get(x) );
  