Project

General

Profile

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

    
14

    
15
#my $url = "http://indus.nceas.ucsb.edu/knb-test/metacat";
16
#my $url = "http://metacat.nceas.ucsb.edu/knb/servlet/metacat";
17
#my $url = "http://dhcp84.nceas.ucsb.edu:8080/knp/servlet/metacat";
18
#my $url = $infile
19

    
20
if ($metacat) {
21
    $metacat->set_options( metacatUrl => $url );
22
} else {
23
#print "Failed during metacat creation.";
24
    $error = 1;
25
    exit();
26
}
27

    
28
# Login to metacat
29
# //print "Logging in to metacat..........\n";
30
my $response1 = $metacat->login($username, $password);
31
if (! $response1) {
32
#    //print $metacat->getMessage();
33
#    //print "Failed during login: metacat.\n";
34
    $error = 2;
35
} else {
36
#    //print "Logged in.\n";
37
}
38

    
39

    
40
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>";
41

    
42
my $response = $metacat->squery($query);
43

    
44
my $mesg =$metacat->getMessage();
45

    
46
#print "\n\ngetting the message ... \n";
47
#print $mesg;
48

    
49
if($mesg eq ""){
50
#    print ("Too much time is reply back from metacat...");
51
    exit();
52
}
53

    
54
my $parser = new XML::DOM::Parser;
55
my $node;
56
my $name;
57
my $doc = $parser->parse($mesg);
58
my $nodes = $doc->getElementsByTagName("docid");
59

    
60
$numberNodes = $nodes->getLength;
61

    
62

    
63
for (my $loop_index =0; $loop_index < $numberNodes; $loop_index++)
64
{
65
    $node = $nodes->item($loop_index);
66
    $name = $node->getFirstChild()->getNodeValue();
67
    
68
    $node = $node->getParentNode(); 
69
    my $tempnodes = $node->getElementsByTagName("param");
70
    my $tempnumberNodes = $tempnodes->getLength;
71
 
72
    my $title = "";
73
    my $keyword = "";
74
    my $cName = "";
75
    my $eBC = "";
76
    my $wBC = "";
77
    my $nBC = "";
78
    my $sBC = "";
79
    
80
 for (my $loop =0; $loop < $tempnumberNodes; $loop++) 
81
 {
82
	my $tempnode = $tempnodes->item($loop);	
83
	my $paramname = $tempnode->getAttributeNode("name")->getValue();
84
	if($paramname eq "dataset/title"){
85
	    $title = $tempnode->getFirstChild()->getNodeValue();
86
	}
87
	if($paramname eq "keyword"){
88
	    $keyword = $keyword.",".$tempnode->getFirstChild()->getNodeValue();
89
	}
90
	if($paramname eq "individualName/surName"){
91
	    $cName = $cName.",".$tempnode->getFirstChild()->getNodeValue();
92
	}
93
	if($paramname eq "eastBoundingCoordinate"){
94
	    $eBC = $tempnode->getFirstChild()->getNodeValue();
95
	}
96
	if($paramname eq "eastbc"){
97
	    $eBC = $tempnode->getFirstChild()->getNodeValue();
98
	}
99
	if($paramname eq "westBoundingCoordinate"){
100
	    $wBC = $tempnode->getFirstChild()->getNodeValue();
101
	}
102
	if($paramname eq "westbc"){
103
	    $wBC = $tempnode->getFirstChild()->getNodeValue();
104
	}
105
	if($paramname eq "northBoundingCoordinate"){
106
	    $nBC = $tempnode->getFirstChild()->getNodeValue();
107
	}
108
	if($paramname eq "northbc"){
109
	    $nBC = $tempnode->getFirstChild()->getNodeValue();
110
	}
111
	if($paramname eq "southBoundingCoordinate"){
112
	    $sBC = $tempnode->getFirstChild()->getNodeValue();
113
	}
114
	if($paramname eq "southbc"){
115
	    $sBC = $tempnode->getFirstChild()->getNodeValue();
116
	}
117
    }
118

    
119
    if($keyword ne "" ){
120
	$keyword = substr ($keyword, 1);
121
    }
122
    if($cName ne "" ){
123
	$cName = substr ($cName, 1);
124
    }
125

    
126
  #  print "$name, $title, ($cName), ($keyword), ($eBC,$wBC,$nBC,$sBC), $url?action=read&docid=$name&qformat=knb, \n";
127
 if ($eBC ne "" && $nBC ne "" && $eBC ne "0" &&  $nBC ne "0") { 
128
    print "$name $eBC $nBC $url?action=read&docid=$name&qformat=knb \n";
129
 }
130
}
131

    
132
#print $numberNodes;
(3-3/7)