Commit 6207348c authored by Patrick's avatar Patrick

Transform all internal store calls (except file SDS calls themselves) to SDS usage

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/tags/StoreToSds@2246 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent 4d99571f
......@@ -17,6 +17,11 @@ from FilePath import :: FilePath
*/
sharedStore :: !String !a -> Shared a | JSONEncode{|*|}, JSONDecode{|*|}, TC a
/*
* Creates a reference to a store identified by a string identifier and namespace identifier.
*/
sharedStoreNS :: !String !String !a -> Shared a | JSONEncode {|*|}, JSONDecode{|*|}, TC a
//PREDEFINED SHARES
// Date & time
......
......@@ -7,22 +7,32 @@ from StdFunc import o, seq
from IWorld import :: IWorld(..)
from Util import qualified currentDate, currentTime, currentDateTime, currentTimestamp, dateToTimestamp
import Shared
from SystemData import sharedStoreNS
from SharedDataSource import write, read
SYSTEM_DATA_NS :== "SystemData"
APP_DATA_NS :== "ApplicationData"
sharedStore :: !String !a -> Shared a | JSONEncode{|*|}, JSONDecode{|*|}, TC a
sharedStore storeId defaultV = createChangeOnWriteSDS
"sharedStore" storeId
sharedStore storeId defaultV = sharedStoreNS APP_DATA_NS storeId defaultV
sharedStoreNS :: !String !String !a -> Shared a | JSONEncode{|*|}, JSONDecode{|*|}, TC a
sharedStoreNS namespace storeId defaultV = createChangeOnWriteSDS
"sharedStore" absoluteStoreId
(get (loadValue NS_APPLICATION_SHARES) defaultV)
write
where
get f defaultV iworld
# (mbV,iworld) = f storeId iworld
# (mbV,iworld) = f absoluteStoreId iworld
# res = case mbV of
Nothing = Ok defaultV
Just v = Ok v
= (res,iworld)
write v iworld = (Ok Void,storeValue NS_APPLICATION_SHARES storeId v iworld)
write v iworld = (Ok Void,storeValue NS_APPLICATION_SHARES absoluteStoreId v iworld)
absoluteStoreId = namespace +++ "-" +++ storeId
currentDateTime :: ReadOnlyShared DateTime
currentDateTime = createReadOnlySDSPredictable SYSTEM_DATA_NS "currentDateTime" read
......@@ -52,25 +62,25 @@ where
// Workflow processes
topLevelTasks :: SharedTaskList Void
topLevelTasks = createReadOnlySDS read
topLevelTasks = createReadOnlySDS read`
where
read iworld
# (list, iworld) = loadValue NS_TASK_INSTANCES "persistent-index" iworld
= ({TaskList|listId = TopLevelTaskList, items = fromMaybe [] list}, iworld)
read` iworld
# (list, iworld) = read (sharedStoreNS NS_TASK_INSTANCES "persistent-index" Nothing) iworld
= ({TaskList|listId = TopLevelTaskList, items = fromMaybe [] (fromOk list)}, iworld)
currentProcesses ::ReadOnlyShared [TaskListItem Void]
currentProcesses = createReadOnlySDS read
currentProcesses = createReadOnlySDS read`
where
read iworld
# (list, iworld) = loadValue NS_TASK_INSTANCES "persistent-index" iworld
= (fromMaybe [] list, iworld)
read` iworld
# (list, iworld) = read (sharedStoreNS NS_TASK_INSTANCES "persistent-index" Nothing) iworld
= (fromMaybe [] (fromOk list), iworld)
processesForCurrentUser :: ReadOnlyShared [TaskListItem Void]
processesForCurrentUser = createReadOnlySDS read
processesForCurrentUser = createReadOnlySDS read`
where
read iworld=:{currentUser}
# (list, iworld) = loadValue NS_TASK_INSTANCES "persistent-index" iworld
= (maybe [] (\l -> [ p \\ p <- l | forWorker currentUser p]) list, iworld)
read` iworld=:{currentUser}
# (list, iworld) = read (sharedStoreNS NS_TASK_INSTANCES "persistent-index" Nothing) iworld
= (maybe [] (\l -> [ p \\ p <- l | forWorker currentUser p]) (fromOk list), iworld)
forWorker user {managementMeta=Just {ManagementMeta|worker=AnyUser}} = True
forWorker (AuthenticatedUser uid1 _ _) {managementMeta=Just {ManagementMeta|worker=UserWithId uid2}} = uid1 == uid2
......
......@@ -10,6 +10,8 @@ from TaskState import :: TaskListEntry
from JSON_NG import :: JSONNode
from StdFile import class FileSystem
from SharedDataSource import class registerSDSDependency, class registerSDSChangeDetection, class reportSDSChange, :: CheckRes(..), :: BasicShareId, :: Hash
import Void
import iTaskClass
:: *IWorld = { application :: !String // The name of the application
, build :: !String // The date/time identifier of the application's build
......@@ -49,6 +51,7 @@ instance FileSystem IWorld
instance registerSDSDependency InstanceNo IWorld
instance registerSDSChangeDetection IWorld
instance reportSDSChange InstanceNo IWorld
instance reportSDSChange Void IWorld
//Sync work queue to disk (Only used with CGI wrapper)
saveWorkQueue :: !*IWorld -> *IWorld
......
......@@ -15,6 +15,10 @@ from SharedDataSource import class registerSDSDependency, class registerSDSChang
import TaskStore, Time, Util, StdList, Base64, _SystemArray, StdBool, StdTuple
import SerializationGraphCopy //TODO: Make switchable from within iTasks module
import Shared
from SystemData import sharedStoreNS
from SharedDataSource import write, read
updateCurrentDateTime :: !*IWorld -> *IWorld
updateCurrentDateTime iworld=:{IWorld|world}
# (dt,world) = currentDateTimeWorld world
......@@ -99,6 +103,12 @@ instance reportSDSChange InstanceNo IWorld
where
reportSDSChange shareId filterFun iworld
= addOutdatedOnShareChange shareId filterFun iworld
//TODO: Look into this, this is required for the write function to be usable??
instance reportSDSChange Void IWorld
where
reportSDSChange shareId filterFun iworld
= addOutdatedOnShareChange shareId (\_ -> False) iworld
// serialise Work as dynamic since it contains functions on unique states
JSONEncode{|Work|} work = [JSONArray [JSONString "_FUNCTION_", JSONString (base64URLEncode (serialize work))]]
......@@ -107,9 +117,10 @@ JSONDecode{|Work|} [JSONArray [JSONString "_FUNCTION_",JSONString string]:c] = (
WORKQUEUE_INDEX :== "workqueue-index"
saveWorkQueue :: !*IWorld -> *IWorld
saveWorkQueue iworld=:{workQueue} = storeValue NS_TASK_INSTANCES WORKQUEUE_INDEX workQueue iworld
saveWorkQueue iworld=:{workQueue} = snd (write workQueue (sharedStoreNS NS_TASK_INSTANCES WORKQUEUE_INDEX []) iworld)
restoreWorkQueue :: !*IWorld -> *IWorld
restoreWorkQueue iworld
# (mbWorkQueue,iworld) = loadValue NS_TASK_INSTANCES WORKQUEUE_INDEX iworld
= {iworld & workQueue = fromMaybe [] mbWorkQueue}
\ No newline at end of file
= case (read (sharedStoreNS NS_TASK_INSTANCES WORKQUEUE_INDEX Nothing) iworld) of
(Ok (Just queue), iworld) = {iworld & workQueue = queue}
(_,iworld) = {iworld & workQueue = []}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment