# EPrints Services/Shelves # adds all the EPrintIds of a Search to a Shelf (given a Search cache_id) use EPrints; use strict; use warnings; my $session = EPrints::Session->new(); exit(0) unless( defined $session ); my $user = $session->current_user; unless( defined $user ) { $session->send_http_header( content_type => "application/json" ); print STDOUT JSON::encode_json( { error => '
You must login to use the Shelves
' } ); $session->terminate; return; } my $shelfid = $session->param( 'shelfid' ); my $cacheid = $session->param( 'cacheid' ); unless( defined $shelfid && defined $cacheid ) { $session->terminate; return; } # sanity checks first my $cachemap = $session->dataset( 'cachemap' )->dataobj( $cacheid ); unless( defined $cachemap ) { # perhaps it timed-out $session->send_http_header( content_type => "application/json" ); print STDOUT JSON::encode_json( { error => '
Search expired. Try starting another search.
' } ); $session->terminate; return; } my $cache_owner_id = $cachemap->get_value( "userid" ); my $user_id = $user->get_id; unless( "$cache_owner_id" eq "$user_id" ) { $session->send_http_header( content_type => "application/json" ); print STDOUT JSON::encode_json( { error => '
You do not own this Search.
' } ); $session->terminate; return; } # instanciate shelf, check current user has the perms to write to it my $shelf = $session->dataset( 'shelf' )->dataobj( $shelfid ); unless( defined $shelf ) { print STDOUT JSON::encode_json( { error => '
Shelf #'.$shelfid.' does not exist.
' } ); $session->terminate; return; } unless( $shelf->has_editor( $user ) ) { print STDOUT JSON::encode_json( { error => '
You may not modify this Shelf.
' } ); $session->terminate; return; } my $list = EPrints::List->new( session => $session, dataset => $session->dataset( 'eprint' ), cache_id => $cacheid ); my $ids = $list->ids(); $shelf->add_items( @$ids ); $session->terminate;