1
|
#!/usr/bin/perl
|
2
|
#
|
3
|
# '$RCSfile$'
|
4
|
# Copyright: 2000 Regents of the University of California
|
5
|
#
|
6
|
# '$Author: sgarg $'
|
7
|
# '$Date: 2004-04-09 16:12:46 -0700 (Fri, 09 Apr 2004) $'
|
8
|
# '$Revision: 2115 $'
|
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 Metacat;
|
32
|
|
33
|
my $metacat1;
|
34
|
my $metacat2;
|
35
|
my $docid;
|
36
|
my $error = 0;
|
37
|
my $xmldoc;
|
38
|
my $xa;
|
39
|
my $response;
|
40
|
|
41
|
my $listname = "list_of_docids";
|
42
|
|
43
|
my $metacat1_url = "http://metacat.nceas.ucsb.edu/knb/metacat";
|
44
|
my $metacat2_url = "http://indus.nceas.ucsb.edu/knb-test/metacat";
|
45
|
my $username = "uid=sgarg,o=NCEAS,dc=ecoinformatics,dc=org";
|
46
|
my $password = "xxxxxxxxxx";
|
47
|
|
48
|
$metacat1 = Metacat->new();
|
49
|
$metacat2 = Metacat->new();
|
50
|
|
51
|
|
52
|
if ($metacat1) {
|
53
|
$metacat1->set_options( metacatUrl => $metacat1_url);
|
54
|
} else {
|
55
|
#die "failed during metacat creation\n";
|
56
|
print "Failed during metacat1 creation.";
|
57
|
$error = 1;
|
58
|
}
|
59
|
|
60
|
|
61
|
# Login to metacat
|
62
|
print "Connecting to metacat1..........\n";
|
63
|
my $response1 = $metacat1->login($username, $password);
|
64
|
if (! $response1) {
|
65
|
print $metacat1->getMessage();
|
66
|
print "Failed during login: metacat1.\n";
|
67
|
$error = 2;
|
68
|
} else {
|
69
|
print "Connected to metacat1\n";
|
70
|
}
|
71
|
|
72
|
if ($metacat2) {
|
73
|
$metacat2->set_options( metacatUrl => $metacat2_url );
|
74
|
} else {
|
75
|
#die "failed during metacat creation\n";
|
76
|
print "Failed during metacat2 creation.";
|
77
|
$error = 3;
|
78
|
}
|
79
|
|
80
|
# Login to metacat
|
81
|
print "Connecting to metacat2..........\n";
|
82
|
my $response2 = $metacat2->login($username, $password);
|
83
|
if (! $response2) {
|
84
|
#print $metacat->getMessage();
|
85
|
#die "failed during login\n";
|
86
|
print $metacat2->getMessage();
|
87
|
print "Failed during login: metacat2.\n";
|
88
|
$error = 4;
|
89
|
} else {
|
90
|
print "Connected to metacat2\n";
|
91
|
}
|
92
|
|
93
|
if($error == 0){
|
94
|
open(file,$listname) || die ("Couldn't open the file");
|
95
|
while(<file>) {
|
96
|
chomp();
|
97
|
$xmldoc = $metacat1->read($_);
|
98
|
$xa = $xmldoc->content;
|
99
|
$response = $metacat2->insert($_, $xa);
|
100
|
print $metacat2->getMessage();
|
101
|
}
|
102
|
} else {
|
103
|
print $error;
|
104
|
}
|