1
|
#!/usr/bin/perl
|
2
|
|
3
|
# check that the correct number or parameters are issued
|
4
|
if (($#ARGV +1) != 3) {die "Usage: %./get_eml.pl <metacat_url> <login> <passwd>\n\n";}
|
5
|
|
6
|
($url, $username, $password) = @ARGV; #get the input file and output file names
|
7
|
|
8
|
|
9
|
use Metacat;
|
10
|
use XML::DOM;
|
11
|
|
12
|
my $metacat = Metacat->new();
|
13
|
#my $username = "uid=knb2003,o=NCEAS,dc=ecoinformatics,dc=org";
|
14
|
#my $password = "afr1ca";
|
15
|
|
16
|
|
17
|
#my $url = "http://indus.nceas.ucsb.edu/knb-test/metacat";
|
18
|
#my $url = "http://metacat.nceas.ucsb.edu/knb/servlet/metacat";
|
19
|
#my $url = "http://dhcp84.nceas.ucsb.edu:8080/knp/servlet/metacat";
|
20
|
#my $url = $infile
|
21
|
|
22
|
if ($metacat) {
|
23
|
$metacat->set_options( metacatUrl => $url );
|
24
|
} else {
|
25
|
#print "Failed during metacat creation.";
|
26
|
$error = 1;
|
27
|
exit();
|
28
|
}
|
29
|
|
30
|
# Login to metacat
|
31
|
# //print "Logging in to metacat..........\n";
|
32
|
my $response1 = $metacat->login($username, $password);
|
33
|
if (! $response1) {
|
34
|
# //print $metacat->getMessage();
|
35
|
# //print "Failed during login: metacat.\n";
|
36
|
$error = 2;
|
37
|
} else {
|
38
|
# //print "Logged in.\n";
|
39
|
}
|
40
|
|
41
|
|
42
|
my $query = "<?xml version=\"1.0\" ?> <pathquery version=\"1.2\"> <querytitle>Untitled-Search-2</querytitle> <returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN</returndoctype> <returndoctype>-//NCEAS//eml-dataset-2.0//EN</returndoctype> <returndoctype>eml://ecoinformatics.org/eml-2.0.0</returndoctype> <returnfield>dataset/title</returnfield> <returnfield>individualName/surName</returnfield> <returnfield>keyword</returnfield><returnfield>westBoundingCoordinate</returnfield><returnfield>eastBoundingCoordinate</returnfield><returnfield>northBoundingCoordinate</returnfield><returnfield>southBoundingCoordinate</returnfield><returnfield>westbc</returnfield><returnfield>eastbc</returnfield><returnfield>northbc</returnfield><returnfield>southbc</returnfield><querygroup operator=\"INTERSECT\"><querygroup operator=\"UNION\"><querygroup operator=\"UNION\"><queryterm searchmode=\"contains\" casesensitive=\"false\"><value>%25</value></queryterm></querygroup></querygroup></querygroup></pathquery>";
|
43
|
|
44
|
my $response = $metacat->squery($query);
|
45
|
|
46
|
my $mesg =$metacat->getMessage();
|
47
|
|
48
|
#print "\n\ngetting the message ... \n";
|
49
|
#print $mesg;
|
50
|
|
51
|
if($mesg eq ""){
|
52
|
# print ("Too much time is reply back from metacat...");
|
53
|
exit();
|
54
|
}
|
55
|
|
56
|
my $parser = new XML::DOM::Parser;
|
57
|
my $node;
|
58
|
my $name;
|
59
|
my $doc = $parser->parse($mesg);
|
60
|
my $nodes = $doc->getElementsByTagName("docid");
|
61
|
|
62
|
$numberNodes = $nodes->getLength;
|
63
|
|
64
|
|
65
|
for (my $loop_index =0; $loop_index < $numberNodes; $loop_index++)
|
66
|
{
|
67
|
$node = $nodes->item($loop_index);
|
68
|
$name = $node->getFirstChild()->getNodeValue();
|
69
|
|
70
|
$node = $node->getParentNode();
|
71
|
my $tempnodes = $node->getElementsByTagName("param");
|
72
|
my $tempnumberNodes = $tempnodes->getLength;
|
73
|
|
74
|
my $title = "";
|
75
|
my $keyword = "";
|
76
|
my $cName = "";
|
77
|
my $eBC = "";
|
78
|
my $wBC = "";
|
79
|
my $nBC = "";
|
80
|
my $sBC = "";
|
81
|
|
82
|
for (my $loop =0; $loop < $tempnumberNodes; $loop++)
|
83
|
{
|
84
|
my $tempnode = $tempnodes->item($loop);
|
85
|
my $paramname = $tempnode->getAttributeNode("name")->getValue();
|
86
|
if($paramname eq "dataset/title"){
|
87
|
$title = $tempnode->getFirstChild()->getNodeValue();
|
88
|
}
|
89
|
if($paramname eq "keyword"){
|
90
|
$keyword = $keyword.",".$tempnode->getFirstChild()->getNodeValue();
|
91
|
}
|
92
|
if($paramname eq "individualName/surName"){
|
93
|
$cName = $cName.",".$tempnode->getFirstChild()->getNodeValue();
|
94
|
}
|
95
|
if($paramname eq "eastBoundingCoordinate"){
|
96
|
$eBC = $tempnode->getFirstChild()->getNodeValue();
|
97
|
}
|
98
|
if($paramname eq "eastbc"){
|
99
|
$eBC = $tempnode->getFirstChild()->getNodeValue();
|
100
|
}
|
101
|
if($paramname eq "westBoundingCoordinate"){
|
102
|
$wBC = $tempnode->getFirstChild()->getNodeValue();
|
103
|
}
|
104
|
if($paramname eq "westbc"){
|
105
|
$wBC = $tempnode->getFirstChild()->getNodeValue();
|
106
|
}
|
107
|
if($paramname eq "northBoundingCoordinate"){
|
108
|
$nBC = $tempnode->getFirstChild()->getNodeValue();
|
109
|
}
|
110
|
if($paramname eq "northbc"){
|
111
|
$nBC = $tempnode->getFirstChild()->getNodeValue();
|
112
|
}
|
113
|
if($paramname eq "southBoundingCoordinate"){
|
114
|
$sBC = $tempnode->getFirstChild()->getNodeValue();
|
115
|
}
|
116
|
if($paramname eq "southbc"){
|
117
|
$sBC = $tempnode->getFirstChild()->getNodeValue();
|
118
|
}
|
119
|
}
|
120
|
|
121
|
if($keyword ne "" ){
|
122
|
$keyword = substr ($keyword, 1);
|
123
|
}
|
124
|
if($cName ne "" ){
|
125
|
$cName = substr ($cName, 1);
|
126
|
}
|
127
|
|
128
|
# print "$name, $title, ($cName), ($keyword), ($eBC,$wBC,$nBC,$sBC), $url?action=read&docid=$name&qformat=knb, \n";
|
129
|
if ($eBC ne "" && $nBC ne "" && $eBC ne "0" && $nBC ne "0") {
|
130
|
print "$name $eBC $nBC $url?action=read&docid=$name&qformat=knb \n";
|
131
|
}
|
132
|
}
|
133
|
|
134
|
#print $numberNodes;
|