/* ======================================================================
The Bodington System Software License, Version 1.0
  
Copyright (c) 2001 The University of Leeds.  All rights reserved.
  
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1.  Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2.  Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3.  The end-user documentation included with the redistribution, if any,
must include the following acknowledgement:  "This product includes
software developed by the University of Leeds
(http://www.bodington.org/)."  Alternately, this acknowledgement may
appear in the software itself, if and wherever such third-party
acknowledgements normally appear.

4.  The names "Bodington", "Nathan Bodington", "Bodington System",
"Bodington Open Source Project", and "The University of Leeds" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
d.gardner@leeds.ac.uk.

5.  The name "Bodington" may not appear in the name of products derived
from this software without prior written permission of the University of
Leeds.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  TITLE,  THE IMPLIED WARRANTIES 
OF QUALITY  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO 
EVENT SHALL THE UNIVERSITY OF LEEDS OR ITS CONTRIBUTORS BE LIABLE FOR 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
=========================================================

This software was originally created by the University of Leeds and may contain voluntary 
contributions from others.  For more information on the Bodington Open Source Project, please 
see http://bodington.org/

====================================================================== */

package org.bodington.assessment;

import java.util.List;
import java.util.Enumeration;
import java.util.Map;
import java.rmi.RemoteException;

import org.bodington.database.PrimaryKey;
import org.bodington.server.*;

/**
 * Interface for objects that represent a users session with a questionnaire.
 * @see org.bodington.assessment.Questionnaire
 * @author Jon Maber
 * @author Alexis O'Connor
 */
