Index: Dev/branches/jos-branch/server/classes/models/Answer.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/Answer.php	(revision 287)
+++ Dev/branches/jos-branch/server/classes/models/Answer.php	(revision 298)
@@ -50,5 +50,6 @@
 		if(is_string($this->question))
 		{
-			$result = Question::get(array("uid" => $this->question));
+			$ans = ResearchToolObject::stripUri($this->question);
+			$result = Question::get(array("uid" => $ans["uid"]));
 			if(!isset($result[0]))
 				return false;
@@ -71,5 +72,5 @@
 			PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
 			PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
-			SELECT DISTINCT ?uid, ?question_code
+			SELECT DISTINCT ?uid, ?to_question
 			WHERE
 			{
@@ -77,5 +78,5 @@
 
 				predicates:uid ?uid ;
-				predicates:question_code ?question_code ;
+				predicates:to_question ?to_question ;
 				' . ResearchToolObject::createArguments($arguments) . '
 			}';
@@ -83,5 +84,5 @@
 		//Query the model
 		$results = $model->sparqlQuery($querystring);	
-	//An answer can have multiple values, get all these values for the answer instances found.
+		//An answer can have multiple values, get all these values for the answer instances found.
 		$answers = array();
 		if(!empty($results))
@@ -89,5 +90,5 @@
 			foreach($results as $result)
 			{
-				$answers[] = new Answer($result['?uid']->label, $result['?question_code']->label, Answer::getValues($model, $result['?uid']->label));
+				$answers[] = new Answer($result['?uid']->label, $result['?to_question']->uri, Answer::getValues($model, $result['?uid']->label));
 			}
 		}
@@ -142,6 +143,6 @@
 		$model->add(new Statement($resourceAnswer, $predicateId, $answerId));
 
-		$questionId = new Literal($this->question->uid);
-		$predicateQId = new Resource(QCODE);
+		$questionId = new Resource(QUESTION . '/' . $this->question->uid);
+		$predicateQId = new Resource(TO_QUESTION);
 		$model->add(new Statement($resourceAnswer, $predicateQId, $questionId));
 
