note
	description: "Summary description for {NEO4J_DATABASE}."
	author: ""
	date: "$Date$"
	revision: "$Revision$"

class
	NEO4J_DATABASE

create
	make

feature {NONE}
--	get_session : HTTP_CLIENT_SESSION
--	local
--		cl: DEFAULT_HTTP_CLIENT
--		sess: HTTP_CLIENT_SESSION
--		ctx: HTTP_CLIENT_REQUEST_CONTEXT

--	do
--		create cl
--		sess := cl.new_session ("http://localhost:7474")
--		sess.set_credentials ("neo4j", "m3riMcCgXvGNJsGGnyE0")
--	    sess.add_header("Content-Type", "application/json")
--	    sess.add_header("Accept", "application/json;charset=UTF-8")

--		create ctx.make_with_credentials_required
--		ctx.add_header ("Content-Type", "application/json")
--		ctx.add_header ("Accept", "application/json;charset=UTF-8")
--		Result := sess
--	end


		make (url : STRING)
		do
			db_url := url
		end


		db_url : STRING

		send_command_to_database ( neo4j_command : STRING) : STRING
		local
			cl: DEFAULT_HTTP_CLIENT
			sess: HTTP_CLIENT_SESSION
			ctx: HTTP_CLIENT_REQUEST_CONTEXT

		do
			Result :=""


				-- GET REQUEST WITH AUTHENTICATION, see http://browserspy.dk/password.php
				-- check header WWW-Authenticate is received (authentication successful)
			create cl
			sess := cl.new_session (db_url)
			sess.set_credentials ("neo4j", "m3riMcCgXvGNJsGGnyE0")
		    sess.add_header("Content-Type", "application/json")
		    sess.add_header("Accept", "application/json;charset=UTF-8")

			create ctx.make_with_credentials_required
			ctx.add_header ("Content-Type", "application/json")
			ctx.add_header ("Accept", "application/json;charset=UTF-8")
			ctx.set_upload_data (neo4j_command)
			if attached sess.get ("/db/data/transaction/commit", ctx) as res then
				if attached {READABLE_STRING_8} res.body as l_body then
					if l_body.has_substring ("%"errors%":[]" ) then
						Result := l_body
					end
				end
			end
		end