public interface QuestionnaireSession extends BuildingSession 
	{
    /**
     * Get the questionnaire that is associated with this session. 
     * @return the questionnaire that is associated with this session.
     * @throws RemoteException if there is some problem.
     * @throws BuildingServerException if there is some problem.
     */
    public Questionnaire getQuestionnaire() throws RemoteException, 
        BuildingServerException;
    
	/**
     * Get the list of questions. This method returns a list of the
     * {@link PrimaryKey}s of the questions. These are ordered on the basis of
     * the value of the {@link QuestionnaireQuestion#getOrdinal()} property.
     * @return the list of the questions.
     * @throws RemoteException if there is some problem.
     * @throws BuildingServerException if there is some problem.
     * @see QuestionnaireQuestion
     * @see QuestionnaireQuestion#getQuestionnaireQuestionId()
     */
	public List getQuestionnaireQuestionIds() throws RemoteException, BuildingServerException;
	
	/**
     * Get a map of the questions. This method returns a map, where each pair
     * pertains to a single question. The key is the value of
     * {@link QuestionnaireQuestion#getQuestionnaireQuestionId()}, the value is
     * the question itself. The ordering is unspecified.
     * @return a map of the questions.
     * @throws RemoteException if there is some problem.
     * @throws BuildingServerException if there is some problem.
     * @see QuestionnaireQuestion
     * @see QuestionnaireQuestion#getQuestionnaireQuestionId()
     */
	public Map getQuestionnaireQuestions() throws RemoteException, BuildingServerException;
	
	/**
     * Get a list of the questions in order. This list contains instances of
     * {@link QuestionnaireQuestion}. These are ordered on the basis of the
     * value of the {@link QuestionnaireQuestion#getOrdinal()} property.
     * @return a list of the questions in order.
     * @throws RemoteException
     * @throws BuildingServerException
     */
	public List getQuestionnaireQuestionsInOrder() throws RemoteException, BuildingServerException;
    
    /**
     * Create a new question.
     * @return the newly created question.
     * @see #createQuestion(int)
     */
    public QuestionnaireQuestion createQuestion() throws RemoteException, BuildingServerException;

    /**
     * Create a new question. The <code>ordinal</code> parameter allows you to
     * specify at which point in the list the new question should go, relative
     * to the existing ones.
     * @param ordinal the ordinal for the new question.
     * @return the newly created question.
     * @see QuestionnaireQuestion#getOrdinal()
     * @see Questionnaire#getMaxOrdinal()
     */
    public QuestionnaireQuestion createQuestion(int ordinal) throws RemoteException, BuildingServerException;
	
	/**
     * Remove the specified question. The specified parameter corresponds to the
     * value of {@link QuestionnaireQuestion#getQuestionnaireQuestionId()}.
     * @param questionID the ID of the question to be removed.
     * @throws RemoteException
     * @throws BuildingServerException
     */
	public void removeQuestion( PrimaryKey questionID ) throws RemoteException, BuildingServerException;

	/**
     * Change the specified question. The <code>questionID</code> parameter
     * corresponds to the value of
     * {@link QuestionnaireQuestion#getQuestionnaireQuestionId()}.
     * @param questionID the ID of the question to be changed.
     * @param question an object containing the new values for the specified
     *        question.
     * @throws RemoteException
     * @throws BuildingServerException
     */
	public void changeQuestion( PrimaryKey questionID, QuestionnaireQuestion question ) throws RemoteException, BuildingServerException;
	
	/**
     * Change the specified question. The <code>questionID</code> parameter
     * corresponds to the value of
     * {@link QuestionnaireQuestion#getQuestionnaireQuestionId()}. The text
     * that can be changed includes the introduction and the text of the
     * statements / responses.
     * @param questionID the ID of the question whose text is to be changed.
     * @param textID the ID of the text to be changed.
     * @param newText the value of the new text.
     * @throws RemoteException
     * @throws BuildingServerException
     */
	public void changeQuestionText( PrimaryKey questionID, PrimaryKey textID, String newText ) throws RemoteException, BuildingServerException;
	
	/**
     * Record a users response to a questionnaire. Across the parameters
     * <code>questionIDs</code>, <code>responses</code> and
     * <code>comments</code> a given index respectively captures (for a user)
     * a specified question, the single selection they made and any free text
     * response they gave.
	 * @param newResult indicates whether this should be stored in a new 
     * {@link QuestionnaireResult} instance.
	 * @param questionIDs an array of the IDs of the
     *        {@link QuestionnaireQuestion} instances.
	 * @param responses an array of the single choices that were selected.
	 * @param comments an array of free text comments.
     * @return ID of the corresponding {@link QuestionnaireResult} instance.
     * @see QuestionnaireQuestion
     */
	public PrimaryKey record( boolean newResult, PrimaryKey[] questionIDs, int[] responses, String[] comments ) throws RemoteException, BuildingServerException;
	
	/**
     * Get the questionnaire result associated with the current user.
	 * @return the questionnaire result associated with the current user.
     * @see #getQuestionnaireResult(PrimaryKey)
	 */
	public QuestionnaireResult getQuestionnaireResult() throws RemoteException, BuildingServerException;

    /**
     * Get the questionnaire result associated with the specified user. This is
     * specifically an associated result object saved to persistence storage. If
     * the user has not yet recorded a set of answers, then this method returns
     * <code>null</code>. For questionnaires that support multiple results
     * and where the user has recorded more than one set of answers, this method
     * returns the most recently recorded result.
     * @param userID the ID of the specified user.
     * @return the questionnaire result associated with the specified user.
     * @see Questionnaire#isMultipleResults()
     * @see org.bodington.server.realm.User
     */
	public QuestionnaireResult getQuestionnaireResult( PrimaryKey userID ) throws RemoteException, BuildingServerException;

    /**
     * Get a list of the questionnaire results associated with the current user.
     * @return a list of the questionnaire results associated with the current
     *         user.
     * @see QuestionnaireResult
     */
    public List getQuestionnaireResults()
    throws RemoteException, BuildingServerException;
    
    /**
     * Get a list of the questionnaire results associated with the questionnaire
     * of the current user.
     * @return a list all the questionnaire results associated with the
     *         questionnaire of the current user.
     * @see #getQuestionnaire()
     * @see QuestionnaireResult
     */
    public List getAllQuestionnaireResults()
    throws RemoteException, BuildingServerException;

	/**
     * Analyse the results associated with the implicit questionnaire. This
     * method will create a list of questionnaire results based on the value of
     * the <code>whereSQL</code> parameter. If this parameter is
     * <code>null</code>, then the search criteria is that of the
     * <code>resource_id</code> field of the implicit questionnaire. If the
     * <code>analysis</code> parameter is non-null, then this will be
     * populated with questionnaire results and responses corresponding to the
     * returned list.
     * @param whereSQL a string representing the <code>WHERE</code> clause of
     *        some SQL representing the criteria upon which to select the
     *        results.
     * @param analysis an object that encapsulates the analysis of a
     *        questionnaire response.
     * @return a list of questionnaire results associated with the implicit
     *         questionnaire.
     * @see org.bodington.database.PersistentObject#findPersistentObjects(String,
     *      String)
     * @see QuestionnaireResult
     * @see QuestionnaireResponse
     * @see QuestionnaireAnalysis#addQuestionnaireResult(QuestionnaireResult)
     * @see QuestionnaireAnalysis#addQuestionnaireResponse(QuestionnaireQuestion,
     *      QuestionnaireResult, QuestionnaireResponse)
     */
	public List analyse( String whereSQL, QuestionnaireAnalysis analysis ) throws RemoteException, BuildingServerException;
	
	/**
     * Export the implicit questionnaire as an XML file. This file is in IMS QTI
     * format. The name that this method gives the file should have the 
     * extension <code>.xml</code> and take the <code>name</code> of the
     * questionnaire.
     * @param includeResults specify whether or not to include questionnaire
     *        results.
     * @param includeResponses specify whether or not to include questionnaire
     *        responses.
	 * @return the name of the XML file that this method exported to.
     * @see QuestionnaireResult
     * @see QuestionnaireResponse
     */
	public String exportXML( boolean includeResults, boolean includeResponses ) throws RemoteException, BuildingServerException;

    /**
     * Import the specified XML file. The file is expected to be in IMS QTI
     * format.
	 * @param fileName the file path to the XML file to be imported.
     * @see org.bodington.assessment.ims.QuestionnaireImsQtiHandler
	 */
	public void importXML( String fileName ) throws RemoteException, BuildingServerException;
    
    /**
     * Export the implicit questionnaire as a CSV file. This file is in
     * <em>comma separated variable</em> format. The name that this method
     * gives the file should have the extension <code>.csv</code> and take the
     * <code>name</code> of the questionnaire.
     * @param includeResults specify whether or not to include questionnaire
     *        results.
     * @param includeResponses specify whether or not to include questionnaire
     *        responses.
     * @return the name of the CSV file that this method exported to.
     * @see QuestionnaireResult
     * @see QuestionnaireResponse
     */
    public String exportCSV( boolean includeResults, boolean includeResponses ) throws RemoteException, BuildingServerException;
	}
	
