Difference between revisions of "Building a DataSet"

From EPrints Documentation
Jump to: navigation, search
(Modify EPrint Status Field)
(Modify EPrint Status Field)
Line 4: Line 4:
 
==Modify EPrint Status Field==
 
==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.
+
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>

Revision as of 07:53, 31 March 2011

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

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.

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 Admin>System Tools>Status to check the dark_archive dataset exists

epadmin update_database_structure <repoid>


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.

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_archive => "action_approve.png" };

	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 and 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.