[Aimmath-commit] AIM/WEB-INF/maple/aim SOAP.mpl,NONE,1.1.2.1
Brought to you by:
gustav_delius,
npstrick
From: Neil S. <nps...@us...> - 2005-03-31 14:50:13
|
Update of /cvsroot/aimmath/AIM/WEB-INF/maple/aim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27982/maple/aim Added Files: Tag: aim-xml SOAP.mpl Log Message: --- NEW FILE: SOAP.mpl --- # Copyright (C) 2004 Neil Strickland # Distributed without warranty under the GPL - see README for details read("Package.mpl"): Package("aim/SOAP"," This package defines functions that handle various SOAP requests "): `Package/Assign`( `aim/RPC/CommandNamespace`, "", "http://aim.shef.ac.uk/AiMInfo" ): `Package/Assign`( `aim/RPC/Service`, "", `new/RPC/Service`( `aim/RPC/CommandNamespace`, "http://schemas.rqp.org/rqp" ) ): `Class/Declare`( `aim/RQP/ItemCache/Entry`, "", ['Field','Content'], ['Field','LastAccessTime'::`Date/RawDate` = 0], ['Constructor', "", proc(this,x_,date_::`Date/RawDate`) if nargs > 1 then this['Content'] := eval(x_); if nargs > 2 then this['LastAccessTime'] := date_; else this['LastAccessTime'] := `Date/CurrentRawDate`(); fi; fi; end ] ): `Class/Declare`( `aim/RQP/ItemCache`, "", ['Constructor', "", proc(this) this['Entries'] := table([]); end ], ['Field','Entries'::table], ['Method','GetEntry', "", proc(this,guid::string,seed_::integer) local i,x,e; e := eval(this['Entries']); i := args[2..-1]; if assigned(e[i]) then x := e[i]; x['LastAccessTime'] := `Date/CurrentRawDate`(); return(eval(x['Content'])); else return(NULL); fi; end ], ['Method','AddEntry'::'void', "", proc(this,x,guid::string,seed_::integer) local i,a; this['Entries'][args[3..-1]] := eval(`new/aim/RQP/ItemCache/Entry`(x)); NULL; end ] ): `aim/RPC/Service`['AddOperation', `aim/RPC/Hello`, "", ['Name',"Hello"], ['Output',"hello"::`XML/string`], ['Process', proc(inp,out) out["hello"] := "Hello, this is the AiM server"; end ] ]: `aim/RPC/Service`['AddOperation', `aim/RPC/Echo`, "", ['Name',"Echo"], ['Input',"echo"::`XML/string` = "Hello"], ['Output',"echo"::`XML/string`], ['Process', proc(inp,out) out["echo"] := inp["echo"]; end ] ]: `aim/RPC/Service`['AddOperation', `aim/RPC/ServerInformation`, "", ['Name',"RQP_ServerInformation"], ['InputMessageName',"ServerInformation"], ['OutputMessageName',"ServerInformationResponse"], ['Output',"description"::`XML/string` = "AiM server. See http://www.aiminfo.net"], ['Output',"cloning"::`XML/boolean` = false], ['Output',"implicitCloning"::`XML/boolean` = true], ['Output',"rendering"::`XML/boolean` = true], ['Output',"templateCaching"::`XML/boolean` = false], ['Output',"itemCaching"::`XML/boolean` = true], ['Output',"inputFormats"::`RQP/ArrayOfanyURI` = ["http://formats.aiminfo.net/aim"]], ['Output',"outputFormats"::`RQP/ArrayOfoutputFormat` = [ ["http://rqp.org/content-types/text", ["http://rqp.org/content-types/text/xhtml-1.0"]], ["http://rqp.org/content-types/image", ["http://rqp.org/content-types/image/gif"]], ["http://rqp.org/content-types/graph", ["http://rqp.org/content-types/graph/gif"]] ] ], ['Output',"outputTemplates"::`RQP/ArrayOfanyURI` = []], ['Process', proc(inp,out) end ] ]: `aim/RPC/Service`['AddOperation', `aim/RPC/ItemInformation`, "", ['Name',"RQP_ItemInformation"], ['InputMessageName',"ItemInformation"], ['OutputMessageName',"ItemInformationResponse"], ['Input',"guid"::`RQP/guid`], ['Input',"source"::`XML/string`], ['Input',"format"::`XML/anyURI`], ['Input',"cache"::`XML/boolean`], ['Output',"warnings"::`RQP/ArrayOfwarning`=[]], ['Output',"sourceCached"::`XML/boolean` = true], ['Output',"format"::`XML/anyURI`=""], ['Output',"sourceErrors"::`RQP/ArrayOferror`=[]], ['Output',"template"::`XML/boolean` = false], ['Output',"adaptive"::`XML/boolean` = true], ['Output',"timeDependent"::`XML/boolean` = false], ['Output',"canComputerScore"::`XML/boolean` = true], ['Output',"solutionAvailable"::`XML/boolean` = true], ['Output',"hintsAvailable"::`XML/boolean` = false], ['Output',"maxScore"::`XML/unsignedInt` = 100], ['Process', proc(inp,out) local item,errs; try item := `aim/SOAP/GetItem`(inp); catch "Compilation failure": errs := lastexception[3]; out["sourceCached"] := false; out["sourceErrors"] := [["http://errors.aiminfo.net/CompilationFailed", __("Compilation failed"), sprintf("%A",errs)]]; return(); end try; out["format"] := inp["format"]; out["maxScore"] := round(100 * item['Value']); return(); end ] ]: `aim/RPC/Service`['AddOperation', `aim/RPC/Render`, "", ['Name',"RQP_Render"], ['InputMessageName',"Render"], ['OutputMessageName',"RenderResponse"], ['Input',"guid"::`RQP/guid`], ['Input',"source"::`XML/string`], ['Input',"format"::`XML/anyURI`], ['Input',"cache"::`XML/boolean`], ['Input',"seed"::`XML/unsignedInt`], ['Input',"templateVars"::`RQP/ArrayOfvariable`], ['Input',"persistentData"::`XML/string`], ['Input',"inputData"::`XML/string`], ['Input',"embedPrefix"::`XML/QName`], ['Input',"state"::`XML/anyURI`], ['Input',"interactive"::`XML/boolean`], ['Input',"renderFormatTemplate"::`XML/anyURI`], ['Input',"renderFormat"::`RQP/ArrayOfoutputFormat`], ['Input',"modalFormatTemplate"::`XML/anyURI`], ['Input',"modalFormat"::`RQP/ArrayOfoutputFormat`], ['Input',"appletBase"::`XML/anyURI`], ['Input',"mediaBase"::`XML/anyURI`], ['Output',"warnings"::`RQP/ArrayOfwarning` = []], ['Output',"sourceCached"::`XML/boolean` = true], ['Output',"seed"::`XML/unsignedInt` = 0], ['Output',"templateVars"::`RQP/ArrayOfvariable` = []], ['Output',"persistentData"::`XML/string` = ""], ['Output',"outcomeVars"::`RQP/ArrayOfvariable` = []], ['Output',"bodyParts"::`RQP/ArrayOfoutputSection` = []], ['Output',"modalParts"::`RQP/ArrayOfoutputSection` = []], ['Process', proc(inp,out) local cache,vrsion,inputdata,label,history,historytable,pdata, context,inst,attempt; cache := evalb(inp["cache"] = true); vrsion := eval(`aim/SOAP/GetItemVersion`(inp,cache)); vrsion['CGIPrefix'] := inp["embedPrefix"]; inputdata := `Util/HTTPPostParse`(inp["inputData"],inp["embedPrefix"]); pdata := inp["persistentData"]; if pdata = "" or pdata = NULL then history := `new/aim/Question/History`(vrsion); else try history := sscanf(pdata,"%m")[1]; catch: error(__("Cannot parse persistent data.")); end try; if not(type([history],[`aim/Question/History`])) then error(__("Cannot parse persistent data.")); fi; fi; historytable := table([vrsion['Label'] = eval(history)]); context := `aim/SOAP/MakeQuizContext`( inp["interactive"], evalb(inputdata["MarkRequested"] <> "false"), true, # show feedback true, # show marks false # do not show solution ); inst := `aim/Question/MakeInstance/Recursive`( vrsion,inputdata,historytable,context); attempt := inst['Attempt']; out["seed"] := vrsion['Seed']; out["persistentData"] := sprintf("%m",eval(history)); out["outcomeVars"] := [["SCORE", [sprintf("%d",round(100*history['Mark']))]], ["RAW_SCORE", [sprintf("%d",round(100*attempt['RawMark']))]], ["IsValid", [sprintf("%A",attempt['IsValid'])]], ["ValidationNote", [attempt['ValidationNote']]], ["AnswerNote", [attempt['AnswerNote']]]]; out["bodyParts"] := inst['ShowParts',context]; NULL; end ] ]: `Package/Assign`( `aim/SOAP/GetItem`, "", proc(inp::table,cache_::boolean) local cache,itemGUID,itemFormat,itemSource,item,vrsion,bits,subj,quiz; global AimRQPCache; cache := `if`(nargs > 1,cache_,true); itemGUID := inp["guid"]; itemFormat := inp["format"]; itemSource := inp["source"]; if itemGUID <> "" then item := AimRQPCache['GetEntry',itemGUID]; if item <> NULL then return(eval(item)); fi; ###TODO: in production mode, remove or protect the following: if `Util/StartsWith`(itemGUID,"AIMFILE") then try bits := [`Util/ColonSplit`(itemGUID)]; subj := eval(DefaultZone['GetSubject',bits[2]]); quiz := eval(subj['GetQuiz',bits[3]]); item := eval(quiz['GetQuestion',bits[4]]); if not(type([item],[`aim/Question`])) then error( "SOAP Fault", "Client", cat("RQP Error: ",__("Malformed question")), "http://rqp.org/errors/itemNotCached"); fi; catch: error( "SOAP Fault:", "Client", cat("RQP Error: ",__("Could not load specified question")), "http://rqp.org/errors/invalidSource"); end try; if not(type([item],[`aim/Question`])) then error( "SOAP Fault:", "Client", cat("RQP Error: ",__("Could not load specified question")), "http://rqp.org/errors/invalidSource"); fi; return(eval(item)); fi; fi; if itemGUID = "" then itemGUID := `Util/MakeGUID`(); fi; if `Util/StripEndSpaces`(itemSource) = "" then error(__("Item is not in the cache, and no source provided")); fi; if itemFormat = "http://aiminfo.net/formats/location" then try bits := [`Util/ColonSplit`(itemSource)]; subj := eval(DefaultZone['GetSubject',bits[1]]); quiz := eval(subj['GetQuiz',bits[2]]); item := eval(quiz['GetQuestion',bits[3]]); if not(type([item],[`aim/Question`])) then error( "SOAP Fault", "Client", cat("RQP Error: ",__("Malformed question")), "http://rqp.org/errors/itemNotCached"); fi; catch: error( "SOAP Fault:", "Client", cat("RQP Error: ",__("Could not load specified question")), "http://rqp.org/errors/invalidSource"); end try; if not(type([item],[`aim/Question`])) then error( "SOAP Fault:", "Client", cat("RQP Error: ",__("Could not load specified question")), "http://rqp.org/errors/invalidSource"); fi; else item := `aim/CompileString`(itemSource); if not(type([item],[`aim/Question`])) then error("Compilation failure: %0",item) fi; item['ItemGUID'] := itemGUID; fi; if cache then AimRQPCache['AddEntry',eval(item),itemGUID]; fi; return(eval(item)); end ): `Package/Assign`( `aim/SOAP/GetItemVersion`, "", proc(inp::table,cache_::boolean) local cache,itemGUID,versionSeed,question,vrsion; global AimRQPCache; cache := `if`(nargs > 1,cache_,true); itemGUID := inp["guid"]; versionSeed := inp["seed"]; if not(type([versionSeed],[integer])) then versionSeed := 1; fi; if versionSeed = 0 then versionSeed := rand(); fi; vrsion := AimRQPCache['GetEntry',itemGUID,versionSeed]; if vrsion <> NULL then return(eval(vrsion)); else question := `aim/SOAP/GetItem`(inp); vrsion := question['MakeVersion',versionSeed]; if not(type([vrsion],[`aim/Question/Version`])) then error( "SOAP Fault:", "Client", cat("RQP Error: ",__("Could not make version of question")), "http://rqp.org/errors/templateProcessingFailed"); fi; if cache then AimRQPCache['AddEntry', eval(vrsion),itemGUID,versionSeed]; fi; return(eval(vrsion)); fi; end ): `Package/Assign`( `aim/SOAP/MakeQuizContext`::`aim/Quiz/Context`, "", proc(interact,markreq,feedback,showmark,showsol) local c; c := `new/aim/Quiz/Context`(); c['StartTime'] := `Date/CurrentDate`(); c['InviteAnswers'] := interact; c['MarkRequested'] := markreq; c['ShowFeedback'] := feedback; c['ShowFeedbackMC'] := feedback; c['ShowRightAnswer'] := showsol; c['ShowSolution'] := showsol; return(eval(c)); end ): ###################################################################### # `RPC/DeclareOperation`( # `aim/RPC/ProcessTemplate`, # "", # ['Name',"RQP_ProcessTemplate"], # ['InputMessageName',"ProcessTemplate"], # ['OutputMessageName',"ProcessTemplateResponse"], # # # ['Input',"guid"::`RQP/guid`], # ['Input',"source"::`XML/string`], # ['Input',"format"::`XML/anyURI`], # ['Input',"cache"::`XML/boolean`], # ['Input',"seed"::`XML/unsignedInt`], # # ['Output',"warnings"::`RQP/ArrayOfwarning`], # ['Output',"sourceCached"::`XML/boolean` = true], # ['Output',"cloneCached"::`XML/boolean` = true], # ['Output',"seed"::`XML/unsignedInt`=0], # ['Output',"templateVars"::`RQP/ArrayOfvariable`] # ): # # `RPC/DeclareOperation`( # `aim/RPC/Clone`, # "", # ['Name',"Clone"], # # ['Input',"guid"::`RQP/guid`], # ['Input',"source"::`XML/string`], # ['Input',"format"::`XML/anyURI`], # ['Input',"cache"::`XML/boolean`], # ['Input',"seed"::`XML/unsignedInt`], # ['Input',"templateVars"::`RQP/ArrayOfvariable`], # # ['Output',"warnings"::`RQP/ArrayOfwarning`], # ['Output',"sourceCached"::`XML/boolean` = true], # ['Output',"cloneCached"::`XML/boolean` = true], # ['Output',"seed"::`XML/unsignedInt`], # ['Output',"templateVars"::`RQP/ArrayOfvariable`], # ['Output',"clone"::`XML/string`=""] # ): `RPC/DeclareOperation`( `aim/RPC/DefaultOperation`, "", ['Name',"DefaultOperation"], ['Process', proc(inp,out) error("SOAP Fault", "Client", "RQP Error: Not implemented", "http://rqp.org/errors/notImplemented") end ] ): EndPackage(): |