Index: openacs-4/packages/imsld/tcl/imsld-gsi-install-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-gsi-install-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/imsld/tcl/imsld-gsi-install-procs.tcl 23 Jun 2009 17:12:33 -0000 1.1 @@ -0,0 +1,235 @@ + +#Elementos en el content repository +# /packages/imsld/tcl/imsld-gsi-install-procs.tcl + +ad_library { + Callback library for GSI installing porpouses. + + @creation-date Nov 2008 + @author lfuente@it.uc3m.es +} + +namespace eval imsld {} +namespace eval imsld::gsi::install {} +namespace eval imsld::gsi::uninstall {} + +#Para cada tipo de item. Se crea el tipo y despues los atributos. +ad_proc -public imsld::gsi::install::do_install { +} { + A wrapper for GSI installation methods +} { + #initialize the cr + imsld::gsi::install::init_cr_model + + #init acs_rels + imsld::gsi::install::init_rels + + #initialize non cr model + imsld::gsi::install::init_noncr_model +} + +ad_proc -public imsld::gsi::uninstall::do_uninstall { +} { + A wrapper for GSI uninstallation methods +} { + #remove acs_rels + imsld::gsi::uninstall::remove_rels + + #clean the content repository + imsld::gsi::install::clean_cr +} + +ad_proc -public imsld::gsi::install::init_cr_model { +} { + Creates cr_item types that correspond to the GSI model +} { + content::type::new -content_type imsld_gsi_service -supertype content_revision -pretty_name "GSI service" -pretty_plural "GSI services" -table_name imsld_gsi_services -id_column gsi_service_id + content::type::attribute::new -content_type imsld_gsi_service -attribute_name environment_id -datatype number -pretty_name "GSI environment ID" -column_spec "integer" + content::type::attribute::new -content_type imsld_gsi_service -attribute_name gsi_tool_id -datatype number -pretty_name "GSI tool ID" -column_spec "integer" + content::type::attribute::new -content_type imsld_gsi_service -attribute_name gsi_constraint_id -datatype number -pretty_name "GSI constraint ID" -column_spec "integer" + content::type::attribute::new -content_type imsld_gsi_service -attribute_name identifier -datatype string -pretty_name "GSI service XML identifier" -column_spec "varchar(100)" + content::type::attribute::new -content_type imsld_gsi_service -attribute_name is_visible_p -datatype string -pretty_name "Is GSI service visible?" -column_spec "varchar(1)" + + + content::type::new -content_type imsld_gsi_alternative -supertype content_revision -pretty_name "GSI Alternative" -pretty_plural "GSI Alternatives" -table_name imsld_gsi_alternatives -id_column gsi_alternative_id + content::type::attribute::new -content_type imsld_gsi_alternative -attribute_name gsi_service_id -datatype number -pretty_name "GSI service ID" -column_spec "integer" + + content::type::attribute::new -content_type imsld_gsi_alternative -attribute_name service_ref -datatype string -pretty_name "GSI Service reference" -column_spec "varchar(100)" + content::type::attribute::new -content_type imsld_gsi_alternative -attribute_name learning_object_ref -datatype string -pretty_name "Learning object reference" -column_spec "varchar(100)" + content::type::attribute::new -content_type imsld_gsi_alternative -attribute_name alternative_order -datatype integer -pretty_name "Sort order of alternative" -column_spec "integer" + + + content::type::new -content_type imsld_gsi_group -supertype content_revision -pretty_name "GSI group" -pretty_plural "GSI groups" -table_name imsld_gsi_groups -id_column gsi_group_id + content::type::attribute::new -content_type imsld_gsi_group -attribute_name identifier -datatype string -pretty_name "GSI group XML identifier" -column_spec "varchar(100)" + content::type::attribute::new -content_type imsld_gsi_group -attribute_name gsi_service_id -datatype integer -pretty_name "GSI service ID" -column_spec "integer" + + + content::type::new -content_type imsld_gsi_tool -supertype content_revision -pretty_name "GSI Tool" -pretty_plural "GSI Tools" -table_name imsld_gsi_tools -id_column gsi_tool_id + + + content::type::new -content_type imsld_gsi_permission -supertype content_revision -pretty_name "GSI Permission" -pretty_plural "GSI Permissions" -table_name imsld_gsi_permissions -id_column gsi_permission_id + content::type::attribute::new -content_type imsld_gsi_permission -attribute_name holder_id -datatype integer -pretty_name "Permission holder ID" -column_spec "integer" + content::type::attribute::new -content_type imsld_gsi_permission -attribute_name action -datatype string -pretty_name "Action" -column_spec "varchar(10)" + content::type::attribute::new -content_type imsld_gsi_permission -attribute_name data_type -datatype string -pretty_name "GSI data type" -column_spec "varchar(20)" + content::type::attribute::new -content_type imsld_gsi_permission -attribute_name owner_id -datatype integer -pretty_name "GSI data owner ID" -column_spec "integer" + + + content::type::new -content_type imsld_gsi_keyword -supertype content_revision -pretty_name "GSI keyword" -pretty_plural "GSI keywords" -table_name imsld_gsi_keywords -id_column gsi_keyword_id + content::type::attribute::new -content_type imsld_gsi_keyword -attribute_name value -datatype string -pretty_name "GSI keyword value" -column_spec "varchar(100)" + + + content::type::new -content_type imsld_gsi_constraint -supertype content_revision -pretty_name "GSI constraint" -pretty_plural "GSI constraints" -table_name imsld_gsi_constraints -id_column gsi_constraint_id + content::type::attribute::new -content_type imsld_gsi_constraint -attribute_name start_date -datatype string -pretty_name "GSI constraint start date" -column_spec "varchar(100)" + content::type::attribute::new -content_type imsld_gsi_constraint -attribute_name stop_date -datatype string -pretty_name "GSI constraint stop date" -column_spec "varchar(100)" + content::type::attribute::new -content_type imsld_gsi_constraint -attribute_name multiplicity -datatype string -pretty_name "GSI constraint multiplicity" -column_spec "varchar(50)" + + +# content::type::new -content_type imsld_gsi_trigger -supertype content_revision -pretty_name "GSI Trigger" -pretty_plural "GSI Triggers" -table_name imsld_gsi_triggers -id_column gsi_trigger_id +# content::type::attribute::new -content_type imsld_gsi_trigger -attribute_name trigger_type -datatype string -pretty_name "GSI trigger type" -column_spec "varchar(100)" + + + content::type::new -content_type imsld_gsi_funct_usage -supertype content_revision -pretty_name "GSI function usage set" -pretty_plural "GSI function usage sets" -table_name imsld_gsi_funct_usage -id_column gsi_funct_usage_id + + content::type::attribute::new -content_type imsld_gsi_funct_usage -attribute_name gsi_trigger_id -datatype number -pretty_name "GSI trigger ID" -column_spec "integer" + content::type::attribute::new -content_type imsld_gsi_funct_usage -attribute_name gsi_constraint_id -datatype number -pretty_name "GSI constraint ID" -column_spec "integer" + content::type::attribute::new -content_type imsld_gsi_funct_usage -attribute_name gsi_function_id -datatype number -pretty_name "GSI function ID" -column_spec "integer" + + +# content::type::new -content_type imsld_gsi_function_param -supertype content_revision -pretty_name "GSI function parameter" -pretty_plural "GSI function parameters" -table_name imsld_gsi_function_params -id_column gsi_function_param_id +# content::type::attribute::new -content_type imsld_gsi_function_param -attribute_name gsi_function_id -datatype number -pretty_name "GSI function ID" -column_spec "integer" +# content::type::attribute::new -content_type imsld_gsi_function_param -attribute_name param_name -datatype string -pretty_name "GSI parameter name" -column_spec "varchar(100)" +# +# +# content::type::new -content_type imsld_gsi_function -supertype content_revision -pretty_name "GSI function" -pretty_plural "GSI functions" -table_name imsld_gsi_functions -id_column gsi_function_id +# content::type::attribute::new -content_type imsld_gsi_function -attribute_name function_name -datatype string -pretty_name "#imsld.asdf#" -column_spec "varchar(100)" + +} + + +ad_proc -public imsld::gsi::install::init_rels { +} { + Creates acs_rel types that correspond to the GSI model +} { + rel_types::new imsld_gsi_trigger_const_rel "GSI Trigger - GSI Constraint rel" "GSI Trigger - GSI constraint rels" \ + content_item 0 {} \ + content_item 0 {} + + rel_types::new imsld_gsi_tools_perm_rel "GSI Tool - GSI Permission rel" "GSI Tool - GSI Permission rels" \ + content_item 0 {} \ + content_item 0 {} + +# rel_types::new imsld_gsi_tools_funct_rel "GSI Tool - GSI Function rel" "GSI Tool - GSI Functions rels" \ +# content_item 0 {} \ +# content_item 0 {} + + rel_types::new imsld_gsi_keywords_tools_rel "GSI Keyword - GSI Tool rel" "GSI Keyword - GSI Tool rels" \ + content_item 0 {} \ + content_item 0 {} + + rel_types::new imsld_gsi_groups_roles_rel "GSI Group - Imsld role rel" "GSI Group - GSI role rels" \ + content_item 0 {} \ + content_item 0 {} +} +ad_proc -public imsld::gsi::install::init_noncr_model { +} { + Fill tables of elements that are not cr_item types +} { + +#supported functions + + set deploy_id [db_nextval acs_object_id_seq] + db_dml insert_deploy_function {INSERT INTO imsld_gsi_functions VALUES (:deploy_id,'deploy' )}; + set close_id [db_nextval acs_object_id_seq] + db_dml insert_close_function {INSERT INTO imsld_gsi_functions VALUES (:close_id, 'close' )}; + #we will need this ID later + set setvalues_id [db_nextval acs_object_id_seq] + db_dml insert_setvalues_function {INSERT INTO imsld_gsi_functions VALUES (:setvalues_id,'set-values')}; + set modifypermissions_id [db_nextval acs_object_id_seq] + db_dml insert_modifypermissions_function {INSERT INTO imsld_gsi_functions VALUES (:modifypermissions_id,'modify-permissions' )}; + +#defined params in supported functions + set param_id [db_nextval acs_object_id_seq] + db_dml insert_setvalues_params {INSERT INTO imsld_gsi_function_params VALUES (:param_id, :setvalues_id, 'mime-type')}; + set param_id [db_nextval acs_object_id_seq] + db_dml insert_setvalues_params {INSERT INTO imsld_gsi_function_params VALUES (:param_id, :setvalues_id, 'item')}; + +#supported triggers + set trigger_id [db_nextval acs_object_id_seq] + db_dml insert_startup_trigger {INSERT INTO imsld_gsi_triggers VALUES (:trigger_id,'startup-action')} + set trigger_id [db_nextval acs_object_id_seq] + db_dml insert_finish_trigger {INSERT INTO imsld_gsi_triggers VALUES (:trigger_id,'finish-action')} + set onComplete_id [db_nextval acs_object_id_seq] + db_dml insert_finish_trigger {INSERT INTO imsld_gsi_triggers VALUES (:onComplete_id,'on-complete-action')} + set onCondition_id [db_nextval acs_object_id_seq] + db_dml insert_finish_trigger {INSERT INTO imsld_gsi_triggers VALUES (:onCondition_id,'on-condition-action')} + +#defined params in supported functions + set param_id [db_nextval acs_object_id_seq] + db_dml insert_setvalues_trig_params {INSERT INTO imsld_gsi_trigger_params VALUES (:param_id, 'if',:onCondition_id)}; + set param_id [db_nextval acs_object_id_seq] + db_dml insert_setvalues_trig_params {INSERT INTO imsld_gsi_trigger_params VALUES (:param_id, 'identifierref',:onComplete_id)}; +} + + +ad_proc -public imsld::gsi::uninstall::remove_rels { +} { + Remove acs_rel types that correspond to the GSI model +} { + #Remove rel types + imsld::rel_type_delete -rel_type imsld_gsi_trigger_const_rel + imsld::rel_type_delete -rel_type imsld_gsi_tools_perm_rel + imsld::rel_type_delete -rel_type imsld_gsi_tools_funct_rel + imsld::rel_type_delete -rel_type imsld_gsi_keywords_tools_rel + imsld::rel_type_delete -rel_type imsld_groups_roles_rel +} + + +ad_proc -public imsld::gsi::uninstall::clean_cr { +} { + Clean GSI types in the content repository +} { + #First, delete attributes (TODO) + content::type::attribute::delete -content_type imsld_gsi_service + content::type::attribute::delete -content_type imsld_gsi_service + content::type::attribute::delete -content_type imsld_gsi_service + content::type::attribute::delete -content_type imsld_gsi_service + content::type::attribute::delete -content_type imsld_gsi_service + content::type::attribute::delete -content_type imsld_gsi_alternative + content::type::attribute::delete -content_type imsld_gsi_alternative + content::type::attribute::delete -content_type imsld_gsi_alternative + content::type::attribute::delete -content_type imsld_gsi_alternative + content::type::attribute::delete -content_type imsld_gsi_group + content::type::attribute::delete -content_type imsld_gsi_group + content::type::attribute::delete -content_type imsld_gsi_permission + content::type::attribute::delete -content_type imsld_gsi_permission + content::type::attribute::delete -content_type imsld_gsi_permission + content::type::attribute::delete -content_type imsld_gsi_permission + content::type::attribute::delete -content_type imsld_gsi_permission + content::type::attribute::delete -content_type imsld_gsi_keyword + content::type::attribute::delete -content_type imsld_gsi_constraint + content::type::attribute::delete -content_type imsld_gsi_constraint + content::type::attribute::delete -content_type imsld_gsi_constraint + content::type::attribute::delete -content_type imsld_gsi_trigger + content::type::attribute::delete -content_type imsld_gsi_funct_usage + content::type::attribute::delete -content_type imsld_gsi_funct_usage + content::type::attribute::delete -content_type imsld_gsi_funct_usage + content::type::attribute::delete -content_type imsld_gsi_funct_usage + content::type::attribute::delete -content_type imsld_gsi_function_params + content::type::attribute::delete -content_type imsld_gsi_function_params + content::type::attribute::delete -content_type imsld_gsi_function + + #Second, delete types + content::type::delete -content_type imsld_gsi_service + content::type::delete -content_type imsld_gsi_alternative + content::type::delete -content_type imsld_gsi_group + content::type::delete -content_type imsld_gsi_tool + content::type::delete -content_type imsld_gsi_permission + content::type::delete -content_type imsld_gsi_data + content::type::delete -content_type imsld_gsi_keyword + content::type::delete -content_type imsld_gsi_constraint + content::type::delete -content_type imsld_gsi_trigger + content::type::delete -content_type imsld_gsi_funct_usage + content::type::delete -content_type imsld_gsi_function_param + content::type::delete -content_type imsld_gsi_function +} + Index: openacs-4/packages/imsld/tcl/imsld-gsi-instance-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-gsi-instance-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/imsld/tcl/imsld-gsi-instance-procs.tcl 23 Jun 2009 17:12:33 -0000 1.1 @@ -0,0 +1,71 @@ +# /packages/imsld/tcl/imsld-gsi-procs.tcl + +ad_library { + Procedures for instantiation of gsi namespace. + + @creation-date Nov 2008 + @author lfuente@it.uc3m.es +} + +namespace eval imsld {} +namespace eval imsld::gsi {} +namespace eval imsld::gsi::instance {} + +ad_proc -public imsld::gsi::instance::instantiate_service { + -component_item_id + -run_id + -user_id +} { + @param component_item_id + @param run_id + @param user_id +} { + db_foreach generic_service { + select gserv.gsi_service_id, + coalesce(gserv.is_visible_p, 't') as is_visible_p, + gserv.identifier + from imsld_gsi_services gserv, imsld_environmentsi env + where gserv.environment_id = env.item_id + and env.component_id = :component_item_id + } { + if { ![db_0or1row serv_already_instantiated_p { + select 1 + from imsld_attribute_instances + where owner_id = :gsi_service_id + and run_id = :run_id + and user_id = :user_id + and type = 'isvisible' + }] } { + set instance_id [package_exec_plsql -var_list \ + [list [list instance_id ""] \ + [list owner_id $gsi_service_id] \ + [list type "isvisible"] \ + [list identifier $identifier] \ + [list run_id $run_id] \ + [list user_id $user_id] \ + [list is_visible_p $is_visible_p] \ + [list title ""] \ + [list with_control_p ""]] \ + imsld_attribute_instance new] + +# db_dml insert_new_service_instance { +# INSERT INTO imsld_gsi_serv_instances VALUES (:instance_id, '') +# } + if { ![db_0or1row status_already_set { + select 1 + from imsld_gsi_service_status + where owner_id=:gsi_service_id and + run_id=:run_id + }] } { + set service_status_id [db_nextval acs_object_id_seq] + #insert a row in imsld_gsi_service_status + db_dml insert_new_service_status { + INSERT + INTO imsld_gsi_service_status + VALUES (:service_status_id,:gsi_service_id,:run_id,'not-configured','',now()) + } + } + } + } +} + Index: openacs-4/packages/imsld/tcl/imsld-gsi-parse-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-gsi-parse-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/imsld/tcl/imsld-gsi-parse-procs.tcl 23 Jun 2009 17:12:33 -0000 1.1 @@ -0,0 +1,688 @@ +# /packages/imsld/tcl/imsld-gsi-parse.procs.tcl + +ad_library { + Procedures in the imsld namespace for parsing gsi based xml files. + + @creation-date Oct 2008 + @author lfuente@it.uc3m.es +} + +namespace eval imsld {} +namespace eval imsld::gsi {} +namespace eval imsld::gsi::parse {} + +ad_proc -public imsld::gsi::parse::parse_and_create_genericService { + -service_node + -parent_id + -environment_id + -manifest_id + -manifest + -resource_handler + -tmp_dir +} { + Parse a genericService and stores all the information in the database. + + Returns a list with the new gservice_ids (item_ids) created if there were no errors, or 0 and an explanation messge if there was an error. + Generic services are just stored in the database, but no deployment is done in any sense. + + @param service_node service node to parse +} { + upvar files_struct_list files_struct_list + + set gservice_info [list] + + set imsld_id [db_string get_imsld_from_manifest { + select iii.item_id + from imsld_imsldsi iii, + imsld_cp_organizationsi ico + where ico.manifest_id=:manifest_id and + ico.item_id=iii.organization_id; + }] + + set gservice_identifier [imsld::parse::get_attribute -node $service_node -attr_name identifier] + + set gservice_visibility [imsld::parse::get_attribute -node $service_node -attr_name isvisible] + if { [ string eq $gservice_visibility "true"] } { + set gservice_visibility "t" + } elseif { [llength $gservice_visibility] } { + set gservice_visibility "t" + } else { + set gservice_visibility "f" + } + + set title_node [$service_node selectNodes "*\[local-name()='title'\]"] + imsld::parse::validate_multiplicity -tree $title_node -multiplicity 1 -element_name "Title (genericService)" -lower_than + if { [llength $title_node]} { + set service_title [imsld::parse::get_element_text -node $title_node] + } else { + set service_title "" + } + + set description_node [$service_node selectNodes "*\[local-name()='description'\]"] + imsld::parse::validate_multiplicity -tree $description_node -multiplicity 1 -element_name "Description (genericService)" -lower_than + if { [llength $description_node] } { + set service_description [imsld::gsi::parse::parse_and_create_description -node $description_node] + } else { + set service_description "" + } + + set tool_node [$service_node selectNodes "*\[local-name()='tool'\]"] + imsld::parse::validate_multiplicity -tree $tool_node -multiplicity 1 -element_name "Tool (genericService)" -equal + set tool_id [imsld::gsi::parse::parse_and_create_tool -node $tool_node -parent_id $parent_id] + + set constraints_node [$service_node selectNodes "*\[local-name()='constraints'\]"] + imsld::parse::validate_multiplicity -tree $constraints_node -multiplicity 1 -element_name "Constraints (genericService)" -equal + set constraints_id [imsld::gsi::parse::parse_and_create_constraints -node $constraints_node \ + -parent_id $parent_id \ + -manifest $manifest \ + -manifest_id $manifest_id \ + -tmp_dir $tmp_dir \ + -resource_handler $resource_handler] + + set gservice_id [imsld::item_revision_new -attributes [list [list description $service_description] \ + [list identifier $gservice_identifier] \ + [list is_visible_p $gservice_visibility] \ + [list gsi_tool_id $tool_id] \ + [list environment_id $environment_id] \ + [list gsi_constraint_id $constraints_id]] \ + -content_type imsld_gsi_service \ + -title $service_title \ + -parent_id $parent_id ] + + set alternatives_node [$service_node selectNodes "*\[local-name()='alternatives'\]"] + imsld::parse::validate_multiplicity -tree $alternatives_node -multiplicity 1 -element_name "Alternatives (genericService)" -lower_than + set alternatives_id [imsld::gsi::parse::parse_and_create_alternatives -node $alternatives_node -gsi_service_id $gservice_id -parent_id $parent_id] + + set groups_node [$service_node selectNodes "*\[local-name()='groups'\]"] + imsld::parse::validate_multiplicity -tree $groups_node -multiplicity 1 -element_name "Groups (genericService)" -equal + set groups_id_list [imsld::gsi::parse::parse_and_create_groups -node $groups_node -parent_id $parent_id -gservice_id $gservice_id -imsld_id $imsld_id] + + #permissions (inside tools) require tool_id and group_id, so it is created now + imsld::gsi::parse::parse_and_create_permissions -tool_node $tool_node -parent_id $parent_id -tool_id $tool_id -imsld_id $imsld_id -service_id $gservice_id + + return $gservice_info +} + +ad_proc -public imsld::gsi::parse::parse_and_create_permissions { + -tool_node + -parent_id + -tool_id + -imsld_id + -service_id +} { +} { + set permissions [$tool_node selectNodes "*\[local-name()='permissions'\]/*\[local-name()='permission'\]"] + foreach permission $permissions { + + set holder [$permission selectNodes "*\[local-name()='holder'\]"] + imsld::parse::validate_multiplicity -tree $holder -multiplicity 1 -element_name "holder (permission)" -equal + set group_ref [$holder selectNodes "*\[local-name()='group-ref'\]"] + imsld::parse::validate_multiplicity -tree $group_ref -multiplicity 1 -element_name "group-ref (holder)" -equal + set group_ref_value [imsld::parse::get_attribute -node $group_ref -attr_name ref] + set holder_id [db_string get_holder_from_ref { + select gsi_group_id + from imsld_gsi_groups + where gsi_service_id=:service_id and + identifier=:group_ref_value + }] + + set action [$permission selectNodes "*\[local-name()='action'\]"] + imsld::parse::validate_multiplicity -tree $action -multiplicity 1 -element_name "action (permission)" -equal + set action [imsld::parse::get_attribute -node $action -attr_name type] + + set data [$permission selectNodes "*\[local-name()='data'\]"] + imsld::parse::validate_multiplicity -tree $data -multiplicity 1 -element_name "data (permission)" -equal + set datatype [imsld::parse::get_attribute -node $data -attr_name datatype] + + set group_ref [$data selectNodes "*\[local-name()='owner'\]/*\[local-name()='group-ref'\]"] + imsld::parse::validate_multiplicity -tree $data -multiplicity 1 -element_name "group-ref (owner)" -equal + set group_ref_value [imsld::parse::get_attribute -node $group_ref -attr_name ref] + + #owner_id can be null, with free interpretation (all users, platform default values, etc.)'; + set owner_id [db_string get_holder_from_ref { + select gsi_group_id + from imsld_gsi_groups + where gsi_service_id=:service_id and + identifier=:group_ref_value + }] + + set permission_id [imsld::item_revision_new -attributes [list [list holder_id $holder_id] \ + [list action $action] \ + [list data_type $datatype] \ + [list owner_id $owner_id]] \ + -content_type imsld_gsi_permission \ + -parent_id $parent_id] + + relation_add imsld_gsi_tools_perm_rel $tool_id $permission_id + } + return +} + + +ad_proc -public imsld::gsi::parse::parse_and_create_description { + -node +} { + Parse a description node, as defined in gsi xml schema + + Returns a list with the new description info + + @param node node to parse +} { + set description_item [$node selectNodes "*\[local-name()='item'\]"] + imsld::parse::validate_multiplicity -tree $description_item -multiplicity 1 -element_name "Item (in description)" -equal + + set identifierref [imsld::parse::get_attribute -node $description_item -attr_name identifierref] + return [list $identifierref] +} + + +ad_proc -public imsld::gsi::parse::parse_and_create_groups { + -node + -parent_id + -gservice_id + -imsld_id +} { + Parse a groups node, as defined in gsi xml schema + + Returns a list with all the groups identifiers found. + + @param node node to parse +} { + set groups_info [list] + + set group_list [$node selectNodes "*\[local-name()='group'\]"] + imsld::parse::validate_multiplicity -tree $group_list -multiplicity 1 -element_name "Group (genericService)" -greather_than + + foreach group $group_list { + set group_identifier [imsld::parse::get_attribute -node $group -attr_name identifier] + + set group_id [imsld::item_revision_new -attributes [list [list gsi_service_id $gservice_id] \ + [list identifier $group_identifier]]\ + -content_type imsld_gsi_group \ + -parent_id $parent_id ] + + set roles_in_group [$group selectNodes "*\[local-name()='ld-role'\]"] + imsld::parse::validate_multiplicity -tree $roles_in_group -multiplicity 1 -element_name "ld-role (genericService)" -greather_than + + foreach role $roles_in_group { + set role_ref [$role getAttribute imsld:role-ref] + #FIXME: this way of getting attributes only allow the "imsld" prefix. That is: mismanage the namespaces + + + set role_id [db_string get_role_from_ref { + select ir.item_id + from imsld_rolesi ir, + imsld_componentsi ic + where ic.imsld_id=:imsld_id and + ic.item_id=ir.component_id and + ir.identifier=:role_ref + } ] +# imsld::roles::get_role_id -ref $role_ref -imsld_id $imsld_id +# set role_id [db_string get_item_from_object {select item_id from imsld_rolesi where object_id=:role_id}] + relation_add imsld_gsi_groups_roles_rel $group_id $role_id + } + + lappend groups_info $group_id + } + + return $groups_info +} + +ad_proc -public imsld::gsi::parse::parse_and_create_tool { + -node + -parent_id +} { + Parse a tool node, as defined in gsi xml schema + + Returns a list with all the constraints found. + + @param node node to parse +} { + set tool_info [list] + + set title_node [$node selectNodes "*\[local-name()='title'\]"] + imsld::parse::validate_multiplicity -tree $title_node -multiplicity 1 -element_name "Title (tool)" -lower_than + if { [llength $title_node]} { + set tool_title [imsld::parse::get_element_text -node $title_node] + } else { + set tool_title "" + } + + set description_node [$node selectNodes "*\[local-name()='description'\]"] + imsld::parse::validate_multiplicity -tree $description_node -multiplicity 1 -element_name "Description (tool)" -lower_than + if { [llength $description_node] } { + set tool_description [imsld::gsi::parse::parse_and_create_description -node $description_node] + } else { + set tool_description "" + } + + set tool_id [imsld::item_revision_new -attributes [list [list description $tool_description]] \ + -content_type imsld_gsi_tool \ + -title $tool_title \ + -parent_id $parent_id ] + + + + set keywords_node [$node selectNodes "*\[local-name()='keywords'\]"] + imsld::parse::validate_multiplicity -tree $keywords_node -multiplicity 1 -element_name "Keyword" -equal + set keywords_ids [imsld::gsi::parse::parse_and_create_keywords -node $keywords_node -parent_id $parent_id -gsi_tool_id $tool_id] + + set functions_node [$node selectNodes "*\[local-name()='functions'\]"] + imsld::parse::validate_multiplicity -tree $functions_node -multiplicity 1 -element_name "functions (tool)" -lower_than + if { [llength $functions_node] } { + lappend tool_info [imsld::gsi::parse::parse_and_create_functions -node $functions_node -tool_id $tool_id] + } + + #permissions will be created later (they require the service_id) + + return $tool_id +} + +ad_proc -public imsld::gsi::parse::parse_and_create_keywords { + -node + -parent_id + -gsi_tool_id +} { + Parse a keywords node, as defined in gsi xml schema + + Returns a list with all the keywords found. + + @param node node to parse +} { + set keywords_list [list] + + set keyword [$node selectNodes "*\[local-name()='keyword'\]"] + imsld::parse::validate_multiplicity -tree $keyword -multiplicity 1 -element_name "keyword (keywords)" -greather_than + + foreach word $keyword { + set keyword_value [imsld::parse::get_element_text -node $word] + set keyword_id [imsld::item_revision_new -attributes [list [list value $keyword_value] ]\ + -content_type imsld_gsi_keyword \ + -parent_id $parent_id ] + relation_add imsld_gsi_keywords_tools_rel $keyword_id $gsi_tool_id + lappend keywords_list $keyword_id + } + return $keywords_list +} + +ad_proc -public imsld::gsi::parse::get_function_id { + -function_name +} { + Returns the item_id of the function that responds to a given name, 0 if not found +} { + return [db_string get_gsi_function_id { + select gsi_function_id + from imsld_gsi_functions + where function_name=:function_name + } -default "0"] +} + +ad_proc -public imsld::gsi::parse::get_trigger_id { + -trigger_name +} { + Returns the item_id of the trigger that responds to a given name, 0 if not found +} { + return [db_string get_gsi_trigger_id { + select gsi_trigger_id + from imsld_gsi_triggers + where trigger_type=:trigger_name + } -default "0"] +} + +ad_proc -public imsld::gsi::parse::parse_and_create_functions { + -node + -tool_id +} { + Parse a functions node, as defined in gsi xml schema + + Returns a list with the functions info. + + @param node node to parse +} { + set functions_list [list] + + if { [llength [$node selectNodes "*\[local-name()='deploy'\]"] ] } { + set function_id [imsld::gsi::parse::get_function_id -function_name "deploy"] + db_dml set_relation {INSERT INTO imsld_gsi_tools_funct_rels VALUES (:function_id,:tool_id)} + } + if { [llength [$node selectNodes "*\[local-name()='close'\]"] ] } { + set function_id [imsld::gsi::parse::get_function_id -function_name "close"] + db_dml set_relation {INSERT INTO imsld_gsi_tools_funct_rels VALUES (:function_id,:tool_id)} + } + + if { [llength [$node selectNodes "*\[local-name()='modify-permissions'\]"]] } { + set function_id [imsld::gsi::parse::get_function_id -function_name "modify-permissions"] + db_dml set_relation {INSERT INTO imsld_gsi_tools_funct_rels VALUES (:function_id,:tool_id)} + } + if { [llength [$node selectNodes "*\[local-name()='set-values'\]"]] } { + set function_id [imsld::gsi::parse::get_function_id -function_name "set-values"] + db_dml set_relation {INSERT INTO imsld_gsi_tools_funct_rels VALUES (:function_id,:tool_id)} + } + return +} + +#ad_proc -public imsld::gsi::parse::parse_and_create_permissions { +# -node +#} { +# Parse a permissions node, as defined in gsi xml schema +# +# Returns a list with all the permissions info found. +# +# @param node node to parse +#} { +# set permissions_list [list] +# set permissions [$node selectNodes "*\[local-name()='permission'\]"] +# imsld::parse::validate_multiplicity -tree $permissions -multiplicity 1 -element_name "permission (permissions)" -greather_than +# +# foreach permission $permissions { +# set permission_info [list] +# +# set holder [$permission selectNodes "*\[local-name()='holder'\]"] +# imsld::parse::validate_multiplicity -tree $holder -multiplicity 1 -element_name "holder (permission)" -equal +# set holder_info [list] +# #find group-ref elements +# set group_refs [$holder selectNodes "*\[local-name()='group-ref'\]"] +# imsld::parse::validate_multiplicity -tree $group_refs -multiplicity 1 -element_name "group-ref (holder)" -greather_than +# +# foreach group $group_refs { +# lappend holder_info [list [imsld::parse::get_attribute -node $group -attr_name ref]] +# } +# lappend permission_info $holder_info +# +# set action [$permission selectNodes "*\[local-name()='action'\]"] +# imsld::parse::validate_multiplicity -tree $action -multiplicity 1 -element_name "action (permission)" -equal +# #find type attribute +# lappend permission_info [imsld::parse::get_attribute -node $action -attr_name type] +# +# set data [$permission selectNodes "*\[local-name()='data'\]"] +# imsld::parse::validate_multiplicity -tree $data -multiplicity 1 -element_name "data (permission)" -equal +# #find owner and type +# set data_info [list] +# lappend data_info [imsld::parse::get_attribute -node $data -attr_name datatype] +# set group_refs [$data selectNodes "*\[local-name()='owner'\]/*\[local-name()='group-ref'\]"] +# foreach group_ref_node $group_refs { +# lappend data_info [list [imsld::parse::get_attribute -node $group_ref_node -attr_name ref]] +# } +# lappend permission_info $data_info +# +# +# +# lappend permissions_list $permission_info +# +# } +# +# return $permissions_list +#} + + + +ad_proc -public imsld::gsi::parse::parse_and_create_constraints { + -node + -parent_id + -manifest + -manifest_id + -tmp_dir + -resource_handler +} { + Parse a constraints node, as defined in gsi xml schema + + Returns a list with all the constraints found. + + @param node node to parse +} { + upvar files_struct_list files_struct_list + + set constraints_info [list] + + set life_span_node [$node selectNodes "*\[local-name()='life-span'\]"] + imsld::parse::validate_multiplicity -tree $life_span_node -multiplicity 1 -element_name "life-span" -equal + set start_node [$life_span_node selectNodes "*\[local-name()='start'\]"] + imsld::parse::validate_multiplicity -tree $start_node -multiplicity 1 -element_name "start (in life-span)" -equal + set start_value [list [imsld::parse::get_attribute -node $start_node -attr_name date]] + set stop_node [$life_span_node selectNodes "*\[local-name()='stop'\]"] + imsld::parse::validate_multiplicity -tree $stop_node -multiplicity 1 -element_name "stop (in life-span)" -lower_than + if { [llength $stop_node] } { + lappend stop_value [list [imsld::parse::get_attribute -node $stop_node -attr_name date]] + } else { + lappend stop_value "" + } + + set multiplicity_node [$node selectNodes "*\[local-name()='multiplicity'\]"] + imsld::parse::validate_multiplicity -tree $multiplicity_node -multiplicity 1 -element_name "multiplicity" -equal + set multiplicity_value [imsld::parse::get_attribute -node $multiplicity_node -attr_name type] + + + set constraints_id [imsld::item_revision_new -attributes [list [list start_date $start_value] \ + [list stop_date $stop_value] \ + [list multiplicity $multiplicity_value]] \ + -content_type imsld_gsi_constraint \ + -parent_id $parent_id ] + + set triggers_node [$node selectNodes "*\[local-name()='triggers'\]"] + imsld::parse::validate_multiplicity -tree $triggers_node -multiplicity 1 -element_name "triggers" -equal + imsld::gsi::parse::parse_and_create_triggers -trigger_node $triggers_node \ + -constraint_id $constraints_id \ + -parent_id $parent_id \ + -manifest $manifest \ + -manifest_id $manifest_id \ + -tmp_dir $tmp_dir \ + -resource_handler $resource_handler + + return $constraints_id +} + +ad_proc -public imsld::gsi::parse::parse_and_create_triggers { + -trigger_node + -parent_id + -constraint_id + -manifest + -manifest_id + -tmp_dir + -resource_handler +} { + Parse a triggers node, as defined in gsi xml schema + + Returns a list with all the info. + + @param node node to parse +} { + + upvar files_struct_list files_struct_list + +#all child nodes,only element nodes + set child_nodes [$trigger_node childNodes] + foreach node $child_nodes { + if { [string eq "ELEMENT_NODE" [$node nodeType] ] } { + imsld::parse::validate_multiplicity -tree $node -multiplicity 1 -element_name "action (triggers)" -lower_than +# this line made sense when the type was an attribute +# set type [imsld::parse::get_attribute -node $node -attr_name type] + #the type is the subelement whose name matches in functions table. + #All other childs are trigger params, so they are ignored + set all_trigger_childs [$node childNodes] + foreach child_element $all_trigger_childs { + set tmp_function_id [imsld::gsi::parse::get_function_id -function_name [$child_element nodeName]] + if { ![string eq $tmp_function_id 0] } { + set function_id $tmp_function_id + set parameters [imsld::gsi::parse::get_function_parameter_values -action_node $child_element \ + -manifest $manifest \ + -manifest_id $manifest_id \ + -parent_id $parent_id \ + -tmp_dir $tmp_dir \ + -resource_handler $resource_handler] + } + } +# type [[$node childNodes] nodeName] +# set function_id [imsld::gsi::parse::get_function_id -function_name $type] + set trigger_id [imsld::gsi::parse::get_trigger_id -trigger_name [$node nodeName]] + + + set usage_set_id [imsld::item_revision_new -attributes [list \ + [list gsi_constraint_id $constraint_id] \ + [list gsi_trigger_id $trigger_id] \ + [list gsi_function_id $function_id]] \ + -content_type imsld_gsi_funct_usage \ + -parent_id $parent_id ] + + #I have to obtain trigger parameters here and store them in the database. + imsld::gsi::parse::parse_and_create_trigger_params -node $node \ + -trigger_id $trigger_id \ + -usage_set_id $usage_set_id + + + foreach pair $parameters { + set param_name [lindex $pair 0] + set param_id [db_string get_param_id_form_param_name { + select gsi_function_param_id as param_id + from imsld_gsi_function_params + where param_name=:param_name}] + set value [lindex $pair 1] + db_dml insert_param_value {INSERT INTO imsld_gsi_par_val_rels VALUES (:param_id,:value,:usage_set_id)} + } + } + } +} + +ad_proc -public imsld::gsi::parse::parse_and_create_trigger_params { + -node + -trigger_id + -usage_set_id +} { + Parse a trigger node and look for parameters inside triggers. If found, they are stored in the database +} { + #1- let's check if root node has attributes + set attributes [$node attributes] + set trigger_name [$node localName] + foreach attrib_name $attributes { + #search the corresponding param_id. Both param_name and trigger_name must match + db_1row get_param_id { + select tp.gsi_trigger_param_id as param_id + from imsld_gsi_trigger_params tp + where tp.gsi_param_name=:attrib_name and + tp.gsi_trigger_id=:trigger_id + } + set attrib_value [$node getAttribute $attrib_name] + + #now we can insert in the database + set param_val_id [db_nextval acs_object_id_seq] + db_dml insert_param_value { + INSERT INTO imsld_gsi_trig_param_values VALUES ( :param_val_id, :param_id, :attrib_value, :usage_set_id); + } + } + + #2- check child elements. Only those whose name is in imsld_gsi_trigger_params table are interesting here + set trigger_childs [$node childNodes] + foreach childElement $trigger_childs { + set param_name [$childElement localName] + if {[db_0or1row is_trigger_param_p { + select t.trigger_type, + tp.gsi_trigger_param_id as param_id + from imsld_gsi_triggers t, + imsld_gsi_trigger_params tp + where t.gsi_trigger_id=tp.gsi_trigger_id and + tp.gsi_param_name=:param_name; + }]} { + switch $trigger_type { + "on-condition-action" { + set param_value [$childElement asXML] + } + default {} + } + #now we can insert in the database + set param_val_id [db_nextval acs_object_id_seq] + db_dml insert_param_value { + INSERT INTO imsld_gsi_trig_param_values VALUES ( :param_val_id, :param_id, :param_value, :usage_set_id); + } + } + } +} + +ad_proc -public imsld::gsi::parse::get_function_parameter_values { + -action_node + -manifest + -manifest_id + -parent_id + -tmp_dir + -resource_handler +} { +} { + + upvar files_struct_list files_struct_list + + set param_value_list [list] +# set actual_action_node [$action_node childNodes] +# set action_type [$actual_action_node nodeName] + set action_type [$action_node nodeName] + switch $action_type { + "set-values" { +# set mime_type_value [imsld::parse::get_attribute -node $actual_action_node -attr_name mime-type] + set mime_type_value [imsld::parse::get_attribute -node $action_node -attr_name mime-type] + lappend param_value_list [list "mime-type" $mime_type_value] +# set item_node [$actual_action_node selectNodes "*\[local-name()='item'\]" ] + set item_node [$action_node selectNodes "*\[local-name()='item'\]" ] + if { [llength $item_node] } { + set item_list [imsld::parse::parse_and_create_item -manifest $manifest \ + -manifest_id $manifest_id \ + -item_node $item_node \ + -parent_id $parent_id \ + -tmp_dir $tmp_dir \ + -resource_handler $resource_handler ] + + lappend param_value_list [list "item" [imsld::parse::get_attribute -node $item_node -attr_name identifierref]] + } + } + "modify-permissions" { + lappend param_value_list [list "permission-ref" [imsld::parse::get_attribute -node $actual_action_node -attr_name permission-ref]] + } + "deploy" - + "close" - + default { } + } + return $param_value_list +} + +ad_proc -public imsld::gsi::parse::parse_and_create_alternatives { + -node + -gsi_service_id + -parent_id +} { + Parse an alterntatives node, as defined in gsi xml schema + + Returns a list with all the alternative identifiers found. + + @param node node to parse +} { + + set alternatives_list [list] + set sort_order 1 + + set alt_services_list [$node selectNodes "*\[local-name()='service-ref'\]"] + if { [llength $alt_services_list] } { + foreach alternative_service $alt_services_list { + set reference [imsld::parse::get_attribute -node $alternative_service -attr_name ref] + set alt_id [imsld::item_revision_new -attributes [list [list alternative_order $sort_order] \ + [list service_ref $reference] \ + [list gsi_service_id $gsi_service_id]] \ + -content_type imsld_gsi_alternative \ + -parent_id $parent_id ] + set sort_order [expr $sort_order + 1] + lappend alternatives_list $alt_id + } + } + + set alt_lo_list [$node selectNodes "*\[local-name()='learning-object-ref'\]"] + if { [llength $alt_lo_list] } { + foreach alternative_lo $alt_lo_list { + set reference [imsld::parse::get_attribute -node $alternative_lo -attr_name identifierref] + set alt_id [imsld::item_revision_new -attributes [list [list alternative_order $sort_order] \ + [list learning_object_ref $reference] \ + [list gsi_service_id $gsi_service_id]] \ + -content_type imsld_gsi_alternative \ + -parent_id $parent_id ] + set sort_order [expr $sort_order + 1] + lappend alternatives_list $alt_id + } + } + + return $alternatives_list +} + Index: openacs-4/packages/imsld/tcl/imsld-gsi-plugin-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-gsi-plugin-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/imsld/tcl/imsld-gsi-plugin-procs.tcl 23 Jun 2009 17:12:33 -0000 1.1 @@ -0,0 +1,11 @@ +ad_library { + Procedures of the different gsi plugins. + + @creation-date Dic 2008 + @author lfuente@it.uc3m.es +} + +set imsld_package_path [acs_package_root_dir imsld] +source "$imsld_package_path/lib/gsi-plugins/gsi-gspread-procs.tcl" +source "$imsld_package_path/lib/gsi-plugins/gsi-xowiki-procs.tcl/" + Index: openacs-4/packages/imsld/tcl/imsld-gsi-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-gsi-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/imsld/tcl/imsld-gsi-procs.tcl 23 Jun 2009 17:12:33 -0000 1.1 @@ -0,0 +1,951 @@ +# /packages/imsld/tcl/imsld-gsi-procs.tcl + +ad_library { + Procedures in the imsld gsi namespace. + + @creation-date Nov 2008 + @author lfuente@it.uc3m.es +} + +namespace eval imsld {} +namespace eval imsld::gsi {} + +ad_proc -public imsld::gsi::execute_conditional_actions { + -run_id +} { + Execute actions triggered by 'on-condition', whose condition evaluation is true. +} { + set action_list [list] + set temptative_actions [imsld::gsi::get_triggered_actions -trigger "on-condition-action" -run_id $run_id] + + foreach action $temptative_actions { + db_1row get_condition_value { + select tpv.gsi_trig_param_value as if_value + from imsld_gsi_trig_param_values tpv, + imsld_gsi_funct_usagei fu + where fu.item_id=tpv.gsi_funct_usage_id + } + set document [dom parse $if_value] + set if_node [$document documentElement] + if {[imsld::expression::eval -run_id $run_id -expression $if_value]} { + lappend action_list $action + } + } + imsld::gsi::action_list_execute -run_id $run_id -actions $action_list +} + +ad_proc -public imsld::gsi::get_services_in_run { + -run_id +} { + Return a list with all service_id that are in a given UoL (the one instantiated by the run_id) +} { + set environments_in_run [db_list get_environments { + select ie.item_id + from imsld_componentsi ici, + imsld_imsldsi iii, + imsld_runs ir, + imsld_environmentsi ie + where ie.component_id=ici.item_id and + ici.imsld_id=iii.item_id and + iii.imsld_id=ir.imsld_id and + ir.run_id=:run_id + }] + if {[llength $environments_in_run]} { + return [db_list get_services_in_run "select gsi_service_id + from imsld_gsi_services + where environment_id in ([template::util::tcl_to_sql_list $environments_in_run])"] + } else { + return [list] + } +} + +ad_proc -public imsld::gsi::get_triggered_actions { + -trigger:required + -run_id +} { + Return a list with all actions triggered by the provided trigger. + If run_id is given, the list is restricted to actions in this run. +} { + set full_actions_list [db_list get_all_trigger_actions { + select gfu.gsi_funct_usage_id + from imsld_gsi_funct_usage gfu, + imsld_gsi_triggers gt + where gt.gsi_trigger_id=gfu.gsi_trigger_id and + gt.trigger_type=:trigger + }] + if {[info exist run_id]} { + set services_in_run [imsld::gsi::get_services_in_run -run_id $run_id] + if {[llength $full_actions_list] && [llength $services_in_run]} { + set actions_list [db_list get_matching_actions " + select gsi_funct_usage_id + from imsld_gsi_funct_usage + where gsi_constraint_id in (select gsi_constraint_id + from imsld_gsi_services + where gsi_service_id in ([template::util::tcl_to_sql_list $services_in_run])) + and gsi_funct_usage_id in ([template::util::tcl_to_sql_list $full_actions_list])"] + } else { + set actions_list [list] + } + return $actions_list + } else { + return $full_actions_list + } +} + +ad_proc -public imsld::gsi::get_service_multiplicity { + -gservice_id +} { + Return a string with the multiplicity of a given service +} { + + return [db_string get_multiplicity { + select c.multiplicity + from imsld_gsi_constraintsi c, + imsld_gsi_services s + where s.gsi_constraint_id=c.item_id + and s.gsi_service_id=:gservice_id + } -default ""] +} + +ad_proc -public imsld::gsi::get_service_startup_actions { + -gservice_id +} { + Return a list of lists containing all actions requested at startup for a given services. Each element in list contains a list + with name, and a list of param_names param_values +} { + #get usages from gservice where trigger is startup + set usages [db_list get_usages { + select fu.gsi_funct_usage_id + from imsld_gsi_funct_usage fu, + imsld_gsi_services serv, + imsld_gsi_triggers trig + where fu.gsi_constraint_id = serv.gsi_constraint_id and + serv.gsi_service_id = :gservice_id and + fu.gsi_trigger_id = trig.gsi_trigger_id and + trig.trigger_type = 'startup-action' + }] + + #get full data from these usages + set full_data_list [list] + foreach usage_id $usages { + #si es deploy o close, la lista es {deploy {} {}} o {close {} {}} + set function_name [db_string get_funtion_name { + select fu.function_name + from imsld_gsi_funct_usage us, + imsld_gsi_functions fu + where us.gsi_function_id=fu.gsi_function_id and + us.gsi_funct_usage_id=:usage_id; + }] + if {[string eq $function_name "deploy"] || [string eq $function_name "close"] } { + lappend full_data_list [list $function_name {} {}] + } else { + #si es set-value o modify-permissions, llevará parámetros, más de uno + #la lista tendrá la forma: {set-values {name1 value1} {name2 value2} .... } + set data_set [db_list_of_lists get_params { + select param.param_name, + pvrel.gsi_param_value + from imsld_gsi_funct_usagei us, + imsld_gsi_functions fu, + imsld_gsi_par_val_rels pvrel, + imsld_gsi_function_params param + where fu.gsi_function_id=us.gsi_function_id and + pvrel.gsi_function_usage_id=us.item_id and + param.gsi_function_param_id=pvrel.gsi_function_param_id and + us.gsi_funct_usage_id=:usage_id + }] + set named_data_set [linsert $data_set 0 $function_name] + lappend full_data_list $named_data_set + } + } + return $full_data_list +} + +ad_proc -public imsld::gsi::get_group_from_role { + -gservice_id + -role_id +} { + If found, returns the group_id in the mapping group-role in the given service. Otherwise, return empty string +} { + return [db_string get_group_id { + select iggi.gsi_group_id + from imsld_rolesi iri, + imsld_gsi_groupsi iggi, + acs_rels ar, + imsld_gsi_servicesi igsi + where iri.role_id=:role_id and + iri.item_id=ar.object_id_two and + ar.object_id_one=iggi.item_id and + igsi.item_id=iggi.gsi_service_id and + igsi.gsi_service_id=:gservice_id + } -default ""] +} + +ad_proc -public imsld::gsi::get_group_permissions { + -group_id +} { + Return a list with all the permissions found for a given group. Each permission is a list with the form \{ actionType objectType ObjectOwner\} +} { + return [db_list_of_lists get_group_permissions { + select action, + data_type, + owner_id + from imsld_gsi_permissions + where holder_id=:group_id + }] +} +ad_proc -public imsld::gsi::get_service_name { + -gservice_id +} { + If exists in database, returns the title of the service. Otherwise return the string \"Service link\" +} { + return [db_string get_service_title { + SELECT title + FROM imsld_gsi_servicesi + WHERE gsi_service_id=:gservice_id + } -default "Service link"] +} + + +ad_proc -public imsld::gsi::change_service_status { + -gservice_id + -run_id + -status +} { + @param gservice_id + @param run_id + @param status + + Changes the status of a service instance +} { + db_dml change_service_status { + UPDATE imsld_gsi_service_status + SET status=:status, last_modified=now() + WHERE owner_id=:gservice_id and run_id=:run_id + } + return +} + +ad_proc -public imsld::gsi::get_roles_in_group { + -group_id:required +} { + @param group_id + The method returns all roles (user_id) in the group. +} { + return [db_list get_roles_id { + select roles.role_id + from acs_rels ar, + imsld_gsi_groupsi g, + imsld_rolesi roles + where object_id_one=g.item_id and + ar.rel_type='imsld_gsi_groups_roles_rel' and + roles.item_id=ar.object_id_two and + g.gsi_group_id=group_id + }] +} + + +ad_proc -public imsld::gsi::get_users_in_group { + -group_id:required +} { + @param group_id + The method returns all members (user_id) in the group. +} { + set roles [imsld::gsi::get_roles_in_group -group_id $group_id] + set all_users [list] + foreach role $roles { + set users_in_role [imsld::roles::get_users_in_role -role_id $role] + lappend all_users $users_in_role + } + return $all_users +} + + +ad_proc -public imsld::gsi::get_service_status { + -gservice_id + -run_id +} { + @param gservice_id + @param run_id + + Returns the status of a service instance +} { + return [db_string get_service_status { + SELECT status + FROM imsld_gsi_service_status + WHERE owner_id=:gservice_id and run_id=:run_id + }] +} + +ad_proc -public imsld::gsi::get_roles_in_service { + -gservice_id +} { + Returns a list with the roles_id involved in the service +} { + return [db_list get_roles { + select r.role_id + from imsld_rolesi r, + acs_rels ar, + imsld_gsi_groupsi g, + imsld_gsi_servicesi s + where s.item_id=g.gsi_service_id and + ar.object_id_one=g.item_id and + ar.object_id_two=r.item_id}] +} + +ad_proc -public imsld::gsi::get_users_in_service { + -gservice_id + -run_id +} { + Returns a list with the roles_id involved in the service +} { + + set roles_list [imsld::gsi::get_roles_in_service -gservice_id $gservice_id] + set users_in_service [list] + + foreach role_id $roles_list { + set tmp_list [concat $users_in_service [imsld::roles::get_users_in_role -role_id $role_id -run_id $run_id]] + set users_in_service $tmp_list + } + + return $users_in_service +} + +ad_proc -public imsld::gsi::get_gservice_url { + -user_id + -run_id + -gservice_id +} { + Returns the service URL previously stored in the database +} { + set out_list [db_list_of_lists get_gservice_url { + select gsi_inst.url, + gsi_inst.url_title + from imsld_attribute_instances att, + imsld_gsi_serv_instances gsi_inst + where att.run_id=:run_id and + att.owner_id=:gservice_id and + att.user_id=:user_id and + att.instance_id=gsi_inst.service_instance_id; + }] + + return $out_list +} + +ad_proc -public imsld::gsi::find_and_process_gsi_service_as_ul { + -environment_id + -user_id + -run_id + -dom_node + -dom_doc +} { + Fill an html list (in a dom tree) with the associated resources referenced from the given generic service. + @param environment_id + @param run_id + @param dom_node + @param dom_doc + + @return a list of all generic services included in the list +} { +#TODO: hacer una query más completa + set gservices_list [db_list gservices_in_environment { + SELECT igs.gsi_service_id + FROM imsld_gsi_services igs, + imsld_environmentsi iei + WHERE iei.environment_id=:environment_id and + igs.environment_id=iei.item_id + }] + + foreach gservice $gservices_list { + set gservice_node_li [$dom_doc createElement li] + set url_list [imsld::gsi::get_gservice_url -user_id $user_id -gservice_id $gservice -run_id $run_id] + + set ul_node [$dom_doc createElement ul] + foreach url $url_list { + set li_node [$dom_doc createElement li] + set a_node [$dom_doc createElement a] + $a_node setAttribute href "[lindex $url 0]" + $a_node setAttribute target "content" + set title_text [imsld::gsi::get_service_name -gservice_id $gservice] + set gservice_title [$dom_doc createTextNode [lindex $url 1]] + $a_node appendChild $gservice_title + $li_node appendChild $a_node + $ul_node appendChild $li_node + } + $gservice_node_li appendChild $ul_node + + $dom_node appendChild $gservice_node_li + } + return $gservices_list +} + +ad_proc -public imsld::gsi::store_check_results { + -service_response + -gservice_id + -run_id +} { +} { + #insert the request (including the answer yet) in tables... + set request_id [lindex $service_response 0] + set function_response [lindex $service_response 1] + set permissions_response [lindex $service_response 2] + + db_dml initialize_request { + UPDATE imsld_gsi_service_requests + SET function_response=:function_response, permissions_response=:permissions_response + WHERE gsi_request_id=:request_id + } + + return true +} + +ad_proc -public imsld::gsi::get_request_response { + -request_id +} { + Returns a list with the response of a given request. Functions_response is in index 0, permissions in index 1 +} { + if { [db_0or1row get_request_response { + SELECT function_response, permissions_response + FROM imsld_gsi_service_requests + WHERE gsi_request_id=:request_id } ] + } { + return [list $function_response $permissions_response] + } else { + return [list "" ""] + } +} + +ad_proc -public imsld::gsi::get_function_request_values { + -gservice_id +} { + Builds a list containing function requirements information of a given service. +} { + set functions [list [list "deploy" {}] [list "close" {}]] + return $functions +} + +ad_proc -public imsld::gsi::get_permission_request_values { + -gservice_id +} { + Builds a list containing function requirements information of a given service. +} { + set permissions [list [list "read" "contribution" "user"] [list "write" "context" {} ] ] + return $permissions +} + +ad_proc -public imsld::gsi::register_plugin { + -plugin_string_id + -plugin_URI +} { + Fills the imsld_gsi_plugins table. Each time a plugin is installed, this procedure must be called to insert a new row. The plugin_string_id is used as short name for plugins, for folder names of procedure names. + + It can happen that a service retrieved from the registry uses a plugin that is not in the table. In this case, the plugin must be installed (otherwise, the service won't work properly). +} { + db_dml insert_plugin { + INSERT INTO imsld_gsi_plugins VALUES (:plugin_string_id,:plugin_URI); + } +} + +ad_proc -public imsld::gsi::get_plugin_identifier { + -plugin_URI +} { + Given a plugin_URI, returns its corresponding identifier or empty string if nothing found. +} { + set return_value [db_string get_plugin_identifier {SELECT plugin_string_id FROM imsld_gsi_plugins where plugin_uri=:plugin_URI} -default ""] + return $return_value +} + + +ad_proc -public imsld::gsi::initialize_check_request { + -gservice_id + -plugin_URI + -run_id +} { + Inserts a row in the imsld_gsi_service_requests table, without filling the response fields. +} { + #check if the plugin is registered + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_URI] + if {[string eq $plugin_string_id ""]} { + ns_log Notice "no existe plugin, algo habrá que hacer" + return + } + + #get the serv_status_id + set serv_status_id [db_string get_status_id { + SELECT service_status_id + FROM imsld_gsi_service_status + WHERE owner_id=:gservice_id and run_id=:run_id + }] + + #insert the request (if not exists) in tables... + if { ![db_0or1row is_already_inserted { + select 1 from imsld_gsi_service_requests where serv_status_id=:serv_status_id and plugin_URI=:plugin_URI + }] } { + set gsi_request_id [db_nextval acs_object_id_seq] + db_dml initialize_request { + INSERT + INTO imsld_gsi_service_requests + VALUES ( :gsi_request_id, :serv_status_id, :plugin_URI, '','', now() ) + } + } +} + +ad_proc -public imsld::gsi::get_roles_with_permissions { + -gservice_id + -data_type + -action +} { + Returns a list with all the roles that takes a pair of action-data_type permission in a given service +} { + return [db_list get_admin_role { + select r.object_id + from imsld_gsi_servicesi serv, + acs_rels ar, + imsld_rolesi r, + imsld_gsi_groupsi g, + imsld_gsi_permissions p + where p.action=:action and + p.data_type=:data_type and + g.gsi_service_id=serv.item_id and + g.gsi_group_id=p.holder_id and + ar.object_id_one=g.item_id and + r.item_id=ar.object_id_two and + serv.gsi_service_id=:gservice_id + }] +} + + + + + + + +#methods that must be implemented by all plugins +################################################# + + +ad_proc -public imsld::gsi::send_check_request { + -gservice_id + -plugin_URI + -run_id +} { + Sends a check-request to the service, in order to ask for funcionality support + @param gservice_id "The service that needs to be configured" + @param plugin_URI "The plugin that manages the request" + @param run_id "since a service can request from several runs, the run_id provides identification completeness." + + @return a list of service capabilities +} { + #build parameters to check (functions and permissions) + set request_functions [imsld::gsi::get_function_request_values -gservice_id $gservice_id] + set request_permissions [imsld::gsi::get_permission_request_values -gservice_id $gservice_id] + + #based on the plugin, build the name of the procedure to be called + set plugin_namespace "p_" + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_URI] + + if {![string eq $plugin_string_id ""]} { + append plugin_namespace $plugin_string_id + } else { + ns_log Notice "no existe plugin, algo habrá que hacer" + return [list] + } + set procedure_name "imsld::gsi::${plugin_namespace}::send_check_request \$request_functions \$request_permissions" + + #insert or replace row + set serv_status_id [db_string get_status_id { + SELECT service_status_id + FROM imsld_gsi_service_status + WHERE owner_id=:gservice_id and run_id=:run_id + }] + + if {[db_0or1row is_already_requested { + select gsi_request_id + from imsld_gsi_service_requests + where serv_status_id=:serv_status_id and + plugin_uri=:plugin_URI + }]} { + #replace row + db_dml update_request { + UPDATE imsld_gsi_service_requests + SET last_modified=now(), + function_response='', + permissions_response='' + WHERE plugin_uri=:plugin_URI and + serv_status_id=:serv_status_id + } + } else { + #insert the request (no answer yet) in tables... + set gsi_request_id [db_nextval acs_object_id_seq] + db_dml initialize_request { + INSERT + INTO imsld_gsi_service_requests + VALUES ( :gsi_request_id, :serv_status_id, :plugin_URI, '','', now() ) + } + } + + #eval the procedure + set plugin_response [eval $procedure_name] + set composed_response [linsert $plugin_response 0 $gsi_request_id] + +#composed_respose[0] = request identifier +#composed_respose[1] = functions response +#composed_respose[2] = permissions response + #return method response + return $composed_response +} + +#the following method is done with the list returned by "send_check_request", it is not plugin business +#ad_proc -public imsld::gsi::store_service_response { +# -gservice_id +# -plugin_URI +# -run_id + + +ad_proc -public imsld::gsi::request_configured_instance { + -gservice_id + -plugin_URI + -run_id + -user_id +} { + Once a service has been choosen and users mapped, request URL of a given user. + @param gservice_id "The service that needs to be configured" + @param plugin_URI "The plugin that manages the request" + @param run_id "since a service can request from several runs, the run_id provides identification completeness." + @param user_id "The user of the instance" + + @return The url of the instance. +} { + #based on the plugin, build the name of the procedure to be called + set plugin_namespace "p_" + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_URI] + + #check for correctness + if {![string eq $plugin_string_id ""]} { + append plugin_namespace $plugin_string_id + } else { + ns_log Notice "no existe plugin, algo habrá que hacer" + return "" + } + + #build and eval procedure name + + set procedure_name "imsld::gsi::${plugin_namespace}::request_configured_instance -run_id \$run_id -user_id \$user_id -gservice_id $gservice_id" + set configured_instance [eval $procedure_name] + + return $configured_instance +} + + +#the following method is done with the URL returned by "request_configured_instance", it is not plugin business +#ad_proc -public imsld::gsi::store_configured_instance { +# -gservice_id +# -plugin_URI +# -run_id + +ad_proc -public imsld::gsi::get_external_user { + -plugin_URI + -run_id + -user_id +} { + Returns username from an external service that a given user is related to. If no user found, returns empty string + This procedure just redirect to a proper plugin + + @param plugin_URI "The plugin that manages the request" + @param run_id "since a service can request from several runs, the run_id provides identification completeness." + @param user_id "The user of the instance" + +} { + set external_username "" + + #based on the plugin, build the name of the procedure to be called + set plugin_namespace "p_" + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_URI] + + #check for correctness + if {![string eq $plugin_string_id ""]} { + append plugin_namespace $plugin_string_id + } else { + ns_log Notice "no existe plugin, algo habrá que hacer" + return "" + } + + #build and eval procedure name + set procedure_name "imsld::gsi::${plugin_namespace}::get_external_user -run_id \$run_id -user_id \$user_id" + set external_username [eval $procedure_name] + + return $external_username +} + +ad_proc -public imsld::gsi::get_external_credentials { + -plugin_URI + -run_id + -user_id +} { + Returns credentials from an external service that a given user is related to. If no user found, returns empty string + This procedure just redirect to a proper plugin + + @param plugin_URI "The plugin that manages the request" + @param run_id "since a service can request from several runs, the run_id provides identification completeness." + @param user_id "The user of the instance" + +} { + set external_credentials "" + + #based on the plugin, build the name of the procedure to be called + set plugin_namespace "p_" + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_URI] + + #check for correctness + if {![string eq $plugin_string_id ""]} { + append plugin_namespace $plugin_string_id + } else { + ns_log Notice "no existe plugin, algo habrá que hacer" + return "" + } + + #build and eval procedure name + set procedure_name "imsld::gsi::${plugin_namespace}::get_external_credentials -run_id \$run_id -user_id \$user_id" + set external_credentials [eval $procedure_name] + + return $external_credentials +} + + +ad_proc -public imsld::gsi::map_user { + -plugin_URI + -run_id + -user_id + -external_user + -external_credentials +} { + Map a user with a corresponding external service user. Additionally, a password is provided (OpenAuth is just a good idea today) + @param plugin_URI "The plugin that manages the request" + @param run_id "since a service can request from several runs, the run_id provides identification completeness." + @param user_id "The user of the instance" + @param external_user "The external user to do the mapping" + @param external_credentials "If required, the external pass to access service" + + @return boolean +} { + #based on the plugin, build the name of the procedure to be called + set plugin_namespace "p_" + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_URI] + + #check for correctness + if {![string eq $plugin_string_id ""]} { + append plugin_namespace $plugin_string_id + } else { + ns_log Notice "no existe plugin, algo habrá que hacer" + return "" + } + + #build procedure name + set procedure "imsld::gsi::${plugin_namespace}::map_user -run_id \$run_id -user_id \$user_id" + #build parameters + if {![info exists external_user] && ![info exists external_credentials]} { + set parameters "" + } elseif {[info exists external_user] && ![info exists external_credentials]} { + set parameters "-external_user $external_user" + } elseif {![info exists external_user] && [info exists external_credentials]} { + set parameters "-external_credentials $external_credentials" + } else { + set parameters "-external_user $external_user -external_credentials $external_credentials" + } + + set procedure_name [concat $procedure $parameters] + eval $procedure_name + + return +} + + +ad_proc -public imsld::gsi::initialize_user { + -plugin_URI + -run_id + -user_id +} { + Initializes a user mapping with a corresponding external service user + @param plugin_URI "The plugin that manages the request" + @param run_id "since a service can request from several runs, the run_id provides identification completeness." + @param user_id "The user of the instance" + +} { + #based on the plugin, build the name of the procedure to be called + set plugin_namespace "p_" + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_URI] + + #check for correctness + if {![string eq $plugin_string_id ""]} { + append plugin_namespace $plugin_string_id + } else { + ns_log Notice "no existe plugin, algo habrá que hacer" + return "" + } + + #build and eval procedure name + set procedure_name "imsld::gsi::${plugin_namespace}::initialize_user -run_id \$run_id -user_id \$user_id" + eval $procedure_name + + return +} + + + +ad_proc -public imsld::gsi::perform_startup_actions { + -plugin_URI + -run_id + -gservice_id + -multiplicity + -startup_actions +} { + Perform the startup-actions of a given service. That is, deploy and (if required) set initial values. The meaning + of each of these verbs depends on the handler plugin + + @param plugin_URI "The plugin that manages the request" + @param run_id "since a service can request from several runs, the run_id provides identification completeness." + @param gservice_id "The service_id to be configured" + +} { + #based on the plugin, build the name of the procedure to be called + set plugin_namespace "p_" + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_URI] + + #check for correctness + if {![string eq $plugin_string_id ""]} { + append plugin_namespace $plugin_string_id + } else { + ns_log Notice "no existe plugin, algo habrá que hacer" + return "" + } +# set startup_actions [imsld::gsi::get_service_startup_actions -gservice_id $gservice_id] + #build and eval procedure name + set procedure_name "imsld::gsi::${plugin_namespace}::perform_startup_actions -gservice_id \$gservice_id -run_id \$run_id -startup_actions \$startup_actions -multiplicity \$multiplicity" + eval $procedure_name + + return +} + +ad_proc -public imsld::gsi::action_list_execute { + -plugin_URI + -run_id + -gservice_id + -multiplicity + -actions +} { + Perform a list of actions in a given service. The meaning of the actions depends on the handler plugin + + @param plugin_URI "The plugin that manages the request" + @param run_id "since a service can request from several runs, the run_id provides identification completeness." + @param gservice_id "The service_id to be configured" + +} { + if {![info exist gservice_id]} { + #FIXME:we can obtain gservice_id because all of them belongs to the same service, obviously there's only one service + #what happens when more than a service appear? + #just an idea (I have no time to think more on this): a db_list and a foreach can solve the problem + db_1row get_service_id "select s.gsi_service_id as gservice_id + from imsld_gsi_services s, + imsld_gsi_funct_usage fu + where s.gsi_constraint_id=fu.gsi_constraint_id and + fu.gsi_funct_usage_id in ([template::util::tcl_to_sql_list $actions]) + group by gservice_id" + } + + if {![info exist multiplicity]} { + db_1row get_service_multiplicity { + select c.multiplicity as multiplicity + from imsld_gsi_services s, + imsld_gsi_constraintsi c + where c.item_id=s.gsi_constraint_id and + s.gsi_service_id=:gservice_id + } + } + + if {![info exist plugin_URI]} { + db_1row get_plugin_URI { + select plugin_uri as plugin_URI + from imsld_gsi_service_status + where owner_id=:gservice_id and + run_id=:run_id + } + } + #based on the plugin, build the name of the procedure to be called + set plugin_namespace "p_" + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_uri] + + #check for correctness + if {![string eq $plugin_string_id ""]} { + append plugin_namespace $plugin_string_id + } else { + ns_log Notice "no existe plugin, algo habrá que hacer" + return "" + } + #build and eval procedure name + set procedure_name "imsld::gsi::${plugin_namespace}::action_list_execute -gservice_id \$gservice_id -run_id \$run_id -actions \$actions -multiplicity \$multiplicity" + eval $procedure_name +} + + +ad_proc -public imsld::gsi::get_external_value { + -plugin_URI + -run_id:required + -gservice_id + -multiplicity + -node:required + -user_id +} { + Receive a node external-value dom node and a run_id and call the proper plugin to obtain the value from the service. + The meaning of the attributes depends on the handler plugin +} { + if {![info exist user_id]} { + set user_id [ad_conn user_id] + } + if {![info exist gservice_id]} { + #Given the serviceref, whe can obtain the service_id, since we also have the run_id + #Note: there can be more than one service with the same identifier (form different UoLs), + # so the run_id is used to guarantee uniqueness + set services_in_run [imsld::gsi::get_services_in_run -run_id $run_id] + if {[llength $services_in_run]} { + db_1row get_service_id "select gsi_service_id as gservice_id + from imsld_gsi_services + where identifier='assessment-service' and + gsi_service_id in ([template::util::tcl_to_sql_list $services_in_run])" + } + } + + if {![info exist multiplicity]} { + db_1row get_service_multiplicity { + select c.multiplicity as multiplicity + from imsld_gsi_services s, + imsld_gsi_constraintsi c + where c.item_id=s.gsi_constraint_id and + s.gsi_service_id=:gservice_id + } + } + + if {![info exist plugin_URI]} { + db_1row get_plugin_URI { + select plugin_uri as plugin_URI + from imsld_gsi_service_status + where owner_id=:gservice_id and + run_id=:run_id + } + } else { + set plugin_uri $plugin_URI + } + + #based on the plugin, build the name of the procedure to be called + set plugin_namespace "p_" + set plugin_string_id [imsld::gsi::get_plugin_identifier -plugin_URI $plugin_uri] + + #check for correctness + if {![string eq $plugin_string_id ""]} { + append plugin_namespace $plugin_string_id + } else { + ns_log Notice "no existe plugin, algo habrá que hacer" + return "" + } + #build and eval procedure name + set procedure_name "imsld::gsi::${plugin_namespace}::get_external_value -gservice_id \$gservice_id -run_id \$run_id -node \$node -multiplicity \$multiplicity -user_id $user_id" + eval $procedure_name +}