Index: Dev/branches/jos-branch/server/classes/models/AnswerSet.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/AnswerSet.php	(revision 287)
+++ Dev/branches/jos-branch/server/classes/models/AnswerSet.php	(revision 298)
@@ -46,5 +46,6 @@
 		if(is_string($this->survey))
 		{
-			$result = Survey::get(array("uid" => $this->survey));
+			$surv = ResearchToolObject::stripUri($this->survey);
+			$result = Survey::get(array("uid" => $surv["uid"]));
 			if(!isset($result[0]))
 				return false;
@@ -53,5 +54,6 @@
 		if(is_string($this->respondent))
 		{
-			$result = Respondent::get(array("uid" => $this->respondent));
+			$resp = ResearchToolObject::stripUri($this->respondent);
+			$result = Respondent::get(array("uid" => $resp["uid"]));
 			if(!isset($result[0]))
 				return false;
@@ -63,5 +65,6 @@
 			foreach($this->answers as $answer)
 			{
-				$result = Answer::get(array("uid" => $answer));
+				$answ = ResearchToolObject::stripUri($answer);
+				$result = Answer::get(array("uid" => $answ["uid"]));
 				if(!isset($result[0]))
 					return false;
@@ -91,5 +94,4 @@
 		$model = ResearchToolObject::load(AnswerSet::$filename);
 
-
 		$resourceAnswerSet = new Resource(ANSWERSET . '/' . $this->uid);
 		//Remove the old value stored with the given id
@@ -105,9 +107,9 @@
 		$model->add(new Statement($resourceAnswerSet, $predicateId, $answerSetId));
 
-		$surveyId = new Literal($this->survey->uid);
+		$surveyId = new Resource(SURVEY . '/' . $this->survey->uid);
 		$predicateSurvey = new Resource(FOR_SURVEY);
 		$model->add(new Statement($resourceAnswerSet, $predicateSurvey, $surveyId));
 
-		$respondentId = new Literal($this->respondent->uid);
+		$respondentId = new Resource(RESPONDENT . '/' . $this->respondent->uid);
 		$predicateRespondent = new Resource(BY_RESPONDENT);
 		$model->add(new Statement($resourceAnswerSet, $predicateRespondent, $respondentId));
@@ -121,5 +123,5 @@
 			foreach($this->answers as $answer)
 			{
-				$answerId = new Literal($answer->uid);
+				$answerId = new Resource(ANSWER . '/' . $answer->uid);
 				$predicateAnswer = new Resource(GIVEN_ANSWER);
 				$model->add(new Statement($resourceAnswerSet, $predicateAnswer, $answerId));
@@ -160,6 +162,6 @@
 			foreach($results as $result)
 			{
-				$survey = $result['?for_survey']->label;
-				$respondent = $result['?by_respondent']->label;
+				$survey = $result['?for_survey']->uri;
+				$respondent = $result['?by_respondent']->uri;
 				$datetime = new DateTime();
 				$datetime->setTimestamp(intval($result['?datetime']->label));
Index: Dev/branches/jos-branch/server/classes/models/ApplicationInstance.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/ApplicationInstance.php	(revision 287)
+++ Dev/branches/jos-branch/server/classes/models/ApplicationInstance.php	(revision 298)
@@ -128,6 +128,4 @@
 	{
 		$model = ResearchToolObject::load(ApplicationInstance::$filename);
-		$model->writeAsHTMLTable();
-
 		//Build the query string
 		$querystring = '
@@ -162,6 +160,4 @@
 		}
 		return $aInstances;
-
-
 	}
 
Index: Dev/branches/jos-branch/server/classes/models/ResearchToolObject.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/ResearchToolObject.php	(revision 287)
+++ Dev/branches/jos-branch/server/classes/models/ResearchToolObject.php	(revision 298)
@@ -61,9 +61,9 @@
 			{
 				case "uid" : $addition = "predicates:uid '" . $arguments[$key] . "'\n"; break;
-				case "question" : $addition = "predicates:question_code '" . $arguments[$key] . "'\n"; break;
+				case "to_question" : $addition = "predicates:to_question <" . QUESTION . '/' . $arguments[$key] . ">\n"; break;
 				case "values": foreach($arguments[$key] as $value) { $addition = $addition . "predicates:answered '" . $value . "'\n"; } break;
-				case "survey" : $addition = "predicates:for_survey '" . $arguments[$key] . "'\n"; break;
-				case "respondent" : $addition = "predicates:by_respondent '" . $arguments[$key] . "'\n"; break;
-				case "answers" : foreach($arguments[$key] as $answer) { $addition = $addition . "predicates:given_answer '" . $answer . "'\n"; } break;
+				case "survey" : $addition = "predicates:for_survey <" . SURVEY . '/' . $arguments[$key] . ">\n"; break;
+				case "respondent" : $addition = "predicates:by_respondent <" . RESPONDENT . '/' . $arguments[$key] . ">\n"; break;
+				case "answers" : foreach($arguments[$key] as $answer) { $addition = $addition . "predicates:given_answer <" . ANSWER . '/' . $answer . ">\n"; } break;
 				case "title" : $addition = "predicates:title '" . $arguments[$key] . "'\n"; break;
 				case "description" : $addition = "predicates:description '" . $arguments[$key] . "'\n"; break;
@@ -75,18 +75,21 @@
 				case "email" : $addition = "predicates:email '" . $arguments[$key] . "'\n"; break;
 				case "password" : $addition = "predicates:password '" . $arguments[$key] . "'\n"; break;
-				case "creator" : $addition = "predicates:creator '" . $arguments[$key] . "'\n"; break;
+				case "creator" : $addition = "predicates:creator <" . USER . '/' . $arguments[$key] . ">\n"; break;
 				case "creationdate" : $addition = "predicates:creationdate '" . $arguments[$key] . "'\n"; break;
-				case "applications" : foreach($arguments[$key] as $application) { $addition = $addition . "predicates:has_application '" . $application . "'\n"; } break;
-				case "surveys" : foreach($arguments[$key] as $survey) { $addition = $addition . "predicates:has_survey '" . $survey . "'\n"; } break;
-				case "answersets" : foreach($arguments[$key] as $answerset) { $addition = $addition . "predicates:has_answerset '" . $answerset . "'\n"; } break;
-				case "questions" : foreach($arguments[$key] as $question) { $addition = $addition . "predicates:has_question '" . $question . "'\n"; } break;
+				case "applications" : foreach($arguments[$key] as $application) { $addition = $addition . "predicates:has_application <" . APPLICATION . '/' . $application . ">\n"; } break;
+				case "surveys" : foreach($arguments[$key] as $survey) { $addition = $addition . "predicates:has_survey <" . SURVEY . '/' . $survey . ">\n"; } break;
+				case "answersets" : foreach($arguments[$key] as $answerset) { $addition = $addition . "predicates:has_answerset <" . ANSWERSET . '/' . $answerset . ">\n"; } break;
+				case "questions" : foreach($arguments[$key] as $question) { $addition = $addition . "predicates:has_question <" . QUESTION . '/' . $question . ">\n"; } break;
 				case "location" : $addition = "predicates:location '" . $arguments[$key] . "'\n"; break;
-				case "facilitator" : $addition = "predicates:facilitator '" . $arguments[$key] . "'\n"; break;
+				case "facilitator" : $addition = "predicates:facilitator <" . USER . '/' . $arguments[$key] . ">\n"; break;
 				case "starttime" : $addition = "predicates:starttime '" . $arguments[$key] . "'\n"; break;
 				case "endtime" : $addition = "predicates:endtime '" . $arguments[$key] . "'\n"; break;
-				case "session" : $addition = "predicates:of_session '" . $arguments[$key] . "'\n"; break;
+				case "session" : $addition = "predicates:of_session <" . SURVEY . '/' . $arguments[$key] . ">\n"; break;
 				case "resultset" : $addition = "predicates:has_resultset '" . $arguments[$key] . "'\n"; break;
 				case "of_application" : $addition = "predicates:of_application <" . APPLICATION . '/' .  $arguments[$key] . ">\n"; break;
 				case "open" : $addition = "predicates:open '" . $arguments[$key] . "\n"; break;
+				case "applicationinstances" : foreach($arguments[$key] as $instance) { $addition = $addition . "predicates:has_applicationinstance <" . APPLICATIONINSTANCE . '/' . $instance . ">\n"; } break; 
+				case "has_surveyinstance" : foreach($arguments[$key] as $instance) { $addition = $addition . "predicates:has_surveyinstance <" . SURVEYINSTANCE . '/' . $instance . ">\n"; } break;
+				case "preset_answers" : foreach($arguments[$key] as $instance) { $addition = $addition . "predicates:preset_answer <" . ANSWER . '/' . $instance . ">\n"; } break;
 			}
 			$argumentString = $argumentString . $addition;
Index: Dev/branches/jos-branch/server/classes/models/ResultSet.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/ResultSet.php	(revision 287)
+++ 	(revision )
@@ -1,165 +1,0 @@
-<?php
-// Survey database interface class as intermediate for storing data from the site to the RDF database 
-require_once 'rdfConstants.php';
-// Include RAP Library to write RDF files
-include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
-
-/**
- * Description of ResultSet
- */
-class ResultSet extends ResearchToolObject{
-
-	private static $filename = 'data/results/resultsets.rdf';
-
-	public $answersets;
-	public $playerresults;
-	public $groupresults;
-	public $periodicresults;
-
-	/**
-	 * Constructor for an ResultSet object.
-	 * @param type $uid
-	 * @param type $answersets;
-	 * @param type $playerresults;
-	 * @param type $groupresults;
-	 * @param type $periodicresults;
-	 */
-	public function __construct($uid=null, $answersets = null, $playerresults = null, $groupresults = null, $periodicresults = null)
-	{
-		if(!isset($uid))
-		{
-			$uid = md5(uniqid(rand(), true));
-		}
-		
-		$this->uid = $uid;
-		$this->answersets = $answersets;
-		$this->playerresults = $playerresults;
-		$this->groupresults = $groupresults;
-		$this->periodicresults = $periodicresults;
-	}
-
-	/**
-	 * funtion evaluate()
-	 * evaluates the references of all results
-	 */
-	public function evaluate()
-	{
-		if(!empty($this->answersets) && is_string($this->answersets[0]))
-		{
-			$newAnswerSets = array();
-			foreach($this->answersets as $answerSet)
-			{
-				$result = AnswerSet::get(array("uid" => $answerSet));
-				if(!isset($result[0]))
-					return false;
-				$newAnswerSets[] = $result[0];
-			}			
-			$this->answersets = $newAnswerSets;
-		}
-		//TODO: Evaluate the other sets when they are implemented.
-
-		return true;
-	}
-
-	/**
-	 * function save()
-	 * Saves the current object into the database.
-	 */
-	public function save()
-	{
-		//If evaluation fails, some references are incorrect.
-		//We shouldn't save in this case. Instead - let the user know. This function returns false if the evaluation has failed.
-		//TODO: Decide how to fix invalid references graciously.
-		if(!$this->evaluate()) 
-			throw new Exception('Evaluation failed.');
-
-        //Ensure the required folder exists.
-		if(!is_dir('data/results/'))
-			mkdir('data/results/');
-
-		$model = ResearchToolObject::load(ResultSet::$filename);
-
-		$resourceResultSet = new Resource(RESULTSET . '/' . $this->uid);
-		//Remove the old value stored with the given id
-		$model->subtract($model->find($resourceResultSet, null, null));
-
-		//Set new values
-		$resourceResultSetType = new Resource(RESULTSET);
-		$predicateRType = new Resource(RTYPE);
-		$model->add(new Statement($resourceResultSet, $predicateRType, $resourceResultSetType));
-
-		$resultSetId = new Literal($this->uid);
-		$predicateId = new Resource(UID);
-		$model->add(new Statement($resourceResultSet, $predicateId, $resultSetId));
-
-		if(isset($this->answersets))
-		{
-			foreach($this->answersets as $answerset)
-			{
-				$answerSetId = new Literal($answerset->uid);
-				$predicateAnswerSet = new Resource(HAS_ANSWERSET);
-				$model->add(new Statement($resourceResultSet, $predicateAnswerSet, $answerSetId));
-			}
-		}
-
-		//TODO: store other sets when they are implemented.
-
-		$model->saveAs(ResultSet::$filename, 'rdf');
-		return true;
-	}
-
-	/**
-	 * function get()
-	 * @param type $arguments : An array having one or more of the following elements:
-	 * 'uid', 'answersets', 'playerresults', 'groupresults', 'periodicresults'
-	 */
-	public static function get($arguments)
-	{
-		$model = ResearchToolObject::load(ResultSet::$filename);
-		//Build the query string
-		$querystring = '
-			PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
-			PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
-			SELECT DISTINCT ?uid
-			WHERE
-			{
-				_resultset predicates:resource_type resources:resultset ;
-				predicates:uid ?uid ;
-				' . ResearchToolObject::createArguments($arguments) . '
-			}';
-		//Query the model
-		$results = $model->sparqlQuery($querystring);
-		$resultSets = array();
-		if(!empty($results))
-		{
-			foreach($results as $result)
-			{
-				$answerSets = ResultSet::getAnswerSets($model, $result['?uid']->label);
-				$resultSets[] = new ResultSet($result['?uid']->label, $answerSets, array(), array(), array());
-			}
-		}
-		return $resultSets;
-	}
-
-	/**
-	 * function getAnswerSets()
-	 * @param type $uid : The ResultSet uid for which the answerSets should be retrieved.
-	 */
-	private static function getAnswerSets($model, $uid)
-	{
-		$result = $model->findRegex("[(".$uid.")]", "[(has_answerset)]" ,null);
-		$iterator = $result->getStatementIterator();
-		$answersets = array();
-		while($iterator->hasNext())
-		{
-			$element = $iterator->next();
-			$answersets[] = $element->getLabelObject();
-		}
-		return $answersets;
-	}
-
-    public static function create($obj) {
-        return new ResultSet($obj->uid, $obj->answersets, $obj->playerresults, 
-                $obj->groupresults, $obj->periodicresults);
-    }
-}
Index: Dev/branches/jos-branch/server/classes/models/Session.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/Session.php	(revision 287)
+++ Dev/branches/jos-branch/server/classes/models/Session.php	(revision 298)
@@ -48,5 +48,6 @@
 		if(is_string($this->creator))
 		{
-			$result = User::get(array("uid" => $this->creator));
+			$crea = ResearchToolObject::stripUri($this->creator);
+			$result = User::get(array("uid" => $crea["uid"]));
 			if(!isset($result[0]))
 				return false;
@@ -54,13 +55,18 @@
 		}
 		if(!empty($this->pipeline) && is_string($this->pipeline[0]))
-		{
+		{	
 			$newPipeline = array();
 			foreach($this->pipeline as $element)
 			{
-				//Check if the element's UID can be found in surveys, if not: 
-				//Check applications. If it isn't in either: invalid reference.
-				$result = Survey::get(array("uid" => $element));
-				if(!isset($result[0]))
-					$result = Application::get(array("uid" => $element));
+				$ele = ResearchToolObject::stripUri($element);
+				$result;
+				if($ele["type"] == "survey")
+				{
+					$result = Survey::get(array("uid" => $ele["uid"]));	
+				}
+				else if($ele["type"] == "application")
+				{
+					$result = Application::get(array("uid" => $ele["uid"]));
+				}
 				if(!isset($result[0]))
 					return false;
@@ -107,5 +113,5 @@
 		$model->add(new Statement($resourceSession, $predicateTitle, $sessionTitle));
 
-		$sessionCreator = new Literal($this->creator->uid);
+		$sessionCreator = new Resource(USER . '/' . $this->creator->uid);
 		$predicateCreator = new Resource(CREATOR);
 		$model->add(new Statement($resourceSession, $predicateCreator, $sessionCreator));
@@ -121,10 +127,16 @@
 			foreach($this->pipeline as $element)
 			{
-				$sessionObject = new Literal($element->uid);
+				$sessionObject = null;
 				$predicateObject = null;
 				if(get_class($element) == "Application")
+				{
+					$sessionObject = new Resource(APPLICATION . '/' . $element->uid);
 					$predicateObject = new Resource(HAS_APPLICATION);
+				}
 				else if(get_class($element) == "Survey")
+				{
+					$sessionObject = new Resource(SURVEY . '/' . $element->uid);
 					$predicateObject = new Resource(HAS_SURVEY);
+				}
 				if(isset($predicateObject))
 					$model->add(new Statement($resourceSession, $predicateObject, $sessionObject));
@@ -132,14 +144,4 @@
 		}
 
-		if(isset($this->answersets))
-		{
-			foreach($this->answersets as $answerset)
-			{
-				$sessionAnswerSet = new Literal($answerset->uid);
-				$predicateAnswerSet = new Resource(HAS_ANSWERSET);
-				$model->add(new Statement($resourceSession, $predicateAnswerSet, $sessionAnswerSet));
-			}
-		}
-		
 		return $model->saveAs(Session::$filename, 'rdf');
 	}
@@ -178,5 +180,5 @@
 				//Create a session object out of every result, get all required fields as well.
 				$pipeline = Session::getPipeline($model, $result['?uid']->label);
-				$creator = $result['?creator']->label;
+				$creator = $result['?creator']->uri;
 				$creationdate = new DateTime();
 				$creationdate->setTimestamp(intval($result['?creationdate']->label));
Index: Dev/branches/jos-branch/server/classes/models/SessionInstance.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/SessionInstance.php	(revision 287)
+++ Dev/branches/jos-branch/server/classes/models/SessionInstance.php	(revision 298)
@@ -22,5 +22,6 @@
 	public $notes;
 	public $session;
-	public $resultset;
+	public $surveyinstances;
+	public $applicationinstances;
 
 	/**
@@ -34,7 +35,8 @@
 	 * @param type $notes
 	 * @param type $session
-	 * @param type $resultset
-	 */
-	public function __construct($uid = null, $title = null, $location = null, $facilitator = null, $starttime = null, $endtime = null, $notes = null, $session = null, $resultset = null)
+	 * @param type $surveyinstances
+	 * @param type $applicationinstances
+	 */
+	public function __construct($uid = null, $title = null, $location = null, $facilitator = null, $starttime = null, $endtime = null, $notes = null, $session = null, $surveyinstances = null, $applicationinstances = null)
 	{
 		if(!isset($uid))
@@ -50,5 +52,6 @@
 		$this->notes = $notes;
 		$this->session = $session;
-		$this->resultset = $resultset;
+		$this->surveyinstances = $surveyinstances;
+		$this->applicationinstances = $applicationinstances;
 	}
 
@@ -61,5 +64,6 @@
 		if(is_string($this->facilitator))
 		{
-			$result = User::get(array("uid" => $this->facilitator));
+			$faci = ResearchToolObject::stripUri($this->facilitator);
+			$result = User::get(array("uid" => $faci["uid"]));
 			if(!isset($result[0]))
 				return false;
@@ -69,16 +73,36 @@
 		if(is_string($this->session))
 		{
-			$result = Session::get(array("uid" => $this->session));
+			$sess = ResearchToolObject::stripUri($this->session);
+			$result = Session::get(array("uid" => $sess["uid"]));
 			if(!isset($result[0]))
 				return false;
 			$this->session = $result[0]; 
 		}
-
-		if(is_string($this->resultset))
-		{
-			$result = ResultSet::get(array("uid" => $this->resultset));
-			if(!isset($result[0]))
-				return false;
-			$this->resultset = $result[0];
+		if(!empty($this->surveyinstances) && is_string($this->surveyinstances[0]))
+		{
+			$newSurveyInstances = array();
+			foreach($this->surveyinstances as $surveyInstance)
+			{
+				$sins = ResearchToolObject::stripUri($surveyInstance);
+				$result = SurveyInstance::get(array("uid" => $sins["uid"]));
+				if(!isset($result[0]))
+					return false;
+				$newSurveyInstances[] = $result[0];
+			}
+			$this->surveyinstances = $newSurveyInstances;
+		}
+
+		if(!empty($this->applicationinstances) && is_string($this->applicationinstances[0]))
+		{
+			$newApplicationInstances = array();
+			foreach($this->applicationinstances as $applicationInstance)
+			{
+				$ains = ResearchToolObject::stripUri($applicationInstance);
+				$result = ApplicationInstance::get(array("uid" => $ains["uid"]));
+				if(!isset($result[0]))
+					return false;
+				$newApplicationInstances[] = $result[0];
+			}
+			$this->applicationinstances = $newApplicationInstances;
 		}
 		return true;
@@ -124,5 +148,5 @@
 		$model->add(new Statement($resourceSInstance, $predicateLocation, $sInstanceLocation));
 
-		$sInstanceFacilitator = new Literal($this->facilitator->uid);
+		$sInstanceFacilitator = new Resource(USER . '/' . $this->facilitator->uid);
 		$predicateFacilitator = new Resource(FACILITATOR);
 		$model->add(new Statement($resourceSInstance, $predicateFacilitator, $sInstanceFacilitator));
@@ -146,15 +170,28 @@
 		}
 
-		$sInstanceSession = new Literal($this->session->uid);
+		$sInstanceSession = new Resource(SESSION . '/' . $this->session->uid);
 		$predicateSession = new Resource(OF_SESSION);
 		$model->add(new Statement($resourceSInstance, $predicateSession, $sInstanceSession));
 
-		if(isset($this->resultset))
-		{
-			//$sInstanceResultSet = new Literal($this->resultset->uid);
-			$sInstanceResultSet = new Literal($this->resultset);
-			$predicateResultSet = new Resource(HAS_RESULTSET);
-			$model->add(new Statement($resourceSInstance, $predicateResultSet, $sInstanceResultSet));
-		}
+		if(isset($this->surveyinstances))
+		{
+			foreach($this->surveyinstances as $surveyinstance)
+			{
+				$sInstanceSurveyInstance = new Resource(SURVEYINSTANCE . '/' . $surveyinstance->uid);
+				$predicateSurveyInstance = new Resource(HAS_SURVEYINSTANCE);
+				$model->add(new Statement($resourceSInstance, $predicateSurveyInstance, $sInstanceSurveyInstance));
+			}
+		}
+
+		if(isset($this->applicationinstances))
+		{
+			foreach($this->applicationinstances as $applicationinstance)
+			{
+				$sInstanceAppInstance = new Resource(APPLICATIONINSTANCE . '/' . $applicationinstance->uid);
+				$predicateAppInstance = new Resource(HAS_APPLICATIONINSTANCE);
+				$model->add(new Statement($resourceSInstance, $predicateAppInstance, $sInstanceAppInstance));
+			}
+		}
+
 		$model->saveAs(SessionInstance::$filename, 'rdf');
 		return true;
@@ -164,5 +201,5 @@
 	 * function get()
 	 * @param type $arguments : An array containing one or more of the following elements:
-	 * 'uid', 'title', 'location', 'facilitator', 'starttime', 'endtime' 'notes', 'session', 'resultset'
+	 * 'uid', 'title', 'location', 'facilitator', 'starttime', 'endtime' 'notes', 'session', 'applicationinstances', 'surveyinstances'
 	 */
 	public static function get($arguments)
@@ -174,5 +211,5 @@
 			PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
 			PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
-			SELECT DISTINCT ?uid, ?title, ?location, ?facilitator, ?starttime, ?endtime, ?of_session, ?has_resultset 
+			SELECT DISTINCT ?uid, ?title, ?location, ?facilitator, ?starttime, ?endtime, ?of_session
 			WHERE
 			{
@@ -185,5 +222,4 @@
 				predicates:endtime ?endtime ;
 				predicates:of_session ?of_session ;
-				predicates:has_resultset ?has_resultset ;
 				' . ResearchToolObject::createArguments($arguments) . '
 	}';
@@ -196,5 +232,5 @@
 			{
 				//Create a SessionInstance object out of every result. Get all the required fields as well.
-				$notes = SessionInstance::getNotes($model, $result['?uid']->label);
+				$fields = SessionInstance::getFields($model, $result['?uid']->label);
 				$resultset = isset($result['?has_resultset']) ? $result['?has_resultset']->label : null;
 				$starttime = new DateTime();
@@ -206,10 +242,11 @@
 					$result['?title']->label,
 					$result['?location']->label,
-					$result['?facilitator']->label,
+					$result['?facilitator']->uri,
 					$starttime,
 					$endtime,
-					$notes,
-					$result['?of_session'],
-					$resultset
+					$fields[0],
+					$result['?of_session']->uri,
+					$fields[1],
+					$fields[2]
 				);
 			}
@@ -219,18 +256,26 @@
 	
 	/**
-	 * function getNotes()
-	 * param type $uid : The SessionInstance uid for which the notes should be retrieved.
-	 */
-	public static function getNotes($model, $uid)
-	{
-		$result = $model->findRegex("[(".$uid.")]", "[(has_note)]", null);
+	 * function getFields()
+	 * param type $uid : The SessionInstance uid for which the fields should be retrieved.
+	 * returns : An array with [0] => all notes, [1] => all SurveyInstances and [2] => all ApplicationInstances.
+	 */
+	public static function getFields($model, $uid)
+	{
+		$result = $model->findRegex("[(".$uid.")]", "[(has_note)|(has_applicationinstance)|(has_surveyinstance)]", null);
 		$iterator = $result->getStatementIterator();
 		$notes = array();
+		$applicationinstances = array();
+		$surveyinstances = array();
 		while($iterator->hasNext())
 		{
 			$element = $iterator->next();
-			$notes[] = $element->getLabelObject();
-		}
-		return $notes;
+			if($element->getLabelPredicate() == HAS_NOTE)
+				$notes[] = $element->getLabelObject();
+			else if($element->getLabelPredicate() == HAS_APPLICATIONINSTANCE)
+				$applicationinstances[] = $element->getLabelObject();
+			else if($element->getLabelPredicate() == HAS_SURVEYINSTANCE)
+				$surveyinstances[] = $element->getLabelObject();
+		}
+		return array($notes, $surveyinstances, $applicationinstances);
 	}
 
Index: Dev/branches/jos-branch/server/classes/models/Survey.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/Survey.php	(revision 287)
+++ Dev/branches/jos-branch/server/classes/models/Survey.php	(revision 298)
@@ -32,7 +32,9 @@
 	public function evaluate()
 	{
+
 		if(is_string($this->creator))
 		{
-			$result = User::get(array("uid" => $this->creator));	
+			$crea = ResearchToolObject::stripUri($this->creator);
+			$result = User::get(array("uid" => $crea["uid"]));	
 			if(!isset($result[0]))
 				return false;
@@ -45,5 +47,6 @@
 			foreach($this->questions as $question)
 			{
-				$result = Question::get(array("code" => $question));
+				$ques = ResearchToolObject::stripUri($question);
+				$result = Question::get(array("uid" => $ques["uid"]));
 				if(!isset($result[0]))
 					return false;
@@ -93,5 +96,5 @@
         
 		$predicateCreator = new Resource(CREATOR);
-		$surveyCreator = new Literal($this->creator->uid);
+		$surveyCreator = new Resource(USER . '/' . $this->creator->uid);
 		$model->add(new Statement($resourceSurvey, $predicateCreator, $surveyCreator));
 
@@ -100,5 +103,5 @@
             foreach($this->questions as $question)
             {
-                $questionUid = new Literal($question->uid);
+				$questionUid = new Resource(QUESTION . '/' . $question->uid);
                 $predicateQuid = new Resource(HAS_QUESTION);
                 $model->add(new Statement($resourceSurvey,$predicateQuid,$questionUid));
@@ -145,5 +148,5 @@
             {
 				$questions = Survey::getQuestions($model, $result['?uid']->label);
-				$creator = $result['?creator']->label;
+				$creator = $result['?creator']->uri;
                 $surveys[] = new Survey($result['?uid']->label, $result['?title']->label, $result['?description']->label, $creator, $questions);
             }
Index: Dev/branches/jos-branch/server/classes/models/SurveyInstance.php
===================================================================
--- Dev/branches/jos-branch/server/classes/models/SurveyInstance.php	(revision 287)
+++ Dev/branches/jos-branch/server/classes/models/SurveyInstance.php	(revision 298)
@@ -26,5 +26,5 @@
      * @param type $answersets: A list of answersets.
      */
-	public function __construct($uid = null, $survey = null, $starttime = null, $endtime = null, $open = null, $presetanswers = null, $answersets = null)
+	public function __construct($uid = null, $survey = null, $starttime = null, $endtime = null, $open = 0, $presetanswers = null, $answersets = null)
     {
         if(!isset($uid))
@@ -37,5 +37,5 @@
         $this->starttime = $starttime;
         $this->endtime = $endtime;
-        $this->open = $open;
+		$this->open = $open;
         $this->presetanswers = $presetanswers;
         $this->answersets = $answersets;
@@ -51,5 +51,6 @@
         if(is_string($this->survey))
         {
-            $result = Survey::get(array("uid" => $this->survey));
+			$surv = ResearchToolObject::stripUri($this->survey);
+            $result = Survey::get(array("uid" => $surv["uid"]));
             if(!isset($result[0]))
             {
@@ -65,5 +66,6 @@
                 foreach($this->presetanswers as $answer)
                 {
-                        $result = Answer::get(array("uid" => $answer));
+						$ans = ResearchToolObject::stripUri($answer);
+                        $result = Answer::get(array("uid" => $ans["uid"]));
                         if(!isset($result[0]))
                                 return false;
@@ -79,5 +81,6 @@
                 foreach($this->answersets as $answerSet)
                 {
-                        $result = AnswerSet::get(array("uid" => $answerSet));
+						$aset = ResearchToolObject::stripUri($answerSet);
+                        $result = AnswerSet::get(array("uid" => $aset["uid"]));
                         if(!isset($result[0]))
                         {
@@ -132,6 +135,5 @@
         $predicateEndTime = new Resource(ENDTIME);
         $model->add(new Statement($resourceSI, $predicateEndTime, $SIEndTime));
-
-        $SIOpen = new Literal($this->open);
+        $SIOpen = new Literal((bool) $this->open);
         $predicateOpen = new Resource(OPEN);
         $model->add(new Statement($resourceSI, $predicateOpen, $SIOpen));
@@ -141,5 +143,5 @@
                 foreach($this->presetanswers as $answer)
                 {
-                        $answerId = new Literal($answer->uid);
+                        $answerId = new Resource(ANSWER . '/' . $answer->uid);
                         $predicateAnswer = new Resource(PRESET_ANSWER);
                         $model->add(new Statement($resourceSI, $predicateAnswer, $answerId));
@@ -151,5 +153,5 @@
                 foreach($this->answersets as $answer)
                 {
-                        $answerSetId = new Literal($answer->uid);
+                        $answerSetId = new Resource(ANSWERSET . '/' . $answer->uid);
                         $predicateAnswerSet = new Resource(HAS_ANSWERSET);
                         $model->add(new Statement($resourceSI, $predicateAnswerSet, $answerSetId));
@@ -163,5 +165,5 @@
 	* Gets the array of SurveyInstance objects belonging tothe arguments supplied.
 	* @param type $arguments: An array containing zero or more of the following keys:
-	* 						  'uid', 'of_survey', 'starttime', 'endtime', 'open', 'preset_answers', 'has_answerset'
+	* 						  'uid', 'of_survey', 'starttime', 'endtime', 'open', 'preset_answers', 'answersets'
 	*/
 	public static function get($arguments)
@@ -195,10 +197,7 @@
 				$endTime = new DateTime();
 				$endTime->setTimestamp(intval($result['?endtime']->label));
-				$open = false;
-				if ($result['?open'] == 'true')
-					$open = true;
-				$presetAnswers = SurveyInstance::getPresetAnswers($model, $result['?uid']->label);
-				$answerSets = SurveyInstance::getAnswerSets($model, $result['?uid']->label);
-				$sInstances[] = new SurveyInstance($result['?uid']->label, $result['?of_survey']->uri, $startTime, $endTime, $open, $presetAnswers, $answerSets);
+				$open = (bool) $result['?open'];
+				$fields = SurveyInstance::getFields($model, $result['?uid']->label);
+				$sInstances[] = new SurveyInstance($result['?uid']->label, $result['?of_survey']->uri, $startTime, $endTime, $open, $fields[0], $fields[1]);
 			}
 		}
@@ -207,37 +206,24 @@
 
 	/**
-	 * function getPresetAnswers()
+	 * function getFields()
 	 * @param type $model : The RDF model to query against.
-	 * @param type $uid : The UID of the SurveyInstance for which the preset answers should be retrieved.
+	 * @param type $uid : The UID of the SurveyInstance for which the preset answers and answersets should be retrieved.
+	 * returns : an array with [0] => all preset answers and [1] => all answersets.
 	 */
-	private static function getPresetAnswers($model, $uid)
+	private static function getFields($model, $uid)
 	{
-		$result = $model->findRegex("[(".$uid.")]", "[(preset_answer)]", null);
+		$result = $model->findRegex("[(".$uid.")]", "[(preset_answer)|(has_answerset)]", null);
 		$iterator = $result->getStatementIterator();
 		$answers = array();
+		$sets = array();
 		while($iterator->hasNext())
 		{
 			$element = $iterator->next();
-			$answers[] = $element->getLabelObject();
+			if($element->getLabelPredicate() == PRESET_ANSWER)
+				$answers[] = $element->getLabelObject();
+			else if($element->getLabelPredicate() == HAS_ANSWERSET)
+				$sets[] = $element->getLabelObject();
 		}
-		return $answers;
-	}
-
-	/**
-	 * function getAnswerSets()
-	 * @param type $model : The RDF model to query against.
-	 * @param type $uid : The UID of the SurveyInstance for which the preset answers should be retrieved.
-	 */
-	private static function getAnswerSets($model, $uid)
-	{
-		$result = $model->findRegex("[(".$uid.")]", "[(has_answerset)]", null);
-		$iterator = $result->getStatementIterator();
-		$answersets = array();
-		while($iterator->hasNext())
-		{
-			$element = $iterator->next();
-			$answersets[] = $element->getLabelObject();
-		}
-		return $answersets;
+		return array($answers, $sets);
 	}
 
