src/java/isac/session/CompodDummy.java
changeset 3918 0417a220729b
parent 3881 72f0be16d83b
equal deleted inserted replaced
3917:75c4cd19f086 3918:0417a220729b
     1 /*********************************************************************
       
     2  * This file is part of the Compod project
       
     3  * Contact: Alexander Nussbaumer (AN, alnuss)
       
     4  *   <alexander.nussbaumer@uni-graz.at>, <alnuss@gmx.net>
       
     5  *   
       
     6  *  modified: AN, 20070916
       
     7  *********************************************************************/
       
     8 
       
     9 package isac.session;
       
    10 
       
    11 
       
    12 /**
       
    13  * This is a dummy implementation of the ICompod interface.
       
    14  * In contrast to a "real" implemenatin, this class does not
       
    15  * connect the Compod services.
       
    16  * 
       
    17  * @author Alexander Nussbaumer (AN)
       
    18  */
       
    19 public class CompodDummy implements ICompod
       
    20 {
       
    21 	// --- fields ---
       
    22 	
       
    23 	/**
       
    24 	 * The lmsid. this is not needed in the dummy, however, the dummy
       
    25 	 * simulates a 'real' compod interface, so it is neccessary to insist
       
    26 	 * of it's usage (exception if not set).
       
    27 	 */
       
    28 	private String lmsid_ = null;
       
    29 
       
    30 	/**
       
    31 	 * isac objects. real object IDs, but only a few in the dummy.
       
    32 	 */
       
    33 	private String[] objects_ = 
       
    34 	{ "exp_IsacCore_Tests_1a.xml", "exp_IsacCore_Tests_1b.xml", "exp_IsacCore_Tests_1c.xml" };
       
    35 	
       
    36 	/**
       
    37 	 * Index of the object which will be the next to be shown to the user.
       
    38 	 * If session is not active, than index is -1. 
       
    39 	 */
       
    40 	private int objectindex_ = -1;
       
    41 
       
    42 	/**
       
    43 	 * Keeps inforamtion which type of session is currently running:
       
    44 	 * "assessment" or "course", or null if no session is active.
       
    45 	 * Maybe enum would be better than string. 
       
    46 	 */
       
    47 	private String sessiontype_ = null;
       
    48 	
       
    49 	/**
       
    50 	 * Keeps information about the session state.
       
    51 	 */
       
    52 	private SessionState sessionstate_ = null;
       
    53 
       
    54 	/**
       
    55 	 * Keeps availability information about knowledge and competence state. 
       
    56 	 */
       
    57 	private KnowledgeStateQuality knowledgestatequality_ = null;
       
    58 	
       
    59 	
       
    60 	// --- constructor ---
       
    61 	
       
    62 	/**
       
    63 	 * Constructor: initialisation
       
    64 	 */
       
    65 	public CompodDummy ()
       
    66 	{
       
    67 		// initialisation
       
    68 		
       
    69 		// no session at the beginning
       
    70 		sessionstate_ = SessionState.INACTIVE;
       
    71 
       
    72 		// empty set at beginning, empty set is also a possible knowledge state
       
    73 		knowledgestatequality_ = KnowledgeStateQuality.AVAILABLE; 
       
    74 	}
       
    75 	
       
    76 	/**
       
    77 	 * @see ICompod#setLMSID(java.lang.String)
       
    78 	 */
       
    79 	public void setLMSID(String lmsid) throws Exception
       
    80 	{
       
    81 		lmsid_ = lmsid;
       
    82 	}
       
    83 
       
    84     /**
       
    85      * @see isac.session.ICompod#setScopeByTopic(java.lang.String, java.lang.String)
       
    86      */
       
    87     public void setScopeByTopic (String username, String topic) throws Exception
       
    88     {
       
    89 		if (lmsid_ == null)
       
    90 			throw new Exception ("lmsid is not set");
       
    91 		
       
    92     	// not used in dummy
       
    93     }
       
    94 
       
    95 	/**
       
    96 	 * @see ICompod#startSession(java.lang.String, java.lang.String)
       
    97 	 */
       
    98 	public boolean startSession(String username, String sessiontype) throws Exception
       
    99 	{
       
   100 		if (lmsid_ == null)
       
   101 			throw new Exception ("lmsid is not set");
       
   102 		
       
   103 		// user is ignored in this dummy
       
   104 		
       
   105 		// if a session is already running then return 
       
   106 		if (sessionstate_ == SessionState.ACTIVE)
       
   107 			return false;
       
   108 	
       
   109 		// activate and initialise session
       
   110 		sessionstate_ = SessionState.ACTIVE;
       
   111 		sessiontype_ = sessiontype;
       
   112 		objectindex_ = 0; 
       
   113 		// during an assessment, the knowledge and competence state is not available
       
   114 		if (sessiontype_ == "assessment")
       
   115 			knowledgestatequality_ = KnowledgeStateQuality.UNAVAILABLE;
       
   116 		
       
   117 		return true;
       
   118 	}
       
   119 
       
   120 	/**
       
   121 	 * @see ICompod#stopSession(java.lang.String, boolean)
       
   122 	 */
       
   123 	public boolean stopSession(String username, boolean cancel) throws Exception
       
   124 	{
       
   125 		if (lmsid_ == null)
       
   126 			throw new Exception ("lmsid is not set");
       
   127 
       
   128 		// user and cancel type is ignored in this dummy
       
   129 		
       
   130 		// if a session is not running then return 
       
   131 		if (sessionstate_ == SessionState.INACTIVE)
       
   132 			return false;
       
   133 	
       
   134 		// stop session
       
   135 		sessionstate_ = SessionState.INACTIVE;
       
   136 		knowledgestatequality_ = KnowledgeStateQuality.PRELIMINARY;
       
   137 		objectindex_ = -1; 
       
   138 		
       
   139 		return true;
       
   140 	}
       
   141 	
       
   142 
       
   143 	/**
       
   144 	 * @see ICompod#getSessionStatus(java.lang.String)
       
   145 	 */
       
   146 	public SessionState getSessionState(String username) throws Exception 
       
   147 	{
       
   148 		if (lmsid_ == null)
       
   149 			throw new Exception ("lmsid is not set");
       
   150 		
       
   151 		return sessionstate_;
       
   152 	}
       
   153 
       
   154 
       
   155 	/**
       
   156 	 * @see ICompod#getNextObjects(java.lang.String)
       
   157 	 */
       
   158 	public String[] getNextObjects(String username) throws Exception 
       
   159 	{
       
   160 		if (lmsid_ == null)
       
   161 			throw new Exception ("lmsid is not set");
       
   162 		
       
   163 		// return if no session is active
       
   164 		if (sessionstate_ == SessionState.INACTIVE)
       
   165 			return null;
       
   166 		
       
   167 		// system invariant: this case should not happen
       
   168 		int objectnumber = objects_.length;
       
   169 		if (objectindex_ < 0 || objectindex_ >= objectnumber)
       
   170 			return null; 
       
   171 		
       
   172 		// return next objects
       
   173 		String[] nextobjects = new String[1];
       
   174 		nextobjects[0] = objects_[objectindex_];
       
   175 		
       
   176 		// different behaviour if a course is conducted
       
   177 		// in contrast to the assessment, there is no separate update,
       
   178 		// therefore the update has to be done here.
       
   179 		if (sessiontype_ == "course")
       
   180 		{
       
   181 			// update and prepare for getNextObjects
       
   182 			objectindex_++;
       
   183 			
       
   184 			// stop if no more objects are available
       
   185 			if (objectindex_ >= objectnumber)
       
   186 			{
       
   187 				sessionstate_ = SessionState.INACTIVE;
       
   188 				objectindex_ = -1; 
       
   189 			}
       
   190 		}
       
   191 		return nextobjects;
       
   192 	}
       
   193 	
       
   194 	/**
       
   195 	 * @see ICompod#notifyObjectResult(java.lang.String, java.lang.String, boolean)
       
   196 	 */
       
   197 	public void notifyObjectResult(String username, String objectid,
       
   198 			boolean solved) throws Exception 
       
   199 	{
       
   200 		if (lmsid_ == null)
       
   201 			throw new Exception ("lmsid is not set");
       
   202 		
       
   203 		// TODO write data in a file (or on the console)
       
   204 		
       
   205 		// update and prepare for getNextObjects
       
   206 		// WN090111 objectindex_++; only in getNextObjects
       
   207 		
       
   208 		// stop if no more objects are available
       
   209 		int objectnumber = objects_.length;
       
   210 		if (objectindex_ >= objectnumber)
       
   211 		{
       
   212 			sessionstate_ = SessionState.INACTIVE;
       
   213 			knowledgestatequality_ = KnowledgeStateQuality.AVAILABLE;
       
   214 			objectindex_ = -1; 
       
   215 		}
       
   216 	}
       
   217 
       
   218 	/**
       
   219 	 * @see ICompod#notifyObjectMicroResult(java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean)
       
   220 	 */
       
   221 	public void notifyObjectMicroResult(String username, String objectid,
       
   222 			String skillid, String masterylevel, boolean solved) throws Exception 
       
   223 	{
       
   224 		if (lmsid_ == null)
       
   225 			throw new Exception ("lmsid is not set");
       
   226 		
       
   227 		// TODO write data in a file (or on the console)
       
   228 	}
       
   229 	
       
   230 	
       
   231 	/**
       
   232 	 * @see ICompod#getKnowledgeStateQuality(java.lang.String)
       
   233 	 */
       
   234 	public KnowledgeStateQuality getKnowledgeStateQuality(String username) throws Exception 
       
   235 	{
       
   236 		if (lmsid_ == null)
       
   237 			throw new Exception ("lmsid is not set");
       
   238 		
       
   239 		return knowledgestatequality_;
       
   240 	}
       
   241 
       
   242 	/**
       
   243 	 * @see ICompod#getKnowledgeState(java.lang.String)
       
   244 	 */
       
   245 	public String[] getKnowledgeState(String username) throws Exception 
       
   246 	{
       
   247 		if (lmsid_ == null)
       
   248 			throw new Exception ("lmsid is not set");
       
   249 		
       
   250 		String[] knowledgestate = null;
       
   251 		if (knowledgestatequality_ != KnowledgeStateQuality.UNAVAILABLE)
       
   252 			knowledgestate = new String[0];
       
   253 		
       
   254 		return knowledgestate;
       
   255 	}
       
   256 
       
   257 	/**
       
   258 	 * @see ICompod#getCompetenceState(java.lang.String)
       
   259 	 */
       
   260 	public String[] getCompetenceState(String username) throws Exception 
       
   261 	{
       
   262 		if (lmsid_ == null)
       
   263 			throw new Exception ("lmsid is not set");
       
   264 		
       
   265 		String[] competencestate = null;
       
   266 		if (knowledgestatequality_ != KnowledgeStateQuality.UNAVAILABLE)
       
   267 			competencestate = new String[0];
       
   268 		
       
   269 		return competencestate;
       
   270 	}
       
   271 
       
   272 
       
   273 	
       
   274 	/**
       
   275 	 * This main method is used for 
       
   276 	 * 1) testing the dummy implementation and 
       
   277 	 * 2) demonstrating the usage of the ICompod interface.
       
   278 	 * This could also be placed in an external class.
       
   279 	 * 
       
   280 	 * @param args 
       
   281 	 * 		(Command line arguments) not used
       
   282 	 */
       
   283 	public static void main (String[] args)
       
   284 	{
       
   285 		CompodDummy compod = new CompodDummy ();
       
   286 		
       
   287 		System.out.print("Compod Dummy.\n");
       
   288 		
       
   289 		// initialisation
       
   290 		String lmsid = "isac-beta-xxx";
       
   291 		String username = "some wired user";
       
   292 		
       
   293 		try
       
   294 		{
       
   295 			compod.setLMSID (lmsid);
       
   296 		} 
       
   297 		catch (Exception e)
       
   298 		{
       
   299 			e.printStackTrace();
       
   300 			return; // stop
       
   301 		}
       
   302 
       
   303 		// assessment
       
   304 		try
       
   305 		{
       
   306 			System.out.print("- Assessment.\n");
       
   307 			compod.startSession (username, "assessment");
       
   308 			while (compod.getSessionState (username) == SessionState.ACTIVE)
       
   309 			{
       
   310 				String[] nextobjects = compod.getNextObjects (username);
       
   311 				
       
   312 				// output
       
   313 				for (int i = 0; i < nextobjects.length; i++)
       
   314 					System.out.print (nextobjects[i]);
       
   315 				System.out.println ("");
       
   316 				
       
   317 				compod.notifyObjectResult(username, nextobjects[0], true);
       
   318 			}
       
   319 		} 
       
   320 		catch (Exception e)
       
   321 		{
       
   322 			e.printStackTrace();
       
   323 		}
       
   324 		
       
   325 		// course
       
   326 		try
       
   327 		{
       
   328 			System.out.print("- Course.\n");
       
   329 			compod.startSession (username, "course");
       
   330 			while (compod.getSessionState (username) == SessionState.ACTIVE)
       
   331 			{
       
   332 				String[] nextobjects = compod.getNextObjects (username);
       
   333 				
       
   334 				// output
       
   335 				for (int i = 0; i < nextobjects.length; i++)
       
   336 					System.out.print (nextobjects[i]);
       
   337 				System.out.println ("");
       
   338 			}
       
   339 		} 
       
   340 		catch (Exception e)
       
   341 		{
       
   342 			e.printStackTrace();
       
   343 		}
       
   344 		
       
   345 		
       
   346 	}
       
   347 
       
   348 
       
   349 
       
   350 
       
   351 	
       
   352 	
       
   353 	
       
   354 	
       
   355 	
       
   356 	
       
   357 }