definition:
|
entity2Tuple :: ViewGenerator
entity2Tuple erdname (Entity entityName attrlist) relationships allEntities =
let
manyToManyEntities = manyToMany allEntities (Entity entityName attrlist)
manyToOneEntities = manyToOne (Entity entityName attrlist) relationships
in
stCmtFunc
("Transformation from entity type "++entityName++" to a tuple\n"++
"which can be used in WUI specifications.")
(viewModuleName entityName, (lowerFirst entityName)++"2Tuple") 2 Public
(
foldr (CFuncType)
(entityInterface (filter notKey attrlist)
manyToOneEntities manyToManyEntities)
(
(map ctvar manyToOneEntities) ++
[(if null manyToManyEntities
then baseType (model erdname, entityName)
else tupleType
([ctvar entityName] ++
map (\ (name,_) -> listType (ctvar name))
manyToManyEntities)
)]
)
)
[simpleRule
(
(map (\ (name, varId) -> CPVar(varId,(lowerFirst name)))
(zip manyToOneEntities [1..])) ++
[
tuplePattern
(
CPVar (1, lowerFirst entityName) :
(map (\ ((ename,erel), varId) ->
CPVar (varId, lowerFirst $ erel ++ ename ++ "s"))
(zip manyToManyEntities [1..]))
)
]
)
(tupleExpr
(map (\ (Attribute a _ _ _) ->
applyF (model erdname, lowerFirst entityName ++ a)
[cvar (lowerFirst entityName)])
(filter notKey attrlist) ++
map (\e -> cvar (lowerFirst e)) manyToOneEntities ++
map (\ (ename,erel) -> cvar (lowerFirst $ erel ++ ename ++ "s"))
manyToManyEntities)
)]
|