feature {NEO4J_DATABASE_UTILITY_TEST_SET}
		escape_characters ( in :STRING) : STRING  -- Note: Escape sequences from this page, heading "2.3.2 Note on string literals", in the neo4j documentation: https://neo4j.com/docs/cypher-manual/current/syntax/expressions/
												  -- Note: Eiffel escape sequeces are described at this page: https://www.eiffel.org/doc/eiffel/Eiffel_programming_language_syntax

		local
			res : STRING
			escape_ch_found : BOOLEAN
		do
			create res.make (in.count)
			across in as ch  loop
				if not escape_ch_found and ch.item.is_equal ('\') then
					escape_ch_found := true
				else
					if escape_ch_found then
						escape_ch_found := false
						if ch.item.is_equal ('n') or ch.item.is_equal ('t') then
							res.append_character ('\')
							res.append_character (ch.item)
						elseif  ch.item.is_equal ('%"') then
							res.append_character ('\')
							res.append_character ('\')
							res.append_character ('\')
							res.append_character (ch.item)
						elseif ch.item.is_equal ('\') then
							res.append_character ('\')
							res.append_character ('\')
							res.append_character ('\')
							res.append_character ('\')
						else
							res.append_character ('\')
							res.append_character ('\')
							res.append_character (ch.item)
						end
					else
						if ch.item.is_equal ('%'') then -- Since JSON concider ' as a normal character it does not need to be escaped but I need to escape it in the Cypher, but \ is an escape character so I need to escape the \ with another \
							res.append_character ('\')
							res.append_character ('\')
							res.append_character (ch.item)
						else
							res.append_character (ch.item)
						end
					end
				end
			end
			if escape_ch_found then -- Lat character in "in" was a \
				res.append_character ('\')
				res.append_character ('\')

			end
			Result := res
		end


feature
-- TODO Maybe I should call this within this class so that I return data that do not need to call this
		replace_escaped_characters ( in :STRING) : STRING  -- Note: Escape sequences from this page, heading "2.3.2 Note on string literals", in the neo4j documentation: https://neo4j.com/docs/cypher-manual/current/syntax/expressions/
		local
			newline: STRING
			tab : STRING
			escape_ch_found : BOOLEAN
			res : STRING
		do
			create res.make (in.count)
			across in as ch  loop
				if not escape_ch_found and ch.item.is_equal ('\') then
					escape_ch_found := true
				else
					if escape_ch_found then
						escape_ch_found := false
						if ch.item.is_equal ('n') then
							res.append_code (10)
						elseif ch.item.is_equal ('t') then
							res.append_code (9)
						elseif ch.item.is_equal ('%'') then
							res.append_character (ch.item)
						elseif ch.item.is_equal ('\') then
							res.append_character (ch.item)
						elseif ch.item.is_equal ('%"') then
							res.append_character (ch.item)
						else -- We do not know what kind of escape sequence that we got so we just forward it. Also the \ can be just forwarded
							res.append_character ('\')
							res.append_character (ch.item)
						end

					else -- Normal character
						res.append_character (ch.item)
					end
				end
			end

			Result := res
		end






		create_task ( user:STRING; summary : STRING; UID : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MERGE (n:TASK" + " {user: '" + user +  "',created: '" + current_date + "T" + current_time +  "',summary: '" + escape_characters ( summary ) + "', notes: '"+ ""  + "', status: '"+ "created" + "', UID: '" + UID + "' } " +     ") RETURN id(n)%"  } ]}")
		end


		create_task_with_creation_date ( user:STRING; summary : STRING; UID : STRING; creation_date : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MERGE (n:TASK" + " {user: '" + user +  "',created: '" + creation_date +  "',summary: '" + escape_characters ( summary ) + "', notes: '"+ ""  + "', status: '"+ "created" + "', UID: '" + UID + "' } " +     ") RETURN id(n)%"  } ]}")
		end

		list_all_tasks ( user : STRING) : STRING
		do
			Result :=  send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (n:TASK" + " {user: '" + user + "' }) where (NOT n.status = 'deleted' ) RETURN n.UID, n.summary, n.status, n.startdate, n.enddate, n.notes%"  } ]}")
		end

		list_all_tasks_search_summary ( user : STRING; search_for : STRING) : STRING
		do
			Result :=  send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (n:TASK" + " {user: '" + user + "' }) where n.summary CONTAINS '" + search_for + "' AND (NOT n.status = 'deleted' ) RETURN n.UID, n.summary, n.status, n.startdate, n.enddate, n.notes%"  } ]}")
		end

		list_tasks_without_project (user : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (t:TASK" + " {user: '" + user + "' } ) WHERE NOT  ((:PROJECT ) -[*1..4]-> (t)) AND (NOT t.status = 'deleted' ) RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes%"  } ]}")
		end

		edit_task (UID: STRING) : STRING -- TODO. Might rename this to get_task_information or something similar. From the start it was only used when preparing for editing but it can be used for other prurposes also.
		do
			Result:= send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (n:TASK" + " {UID: '" + UID + "' }) RETURN n.UID, n.status, n.summary, n.startdate, n.enddate, n.notes%"  } ]}")
		end

		get_subtasks (UID: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (n:TASK" + " {UID: '" + UID + "' })-[INCLUDES]->(sub:TASK) RETURN sub.UID, sub.status, sub.summary, sub.startdate, sub.enddate, sub.notes%"  } ]}")
		end

		get_parent_task ( UID: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (n:TASK" + " {UID: '" + UID + "' })<-[INCLUDES]-(parent:TASK) RETURN parent.UID, parent.status, parent.summary, parent.startdate, parent.enddate, parent.notes%"  } ]}")
		end

		get_projects_that_refers_to_the_task  ( user : STRING; UID: STRING) : STRING
		do
			-- TODO Do we really need to have the user? Since projects that refers to this task can not be defined in any other users space. At least until we develop for several users.
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (t:TASK  {UID: '" + UID + "' }  ) <-- (p:PROJECT " + " {user: '" + user + "' } )  RETURN p.UID%"  } ]}")
		end

		update_task (task : TASK_DATA)
		local
			database_response : STRING
		do
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (x:TASK" + " {UID: '" + task.uid + "' }) set x.summary = '" + escape_characters ( task.summary) + "' set x.startdate = '" + task.startdate + "' set x.enddate = '" + task.enddate +  "' set x.notes = '" + escape_characters ( task.notes) + "' return x%"  } ]}")
		end


		get_inbox_according_to_filter_no_start_date_set ( User : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) --> (n:STATUS  {user: '" + user + "' } )  MATCH (t:TASK {user: '" + user + "' , status : n.status } ) WHERE NOT  ((:PROJECT ) -[*1..4]-> (t))  AND ( t.startdate = '' OR t.startdate is null)   RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes, 'inbox'%"  } ]}")
		end


		get_inbox_according_to_filter_date_filter_not_set( User : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) --> (n:STATUS  {user: '" + user + "' } )  MATCH (t:TASK {user: '" + user + "' , status : n.status } ) WHERE NOT  ((:PROJECT ) -[*1..4]-> (t)) RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes, 'inbox'%"  } ]}")
		end


		get_inbox_according_to_filter_date_filter_set( User : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) --> (n:STATUS  {user: '" + user + "' } )  MATCH (t:TASK {user: '" + user + "' , status : n.status } ) WHERE (NOT  ((:PROJECT ) -[*1..4]-> (t))) and ( t.startdate <= f.startdate)  AND ( NOT t.startdate = '' AND NOT t.startdate is null)  RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes, 'inbox'%"  } ]}")
--																							  MATCH (f:FILTER  {user: '            ' }  ) --> (n:STATUS  {user: ' date_filter' } )  MATCH (t:TASK {user: 'UnitTestUser' , status : n.status } ) WHERE (NOT  ((:PROJECT ) -[*1..4]-> (t))) and ( t.startdate <= f.startdate)  AND ( NOT t.startdate = '' AND NOT t.startdate is null)  RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes, 'inbox'
		end



-- TODO These two are very similar. Write one and update the code using them instead.
--		get_filter_start_date_and_if_inbox_is_included (user: STRING) : STRING
--		do
--			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) RETURN f.startdate, f.inbox%"  } ]}")
--		end

		get_filter_if_inbox_is_included (user: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) RETURN f.inbox %"  } ]}")
		end

--		date_filter (user : STRING) : STRING
--		do
--			Result:= send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) RETURN f.startdate, f.enddate, f.nostartdate, f.noenddate %"  } ]}")
--		end


-- TODO This to replace the three above		
		get_filter_information (user: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) RETURN f.startdate, f.enddate, f.nostartdate, f.noenddate, f.inbox%"  } ]}")
		end


		get_filter_projects_included (user: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) --> (p:PROJECT " + " {user: '" + user + "' } )  RETURN p.UID%"  } ]}")
		end


-- TODO Merege the below to one method.
		get_tasks_with_current_filter_but_start_date_set ( user : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) --> (n:STATUS  {user: '" + user + "' } ) MATCH (f:FILTER  {user: '" + user + "' }  ) --> (p:PROJECT " + " {user: '" + user + "' } )  MATCH (proj:PROJECT {UID : p.UID})-->(t:TASK {status : n.status})  where (( t.startdate <= f.startdate)  AND ( NOT t.startdate = '' AND NOT t.startdate is null))     RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes, p.name, p.UID ORDER by p.name%"  } ]}")
		end

		get_tasks_with_current_filter_but_start_date_not_set ( user : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) --> (n:STATUS  {user: '" + user + "' } ) MATCH (f:FILTER  {user: '" + user + "' }  ) --> (p:PROJECT " + " {user: '" + user + "' } )  MATCH (proj:PROJECT {UID : p.UID})-->(t:TASK {status : n.status})   RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes, p.name, p.UID ORDER by p.name %"  } ]}")
		end


		get_tasks_with_current_filter_with_no_start_date_set ( user : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) --> (n:STATUS  {user: '" + user + "' } ) MATCH (f:FILTER  {user: '" + user + "' }  ) --> (p:PROJECT " + " {user: '" + user + "' } )  MATCH (proj:PROJECT {UID : p.UID})-->(t:TASK {status : n.status})  WHERE ( t.startdate = '' OR t.startdate is null) RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes, p.name, p.UID ORDER by p.name %"  } ]}")
		end


		get_tasks_within_a_specific_project_concidering_status_filter_only ( user : STRING; project_UID : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) --> (n:STATUS  {user: '" + user + "' } )   MATCH (proj:PROJECT {UID : '" + project_UID + "' })-->(t:TASK {status : n.status})   RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes  %"  } ]}")
		end





		create_project (User: STRING; project_name : STRING; uid: STRING)
		local
			database_response : STRING
		do
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MERGE (n:PROJECT" + " { user: '" + user +  "',name: '" + escape_characters ( project_name ) + "',  status: '"+ "created" + "', UID: '" + UID + "' } " +     ") RETURN id(n)%"  } ]}")
		end

		get_list_of_projects(user: STRING): STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (n:PROJECT " + " {user: '" + user + "' }) where (NOT n.status = 'deleted' )   RETURN n.UID, n.name, n.status%"  } ]}")
		end

		edit_project (UID : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (n:PROJECT" + " {UID: '" + UID + "' }) RETURN n.UID, n.name%"  } ]}")
		end

		update_project (project_name : STRING; uid: STRING)
		local
			database_response : STRING
		do
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (x:PROJECT" + " {UID: '" + uid + "' }) set x.name = '" + escape_characters ( project_name ) + "' return x%"  } ]}")
		end



		get_late_tasks(user: STRING) : STRING
		local
			late_date_time : STRING
			d: DATE
		do
			late_date_time := current_date + "T23:59"
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (t:TASK" + " {user: '" + user + "' } ) WHERE (t.enddate <> '' AND NOT (t.enddate IS NULL) AND t.enddate < '" + late_date_time + "'  AND (NOT t.status = 'deleted' )  AND (NOT t.status = 'done' )) RETURN t.UID, t.summary, t.status, t.startdate, t.enddate, t.notes, 'Late tasks'%"  } ]}")
		end

		current_date : STRING -- TODO. How to test this feature? Mockup the DATE class and have it as parameter, or use a class factory?
		local
			d: DATE
		do
			create d.make_now
			Result := d.year.out + "-"
			if d.month < 10 then
				Result := Result + "0"
			end
			Result := Result +  d.month.out + "-"
			if d.day < 10 then
				Result := Result + "0"
			end
			Result := Result + d.day.out
		end

		current_time : STRING -- TODO. How to test this feature? Mockup the TIME class and have it as parameter, or use a class factory?
		local
			t : TIME
		do
			create t.make_now
			Result := ""
			if t.hour < 10 then
				Result := Result + "0"
			end
			Result := Result +  t.hour.out + ":"
			if t.minute < 10 then
				Result := Result + "0"
			end
			Result := Result + t.minute.out
		end


