Project

General

Profile

1
#!/usr/bin/perl
2
#
3
#  '$RCSfile$'
4
#  Copyright: 2000 Regents of the University of California 
5
#
6
#   '$Author: leinfelder $'
7
#     '$Date: 2013-09-23 15:54:55 -0700 (Mon, 23 Sep 2013) $'
8
# '$Revision: 8265 $' 
9
# 
10
# This program is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 2 of the License, or
13
# (at your option) any later version.
14
#
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
# GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License
21
# along with this program; if not, write to the Free Software
22
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
#
24
#
25
# This is a CGI application for inserting metadata documents into
26
# the Metacat database.  It utilizes the Metacat.pm module for most work.
27
# You can specify two metacats and a list of documents. This script will
28
# copy documents from one metacat to another.
29

    
30

    
31
use lib qw(/opt/local/lib/perl5/site_perl/5.12.3);
32
use Metacat;
33

    
34
my $metacat1;
35
my $metacat2;
36
my $docid;
37
my $error = 0;
38
my $xmldoc;
39
my $xa;
40
my $response;
41

    
42
my $listname = "list_of_docids";
43

    
44
my $metacat1_url = "https://mn-stage-ucsb-1.dataone.org/metacat/metacat";
45
my $metacat2_url = "https://demo2.test.dataone.org/metacat/metacat";
46
my $username = "uid=kepler,o=unaffiliated,dc=ecoinformatics,dc=org";
47
my $password = "xxx";
48

    
49
$metacat1 = Metacat->new();
50
$metacat2 = Metacat->new();
51

    
52

    
53
if ($metacat1) {
54
    $metacat1->set_options( metacatUrl => $metacat1_url);
55
} else {
56
    #die "failed during metacat creation\n";
57
    print "Failed during metacat1 creation.";
58
    $error = 1;
59
}
60

    
61

    
62
# Login to metacat
63
print "Connecting to metacat1..........\n";
64
my $response1 = $metacat1->login($username, $password);
65
if (! $response1) {
66
    print $metacat1->getMessage();
67
    print "Failed during login: metacat1.\n";
68
    $error = 2;
69
} else {
70
    print "Connected to metacat1\n";
71
}
72

    
73
if ($metacat2) {
74
    $metacat2->set_options( metacatUrl => $metacat2_url );
75
} else {
76
    #die "failed during metacat creation\n";
77
    print "Failed during metacat2 creation.";
78
    $error = 3;
79
}
80

    
81
# Login to metacat
82
print "Connecting to metacat2..........\n";
83
my $response2 = $metacat2->login($username, $password);
84
if (! $response2) {
85
    #print $metacat->getMessage();
86
    #die "failed during login\n";
87
    print $metacat2->getMessage();
88
    print "Failed during login: metacat2.\n";
89
    $error = 4;
90
} else {
91
    print "Connected to metacat2\n";
92
}
93

    
94
if($error == 0){
95
    open(file,$listname) || die ("Couldn't open the file");
96
    while(<file>) {
97
	chomp();
98
	$xmldoc = $metacat1->read($_);
99
	$xa = $xmldoc->content;
100
	$response = $metacat2->insert($_, $xa);
101
	print $metacat2->getMessage();
102
    }
103
} else {
104
    print $error;
105
}
(13-13/14)