Index: openacs-4/contrib/packages/simulation/simulation.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/Attic/simulation.info,v diff -u -N -r1.4 -r1.5 --- openacs-4/contrib/packages/simulation/simulation.info 27 Oct 2003 07:31:54 -0000 1.4 +++ openacs-4/contrib/packages/simulation/simulation.info 10 Nov 2003 17:06:21 -0000 1.5 @@ -13,16 +13,17 @@ Workflow-based task simulator. 2003-10-13 - - - + + + + - + Index: openacs-4/contrib/packages/simulation/tcl/apm-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/apm-callback-procs.tcl,v diff -u -N -r1.6 -r1.7 --- openacs-4/contrib/packages/simulation/tcl/apm-callback-procs.tcl 31 Oct 2003 11:08:38 -0000 1.6 +++ openacs-4/contrib/packages/simulation/tcl/apm-callback-procs.tcl 10 Nov 2003 16:56:56 -0000 1.7 @@ -8,7 +8,14 @@ namespace eval simulation::apm {} +ad_proc -private simulation::apm::after_install {} { + simulation::notification::xml_map::register +} +ad_proc -private simulation::apm::before_uninstall {} { + simulation::notification::xml_map::unregister +} + ad_proc -private simulation::apm::after_instantiate { {-package_id:required} } { @@ -24,4 +31,3 @@ -context_id $package_id \ -content_types { sim_character sim_prop sim_location sim_stylesheet image }] } - Index: openacs-4/contrib/packages/simulation/tcl/notification-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/notification-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/tcl/notification-procs.tcl 10 Nov 2003 16:56:56 -0000 1.1 @@ -0,0 +1,76 @@ +ad_library { + Procs related to notifications. + + @author Peter Marklund + @creation-date 2003-11-10 + @cvs-id $Id: notification-procs.tcl,v 1.1 2003/11/10 16:56:56 peterm Exp $ +} + +namespace eval simulation::notification {} +namespace eval simulation::notification::xml_map {} + +ad_proc -private simulation::notification::xml_map::register {} { + db_transaction { + set spec [list \ + contract_name "NotificationType" \ + name [sc_name] \ + aliases { + GetURL simulation::notification::xml_map::get_url + ProcessReply simulation::notification::xml_map::process_reply + } \ + owner [simulation::package_key]] + set sc_impl_id [acs_sc::impl::new_from_spec -spec $spec] + + notification::type::new \ + -all_intervals \ + -all_delivery_methods \ + -sc_impl_id $sc_impl_id \ + -short_name [type_short_name] \ + -pretty_name [type_pretty_name] \ + -description [type_description] + } +} + +ad_proc -private simulation::notification::xml_map::unregister {} { + db_transaction { + notification::type::delete -short_name [type_short_name] + + acs_sc::impl::delete \ + -contract_name "NotificationType" \ + -impl_name [sc_name] + } +} + +ad_proc -private simulation::notification::xml_map::sc_id {} { + return [acs_sc::impl::get_id \ + -owner [simulation::package_key] \ + -name [sc_name]] +} + +ad_proc -private simulation::notification::xml_map::sc_name {} { + return "MapXMLNotification" +} + +ad_proc -private simulation::notification::xml_map::type_short_name {} { + return "map_xml" +} + +ad_proc -private simulation::notification::xml_map::type_pretty_name {} { + return "Map XML" +} + +ad_proc -private simulation::notification::xml_map::type_description {} { + return "Notification of changes to the Map XML file." +} + +ad_proc -public simulation::notification::xml_map::get_url { + object_id +} { + # Todo: Implement this proc +} + +ad_proc -public simulation::notification::xml_map::process_reply { + reply_id +} { + # Todo: Implement this proc +} Index: openacs-4/contrib/packages/simulation/tcl/object-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/object-procs.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/tcl/object-procs.tcl 7 Nov 2003 16:08:45 -0000 1.1 +++ openacs-4/contrib/packages/simulation/tcl/object-procs.tcl 10 Nov 2003 16:56:56 -0000 1.2 @@ -7,52 +7,146 @@ } namespace eval simulation::object {} +namespace eval simulation::object::xml {} -ad_proc -public simulation::object::schedule_generate_xml_file { - {-package_id ""} +ad_proc -private simulation::object::xml::file_sweeper {} { + Loop over all simulation package instances and re-generate + XML map files for them. + + @see simulation::object::xml::generate_file + + @author Peter Marklund } { -

- Schedules the proc simulation::object::generate_xml_file to be - executed now in its own thread. -

+ set simulation_package_ids [db_list simulation_package_ids { + select package_id + from apm_packages + where package_key = 'simulation' + }] -

- This proc needs to be invoked upon the create, edit, and delete - event for simulation objects that have the on_map_p attribute - set to true. It also needs to be invoked if the on_map_p attribute - is toggled from false to true for a sim object. -

+ ns_log Notice "Proc simulation::object::xml::file_sweeper executing with simulation_package_ids=$simulation_package_ids" + foreach package_id $simulation_package_ids { + generate_file -package_id $package_id + } + ns_log Notice "Finished executing simulation::object::xml::file_sweeper" +} - +ad_proc -private simulation::object::xml::generate_file { + {-package_id:required} +} { + Generate map XML document for the package. Compare the XML + document with any existing XML document for the package and + write the new document to the filesystem if it differs from + the existing document. Sends a notification if the file + was generated or if there were errors generating the file. + @see simulation::object::xml::get_doc + + @return 1 if a new XML file was written and 0 otherwise + @author Peter Marklund } { - if { [empty_string_p $package_id] } { - set package_id [ad_conn package_id] + set errors [list] + + set parameter_name "MapXmlFilePath" + set file_path [parameter::get -parameter $parameter_name -package_id $package_id] + + # An empty file_path signifies that no XML map file should be generated + if { [empty_string_p $file_path] } { + return } - ad_schedule_proc -thread t -once t 0 simulation::object::generate_xml_file -package_id $package_id + # file_path validity check + set file_path_error_prefix "Parameter simulation.$parameter_name for package $package_id has invalid value \"${file_path}\"." + if { ![regexp {^/} $file_path] } { + set error_message "$file_path_error_prefix It needs to start with /" + lappend errors $error_message + ns_log Error $error_message + } + if { ![file readable $file_path] } { + set error_message "$file_path_error_prefix The file is not readable" + lappend errors $error_message + ns_log Error $error_message + } + + set wrote_file_p 0 + with_catch errmsg { + + if { [llength $errors] == 0 } { + set old_xml_doc [template::util::read_file $file_path] + set new_xml_doc [get_doc -package_id $package_id] + set xml_changed_p [ad_decode [string compare $old_xml_doc $new_xml_doc] 0 0 1] + error hej + if { $xml_changed_p } { + template::util::write_file $file_path + set wrote_file_p 1 + } + } + } { + global errorInfo + set error_message "Generating XML file failed with error message: $errmsg\n\n$errorInfo" + ns_log Error $error_message + lappend errors $error_message + } + + if { $wrote_file_p || [llength $errors] > 0 } { + notify \ + -package_id $package_id \ + -file_path $file_path \ + -wrote_file_p $wrote_file_p \ + -errors $errors + } + + return $wrote_file_p } -ad_proc -public simulation::object::generate_xml_file { +ad_proc -private simulatation::object::xml::notify { {-package_id:required} + {-file_path:required} + {-wrote_file_p:required} + {-errors:required} } { -

- Re-generates (or generates for the first time) the XML file - containing information about all simulation objects that are - to be on the SIMBUILD flash map. -

+ Send a notification about the results of an XML file generation. @author Peter Marklund } { - ########## - # Get data to be written to file - ########## + set package_url "[ad_url][apm_package_url_from_id $package_id]" - # Get a list of names of tables storing the on_map_p attribute for - # items created in the given package + set subject "XML File generation results for package at ${package_url}" + + if { $wrote_file_p } { + append body "An XML file was written to file at \"$file_path\"." + } else { + append body "An XML file could not be written to file at \"$file_path\"." + } + + if { [llength $errors] > 0 } { + set all_errors [join $errors "\n\n"] + append body "\n\nThe following errors were encountered: + +$all_errors + +" + } + + # Send notification +} + +ad_proc -private simulation::object::xml::get_doc { + {-package_id:required} +} { + Generates XML for all relevant simulation objects in the given + package (that have on_map_p attribute set to true). + + @return An XML document + + @author Peter Marklund +} { + set full_package_url "[ad_url][apm_package_url_from_id $package_id]" + + # Get table names and id column names for the on_map_p attribute of each object type + # By using the multirow we avoid a nested db_foreach set parent_id [bcms::folder::get_id_by_package_id -parent_id 0] - set sim_table_lists [db_list select_sim_tables { + db_multirow -local sim_table_list select_sim_tables { select aot.table_name, aot.id_column from acs_object_types aot, @@ -64,110 +158,79 @@ where ci.parent_id = :parent_id and ci.content_type = aot.object_type ) - }] + } - foreach sim_table $sim_table_list { - set table_name [lindex $sim_table 0] - set id_column [lindex $sim_table 1] + # Open XML document + set xml_doc "\n\n" - set object_lists [db_list_of_lists select_on_map_objects " - select ci.item_id, - cr.content_type - cr.title, - ci.name, + # Object type loop. + template::multirow -local foreach sim_table_list { + ns_log Notice " + select ci.item_id as id, + cr.title as name, + ci.name as uri, cr.description, + ci.content_type, + (select min(ci2.name) + from cr_item_rels cir, + cr_items ci2 + where cir.item_id = ci.item_id + and cir.related_object_id = ci2.item_id + and cir.relation_tag = 'thumbnail') as thumbnail_uri from cr_items ci - cr_revisions cr + left outer join cr_item_rels cir on (cir.item_id = ci.item_id), + cr_revisions cr, $table_name st where st.on_map_p = 't' - and st.$id_column = ci.item_id + and st.$id_column = cr.revision_id and ci.live_revision = cr.revision_id and ci.parent_id = :parent_id - "] - } + order by ci.name + " + db_foreach select_on_map_objects " + select ci.item_id as id, + cr.title as name, + ci.name as uri, + cr.description, + ci.content_type, + (select min(ci2.name) + from cr_item_rels cir, + cr_items ci2 + where cir.item_id = ci.item_id + and cir.related_object_id = ci2.item_id + and cir.relation_tag = 'thumbnail') as thumbnail_uri + from cr_items ci + left outer join cr_item_rels cir on (cir.item_id = ci.item_id), + cr_revisions cr, + $table_name st + where st.on_map_p = 't' + and st.$id_column = cr.revision_id + and ci.live_revision = cr.revision_id + and ci.parent_id = :parent_id + order by ci.name + " { + set url "$full_package_url/object/$name" - ########## - # Generate XML document - ########## + if { [lsearch -exact {sim_location sim_prop sim_character} $content_type] != -1 } { + set thumbnail_url "${full_package_url}object-content/${thumbnail_uri}" + } else { + set thumbnail_url "" + } - set xml_doc " -" - foreach object_list $object_lists { - append xml_doc [generate_xml \ - -item_id [lindex $object_list 0] \ - -content_type [lindex $object_list 1] \ - -title [lindex $object_list 2] \ - -name [lindex $object_list 3] \ - -description [lindex $object_list 4]] - } - append xml_doc "" + append xml_doc " \n" + # Assuming var names are identical to XML tag names + set xml_tag_names {name url thumbnail_url description} + foreach tag_name $xml_tag_names { + append xml_doc " <${tag_name}>[ad_quotehtml [set ${tag_name}]]\n" + } + append xml_doc " \n" - ########## - # Write to file - ########## + } ;# End object loop - # TODO: make filepath a parameter - set file_path "/tmp/map-objects.xml" - set file_id [open $file_path w] - puts $file_id $xml_doc - close $catalog_file_id -} + } ;# End object type loop -ad_proc -public simulation::object::generate_xml { - {-item_id:required} - {-content_type ""} - {-title ""} - {-name ""} - {-description ""} -} { -

- Generate XML to be used by the CityBuild flash map for a certain - simulation object. Requires there to be an HTTP connection as it - uses ad_conn package_url to get the URL of the object. -

+ # Close XML document + append xml_doc "
\n" - @param item_id Stored in cr_items.item_id - @param content_type Stored in cr_items.content_type - @param title Stored in cr_revisions.title - @param name Stored in cr_items.name - @param description Stored in cr_revisions.description - - @author Peter Marklund -} { - # Set default values for optional args - set optional_args {content_type title name description} - foreach arg_name $optional_args { - if { [empty_string_p [set $arg_name]] } { - if { ![info exists item_info] } { - array set item_info [bcms::item::get_item -item_id $item_id -revision live] - } - - set $arg_name $item_info($arg_name) - } - } - - # Get object url and thumbnail url - set full_package_url "[ad_url]/[ad_conn package_url]" - set url "$full_package_url/object/$name" - if { [lsearch -exact {sim_location sim_prop sim_character} $content_type] != -1 } { - set thumbnail_list [bcms::item::list_related_items \ - -return_list \ - -item_id $item_id \ - -relation_tag thumbnail] - set thumbnail_uri [lindex [lindex $thumbnail_list 0] 1] - set thumbnail_url "$full_package_url/object-content/$thumbnail_uri" - } else { - set thumbnail_url "" - } - - # Create XML document - append flash_xml " - $item_id - [ad_quotehtml $name] - [ad_quotehtml $url] - [ad_quotehtml $thumbnail_url] - [ad_quotehtml $description] -" - - return $flash_xml + return $xml_doc } Index: openacs-4/contrib/packages/simulation/tcl/simulation-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/simulation-init.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/tcl/simulation-init.tcl 10 Nov 2003 16:56:56 -0000 1.1 @@ -0,0 +1,14 @@ +ad_library { + Do initialization at server startup for the simulation package. + + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: simulation-init.tcl,v 1.1 2003/11/10 16:56:56 peterm Exp $ +} + +ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 02 00] simulation::object::xml::file_sweeper + +# FOR DEVELOPMENT ONLY +# TODO (pm debug): remove for production: +foreach package_key {simulation workflow} { + apm_watch_all_files $package_key +} Index: openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/simulation-procs.tcl,v diff -u -N -r1.7 -r1.8 --- openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 6 Nov 2003 15:35:47 -0000 1.7 +++ openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 10 Nov 2003 16:56:56 -0000 1.8 @@ -13,6 +13,10 @@ namespace eval simulation::character {} namespace eval simulation::role {} +ad_proc -public simulation::package_key {} { + return simulation +} + ad_proc -public simulation::object_type::get_options { } { Generate a list of object types formatted as an option list for form-builder's widgets. foo. Index: openacs-4/contrib/packages/simulation/www/object-list.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/object-list.adp,v diff -u -N -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/www/object-list.adp 29 Oct 2003 18:48:09 -0000 1.2 +++ openacs-4/contrib/packages/simulation/www/object-list.adp 10 Nov 2003 16:56:57 -0000 1.3 @@ -2,6 +2,10 @@ @page_title;noquote@ @context;noquote@ +

+@notification_widget;noquote@ +

+

Index: openacs-4/contrib/packages/simulation/www/object-list.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/object-list.tcl,v diff -u -N -r1.9 -r1.10 --- openacs-4/contrib/packages/simulation/www/object-list.tcl 31 Oct 2003 08:43:15 -0000 1.9 +++ openacs-4/contrib/packages/simulation/www/object-list.tcl 10 Nov 2003 16:56:57 -0000 1.10 @@ -84,3 +84,9 @@ } set create_object_url [export_vars -base object-edit { parent_id }] + +set notification_widget [notification::display::request_widget \ + -type [simulation::notification::xml_map::type_short_name] \ + -object_id [ad_conn package_id] \ + -pretty_name [simulation::notification::xml_map::type_pretty_name] \ + -url "[ad_conn url]?[ad_conn query]"] Index: openacs-4/contrib/packages/simulation/www/doc/design.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/doc/Attic/design.html,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/www/doc/design.html 16 Oct 2003 09:52:32 -0000 1.1 +++ openacs-4/contrib/packages/simulation/www/doc/design.html 10 Nov 2003 16:56:57 -0000 1.2 @@ -1 +1,2 @@ -Design

Design


View comments on this page at openacs.org
+ +Design

Design


View comments on this page at openacs.org
Index: openacs-4/contrib/packages/simulation/www/doc/index.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/doc/Attic/index.html,v diff -u -N -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/www/doc/index.html 17 Oct 2003 08:53:55 -0000 1.2 +++ openacs-4/contrib/packages/simulation/www/doc/index.html 10 Nov 2003 16:56:57 -0000 1.3 @@ -1 +1,2 @@ -Simulation
View comments on this page at openacs.org
+ +Simulation
View comments on this page at openacs.org
Index: openacs-4/contrib/packages/simulation/www/doc/install-sect1.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/doc/Attic/install-sect1.html,v diff -u -N -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/www/doc/install-sect1.html 17 Oct 2003 12:02:45 -0000 1.2 +++ openacs-4/contrib/packages/simulation/www/doc/install-sect1.html 10 Nov 2003 16:56:57 -0000 1.3 @@ -1,4 +1,5 @@ -Package installation

Package installation

Requires workflow and bcms and their prerequisites.

  • Option 1: use a custom tarball which includes those modules. In + +Package installation

    Package installation

    Requires workflow and bcms and their prerequisites.

    • Option 1: use a custom tarball which includes those modules. In that case, the custom tarball will have a file install.xml in its root directory, so that installing OpenACS normally will produce a simulation server.

      Notes on custom tarball creation:

      Index: openacs-4/contrib/packages/simulation/www/doc/install.html
      ===================================================================
      RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/doc/Attic/install.html,v
      diff -u -N -r1.1 -r1.2
      --- openacs-4/contrib/packages/simulation/www/doc/install.html	16 Oct 2003 09:52:32 -0000	1.1
      +++ openacs-4/contrib/packages/simulation/www/doc/install.html	10 Nov 2003 16:56:57 -0000	1.2
      @@ -1 +1,2 @@
      -Installation

      Installation


      Table of Contents

      Package installation
      View comments on this page at openacs.org
      + +Installation

      Installation


      Table of Contents

      Package installation
      View comments on this page at openacs.org
      Index: openacs-4/contrib/packages/simulation/www/doc/object-orientation-notes.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/doc/Attic/object-orientation-notes.html,v diff -u -N -r1.3 -r1.4 --- openacs-4/contrib/packages/simulation/www/doc/object-orientation-notes.html 17 Oct 2003 12:02:45 -0000 1.3 +++ openacs-4/contrib/packages/simulation/www/doc/object-orientation-notes.html 10 Nov 2003 16:56:57 -0000 1.4 @@ -1,4 +1,5 @@ -Notes on an object-oriented simulated space

      Notes on an object-oriented simulated space

      An OpenACS simulation is a collection of interactive + +Notes on an object-oriented simulated space

      Notes on an object-oriented simulated space

      An OpenACS simulation is a collection of interactive objects, plus a set of roles and tasks. In the first part, it is conceptually similar to a MOO (Multiple-User Dungeon, Object-Oriented). This is a technology dating to 1990, in which @@ -10,7 +11,7 @@ Games), which are essentially MOOs with graphical instead of textual interfaces. Given their lineage and success, it makes sense to draw on MOO technology when designing our simulation - object model.

      Objects

      Basic MOO objects

      +      object model.

      Objects

      Basic MOO objects

       Root Class
         Room
         Thing
      @@ -27,13 +28,13 @@
           Exit
           Container
             Openable Container
      -

      Object Attributes

      (From the LambdaMOO Programmer's Manual

      +

      Object Attributes

      (From the LambdaMOO Programmer's Manual

       There are three fundamental attributes to every object:
       
          1. A flag (either true or false) specifying whether or not the object represents a player,
          2. The object that is its parent, and
          3. A list of the objects that are its children; that is, those
      -   objects for which this object is their parent. 

      "Every object has eight built-in properties whose values are constrained to be of particular types. "

      +   objects for which this object is their parent. 

      "Every object has eight built-in properties whose values are constrained to be of particular types. "

       name         a string, the usual name for this object
       owner        an object, the player who controls access to it
       location     an object, where the object is in virtual reality
      @@ -43,4 +44,4 @@
       r            a bit, is the object publicly readable?
       w            a bit, is the object publicly writable?
       f            a bit, is the object fertile?
      -

      Verbs

      Minimal MOO verbs:

      • put

        take

        get

        drop

      View comments on this page at openacs.org
      +

      Verbs

      Minimal MOO verbs:

      • put

        take

        get

        drop

      View comments on this page at openacs.org
      Index: openacs-4/contrib/packages/simulation/www/doc/xml/Makefile =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/doc/xml/Attic/Makefile,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/www/doc/xml/Makefile 16 Oct 2003 09:52:32 -0000 1.1 +++ openacs-4/contrib/packages/simulation/www/doc/xml/Makefile 10 Nov 2003 16:56:57 -0000 1.2 @@ -18,4 +18,4 @@ all: - cd .. ; $(XSLTPROC) --nonet --novalid --xinclude ../../../../../packages/acs-core-docs/www/xml/openacs.xsl xml/index.xml \ No newline at end of file + cd .. ; $(XSLTPROC) --nonet --novalid --xinclude ../../../../packages/acs-core-docs/www/xml/openacs.xsl xml/index.xml \ No newline at end of file Index: openacs-4/packages/simulation/simulation.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/simulation.info,v diff -u -N -r1.4 -r1.5 --- openacs-4/packages/simulation/simulation.info 27 Oct 2003 07:31:54 -0000 1.4 +++ openacs-4/packages/simulation/simulation.info 10 Nov 2003 17:06:21 -0000 1.5 @@ -13,16 +13,17 @@ Workflow-based task simulator. 2003-10-13 - - - + + + + - + Index: openacs-4/packages/simulation/tcl/apm-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/apm-callback-procs.tcl,v diff -u -N -r1.6 -r1.7 --- openacs-4/packages/simulation/tcl/apm-callback-procs.tcl 31 Oct 2003 11:08:38 -0000 1.6 +++ openacs-4/packages/simulation/tcl/apm-callback-procs.tcl 10 Nov 2003 16:56:56 -0000 1.7 @@ -8,7 +8,14 @@ namespace eval simulation::apm {} +ad_proc -private simulation::apm::after_install {} { + simulation::notification::xml_map::register +} +ad_proc -private simulation::apm::before_uninstall {} { + simulation::notification::xml_map::unregister +} + ad_proc -private simulation::apm::after_instantiate { {-package_id:required} } { @@ -24,4 +31,3 @@ -context_id $package_id \ -content_types { sim_character sim_prop sim_location sim_stylesheet image }] } - Index: openacs-4/packages/simulation/tcl/notification-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/notification-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/tcl/notification-procs.tcl 10 Nov 2003 16:56:56 -0000 1.1 @@ -0,0 +1,76 @@ +ad_library { + Procs related to notifications. + + @author Peter Marklund + @creation-date 2003-11-10 + @cvs-id $Id: notification-procs.tcl,v 1.1 2003/11/10 16:56:56 peterm Exp $ +} + +namespace eval simulation::notification {} +namespace eval simulation::notification::xml_map {} + +ad_proc -private simulation::notification::xml_map::register {} { + db_transaction { + set spec [list \ + contract_name "NotificationType" \ + name [sc_name] \ + aliases { + GetURL simulation::notification::xml_map::get_url + ProcessReply simulation::notification::xml_map::process_reply + } \ + owner [simulation::package_key]] + set sc_impl_id [acs_sc::impl::new_from_spec -spec $spec] + + notification::type::new \ + -all_intervals \ + -all_delivery_methods \ + -sc_impl_id $sc_impl_id \ + -short_name [type_short_name] \ + -pretty_name [type_pretty_name] \ + -description [type_description] + } +} + +ad_proc -private simulation::notification::xml_map::unregister {} { + db_transaction { + notification::type::delete -short_name [type_short_name] + + acs_sc::impl::delete \ + -contract_name "NotificationType" \ + -impl_name [sc_name] + } +} + +ad_proc -private simulation::notification::xml_map::sc_id {} { + return [acs_sc::impl::get_id \ + -owner [simulation::package_key] \ + -name [sc_name]] +} + +ad_proc -private simulation::notification::xml_map::sc_name {} { + return "MapXMLNotification" +} + +ad_proc -private simulation::notification::xml_map::type_short_name {} { + return "map_xml" +} + +ad_proc -private simulation::notification::xml_map::type_pretty_name {} { + return "Map XML" +} + +ad_proc -private simulation::notification::xml_map::type_description {} { + return "Notification of changes to the Map XML file." +} + +ad_proc -public simulation::notification::xml_map::get_url { + object_id +} { + # Todo: Implement this proc +} + +ad_proc -public simulation::notification::xml_map::process_reply { + reply_id +} { + # Todo: Implement this proc +} Index: openacs-4/packages/simulation/tcl/object-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/object-procs.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/simulation/tcl/object-procs.tcl 7 Nov 2003 16:08:45 -0000 1.1 +++ openacs-4/packages/simulation/tcl/object-procs.tcl 10 Nov 2003 16:56:56 -0000 1.2 @@ -7,52 +7,146 @@ } namespace eval simulation::object {} +namespace eval simulation::object::xml {} -ad_proc -public simulation::object::schedule_generate_xml_file { - {-package_id ""} +ad_proc -private simulation::object::xml::file_sweeper {} { + Loop over all simulation package instances and re-generate + XML map files for them. + + @see simulation::object::xml::generate_file + + @author Peter Marklund } { -

      - Schedules the proc simulation::object::generate_xml_file to be - executed now in its own thread. -

      + set simulation_package_ids [db_list simulation_package_ids { + select package_id + from apm_packages + where package_key = 'simulation' + }] -

      - This proc needs to be invoked upon the create, edit, and delete - event for simulation objects that have the on_map_p attribute - set to true. It also needs to be invoked if the on_map_p attribute - is toggled from false to true for a sim object. -

      + ns_log Notice "Proc simulation::object::xml::file_sweeper executing with simulation_package_ids=$simulation_package_ids" + foreach package_id $simulation_package_ids { + generate_file -package_id $package_id + } + ns_log Notice "Finished executing simulation::object::xml::file_sweeper" +} - +ad_proc -private simulation::object::xml::generate_file { + {-package_id:required} +} { + Generate map XML document for the package. Compare the XML + document with any existing XML document for the package and + write the new document to the filesystem if it differs from + the existing document. Sends a notification if the file + was generated or if there were errors generating the file. + @see simulation::object::xml::get_doc + + @return 1 if a new XML file was written and 0 otherwise + @author Peter Marklund } { - if { [empty_string_p $package_id] } { - set package_id [ad_conn package_id] + set errors [list] + + set parameter_name "MapXmlFilePath" + set file_path [parameter::get -parameter $parameter_name -package_id $package_id] + + # An empty file_path signifies that no XML map file should be generated + if { [empty_string_p $file_path] } { + return } - ad_schedule_proc -thread t -once t 0 simulation::object::generate_xml_file -package_id $package_id + # file_path validity check + set file_path_error_prefix "Parameter simulation.$parameter_name for package $package_id has invalid value \"${file_path}\"." + if { ![regexp {^/} $file_path] } { + set error_message "$file_path_error_prefix It needs to start with /" + lappend errors $error_message + ns_log Error $error_message + } + if { ![file readable $file_path] } { + set error_message "$file_path_error_prefix The file is not readable" + lappend errors $error_message + ns_log Error $error_message + } + + set wrote_file_p 0 + with_catch errmsg { + + if { [llength $errors] == 0 } { + set old_xml_doc [template::util::read_file $file_path] + set new_xml_doc [get_doc -package_id $package_id] + set xml_changed_p [ad_decode [string compare $old_xml_doc $new_xml_doc] 0 0 1] + error hej + if { $xml_changed_p } { + template::util::write_file $file_path + set wrote_file_p 1 + } + } + } { + global errorInfo + set error_message "Generating XML file failed with error message: $errmsg\n\n$errorInfo" + ns_log Error $error_message + lappend errors $error_message + } + + if { $wrote_file_p || [llength $errors] > 0 } { + notify \ + -package_id $package_id \ + -file_path $file_path \ + -wrote_file_p $wrote_file_p \ + -errors $errors + } + + return $wrote_file_p } -ad_proc -public simulation::object::generate_xml_file { +ad_proc -private simulatation::object::xml::notify { {-package_id:required} + {-file_path:required} + {-wrote_file_p:required} + {-errors:required} } { -

      - Re-generates (or generates for the first time) the XML file - containing information about all simulation objects that are - to be on the SIMBUILD flash map. -

      + Send a notification about the results of an XML file generation. @author Peter Marklund } { - ########## - # Get data to be written to file - ########## + set package_url "[ad_url][apm_package_url_from_id $package_id]" - # Get a list of names of tables storing the on_map_p attribute for - # items created in the given package + set subject "XML File generation results for package at ${package_url}" + + if { $wrote_file_p } { + append body "An XML file was written to file at \"$file_path\"." + } else { + append body "An XML file could not be written to file at \"$file_path\"." + } + + if { [llength $errors] > 0 } { + set all_errors [join $errors "\n\n"] + append body "\n\nThe following errors were encountered: + +$all_errors + +" + } + + # Send notification +} + +ad_proc -private simulation::object::xml::get_doc { + {-package_id:required} +} { + Generates XML for all relevant simulation objects in the given + package (that have on_map_p attribute set to true). + + @return An XML document + + @author Peter Marklund +} { + set full_package_url "[ad_url][apm_package_url_from_id $package_id]" + + # Get table names and id column names for the on_map_p attribute of each object type + # By using the multirow we avoid a nested db_foreach set parent_id [bcms::folder::get_id_by_package_id -parent_id 0] - set sim_table_lists [db_list select_sim_tables { + db_multirow -local sim_table_list select_sim_tables { select aot.table_name, aot.id_column from acs_object_types aot, @@ -64,110 +158,79 @@ where ci.parent_id = :parent_id and ci.content_type = aot.object_type ) - }] + } - foreach sim_table $sim_table_list { - set table_name [lindex $sim_table 0] - set id_column [lindex $sim_table 1] + # Open XML document + set xml_doc "\n\n" - set object_lists [db_list_of_lists select_on_map_objects " - select ci.item_id, - cr.content_type - cr.title, - ci.name, + # Object type loop. + template::multirow -local foreach sim_table_list { + ns_log Notice " + select ci.item_id as id, + cr.title as name, + ci.name as uri, cr.description, + ci.content_type, + (select min(ci2.name) + from cr_item_rels cir, + cr_items ci2 + where cir.item_id = ci.item_id + and cir.related_object_id = ci2.item_id + and cir.relation_tag = 'thumbnail') as thumbnail_uri from cr_items ci - cr_revisions cr + left outer join cr_item_rels cir on (cir.item_id = ci.item_id), + cr_revisions cr, $table_name st where st.on_map_p = 't' - and st.$id_column = ci.item_id + and st.$id_column = cr.revision_id and ci.live_revision = cr.revision_id and ci.parent_id = :parent_id - "] - } + order by ci.name + " + db_foreach select_on_map_objects " + select ci.item_id as id, + cr.title as name, + ci.name as uri, + cr.description, + ci.content_type, + (select min(ci2.name) + from cr_item_rels cir, + cr_items ci2 + where cir.item_id = ci.item_id + and cir.related_object_id = ci2.item_id + and cir.relation_tag = 'thumbnail') as thumbnail_uri + from cr_items ci + left outer join cr_item_rels cir on (cir.item_id = ci.item_id), + cr_revisions cr, + $table_name st + where st.on_map_p = 't' + and st.$id_column = cr.revision_id + and ci.live_revision = cr.revision_id + and ci.parent_id = :parent_id + order by ci.name + " { + set url "$full_package_url/object/$name" - ########## - # Generate XML document - ########## + if { [lsearch -exact {sim_location sim_prop sim_character} $content_type] != -1 } { + set thumbnail_url "${full_package_url}object-content/${thumbnail_uri}" + } else { + set thumbnail_url "" + } - set xml_doc " -" - foreach object_list $object_lists { - append xml_doc [generate_xml \ - -item_id [lindex $object_list 0] \ - -content_type [lindex $object_list 1] \ - -title [lindex $object_list 2] \ - -name [lindex $object_list 3] \ - -description [lindex $object_list 4]] - } - append xml_doc "" + append xml_doc " \n" + # Assuming var names are identical to XML tag names + set xml_tag_names {name url thumbnail_url description} + foreach tag_name $xml_tag_names { + append xml_doc " <${tag_name}>[ad_quotehtml [set ${tag_name}]]\n" + } + append xml_doc " \n" - ########## - # Write to file - ########## + } ;# End object loop - # TODO: make filepath a parameter - set file_path "/tmp/map-objects.xml" - set file_id [open $file_path w] - puts $file_id $xml_doc - close $catalog_file_id -} + } ;# End object type loop -ad_proc -public simulation::object::generate_xml { - {-item_id:required} - {-content_type ""} - {-title ""} - {-name ""} - {-description ""} -} { -

      - Generate XML to be used by the CityBuild flash map for a certain - simulation object. Requires there to be an HTTP connection as it - uses ad_conn package_url to get the URL of the object. -

      + # Close XML document + append xml_doc "
      \n" - @param item_id Stored in cr_items.item_id - @param content_type Stored in cr_items.content_type - @param title Stored in cr_revisions.title - @param name Stored in cr_items.name - @param description Stored in cr_revisions.description - - @author Peter Marklund -} { - # Set default values for optional args - set optional_args {content_type title name description} - foreach arg_name $optional_args { - if { [empty_string_p [set $arg_name]] } { - if { ![info exists item_info] } { - array set item_info [bcms::item::get_item -item_id $item_id -revision live] - } - - set $arg_name $item_info($arg_name) - } - } - - # Get object url and thumbnail url - set full_package_url "[ad_url]/[ad_conn package_url]" - set url "$full_package_url/object/$name" - if { [lsearch -exact {sim_location sim_prop sim_character} $content_type] != -1 } { - set thumbnail_list [bcms::item::list_related_items \ - -return_list \ - -item_id $item_id \ - -relation_tag thumbnail] - set thumbnail_uri [lindex [lindex $thumbnail_list 0] 1] - set thumbnail_url "$full_package_url/object-content/$thumbnail_uri" - } else { - set thumbnail_url "" - } - - # Create XML document - append flash_xml " - $item_id - [ad_quotehtml $name] - [ad_quotehtml $url] - [ad_quotehtml $thumbnail_url] - [ad_quotehtml $description] -" - - return $flash_xml + return $xml_doc } Index: openacs-4/packages/simulation/tcl/simulation-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/simulation-init.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/tcl/simulation-init.tcl 10 Nov 2003 16:56:56 -0000 1.1 @@ -0,0 +1,14 @@ +ad_library { + Do initialization at server startup for the simulation package. + + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: simulation-init.tcl,v 1.1 2003/11/10 16:56:56 peterm Exp $ +} + +ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 02 00] simulation::object::xml::file_sweeper + +# FOR DEVELOPMENT ONLY +# TODO (pm debug): remove for production: +foreach package_key {simulation workflow} { + apm_watch_all_files $package_key +} Index: openacs-4/packages/simulation/tcl/simulation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/simulation-procs.tcl,v diff -u -N -r1.7 -r1.8 --- openacs-4/packages/simulation/tcl/simulation-procs.tcl 6 Nov 2003 15:35:47 -0000 1.7 +++ openacs-4/packages/simulation/tcl/simulation-procs.tcl 10 Nov 2003 16:56:56 -0000 1.8 @@ -13,6 +13,10 @@ namespace eval simulation::character {} namespace eval simulation::role {} +ad_proc -public simulation::package_key {} { + return simulation +} + ad_proc -public simulation::object_type::get_options { } { Generate a list of object types formatted as an option list for form-builder's widgets. foo. Index: openacs-4/packages/simulation/www/object-list.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/object-list.adp,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/simulation/www/object-list.adp 29 Oct 2003 18:48:09 -0000 1.2 +++ openacs-4/packages/simulation/www/object-list.adp 10 Nov 2003 16:56:57 -0000 1.3 @@ -2,6 +2,10 @@ @page_title;noquote@ @context;noquote@ +

      +@notification_widget;noquote@ +

      +

      Index: openacs-4/packages/simulation/www/object-list.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/object-list.tcl,v diff -u -N -r1.9 -r1.10 --- openacs-4/packages/simulation/www/object-list.tcl 31 Oct 2003 08:43:15 -0000 1.9 +++ openacs-4/packages/simulation/www/object-list.tcl 10 Nov 2003 16:56:57 -0000 1.10 @@ -84,3 +84,9 @@ } set create_object_url [export_vars -base object-edit { parent_id }] + +set notification_widget [notification::display::request_widget \ + -type [simulation::notification::xml_map::type_short_name] \ + -object_id [ad_conn package_id] \ + -pretty_name [simulation::notification::xml_map::type_pretty_name] \ + -url "[ad_conn url]?[ad_conn query]"] Index: openacs-4/packages/simulation/www/doc/design.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/doc/design.html,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/simulation/www/doc/design.html 16 Oct 2003 09:52:32 -0000 1.1 +++ openacs-4/packages/simulation/www/doc/design.html 10 Nov 2003 16:56:57 -0000 1.2 @@ -1 +1,2 @@ -Design

      Design


      View comments on this page at openacs.org
      + +Design

      Design


      View comments on this page at openacs.org
      Index: openacs-4/packages/simulation/www/doc/index.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/doc/index.html,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/simulation/www/doc/index.html 17 Oct 2003 08:53:55 -0000 1.2 +++ openacs-4/packages/simulation/www/doc/index.html 10 Nov 2003 16:56:57 -0000 1.3 @@ -1 +1,2 @@ -Simulation
      View comments on this page at openacs.org
      + +Simulation
      View comments on this page at openacs.org
      Index: openacs-4/packages/simulation/www/doc/install-sect1.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/doc/install-sect1.html,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/simulation/www/doc/install-sect1.html 17 Oct 2003 12:02:45 -0000 1.2 +++ openacs-4/packages/simulation/www/doc/install-sect1.html 10 Nov 2003 16:56:57 -0000 1.3 @@ -1,4 +1,5 @@ -Package installation

      Package installation

      Requires workflow and bcms and their prerequisites.

      • Option 1: use a custom tarball which includes those modules. In + +Package installation

        Package installation

        Requires workflow and bcms and their prerequisites.

        • Option 1: use a custom tarball which includes those modules. In that case, the custom tarball will have a file install.xml in its root directory, so that installing OpenACS normally will produce a simulation server.

          Notes on custom tarball creation:

          Index: openacs-4/packages/simulation/www/doc/install.html
          ===================================================================
          RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/doc/install.html,v
          diff -u -N -r1.1 -r1.2
          --- openacs-4/packages/simulation/www/doc/install.html	16 Oct 2003 09:52:32 -0000	1.1
          +++ openacs-4/packages/simulation/www/doc/install.html	10 Nov 2003 16:56:57 -0000	1.2
          @@ -1 +1,2 @@
          -Installation

          Installation


          Table of Contents

          Package installation
          View comments on this page at openacs.org
          + +Installation

          Installation


          Table of Contents

          Package installation
          View comments on this page at openacs.org
          Index: openacs-4/packages/simulation/www/doc/object-orientation-notes.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/doc/object-orientation-notes.html,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/simulation/www/doc/object-orientation-notes.html 17 Oct 2003 12:02:45 -0000 1.3 +++ openacs-4/packages/simulation/www/doc/object-orientation-notes.html 10 Nov 2003 16:56:57 -0000 1.4 @@ -1,4 +1,5 @@ -Notes on an object-oriented simulated space

          Notes on an object-oriented simulated space

          An OpenACS simulation is a collection of interactive + +Notes on an object-oriented simulated space

          Notes on an object-oriented simulated space

          An OpenACS simulation is a collection of interactive objects, plus a set of roles and tasks. In the first part, it is conceptually similar to a MOO (Multiple-User Dungeon, Object-Oriented). This is a technology dating to 1990, in which @@ -10,7 +11,7 @@ Games), which are essentially MOOs with graphical instead of textual interfaces. Given their lineage and success, it makes sense to draw on MOO technology when designing our simulation - object model.

          Objects

          Basic MOO objects

          +      object model.

          Objects

          Basic MOO objects

           Root Class
             Room
             Thing
          @@ -27,13 +28,13 @@
               Exit
               Container
                 Openable Container
          -

          Object Attributes

          (From the LambdaMOO Programmer's Manual

          +

          Object Attributes

          (From the LambdaMOO Programmer's Manual

           There are three fundamental attributes to every object:
           
              1. A flag (either true or false) specifying whether or not the object represents a player,
              2. The object that is its parent, and
              3. A list of the objects that are its children; that is, those
          -   objects for which this object is their parent. 

          "Every object has eight built-in properties whose values are constrained to be of particular types. "

          +   objects for which this object is their parent. 

          "Every object has eight built-in properties whose values are constrained to be of particular types. "

           name         a string, the usual name for this object
           owner        an object, the player who controls access to it
           location     an object, where the object is in virtual reality
          @@ -43,4 +44,4 @@
           r            a bit, is the object publicly readable?
           w            a bit, is the object publicly writable?
           f            a bit, is the object fertile?
          -

          Verbs

          Minimal MOO verbs:

          • put

            take

            get

            drop

          View comments on this page at openacs.org
          +

          Verbs

          Minimal MOO verbs:

          • put

            take

            get

            drop

          View comments on this page at openacs.org
          Index: openacs-4/packages/simulation/www/doc/xml/Makefile =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/doc/xml/Makefile,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/simulation/www/doc/xml/Makefile 16 Oct 2003 09:52:32 -0000 1.1 +++ openacs-4/packages/simulation/www/doc/xml/Makefile 10 Nov 2003 16:56:57 -0000 1.2 @@ -18,4 +18,4 @@ all: - cd .. ; $(XSLTPROC) --nonet --novalid --xinclude ../../../../../packages/acs-core-docs/www/xml/openacs.xsl xml/index.xml \ No newline at end of file + cd .. ; $(XSLTPROC) --nonet --novalid --xinclude ../../../../packages/acs-core-docs/www/xml/openacs.xsl xml/index.xml \ No newline at end of file