feature -- Manage project and task relations

		connect_tasks ( task_uid : STRING; subtask_uid : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (my_task:TASK" + " {UID: '" + task_UID + "' }) MATCH (my_subtask:TASK" + " {UID: '" + subtask_UID + "' })" +     "merge  (my_task)-[:INCLUDES]->(my_subtask) RETURN my_subtask%"  } ]}")
		end

		connect_task_to_project (project_uid : STRING; task_uid : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (my_task:TASK" + " {UID: '" + task_UID + "' }) MATCH (my_project:PROJECT" + " {UID: '" + project_UID + "' })" +     "merge  (my_project)-[:INCLUDES]->(my_task) RETURN my_project%"  } ]}")
		end

		remove_connection_between_task_and_project (project_uid : STRING; task_uid : STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (my_task:TASK" + " {UID: '" + task_UID + "' }) MATCH (my_project:PROJECT" + " {UID: '" + project_UID + "' })" +     "MATCH  (my_project)-[i:INCLUDES]->(my_task) delete i%"  } ]}")
		end



feature -- filter


		set_filter_nostartdate( user: string) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER" + " {user: '" + user + "' }) set f.nostartdate = 'true' return f%"  } ]}")
		end

		unset_filter_nostartdate( user: string) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER" + " {user: '" + user + "' }) set f.nostartdate = 'false' return f%"  } ]}")
		end

		set_filter_noenddate( user: string) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER" + " {user: '" + user + "' }) set f.noenddate = 'true' return f%"  } ]}")
		end

		unset_filter_noenddate( user: string) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER" + " {user: '" + user + "' }) set f.noenddate = 'false' return f%"  } ]}")
		end



		status_filter (user : STRING) : STRING
		do
			Result:= send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER  {user: '" + user + "' }  ) --> (s:STATUS " + " {user: '" + user + "' } )  RETURN s.status%"  } ]}")
		end


		undo_task(uid: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (x:TASK" + " {UID: '" + uid + "' }) set x.status = 'working' return x%"  } ]}")
		end

		set_task_to_done(uid: STRING) : STRING
		do
			Result :=send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (x:TASK" + " {UID: '" + UID + "' }) set x.status = 'done' set x.donedate = '" + current_date + "T" + current_time  + "' return x%"  } ]}")
		end

