Difference between revisions of "Building a DataSet"
m (Added '_dark' to correctly link icon file with action) |
|||
(13 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:EPrints_Bazaar]] | [[Category:EPrints_Bazaar]] | ||
+ | In this excercise we will be adding a dark archive to the repository. A dark achive is for papers which need to be stored but never seen possibly because the contain sensitive content. We will create a virtual dataset callled dark_archive and make a plugin for moving eprints into the dark_archive dataset. We will then modify the API excercise so that it searches the dark_archive rather than the eprint dataset. Finally we should add a mechanism to move items out of the dark archive. | ||
+ | |||
==Modify EPrint Status Field== | ==Modify EPrint Status Field== | ||
− | We must | + | |
+ | Since our dark archive will contain eprints we will be making a new virtual dataset. A virtual dataset is a sub set of an existing dataset. Values of metadata fields on an object can be used to determine which virtual datasets it is in. The inbox, archive and buffer are all virtual datasets of the eprint dataset. The field which defines these virtual datasets is the "eprint_status" field. We must modify this field so it has an extra value "dark_archive". To do this add the following code to the postins method of your plugin configuation file from the workflow excercise. (Note you should not add the coresponding remove_dataset_field) | ||
+ | |||
<pre> | <pre> | ||
− | + | $repository->config->add_dataset_field( "eprint", { | |
name=>"eprint_status", type=>"set", required=>1, | name=>"eprint_status", type=>"set", required=>1, | ||
− | options=>[qw/ inbox buffer archive deletion dark_archive /] | + | options=>[qw/ inbox buffer archive deletion dark_archive /], |
replace_core=>1 #this flag must be used with EXTREME caution, it makes is very easy to break things | replace_core=>1 #this flag must be used with EXTREME caution, it makes is very easy to break things | ||
− | }); | + | }, reuse => 1 ); |
+ | |||
</pre> | </pre> | ||
==Add the dark archive dataset definition== | ==Add the dark archive dataset definition== | ||
+ | Next we need to defined the virtual dataset. The configuration below defines a virtual dataset for items in the EPrint Dataset which have the eprint_status of dark archive. | ||
<pre> | <pre> | ||
− | dark_archive = | + | $c->{datasets}->{dark_archive} = { |
sqlname => "eprint", | sqlname => "eprint", | ||
virtual => 1, | virtual => 1, | ||
Line 23: | Line 29: | ||
dataset_id_field => "eprint_status", | dataset_id_field => "eprint_status", | ||
datestamp => "lastmod", | datestamp => "lastmod", | ||
− | }, | + | }; |
+ | </pre> | ||
+ | |||
+ | Now we reload the configuration. Check the http://repository.name.ac.uk/cgi/counter to check the dark_archive dataset exists. You should see the dark_archive listed with 0 items. | ||
+ | |||
+ | '''NOTE - in 3.3.10 (and possibly earlier) dark_archive will not show on the counter page until there is at least one eprint with that status''' | ||
+ | |||
+ | ==Build a screen to move an object to the archive== | ||
+ | Now that our we have our dataset we should move things into it. We do this by building a screen plugin which can set the eprint_status field to "dark_archive". Some simple code is bellow. Some obvious expansions to this code would be to change the allow_move_dark_archive method so that it uses roles to check if a user is allowed to move items into the dark archive. You may also want to add an icon for the plugin. As in previous excercises you will need to add the appropriate phrases. | ||
+ | <pre> | ||
+ | package EPrints::Plugin::Screen::EPrint::MoveToDarkArchive; | ||
+ | |||
+ | @ISA = ( 'EPrints::Plugin::Screen::EPrint' ); | ||
+ | |||
+ | use strict; | ||
+ | |||
+ | sub new | ||
+ | { | ||
+ | my( $class, %params ) = @_; | ||
+ | |||
+ | my $self = $class->SUPER::new(%params); | ||
+ | |||
+ | # $self->{priv} = # no specific priv - one per action | ||
+ | |||
+ | $self->{actions} = [qw/ move_dark_archive /]; | ||
+ | |||
+ | $self->{appears} = [ | ||
+ | { place => "eprint_editor_actions", action => "move_dark_archive", position => 400, }, | ||
+ | { place => "eprint_item_actions", action => "move_dark_archive", position => 400, }, | ||
+ | ]; | ||
+ | #$self->{action_icon} = { move_dark_archive => "action_approve.png" }; #un-comment this line to use image button rather than text button | ||
+ | |||
+ | return $self; | ||
+ | } | ||
+ | |||
+ | sub obtain_lock | ||
+ | { | ||
+ | my( $self ) = @_; | ||
+ | |||
+ | return $self->could_obtain_eprint_lock; | ||
+ | } | ||
+ | |||
+ | sub about_to_render | ||
+ | { | ||
+ | my( $self ) = @_; | ||
+ | |||
+ | $self->EPrints::Plugin::Screen::EPrint::View::about_to_render; | ||
+ | } | ||
+ | |||
+ | sub allow_move_dark_archive | ||
+ | { | ||
+ | my( $self ) = @_; | ||
+ | |||
+ | return 0 unless $self->could_obtain_eprint_lock; | ||
+ | return 1; | ||
+ | } | ||
+ | |||
+ | sub action_move_dark_archive | ||
+ | { | ||
+ | my( $self ) = @_; | ||
+ | |||
+ | $self->{processor}->{eprint}->remove_static; | ||
+ | $self->{processor}->{eprint}->set_value("eprint_status", "dark_archive"); | ||
+ | $self->{processor}->{eprint}->commit; | ||
+ | |||
+ | $self->add_result_message( 1 ); | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | sub add_result_message | ||
+ | { | ||
+ | my( $self, $ok ) = @_; | ||
+ | |||
+ | if( $ok ) | ||
+ | { | ||
+ | $self->{processor}->add_message( "message", | ||
+ | $self->html_phrase( "status_changed", | ||
+ | status=>$self->{processor}->{eprint}->render_value( "eprint_status" ) ) ); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | $self->{processor}->add_message( "error", | ||
+ | $self->html_phrase( | ||
+ | "cant_move", | ||
+ | id => $self->{session}->make_text( | ||
+ | $self->{processor}->{eprintid} ) ) ); | ||
+ | } | ||
+ | |||
+ | $self->{processor}->{screenid} = "EPrint::View"; | ||
+ | } | ||
+ | |||
+ | 1; | ||
+ | |||
</pre> | </pre> | ||
− | + | ==Modify my first bazaar package to show the contents of dark_archive== | |
+ | Finally we modify the screen plugin we made in the [[Using_the_new_API|API excercise]] so that searches the dark_archive not the eprint dataset. You could also change the render method to add the move_to_buffer plugin so that a user can move an item out of the dark archive into the buffer. There are a number of ways to improve the user interface produced by this excercise, these are left for the reader to experiment with. |
Latest revision as of 11:40, 6 March 2013
In this excercise we will be adding a dark archive to the repository. A dark achive is for papers which need to be stored but never seen possibly because the contain sensitive content. We will create a virtual dataset callled dark_archive and make a plugin for moving eprints into the dark_archive dataset. We will then modify the API excercise so that it searches the dark_archive rather than the eprint dataset. Finally we should add a mechanism to move items out of the dark archive.
Contents
Modify EPrint Status Field
Since our dark archive will contain eprints we will be making a new virtual dataset. A virtual dataset is a sub set of an existing dataset. Values of metadata fields on an object can be used to determine which virtual datasets it is in. The inbox, archive and buffer are all virtual datasets of the eprint dataset. The field which defines these virtual datasets is the "eprint_status" field. We must modify this field so it has an extra value "dark_archive". To do this add the following code to the postins method of your plugin configuation file from the workflow excercise. (Note you should not add the coresponding remove_dataset_field)
$repository->config->add_dataset_field( "eprint", { name=>"eprint_status", type=>"set", required=>1, options=>[qw/ inbox buffer archive deletion dark_archive /], replace_core=>1 #this flag must be used with EXTREME caution, it makes is very easy to break things }, reuse => 1 );
Add the dark archive dataset definition
Next we need to defined the virtual dataset. The configuration below defines a virtual dataset for items in the EPrint Dataset which have the eprint_status of dark archive.
$c->{datasets}->{dark_archive} = { sqlname => "eprint", virtual => 1, class => "EPrints::DataObj::EPrint", confid => "eprint", import => 1, index => 1, filters => [ { meta_fields => [ 'eprint_status' ], value => 'dark_archive', describe=>0 } ], dataset_id_field => "eprint_status", datestamp => "lastmod", };
Now we reload the configuration. Check the http://repository.name.ac.uk/cgi/counter to check the dark_archive dataset exists. You should see the dark_archive listed with 0 items.
NOTE - in 3.3.10 (and possibly earlier) dark_archive will not show on the counter page until there is at least one eprint with that status
Build a screen to move an object to the archive
Now that our we have our dataset we should move things into it. We do this by building a screen plugin which can set the eprint_status field to "dark_archive". Some simple code is bellow. Some obvious expansions to this code would be to change the allow_move_dark_archive method so that it uses roles to check if a user is allowed to move items into the dark archive. You may also want to add an icon for the plugin. As in previous excercises you will need to add the appropriate phrases.
package EPrints::Plugin::Screen::EPrint::MoveToDarkArchive; @ISA = ( 'EPrints::Plugin::Screen::EPrint' ); use strict; sub new { my( $class, %params ) = @_; my $self = $class->SUPER::new(%params); # $self->{priv} = # no specific priv - one per action $self->{actions} = [qw/ move_dark_archive /]; $self->{appears} = [ { place => "eprint_editor_actions", action => "move_dark_archive", position => 400, }, { place => "eprint_item_actions", action => "move_dark_archive", position => 400, }, ]; #$self->{action_icon} = { move_dark_archive => "action_approve.png" }; #un-comment this line to use image button rather than text button return $self; } sub obtain_lock { my( $self ) = @_; return $self->could_obtain_eprint_lock; } sub about_to_render { my( $self ) = @_; $self->EPrints::Plugin::Screen::EPrint::View::about_to_render; } sub allow_move_dark_archive { my( $self ) = @_; return 0 unless $self->could_obtain_eprint_lock; return 1; } sub action_move_dark_archive { my( $self ) = @_; $self->{processor}->{eprint}->remove_static; $self->{processor}->{eprint}->set_value("eprint_status", "dark_archive"); $self->{processor}->{eprint}->commit; $self->add_result_message( 1 ); } sub add_result_message { my( $self, $ok ) = @_; if( $ok ) { $self->{processor}->add_message( "message", $self->html_phrase( "status_changed", status=>$self->{processor}->{eprint}->render_value( "eprint_status" ) ) ); } else { $self->{processor}->add_message( "error", $self->html_phrase( "cant_move", id => $self->{session}->make_text( $self->{processor}->{eprintid} ) ) ); } $self->{processor}->{screenid} = "EPrint::View"; } 1;
Modify my first bazaar package to show the contents of dark_archive
Finally we modify the screen plugin we made in the API excercise so that searches the dark_archive not the eprint dataset. You could also change the render method to add the move_to_buffer plugin so that a user can move an item out of the dark archive into the buffer. There are a number of ways to improve the user interface produced by this excercise, these are left for the reader to experiment with.