Index: openacs-4/packages/logger/sql/oracle/logger-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/sql/oracle/logger-create.sql 5 Apr 2003 10:16:16 -0000 1.1 @@ -0,0 +1,9 @@ +-- +-- Logger Oracle data model +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- @creation-date 2003-04-03 + +@logger-tables-create.sql +@logger-packages-create.sql Index: openacs-4/packages/logger/sql/oracle/logger-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/sql/oracle/logger-drop.sql 5 Apr 2003 10:16:16 -0000 1.1 @@ -0,0 +1,9 @@ +-- +-- Drop script for the Logger Oracle data model +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- @creation-date 2003-04-03 + +@logger-tables-drop.sql +@logger-packages-drop.sql Index: openacs-4/packages/logger/sql/oracle/logger-packages-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-packages-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/sql/oracle/logger-packages-create.sql 5 Apr 2003 10:16:16 -0000 1.1 @@ -0,0 +1,115 @@ +-- +-- Oracle PL/SQL packages for the Logger application +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- @creation-date 2003-04-03 + +------------------------------------ +-- Package definititions +------------------------------------ + +create or replace package logger_project +as + function new ( + project_id in integer default null, + name in cr_revisions.title%TYPE, + description in cr_revisions.description%TYPE default null, + project_lead in integer, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE default null, + package_id in apm_packages.package_id%TYPE + ) return integer; + + procedure delete ( + project_id in integer + ); + + function name ( + project_id in integer + ) return varchar2; + +end logger_project; +/ +show errors; + +------------------------------------ +-- Package body implementations +------------------------------------ + +create or replace package body logger_project +as + function new ( + project_id in integer default null, + name in cr_revisions.title%TYPE, + description in cr_revisions.description%TYPE default null, + project_lead in integer, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE default null, + package_id in apm_packages.package_id%TYPE + ) return integer + is + v_project_id integer; + begin + v_project_id := acs_object.new( + object_id => project_id, + object_type => 'logger_project', + context_id => package_id, + creation_ip => creation_ip, + creation_user => creation_user + ); + + insert into logger_projects (project_id, name, description, project_lead) + values (v_project_id, name, description, project_lead); + + insert into logger_project_pkg_map (project_id, package_id) + values (v_project_id, logger_project.new.package_id); + + return v_project_id; + end new; + + procedure delete ( + project_id in integer + ) + is + begin + -- Delete all variables only mapped to this project. This will cascade + -- referencing measurements + for rec in (select variable_id + from logger_variables + where exists (select 1 + from logger_project_pkg_map + where project_id = logger_project.delete.project_id + ) + and not exists (select 1 + from logger_project_pkg_map + where project_id <> logger_project.delete.project_id + ) + ) + loop + delete from logger_variables where variable_id = rec.variable_id; + end loop; + + -- Delete the project acs object. This will cascade the row in the logger_projects table + -- as well as all remaining measurements and projections in the project + acs_object.delete(project_id); + + end delete; + + function name ( + project_id in integer + ) return varchar2 + is + v_name logger_projects.name%TYPE; + begin + select name + into v_name + from logger_projects + where project_id = name.project_id; + + return v_name; + end name; + +end logger_project; +/ +show errors; Index: openacs-4/packages/logger/sql/oracle/logger-packages-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-packages-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/sql/oracle/logger-packages-drop.sql 5 Apr 2003 10:16:16 -0000 1.1 @@ -0,0 +1,8 @@ +-- +-- Drop script for Oracle PL/SQL packages in the Logger application +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- @creation-date 2003-03-28 + +drop package logger_project; Index: openacs-4/packages/logger/sql/oracle/logger-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-tables-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/sql/oracle/logger-tables-create.sql 5 Apr 2003 10:16:16 -0000 1.1 @@ -0,0 +1,192 @@ +-- Oracle tables for the Logger application +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- @creation-date 3:d of April 2003 + +create table logger_projects ( + project_id integer + constraint logger_projects_pk + primary key + constraint logger_projects_pid_fk + references acs_objects(object_id) + on delete cascade, + name varchar(1000), + description varchar(4000), + active_p char(1) + default 't' + constraint logger_projects_ap_nn + not null + constraint logger_projects_ap_ck + check (active_p in ('t', 'f')), + project_lead integer + constraint logger_projects_pl_nn + not null + constraint logger_projects_pl_fk + references users(user_id) +); + +comment on table logger_projects is ' + Log entries are grouped by projects. Once we have a dedicated + project management package for OpenACS this table will be superseeded by + tables in that package. In order to make such a change easier in the future + we are not referencing the logger_projects table directly in the logger datamodel + but instead reference acs_objects. +'; + +begin + acs_object_type.create_type ( + 'logger_project', + 'Logger project', + 'Logger projects', + 'acs_object', + 'logger_projects', + 'project_id', + null, + 'f', + null, + 'logger_project.name' + ); +end; +/ +show errors + +create table logger_project_pkg_map ( + project_id integer + constraint logger_project_pkg_map_pr_fk + references acs_objects(object_id) + on delete cascade, + package_id integer + constraint logger_project_pkg_map_pa_fk + references apm_packages(package_id) + on delete cascade, + constraint logger_project_pkg_map_un + unique (project_id, package_id) +); + +comment on table logger_project_pkg_map is ' + Each project can be mounted in multiple package instances. +'; + +create table logger_variables ( + variable_id integer + constraint logger_variables_pk + primary key, + name varchar(200), + unit varchar(200), + type varchar(50) + default 'additive' + constraint logger_variables_type_nn + not null + constraint logger_variables_type_ck + check (type in ('additive', 'non-additive')) +); + +comment on column logger_variables.type is ' + Indicates if measurements of this variable should be added together or not. + Examples of additive variables are time and money spent at different times during + a project. A non-additive variable would be the amount of money in a bank account. +'; + +create sequence logger_variables_seq; + +create table logger_project_var_map ( + project_id integer + constraint logger_project_var_map_pid_fk + references acs_objects(object_id) + on delete cascade + constraint logger_project_var_map_pid_nn + not null, + variable_id integer + constraint logger_project_var_map_vid_fk + references logger_variables(variable_id) + on delete cascade + constraint logger_project_var_map_vid_nn + not null, + primary_p char(1) + default 't' + constraint logger_project_var_map_pp_nn + not null + constraint logger_project_var_map_pp_ck + check (primary_p in ('t', 'f')), + constraint logger_project_var_map_un + unique(project_id, variable_id) +); + +comment on column logger_project_var_map.primary_p is ' + Every project must have a primary variable which represents what we are + most interested in logging and reporting in that project + - typically time spent on various tasks. +'; + +create table logger_projections ( + projection_id integer + constraint logger_projections_pk + primary key, + project_id integer + constraint logger_projections_pid_nn + not null + constraint logger_projections_pid_fk + references acs_objects(object_id) + on delete cascade, + variable_id integer + constraint logger_projections_vid_nn + not null + constraint logger_projections_vid_fk + references logger_variables(variable_id) + on delete cascade, + start_time date + constraint logger_projections_st_nn + not null, + end_time date + constraint logger_projections_et_nn + not null, + value number + constraint logger_projections_value_nn + not null +); + +comment on table logger_projections is ' + This table allows a project admin to specify expected or targeted logging values + over a particular time period. +'; + +comment on column logger_projections.value is ' + For additive variables the projection value will represent the expected or targeted + sum of measurements during the time range and for non-additive variables it will + represent an average. +'; + +create table logger_measurements ( + measurement_id integer + constraint logger_measurements_pk + primary key, + project_id integer + constraint logger_measurements_pid_fk + references acs_objects(object_id) + on delete cascade, + variable_id integer + constraint logger_measurements_v_id_fk + references logger_variables(variable_id) + on delete cascade, + value number + constraint logger_measurements_value_nn + not null, + time_stamp date + default sysdate + constraint logger_measurements_ts_nn + not null +); + +comment on table logger_measurements is ' + This is the center piece of the logger datamodel that holds the actually reported + data - namely numbers bound to points in time. Given the HR-XML + Time and Reporting standard (see http://www.hr-xml.org) we considered allowing + for explicit start and end times. However, in the interest of simplicity + for the initial release of the package we opted against this. The HR-XML spec talks + about three categories of reports - time events, time intervals, and + expenses incurred. Of those we are initially only supporting the latter two + and for time intervals we don''t support any explicit start and end time (only a timestamp + and a value). Support for those remaining HR-XML use cases can be added on later without + much difficulty. +'; Index: openacs-4/packages/logger/sql/oracle/logger-tables-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-tables-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/sql/oracle/logger-tables-drop.sql 5 Apr 2003 10:16:16 -0000 1.1 @@ -0,0 +1,31 @@ +-- Drop non-procedural data model of the Logger application. +-- NOTE: In general it is not a good idea to source sql drop scripts +-- from the command line since such scripts may assume that any data in package instances +-- has already been dropped by the APM through the before-uninstantiate callback. +-- Use the /acs-admin/apm UI instead to delete packages. +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- @creation-date 3:d of April 2003 + +drop table logger_measurements; + +drop table logger_projections; + +drop table logger_project_var_map; + +drop table logger_variables; + +drop sequence logger_variables_seq; + +drop table logger_project_pkg_map; + +drop table logger_projects; + +begin + acs_object_type.drop_type ( + 'logger_project' + ); +end; +/ +show errors Index: openacs-4/packages/logger/tcl/apm-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/apm-callback-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/apm-callback-procs.tcl 5 Apr 2003 10:16:42 -0000 1.1 @@ -0,0 +1,25 @@ +ad_library { + APM callback procedures in the logger::apm namespace. + + @creation-date 1 April 2003 + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: apm-callback-procs.tcl,v 1.1 2003/04/05 10:16:42 peterm Exp $ +} + +namespace eval logger::apm {} + +ad_proc -public logger::apm::before_uninstantiate { + {-package_id:required} +} { + Deletes all logger projects (and their data) mapped + only to the given package before the package is deleted. + We thus avoid having orphan logger data in the database. + + @author Peter Marklund +} { + set project_id_list [logger::package::projects_only_in_package -package_id $package_id] + foreach project_id $project_id_list { + ns_log Notice "logger::apm::before_uninstantiate - deleting project $project_id for package $package_id" + logger::project::delete -project_id $project_id + } +} Index: openacs-4/packages/logger/tcl/package-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/package-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/package-procs.tcl 5 Apr 2003 10:16:42 -0000 1.1 @@ -0,0 +1,51 @@ +ad_library { +

+ Procedures in the logger::package namespace. Those procedures + operate on logger package objects. +

+ +

+ Unlike many other -procs.tcl files in the logger package this + file contains no ::new and ::delete procedures. The reason + is that packages are created by the APM proc apm_package_instance_new. + When the logger application needs extra data to be setup for package + instances this would be done in an after-instantiate callback in + the file apm-callback-procs.tcl. +

+ + @creation-date 4:th of April 2003 + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: package-procs.tcl,v 1.1 2003/04/05 10:16:42 peterm Exp $ +} + +namespace eval logger::package {} + +ad_proc -public logger::package::projects_only_in_package { + {-package_id:required} +} { + Return the ids of all logger projects that are mapped to + the given package and are not mapped to any other packages. + These are the projects that the package owns. + + @param package_id The id of the package to return projects for + + @return A list of project_id:s. An empty list if there are no matching projects. + + @author Peter Marklund +} { + return [db_list select_projects {}] +} + +ad_proc -public logger::package::all_projects_in_package { + {-package_id:required} +} { + Return a list of ids for all logger projects mapped to the given package.x + + @param package_id The id of the package to return projects for + + @return A list of project_id:s. An empty list if there are no matching projects. + + @author Peter Marklund +} { + return [db_list select_projects {}] +} Index: openacs-4/packages/logger/tcl/package-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/package-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/package-procs.xql 5 Apr 2003 10:16:42 -0000 1.1 @@ -0,0 +1,28 @@ + + + + + + + select project_id + from logger_projects + where exists (select 1 + from logger_project_pkg_map + where package_id = :package_id + and project_id = logger_projects.project_id) + and not exists (select 1 + from logger_project_pkg_map + where package_id <> :package_id + and project_id = logger_projects.project_id) + + + + + + select project_id + from logger_project_pkg_map + where package_id = :package_id + + + + Index: openacs-4/packages/logger/tcl/project-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/project-procs-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/project-procs-oracle.xql 5 Apr 2003 10:16:42 -0000 1.1 @@ -0,0 +1,30 @@ + + + + oracle8.1.6 + + + + begin + :1 := logger_project.new ( + project_id => :project_id, + name => :name, + description => :description, + project_lead => :project_lead, + creation_user => :creation_user, + creation_ip => :creation_ip, + package_id => :package_id + ); + end; + + + + + + begin + logger_project.delete(:project_id); + end; + + + + Index: openacs-4/packages/logger/tcl/project-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/project-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/project-procs.tcl 5 Apr 2003 10:16:42 -0000 1.1 @@ -0,0 +1,190 @@ +ad_library { + Procedures in the logger::project namespace. Those + procedures operate on logger project objects. + + @creation-date 31 March 2003 + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: project-procs.tcl,v 1.1 2003/04/05 10:16:42 peterm Exp $ +} + +namespace eval logger::project {} + +ad_proc -public logger::project::new { + {-name:required} + {-project_id ""} + {-package_id ""} + {-description ""} + {-project_lead ""} + {-creation_user ""} + {-creation_ip ""} +} { +

+ Create a logger project. +

+ +

+ I've tried to design this proc so that it can be used also + if there is no ad_conn connection, for example during a data import. +

+ + @param name The name of the project. + @param project_id Any pre-generated id of the new package. Optional. + @param package_id The id of the Logger package in which the project is created. Defaults + to ad_conn package_id. Also used as context_id. + @param description The description for the proct. Optional. + @param project_lead The user id of the project leader of the project. Defaults + to the currently logged in user. + @param creation_user The user creating the project. Defaults to ad_conn user_id. + @param creation_ip The ip of the user creating the project. Defaults to ad_conn peeraddr + + @return The project_id of the created project. + + @author Peter Marklund +} { + # Use ad_conn to setup default values and check that required values are provided + # if there is no ad_conn + # The lists are on the array format + # var_name1 ad_conn_arg_name1 var_name2 ad_conn_arg_name2 ... + set required_ad_conn_vars [list package_id package_id creation_user user_id] + set optional_ad_conn_vars [list creation_ip peeraddr] + if { [ad_conn isconnected] } { + # HTTP connection available + + # ad_conn provides default values for us + foreach {var_name ad_conn_name} [concat $required_ad_conn_vars $optional_ad_conn_vars] { + if { [empty_string_p [set $var_name]] } { + set $var_name [ad_conn $ad_conn_name] + + # If we are using ad_conn package_id + # we might as well use ad_conn to check that its a logger package + if { [string equal $var_name package_id] } { + if { ![string equal [ad_conn package_key] logger] } { + error "logger::project::new Defaulting package_id to the current package with key [ad_conn package_key] but package must be a logger package" + } + } + } + } + + + } else { + # No HTTP connection + + # Default optional ad_conn vars to the empty string + foreach {var_name ad_conn_name} $optional_ad_conn_vars { + set $var_name "" + } + + # Assert that required ad_conn variables are provided + foreach var_name $required_ad_conn_vars { + if { [empty_string_p [set $var_name]] } { + error "logger::project::new - the $var_name argument was not provided and there is no ad_conn (HTTP) connection so a default value cannot be set" + } + } + } + + # Project lead defaults to creation user + if { [empty_string_p $project_lead] } { + set project_lead $creation_user + } + + set project_id [db_exec_plsql insert_project {}] + + return $project_id +} + +ad_proc -public logger::project::delete { + {-project_id:required} +} { + Delete a logger project and all logger measurements and projections + contained within it. Also deletes all logger variables mapped to this + project that are not mapped to other projects. + + @param project_id The id of the project to delete + + @author Peter Marklund +} { + db_exec_plsql delete_project {} +} + +ad_proc -public logger::project::get { + {-project_id:required} + {-array:required} +} { + Retrieve info about the project with given id into an + array (using upvar) in the callers scope. The + array will contain the keys project_id, name, description, active_p, + and project_lead. + + @param project_id The id of the project to retrieve information about + @param array The name of the array in the callers scope where the information will + be stored + + @return The return value from db_1row. Throws an error if the project doesn't exist. + + @author Peter Marklund +} { + upvar $array project_array + + db_1row select_info {} -column_array project_array +} + +ad_proc -public logger::project::add_variable { + {-project_id:required} + {-variable_id:required} + {-primary_p ""} +} { + Associate a logger variable with a logger project. Each + variable can be associated with multiple projects. + + @param project_id The id of the project to add the variable to + @param variable_id The id of the variable to add + @param primary_p Is this the variable we are primarily tracking + in the project? Valid values are t (true) and f (false). The default will + be t if this is the first variable added to the project and + f otherwise. Note that a project must have exactly one primary variable. + If this is the first variable added and primary_p is provided it must + be set to t, otherwise an error will be thrown. + + @return The return code from db_dml. Will throw a database + error if the variable and the project are already mapped. + + @author Peter Marklund +} { + if { ![empty_string_p $primary_p] } { + ad_assert_arg_value_in_list primary_p {t f} + } + + # Check that there will be exactly one primary_p variable for the project + set exists_primary_p [db_string count_primary_p {}] + if { $exists_primary_p } { + # There is already a primary_p variable so the new one can't be + if { [string equal $primary_p "t"] } { + error "logger::project::add_variable - invoked with primary_p argument set to t but project $project_id already has a primary_p variable" + } + + set primary_p f + } else { + # There is no primary_p variable so the new one must be + if { [string equal $primary_p "f"] } { + error "logger::project::add_variable - invoked with primary_p argument set to f but project $project_id has no primary_p variable and must have one" + } + + set primary_p t + } + + db_dml insert_mapping {} +} + +ad_proc -public logger::project::get_variables { + {-project_id:required} +} { + Return a list of id:s for the variables in the given project. + + @param project_id The id of the project to return variables for. + + @return A list of variable_id:s + + @author Peter Marklund +} { + return [db_list select_variables {}] +} Index: openacs-4/packages/logger/tcl/project-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/project-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/project-procs.xql 5 Apr 2003 10:16:42 -0000 1.1 @@ -0,0 +1,39 @@ + + + + + + + select project_id, + name, + description, + active_p, + project_lead + from logger_projects + where project_id = :project_id + + + + + + insert into logger_project_var_map (project_id, variable_id, primary_p) + values (:project_id, :variable_id, :primary_p) + + + + + + select count(*) + from logger_project_var_map + where project_id = :project_id + and primary_p = 't' + + + + + + + + + + Index: openacs-4/packages/logger/tcl/variable-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/variable-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/variable-procs.tcl 5 Apr 2003 10:16:42 -0000 1.1 @@ -0,0 +1,77 @@ +ad_library { + Procedures in the logger::variable namespace. Those procedures + operate on logger variable objects. + + @creation-date 4:th of April 2003 + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: variable-procs.tcl,v 1.1 2003/04/05 10:16:42 peterm Exp $ +} + +namespace eval logger::variable {} + +ad_proc -public logger::variable::new { + {-variable_id ""} + {-name:required} + {-unit:required} + {-type "additive"} +} { + Create a new variable to use for logger measurements. The + variable can be tied to logger projects through the + logger::project::add_variable proc. + + @param variable_id Any pre-generated id of the variable. Optional. + @param name The name of the new variable. Required. + @param unit The unit of the variable, for example hours, minutes, or + a currency code such as USD or EUR. + @param type Must be either additive (default) or non-additive. + + @return The id of the created variable. + + @author Peter Marklund +} { + ad_assert_arg_value_in_list type {additive non-additive} + + # Default variable_id to next id in sequence + if { [empty_string_p $variable_id] } { + set variable_id [db_nextval logger_variables_seq] + } + + db_dml insert_variable {} + + return $variable_id +} + +ad_proc -public logger::variable::delete { + {-variable_id:required} +} { + Delete the variable with given id. + + @param variable_id The id of the variable to delete. + + @return The return value of db_dml + + @author Peter Marklund +} { + db_dml delete_variable {} +} + +ad_proc -public logger::variable::get { + {-variable_id:required} + {-array:required} +} { + Retrieve info about the variable with given id into an + array (using upvar) in the callers scope. The + array will contain the keys variable_id, name, unit, and type. + + @param variable_id The id of the variable to retrieve information about + @param array The name of the array in the callers scope where the information will + be stored + + @return The return value from db_1row. Throws an error if the variable doesn't exist. + + @author Peter Marklund +} { + upvar $array project_array + + db_1row select_variable {} -column_array project_array +} Index: openacs-4/packages/logger/tcl/variable-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/variable-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/variable-procs.xql 5 Apr 2003 10:16:42 -0000 1.1 @@ -0,0 +1,30 @@ + + + + + + + insert into logger_variables (variable_id, name, unit, type) + values (:variable_id, :name, :unit, :type) + + + + + + delete from logger_variables + where variable_id = :variable_id + + + + + + select variable_id, + name, + unit, + type + from logger_variables + where variable_id = :variable_id + + + + Index: openacs-4/packages/logger/tcl/test/logger-test-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/test/logger-test-init.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/test/logger-test-init.tcl 5 Apr 2003 10:16:58 -0000 1.1 @@ -0,0 +1,119 @@ +ad_library { + Test cases for the Tcl API of the logger package. The test cases are based + on the acs-automated-testing package + + @author Peter Marklund + @creation-date 31 March 2003 + @cvs-id $Id: logger-test-init.tcl,v 1.1 2003/04/05 10:16:58 peterm Exp $ +} + +aa_register_case logger_create_package { + Test creation and deletion of logger package along with a project, + a few measurements, and other logger data. + + @author Peter Marklund +} { + aa_run_with_teardown -test_code { + ##### + # + # Setup + # + ##### + + # Test constants + set package_name "ACS Automated Testing Logger Test Package" + set project_name "aa_logger_test_project" + array set hours_var { + name Time + unit hours + type additive + } + array set minutes_var { + name Time + unit minutes + type additive + } + array set expense_var { + name Expense + unit EUR + type additive + } + + # Create a package + set package_id [apm_package_instance_new -instance_name $package_name \ + -package_key logger] + + # Create a project in that package + set project_id [logger::project::new -name $project_name \ + -package_id $package_id] + + # Assert that the name of the project can be retrieved + logger::project::get -project_id $project_id \ + -array project_array + aa_equals "Checking that name of project is correct" $project_array(name) $project_name + + # Assert that the project is mapped to the package and not mapped to any other packages + set all_projects_list [logger::package::all_projects_in_package -package_id $package_id] + set only_projects_list [logger::package::projects_only_in_package -package_id $package_id] + foreach list_var_name {all_projects_list only_projects_list} { + set list_var_value [set $list_var_name] + aa_true "The correct project is mapped to the package ($list_var_name)" \ + [expr [llength $list_var_value] == 1 && [string equal [lindex $list_var_value 0] $project_id]] + } + + # Create and map the hours variable (is probably most common) + set hours_var_id [logger::variable::new -name $hours_var(name) \ + -unit $hours_var(unit) \ + -type $hours_var(type)] + logger::project::add_variable -project_id $project_id \ + -variable_id $hours_var_id + + # Create and map the minutes variable + # (variate by pre-generating the variable id this time) + set minutes_var_id [db_nextval logger_variables_seq] + set minutes_var_id [logger::variable::new -variable_id $minutes_var_id \ + -name $minutes_var(name) \ + -unit $minutes_var(unit) \ + -type $minutes_var(type)] + logger::project::add_variable -project_id $project_id \ + -variable_id $minutes_var_id + + # Create and map the expense variable (euros) + set expense_var_id [logger::variable::new -name $expense_var(name) \ + -unit $expense_var(unit) \ + -type $expense_var(type)] + logger::project::add_variable -project_id $project_id \ + -variable_id $expense_var_id + + # Assert that variables are retrievable + logger::variable::get -variable_id $hours_var_id -array hours_var + logger::variable::get -variable_id $minutes_var_id -array minutes_var + logger::variable::get -variable_id $expense_var_id -array expense_var + + # Assert that variables are mapped to the project + set expected_var_list [list $hours_var_id $minutes_var_id $expense_var_id] + set actual_var_list [logger::project::get_variables -project_id $project_id] + aa_true "checking that variables are mapped to project" [util_sets_equal_p $expected_var_list \ + $actual_var_list] + # Create projections + + # Check that the projections can be retrieved + + # Create mesurements + + # Check that measurements are retrievable + + } -teardown_code { + ##### + # + # Teardown + # + ##### + + # Delete the package - deletes all logger data related to the package through the before-uninstantiate callback + apm_package_instance_delete $package_id + + # Check that there is no logger data associated with the deleted package + # TODO... + } +}