--For  Wunderlist migration

		set_task_note(uid: STRING; notes: STRING) : STRING
		do
			Result :=send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (x:TASK" + " {UID: '" + UID + "' }) set x.notes = '" + escape_characters ( notes) + "' return x%"  } ]}")
		end


-- For WUnderlist migration
		set_task_to_done_with_completion_date(uid: STRING; completion_date : STRING) : STRING
		do
			Result :=send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (x:TASK" + " {UID: '" + UID + "' }) set x.status = 'done' set x.donedate = '" + completion_date  + "' return x%"  } ]}")
		end

		add_project_to_filter( user: STRING; uid: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (my_filter:FILTER" + " { user: '" + user +  "',name: '" + "default" + "' }) MATCH (my_project:PROJECT" + " {UID: '" + UID + "' })" +     "merge  (my_filter)-[:INCLUDES]->(my_project) RETURN my_project%"  } ]}")
		end


		remove_project_from_filter( user: STRING; uid: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (my_filter:FILTER" + " { user: '" + user +  "',name: '" + "default" + "' }) MATCH (my_project:PROJECT" + " {UID: '" + UID + "' })" +     "match  (my_filter)-[i:INCLUDES]->(my_project) delete i%"  } ]}")
		end

		add_status_to_filter( user: STRING; uid: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (my_filter:FILTER" + " { user: '" + user +  "',name: '" + "default" + "' }) MATCH (my_status:STATUS" + " { user: '" + user +  "',status: '" + UID + "' })" +     "merge  (my_filter)-[:INCLUDES]->(my_status) RETURN my_status%"  } ]}")
		end


		remove_status_from_filter( user: STRING; uid: STRING) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (my_filter:FILTER" + " { user: '" + user +  "',name: '" + "default" + "' }) MATCH (my_status:STATUS" + " { user: '" + user +  "',status: '" + UID + "' })" +     "match  (my_filter)-[i:INCLUDES]->(my_status) delete i%"  } ]}")
		end

		set_filter_inbox( user: string) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER" + " {user: '" + user + "' }) set f.inbox = 'true' return f%"  } ]}")
		end

		unset_filter_inbox( user: string) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER" + " {user: '" + user + "' }) set f.inbox = 'false' return f%"  } ]}")
		end

		set_filter_date (user : STRING; datefilter : FILTER_DATE_DATA ) : STRING
		do
			Result := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER" + " {user: '" + user + "' }) set f.startdate = '" + datefilter.startdate + "' set f.enddate = '" + datefilter.enddate + "' return f%"  } ]}")
		end


