/* ======================================================================
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.logbook.server;
import java.util.Hashtable;
import java.util.Vector;
import java.rmi.RemoteException;
import org.bodington.database.PrimaryKey;
import org.bodington.server.*;

/**
 * An interface that defines the functionality of a log book session,
 * where a session represents a single user accessing a specific
 * logbook.
 * 
 * @author Jon Maber
 * @author Peter Crowther
 */
public interface LogBookSession extends BuildingSession 
	{

	/**
	 * Finds out if the user closable option is set on the LogBook by 
	 * calling the underlying LogBook object.
	 * 
	 * @return A boolean indicating the state of the option.
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public boolean isUserClosable() throws RemoteException, BuildingServerException;

	/**
	 * Can the current user change the open/closed state of the page?
	 * 
	 * @return The value of this option.
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public boolean canOpenOrClose( PrimaryKey page_id ) throws RemoteException, BuildingServerException;
		
	/**
	 * Closes the LogBook.
	 * 
	 * @param page_id The ID of the page to close or open.
	 * @param closed Whether to close or open the log book.
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public void setPageClosed( PrimaryKey page_id, boolean closed ) throws RemoteException, BuildingServerException;

	/**
	 * Sets the value of the user closable option on the LogBook by 
	 * calling the underlying LogBook object and then saves the LogBook
	 * object to the database.
	 * 
	 * @param b The new  value of the option.
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public void setUserClosable( boolean b ) throws RemoteException, BuildingServerException;

	
	/**
	 * Asks the LogBook object to load all its sections and questions and
	 * puts these into a hashtable keyed against their primary keys. 
	 * 
	 * @return A hashtable containing the sections and questions.
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public Hashtable getSectionAndQuestionTable() throws RemoteException, BuildingServerException;

	/**
	 * Get an array of the sections in their proper order.  These
	 * objects should be treated as read only.
	 * 
	 * @return An array of LogBookSection objects in order.
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public LogBookSection[] getSectionsInOrder() throws RemoteException, BuildingServerException;

	/**
	 * For a specified section get an array of the questions in 
	 * their proper order.  These objects should be treated as read 
	 * only.
	 * 
	 * @param section_id The id of the required section.
	 * @return An array of LogBookQuestion objects
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public LogBookQuestion[] getQuestionsInOrder( PrimaryKey section_id ) throws RemoteException, BuildingServerException;

	/**
	 * Create a new section at the end of the list.
	 * 
	 * @return The LogBookSection created
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public LogBookSection createSection() throws RemoteException, BuildingServerException;

	/**
	 * Create a new question at the end of a sectiont.
	 * 
	 * @return The LogBookQuestion created
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public LogBookQuestion createQuestion( PrimaryKey section_id ) throws RemoteException, BuildingServerException;

	/**
	 * Deletes a specific section.
	 * 
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public void deleteSection( PrimaryKey section_id ) throws RemoteException, BuildingServerException;

	/**
	 * Deletes a specific question.
	 * 
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public void deleteQuestion( PrimaryKey question_id ) throws RemoteException, BuildingServerException;

	/**
	 * Changes a number of properties of a specified section.
	 * It is best if the session does this rather than the calling
	 * code using the setter methods in the LogBookSection 
	 * directly so we can gather all database operations into one 
	 * class.
	 * 
	 * @param section_id An id number of a section in this log book.
	 * @param ordinal The new ordinal value to set.
	 * @param title The new title to set.
	 * @param introduction The new introduction text to set.
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public void changeSection( PrimaryKey section_id, int ordinal, String title, String introduction ) throws RemoteException, BuildingServerException;

	/**
	 * Changes a number of properties of a specified question.
	 * It is best if the session does this rather than the calling
	 * code using the setter methods in the LogBookSection 
	 * directly so we can gather all database operations into one 
	 * class.
	 * 
	 * @param ordinal The new ordinal value to set.
	 * @param title The new title to set.
	 * @param q The new question text to set.
	 * @param help The new help text to set.
	 * @exception java.rmi.RemoteException
	 * @exception BuildingServerException
	 */
	public void changeQuestion( PrimaryKey question_id, int ordinal, String title, String q, String help ) throws RemoteException, BuildingServerException;

	public LogBookPage[] getPagesInOrder()
		throws RemoteException, BuildingServerException;
	public LogBookPage getPageForUser( PrimaryKey user_id )
		throws RemoteException, BuildingServerException;
	public LogBookEntry[] getEntriesInOrder( PrimaryKey question_id, PrimaryKey user_id )
		throws RemoteException, BuildingServerException;
	public LogBookEntry getEntry( PrimaryKey entry_id )
		throws RemoteException, BuildingServerException;
	public String getUserFullName( PrimaryKey user_id )
		throws RemoteException, BuildingServerException;
	public void postEntry( PrimaryKey question_id, PrimaryKey user_id, String text, boolean draft, boolean isPrivate, String linked_url )
		throws RemoteException, BuildingServerException;
	public void editEntry( PrimaryKey entry_id, String text, boolean draft, boolean isPrivate, String linked_url )
		throws RemoteException, BuildingServerException;
	public void selectEntry( PrimaryKey entry_id, boolean select )
		throws RemoteException, BuildingServerException;
	public void markEntriesSeen( PrimaryKey question_id, PrimaryKey user_id )
		throws RemoteException, BuildingServerException;
	public void generateCsvQuestionFile()
		throws RemoteException, BuildingServerException;
    public Vector getViewUserIds()
		throws RemoteException, BuildingServerException;
    public Vector getPageUserIds()
		throws RemoteException, BuildingServerException;
	public Hashtable getLastReadEventTable()
		throws RemoteException, BuildingServerException;
        /**
         * Return an alphabetised list of users who have (if possible is false)
         * or could have but have not (if possible is true) visitor access to the
         * specified page.  Note that the page's author is never returned.
         * @param page The page to which the Visitors should have access.
         * @param possible if true, users who could have access but do not are returned; if false, users who have access are returned.
         */
        public Vector getPeers( LogBookPage page, boolean possible )
		throws RemoteException, BuildingServerException;
        
        /**
         * Add the specified user to the visitors list for the specified page.
         * @param page The page to which the visitor should be added.
         * @param user_id The user_id of the user to be added.
         */
        public void addVisitor( LogBookPage page, PrimaryKey user_id )
		throws RemoteException, BuildingServerException;
        
        /**
         * Remove the specified user from the visitors list for the specified page.
         * @param page The page to which the visitor should be added.
         * @param user_id The user_id of the user to be added.
         */
        public void removeVisitor( LogBookPage page, PrimaryKey user_id )
		throws RemoteException, BuildingServerException;
        

        }