feature -- Delete


		set_project_deleted (UID: STRING)
		local
			database_response : STRING
		do
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (x:PROJECT" + " {UID: '" + UID + "' }) set x.status = 'deleted' return x%"  } ]}")
		end

		set_task_deleted (UID: STRING)
		local
			database_response : STRING
		do
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (x:TASK" + " {UID: '" + UID + "' }) set x.status = 'deleted' return x%"  } ]}")
		end

feature -- User

		add_user( user: STRING)
		local
			database_response : STRING
		do
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MERGE (n:USER" + " {user_name: '" + user + "' } " +  ") RETURN id(n)%"  } ]}")
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MERGE (n:STATUS" + " {user: '" + user + "',status: 'working' } " +  ") RETURN id(n)%"  } ]}")
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MERGE (n:STATUS" + " {user: '" + user + "',status: 'done' } " +  ") RETURN id(n)%"  } ]}")
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MERGE (n:STATUS" + " {user: '" + user + "',status: 'created' } " +  ") RETURN id(n)%"  } ]}")
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MERGE (n:STATUS" + " {user: '" + user + "',status: 'deleted' } " +  ") RETURN id(n)%"  } ]}")
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MERGE (n:FILTER" + " {user: '" + user + "',name: 'default', startdate: '', enddate: '', inbox: 'false', nostartdate: 'false', noenddate: 'false'  } " +  ") RETURN id(n)%"  } ]}")

		end

		remove_user( user: STRING) -- Used by unittesting
		local
			database_response : STRING
		do
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (f:FILTER {user: '" + user + "' })  delete f %"  } ]}")
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (s:STATUS" + " {user: '" + user + "' } " +  ") delete s %"  } ]}")
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (u:USER" + " {user_name: '" + user + "' } ) delete u %"  } ]}")

		end

feature -- Test features

		clean_db (user : STRING)
		local
			database_response : STRING
		do
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH  (p:PROJECT {user: '" + user +"' })-[r]->  (n:TASK {user: '" + user +"' }) delete r%"  } ]}")
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (n:TASK {user: '" + user +"' }) delete n%"  } ]}")
			database_response := send_command_to_database ("{  %"statements%" : [ {    %"statement%" : %"MATCH (n:PROJECT {user: '" + user +"' }) delete n%"  } ]}")
		end

end
