Revision 2783
Added by sgarg about 19 years ago
register-dataset.cgi | ||
---|---|---|
35 | 35 |
use Template; |
36 | 36 |
use Net::SMTP; |
37 | 37 |
use CGI qw/:standard :html3/; |
38 |
use CGI::Session; |
|
38 | 39 |
use strict; |
39 | 40 |
|
40 | 41 |
# Global configuration paramters |
... | ... | |
84 | 85 |
$config->define("hasMethod", { DEFAULT => 'true'} ); |
85 | 86 |
$config->define("temporalRequired", { DEFAULT => 'true'} ); |
86 | 87 |
$config->define("spatialRequired", { DEFAULT => 'true'} ); |
88 |
$config->define("contactEmailAddressRequired", { DEFAULT => 'false'} ); |
|
87 | 89 |
$config->define("publicReadable", { DEFAULT => 'true'} ); |
88 |
$config->define("accessPrincipals", { DEFAULT => ''} );
|
|
89 |
$config->define("accessType", { DEFAULT => ''} );
|
|
90 |
$config->define("moderators", { DEFAULT => ''} );
|
|
91 |
$config->define("moderatorPermission", { DEFAULT => ''} );
|
|
90 | 92 |
$config->define("mailhost"); |
91 | 93 |
$config->define("sender"); |
92 | 94 |
$config->define("recipient"); |
... | ... | |
99 | 101 |
$config->define("responseTemplate", { DEFAULT => 'crap.tmpl'} ); |
100 | 102 |
$config->define("entryFormTemplate", { DEFAULT => 'crap.tmpl'} ); |
101 | 103 |
$config->define("guideTemplate", { DEFAULT => 'crap.tmpl'} ); |
104 |
$config->define("loginFormTemplate", { DEFAULT => 'crap.tmpl'} ); |
|
102 | 105 |
$config->define("confirmDataTemplate", { DEFAULT => 'crap.tmpl'} ); |
103 | 106 |
$config->define("deleteDataTemplate", { DEFAULT => 'crap.tmpl'} ); |
107 |
$config->define("modNotificationTemplate", { DEFAULT => 'crap.tmpl'} ); |
|
104 | 108 |
$config->define("debug", { DEFAULT => '0'} ); |
105 | 109 |
$config->define("lat", { ARGCOUNT => ARGCOUNT_HASH} ); |
106 | 110 |
$config->define("lon", { ARGCOUNT => ARGCOUNT_HASH} ); |
... | ... | |
127 | 131 |
my $entryFormTemplate = $config->entryFormTemplate(); |
128 | 132 |
my $deleteDataTemplate = $config->deleteDataTemplate(); |
129 | 133 |
my $guideTemplate = $config->guideTemplate(); |
134 |
my $loginFormTemplate = $config->loginFormTemplate(); |
|
130 | 135 |
my $confirmDataTemplate = $config->confirmDataTemplate(); |
136 |
my $modNotificationTemplate = $config->modNotificationTemplate(); |
|
131 | 137 |
my $accesspubid = $config->accesspubid(); |
132 | 138 |
my $accesssysid = $config->accesssysid(); |
133 | 139 |
my $datasetpubid = $config->datasetpubid(); |
... | ... | |
144 | 150 |
my $hasMethod = $config->hasMethod(); |
145 | 151 |
my $temporalRequired = $config->temporalRequired(); |
146 | 152 |
my $spatialRequired = $config->spatialRequired(); |
153 |
my $contactEmailAddressRequired = $config->contactEmailAddressRequired(); |
|
147 | 154 |
my $publicReadable = $config->publicReadable(); |
148 |
my $accessPrincipals = $config->accessPrincipals();
|
|
149 |
my $accessType = $config->accessType();
|
|
155 |
my $moderators = $config->moderators();
|
|
156 |
my $moderatorPermission = $config->moderatorPermission();
|
|
150 | 157 |
my $mailhost = $config->mailhost(); |
151 | 158 |
my $sender = $config->sender(); |
152 | 159 |
my $recipient = $config->recipient(); |
... | ... | |
162 | 169 |
my $debug = $config->debug(); |
163 | 170 |
my $lat = $config->get('lat'); |
164 | 171 |
my $lon = $config->get('lon'); |
165 |
|
|
172 |
$debug = 1; |
|
166 | 173 |
# Convert the lat and lon configs into usable data structures |
167 | 174 |
my @sitelist; |
168 | 175 |
my %siteLatDMS; |
... | ... | |
185 | 192 |
# create an instance of the template processor |
186 | 193 |
my $template = Template->new($ttConfig) || die $Template::ERROR, "\n"; |
187 | 194 |
|
188 |
print "Content-type: text/html\n\n"; |
|
189 |
|
|
190 | 195 |
# Set up the template information that is common to all forms |
191 | 196 |
$$templateVars{'cfg'} = $FORM::cfg; |
192 | 197 |
$$templateVars{'recipient'} = $recipient; |
... | ... | |
198 | 203 |
|
199 | 204 |
debug("Registry: Initialized"); |
200 | 205 |
# Process the form based on stage parameter. |
206 |
if ($FORM::stage =~ "loginform") { |
|
207 |
print "Content-type: text/html\n\n"; |
|
208 |
# Send back the login form..... |
|
209 |
my $session = CGI::Session->load() or die CGI::Session->errstr(); |
|
210 |
if ( $session->is_empty ) { |
|
211 |
# no session found ... redirect to login page template |
|
212 |
$template->process( $loginFormTemplate, $templateVars); |
|
213 |
} else { |
|
214 |
# session found ... delete the session.... |
|
215 |
$session->delete(); |
|
216 |
$template->process( $loginFormTemplate, $templateVars); |
|
217 |
} |
|
218 |
exit(0); |
|
219 |
} elsif ($FORM::stage =~ "logout") { |
|
220 |
handleLogoutRequest(); |
|
221 |
exit(0); |
|
222 |
} elsif ($FORM::stage =~ "login") { |
|
223 |
handleLoginRequest(); |
|
224 |
exit(0); |
|
225 |
} elsif ($FORM::stage =~ "mod_accept") { |
|
226 |
handleModAccept(); |
|
227 |
exit(0); |
|
228 |
} elsif ($FORM::stage =~ "mod_decline") { |
|
229 |
handleModDecline(); |
|
230 |
exit(0); |
|
231 |
} elsif ($FORM::stage =~ "mod_revise") { |
|
232 |
handleModRevise(); |
|
233 |
exit(0); |
|
234 |
} |
|
235 |
|
|
236 |
print "Content-type: text/html\n\n"; |
|
237 |
|
|
201 | 238 |
if ($FORM::stage =~ "guide") { |
202 | 239 |
# Send back the information on how to fill the form |
203 | 240 |
$$templateVars{'section'} = "Guide on How to Complete Registry Entries"; |
... | ... | |
277 | 314 |
$$templateVars{'hasMethod'} = $hasMethod; |
278 | 315 |
$$templateVars{'temporalRequired'} = $temporalRequired; |
279 | 316 |
$$templateVars{'spatialRequired'} = $spatialRequired; |
317 |
$$templateVars{'contactEmailAddressRequired'} = $contactEmailAddressRequired; |
|
280 | 318 |
|
281 | 319 |
$$templateVars{'siteList'} = \@sortedSites; |
282 | 320 |
$$templateVars{'section'} = "Entry Form"; |
... | ... | |
516 | 554 |
my $xmldoc = shift; |
517 | 555 |
my $docid = shift; |
518 | 556 |
|
557 |
debug("Trying to insert the following document"); |
|
519 | 558 |
my $notunique = "SUCCESS"; |
520 | 559 |
debug("Registry: Starting insert (D1)"); |
521 | 560 |
my $response = $metacat->insert($docid, $xmldoc); |
... | ... | |
751 | 790 |
push(@invalidParams, "Last name of data set contact is missing.") |
752 | 791 |
unless (hasContent($FORM::origNamelastContact) || |
753 | 792 |
$FORM::useOrigAddress); |
793 |
push(@invalidParams, "Email address of data set contact is missing.") |
|
794 |
unless (hasContent($FORM::origEmailContact) || $FORM::contactEmailAddressRequired ne 'true' ); |
|
754 | 795 |
push(@invalidParams, "Data medium is missing.") |
755 | 796 |
unless (hasContent($FORM::dataMedium) || $FORM::dataMedium =~ /elect/); |
756 | 797 |
push(@invalidParams, "Usage rights are missing.") |
... | ... | |
1425 | 1466 |
$doc .= "<principal>$username</principal>\n"; |
1426 | 1467 |
$doc .= "<permission>all</permission>\n"; |
1427 | 1468 |
$doc .= "</allow>\n"; |
1428 |
$doc .= "<allow>\n"; |
|
1429 |
$doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n"; |
|
1430 |
$doc .= "<permission>all</permission>\n"; |
|
1431 |
$doc .= "</allow>\n"; |
|
1469 |
|
|
1470 |
if($moderators eq ''){ |
|
1471 |
$doc .= "<allow>\n"; |
|
1472 |
$doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n"; |
|
1473 |
$doc .= "<permission>all</permission>\n"; |
|
1474 |
$doc .= "</allow>\n"; |
|
1475 |
} else { |
|
1476 |
foreach(split(":",$moderators)){ |
|
1477 |
$doc .= "<allow>\n"; |
|
1478 |
$doc .= "<principal>".$_."</principal>\n"; |
|
1479 |
$doc .= "<permission>".$moderatorPermission."</permission>\n"; |
|
1480 |
$doc .= "</allow>\n"; |
|
1481 |
} |
|
1482 |
|
|
1483 |
$doc .= "<allow>\n"; |
|
1484 |
$doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n"; |
|
1485 |
$doc .= "<permission>read</permission>\n"; |
|
1486 |
$doc .= "<permission>write</permission>\n"; |
|
1487 |
$doc .= "</allow>\n"; |
|
1488 |
} |
|
1489 |
|
|
1432 | 1490 |
if($publicReadable eq "true"){ |
1433 | 1491 |
$doc .= "<allow>\n"; |
1434 | 1492 |
$doc .= "<principal>public</principal>\n"; |
1435 | 1493 |
$doc .= "<permission>read</permission>\n"; |
1436 | 1494 |
$doc .= "</allow>\n"; |
1437 | 1495 |
} |
1438 |
foreach(split(":",$accessPrincipals)){ |
|
1439 |
$doc .= "<allow>\n"; |
|
1440 |
$doc .= "<principal>".$_."</principal>\n"; |
|
1441 |
$doc .= "<permission>".$accessType."</permission>\n"; |
|
1442 |
$doc .= "</allow>\n"; |
|
1443 |
} |
|
1444 | 1496 |
$doc .= "</access>\n"; |
1445 | 1497 |
|
1446 | 1498 |
$doc .= "</dataset>\n</eml:eml>\n"; |
... | ... | |
1449 | 1501 |
} |
1450 | 1502 |
|
1451 | 1503 |
|
1452 |
################################################################################ |
|
1453 |
# |
|
1454 |
# send an email message notifying the moderator of a new submission |
|
1455 |
# |
|
1456 |
################################################################################ |
|
1457 |
sub sendNotification { |
|
1458 |
my $identifier = shift; |
|
1459 |
my $mailhost = shift; |
|
1460 |
my $sender = shift; |
|
1461 |
my $recipient = shift; |
|
1504 |
sub readDocumentFromMetacat(){ |
|
1462 | 1505 |
|
1463 |
my $smtp = Net::SMTP->new($mailhost); |
|
1464 |
$smtp->mail($sender); |
|
1465 |
$smtp->to($recipient); |
|
1466 |
|
|
1467 |
my $message = <<" ENDOFMESSAGE"; |
|
1468 |
To: $recipient |
|
1469 |
From: $sender |
|
1470 |
Subject: New data submission |
|
1471 |
|
|
1472 |
Data was submitted to the data registry. |
|
1473 |
The identifying information for the new data set is: |
|
1474 |
|
|
1475 |
Identifier: $identifier |
|
1476 |
Title: $FORM::title |
|
1477 |
Submitter: $FORM::providerGivenName $FORM::providerSurName |
|
1478 |
|
|
1479 |
Please review the submmission and grant public read access if appropriate. |
|
1480 |
Thanks |
|
1481 |
|
|
1482 |
ENDOFMESSAGE |
|
1483 |
$message =~ s/^[ \t\r\f]+//gm; |
|
1484 |
|
|
1485 |
$smtp->data($message); |
|
1486 |
$smtp->quit; |
|
1487 |
} |
|
1488 |
|
|
1489 |
|
|
1490 |
################################################################################ |
|
1491 |
# |
|
1492 |
# read the eml document and send back a form with values filled in. |
|
1493 |
# |
|
1494 |
################################################################################ |
|
1495 |
sub modifyData { |
|
1496 |
|
|
1506 |
my $docid = $FORM::docid; |
|
1497 | 1507 |
# create metacat instance |
1498 | 1508 |
my $metacat; |
1499 |
my $docid = $FORM::docid; |
|
1500 | 1509 |
my $httpMessage; |
1501 | 1510 |
my $doc; |
1502 | 1511 |
my $xmldoc; |
... | ... | |
1602 | 1611 |
#open (TFILE,">$tempfile") || die ("Cant open xml file...\n"); |
1603 | 1612 |
#print TFILE $stylesheet->output_string($resultsheet); |
1604 | 1613 |
#close(TFILE); |
1605 |
|
|
1606 |
getFormValuesFromEml2($resultsheet); |
|
1607 | 1614 |
|
1608 | 1615 |
# Delete the files written earlier. |
1609 | 1616 |
unlink @fileArray; |
1610 | 1617 |
|
1611 |
} else {
|
|
1612 |
getFormValuesFromEml2($xmldoc); |
|
1618 |
return $resultsheet;
|
|
1619 |
|
|
1613 | 1620 |
} |
1614 |
} |
|
1621 |
} |
|
1622 |
return $xmldoc; |
|
1623 |
} |
|
1624 |
|
|
1615 | 1625 |
|
1626 |
################################################################################ |
|
1627 |
# |
|
1628 |
# read the eml document and send back a form with values filled in. |
|
1629 |
# |
|
1630 |
################################################################################ |
|
1631 |
sub modifyData { |
|
1632 |
|
|
1633 |
my $xmldoc = readDocumentFromMetacat(); |
|
1634 |
getFormValuesFromEml2($xmldoc); |
|
1635 |
|
|
1616 | 1636 |
if (scalar(@errorMessages)) { |
1617 | 1637 |
# if any errors, print them in the response template |
1618 | 1638 |
$$templateVars{'status'} = 'failure_no_resubmit'; |
... | ... | |
1656 | 1676 |
$$templateVars{'hasTaxonomic'} = $hasTaxonomic; |
1657 | 1677 |
$$templateVars{'hasMethod'} = $hasMethod; |
1658 | 1678 |
$$templateVars{'spatialRequired'} = $spatialRequired; |
1679 |
$$templateVars{'contactEmailAddressRequired'} = $contactEmailAddressRequired; |
|
1659 | 1680 |
$$templateVars{'temporalRequired'} = $temporalRequired; |
1660 | 1681 |
|
1661 | 1682 |
# find out the tag <alternateIdentifier>. |
... | ... | |
2395 | 2416 |
} |
2396 | 2417 |
} |
2397 | 2418 |
|
2419 |
################################################################################ |
|
2420 |
# |
|
2421 |
# function to handle login request |
|
2422 |
# |
|
2423 |
################################################################################ |
|
2424 |
sub handleLoginRequest(){ |
|
2425 |
# Check if a session already exists |
|
2426 |
my $session = CGI::Session->load() or die CGI::Session->errstr(); |
|
2427 |
if ( $session->is_empty ) { |
|
2428 |
# no session found ... check if the login is correct |
|
2429 |
my $username = $FORM::username; |
|
2430 |
my $password = $FORM::password; |
|
2398 | 2431 |
|
2432 |
debug($username); |
|
2433 |
debug($password); |
|
2434 |
my $metacat = Metacat->new(); |
|
2435 |
if ($metacat) { |
|
2436 |
$metacat->set_options( metacatUrl => $metacatUrl ); |
|
2437 |
} else { |
|
2438 |
#die "failed during metacat creation\n"; |
|
2439 |
push(@errorMessages, "Failed during metacat creation."); |
|
2440 |
} |
|
2441 |
my $returnVal = $metacat->login($username,$password); |
|
2442 |
debug($returnVal); |
|
2443 |
if($returnVal > 0){ |
|
2444 |
# valid username and passwd |
|
2445 |
# create a new session and store username and passswd |
|
2446 |
$session = new CGI::Session(); |
|
2447 |
|
|
2448 |
$session->param('username', $username); |
|
2449 |
$session->param('password', $password); |
|
2450 |
|
|
2451 |
if($returnVal == 2 || $returnVal == 4){ |
|
2452 |
# is a moderator. store this information in the session |
|
2453 |
$session->param('moderator', 'true'); |
|
2454 |
} |
|
2455 |
|
|
2456 |
# send redirect to metacat and action = login |
|
2457 |
my $html = "<html><head>"; |
|
2458 |
$html .= "</head><body onload=\"document.loginForm.submit()\">"; |
|
2459 |
$html .= "<form name=\"loginForm\" method=\"post\" action=\"@systemidserver@@servlet-path@\">"; |
|
2460 |
$html .= "<input type=\"hidden\" name=\"action\" value=\"login\" />"; |
|
2461 |
$html .= "<input type=\"hidden\" name=\"username\" value=\"".$FORM::username."\" />"; |
|
2462 |
$html .= "<input type=\"hidden\" name=\"password\" value=\"".$FORM::password."\" />"; |
|
2463 |
$html .= "<input type=\"hidden\" name=\"qformat\" value=\"".$FORM::cfg."\" />"; |
|
2464 |
$html .= "</form></body></html>"; |
|
2465 |
debug($html); |
|
2466 |
debug($session->header()); |
|
2467 |
print $session->header(); |
|
2468 |
print $html; |
|
2469 |
} else { |
|
2470 |
# send back the error template with error message as wrong username password |
|
2471 |
# push(@errorMessages, $metacat->getMessage()); |
|
2472 |
print "Content-type: text/html\n\n"; |
|
2473 |
push(@errorMessages, "Failed during login.\n"); |
|
2474 |
$$templateVars{'status'} = 'login_failure'; |
|
2475 |
$$templateVars{'errorMessages'} = \@errorMessages; |
|
2476 |
$$templateVars{'cfg'} = $FORM::cfg; |
|
2477 |
$$templateVars{'section'} = "Login Status"; |
|
2478 |
$template->process( $responseTemplate, $templateVars); |
|
2479 |
} |
|
2480 |
|
|
2481 |
exit(0); |
|
2482 |
} else { |
|
2483 |
# session found ... redirect to index page |
|
2484 |
my $url = "@systemidserver@@style-skins-path@/".$FORM::cfg."/index.html"; |
|
2485 |
redirect($url); |
|
2486 |
exit(0); |
|
2487 |
} |
|
2488 |
} |
|
2489 |
|
|
2399 | 2490 |
################################################################################ |
2400 | 2491 |
# |
2492 |
# function to handle logout request |
|
2493 |
# |
|
2494 |
################################################################################ |
|
2495 |
sub handleLogoutRequest(){ |
|
2496 |
print "Content-type: text/html\n\n"; |
|
2497 |
# Check if the session exists |
|
2498 |
debug("Stage is logout"); |
|
2499 |
my $session = CGI::Session->load(); |
|
2500 |
if ( $session->is_empty || $session->is_expired) { |
|
2501 |
# no session found ... send back to index.html page ... |
|
2502 |
debug("Session empty or not found"); |
|
2503 |
my $url = "@systemidserver@@style-skins-path@/".$FORM::cfg."/index.html"; |
|
2504 |
redirect($url); |
|
2505 |
# should logout request be sent to metacat??? |
|
2506 |
} else { |
|
2507 |
# get the user name and delete the session |
|
2508 |
debug("Session found"); |
|
2509 |
my $uname = $session->param("username"); |
|
2510 |
$session->delete(); |
|
2511 |
# send redirect to metacat and action = login |
|
2512 |
my $html = "<html><head>"; |
|
2513 |
$html .= "</head><body onload=\"document.loginForm.submit()\">"; |
|
2514 |
$html .= "<form name=\"loginForm\" method=\"post\" action=\"@systemidserver@@servlet-path@\">"; |
|
2515 |
$html .= "<input type=\"hidden\" name=\"action\" value=\"logout\" />"; |
|
2516 |
$html .= "<input type=\"hidden\" name=\"username\" value=\"".$uname."\" />"; |
|
2517 |
$html .= "<input type=\"hidden\" name=\"qformat\" value=\"".$FORM::cfg."\" />"; |
|
2518 |
$html .= "</form></body></html>"; |
|
2519 |
debug($html); |
|
2520 |
print($html); |
|
2521 |
} |
|
2522 |
} |
|
2523 |
|
|
2524 |
################################################################################ |
|
2525 |
# |
|
2526 |
# function to handle accept request for moderator |
|
2527 |
# |
|
2528 |
################################################################################ |
|
2529 |
sub handleModAccept(){ |
|
2530 |
|
|
2531 |
my $metacat; |
|
2532 |
$metacat = Metacat->new(); |
|
2533 |
if ($metacat) { |
|
2534 |
$metacat->set_options( metacatUrl => $metacatUrl ); |
|
2535 |
} else { |
|
2536 |
#die "failed during metacat creation\n"; |
|
2537 |
push(@errorMessages, "Failed during metacat creation."); |
|
2538 |
} |
|
2539 |
|
|
2540 |
print "Content-type: text/html\n\n"; |
|
2541 |
|
|
2542 |
# Check if the session exists |
|
2543 |
debug("Stage is mod_accept"); |
|
2544 |
|
|
2545 |
my $session = CGI::Session->load(); |
|
2546 |
if ( $session->is_empty || $session->is_expired) { |
|
2547 |
# no session found ... send back to index.html page ... |
|
2548 |
push(@errorMessages, "Failed during login.\n"); |
|
2549 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2550 |
return; |
|
2551 |
} |
|
2552 |
|
|
2553 |
# check if logged in user is moderator |
|
2554 |
my $moderator = $session->param("moderator"); |
|
2555 |
if ( $moderator ne 'true') { |
|
2556 |
# no session found ... send back to index.html page ... |
|
2557 |
debug("Logged in user is not moderator"); |
|
2558 |
push(@errorMessages, "Logged in user is not moderator. Please login again as moderator\n"); |
|
2559 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2560 |
return; |
|
2561 |
} |
|
2562 |
|
|
2563 |
# change the access rules |
|
2564 |
|
|
2565 |
## create the access block |
|
2566 |
my $accessblock = ''; |
|
2567 |
$accessblock .= "<access authSystem=\"knb\" order=\"denyFirst\">\n"; |
|
2568 |
$accessblock .= "<allow>\n"; |
|
2569 |
$accessblock .= "<principal>$username</principal>\n"; |
|
2570 |
$accessblock .= "<permission>all</permission>\n"; |
|
2571 |
$accessblock .= "</allow>\n"; |
|
2572 |
|
|
2573 |
foreach(split(":",$moderators)){ |
|
2574 |
$accessblock .= "<allow>\n"; |
|
2575 |
$accessblock .= "<principal>".$_."</principal>\n"; |
|
2576 |
$accessblock .= "<permission>".$moderatorPermission."</permission>\n"; |
|
2577 |
$accessblock .= "</allow>\n"; |
|
2578 |
} |
|
2579 |
|
|
2580 |
$accessblock .= "<allow>\n"; |
|
2581 |
$accessblock .= "<principal>public</principal>\n"; |
|
2582 |
$accessblock .= "<permission>read</permission>\n"; |
|
2583 |
$accessblock .= "</allow>\n"; |
|
2584 |
$accessblock .= "</access>\n"; |
|
2585 |
|
|
2586 |
## read the document from |
|
2587 |
my $docFromMetacat = readDocumentFromMetacat(); |
|
2588 |
my ($emldoc, $temp) = split('<access authSystem=', $docFromMetacat); |
|
2589 |
|
|
2590 |
$emldoc .= $accessblock; |
|
2591 |
$emldoc .= "</dataset>\n</eml:eml>\n"; |
|
2592 |
|
|
2593 |
debug("Document created by handleModAccept is " . $emldoc); |
|
2594 |
|
|
2595 |
# update the document |
|
2596 |
my $docid = $FORM::docid; |
|
2597 |
|
|
2598 |
my $x; |
|
2599 |
my $y; |
|
2600 |
my $z; |
|
2601 |
|
|
2602 |
($x, $y, $z) = split(/\./, $docid); |
|
2603 |
$z++; |
|
2604 |
$docid = "$x.$y.$z"; |
|
2605 |
|
|
2606 |
$emldoc =~ s/packageId=\"docid\"/packageId=\"$docid\"/; |
|
2607 |
|
|
2608 |
my $response = $metacat->update($docid, $emldoc); |
|
2609 |
|
|
2610 |
if (! $response) { |
|
2611 |
debug("Error while updating in handleModAccept."); |
|
2612 |
|
|
2613 |
push(@errorMessages, $metacat->getMessage()); |
|
2614 |
push(@errorMessages, "Failed while updating.\n"); |
|
2615 |
|
|
2616 |
############ TODO: need for proper error message |
|
2617 |
} |
|
2618 |
|
|
2619 |
# get the contact email address from the |
|
2620 |
my $parser = XML::LibXML->new(); |
|
2621 |
my $xmldoc = $parser->parse_string($emldoc); |
|
2622 |
|
|
2623 |
if ($xmldoc eq "" || $doc=~ /<error/) { |
|
2624 |
# not able to parse |
|
2625 |
push(@errorMessages, "Error in reading the docid:".$docid."\n"); |
|
2626 |
} else { |
|
2627 |
my $findNodes = $xmldoc->findnodes('//dataset/contact'); |
|
2628 |
if($findNodes->size() > 0){ |
|
2629 |
# found contact email address |
|
2630 |
my $node = ''; |
|
2631 |
foreach $node ($findNodes->get_nodelist) { |
|
2632 |
$contactEmailAddress = findValue($node,'electronicMailAddress'); |
|
2633 |
my $surName = findValue($node,'individualName/surName'); |
|
2634 |
my $givenName = findValue($node,'individualName/givenName'); |
|
2635 |
my $organizationName = findValue($node,'organizaitionName'); |
|
2636 |
|
|
2637 |
if($surName ne ''){ |
|
2638 |
$contactName = $givenName.' '.$surName; |
|
2639 |
} else { |
|
2640 |
$contactName = $organizationName; |
|
2641 |
} |
|
2642 |
} |
|
2643 |
} else { |
|
2644 |
$contactEmailAddress = ''; |
|
2645 |
} |
|
2646 |
$findNodes = $xmldoc->findnodes('//dataset/title'); |
|
2647 |
if($findNodes->size() > 0){ |
|
2648 |
# found title |
|
2649 |
my $node = ''; |
|
2650 |
foreach $node ($findNodes->get_nodelist) { |
|
2651 |
$title = findValue($node,'../title'); |
|
2652 |
} |
|
2653 |
} else { |
|
2654 |
$title = ''; |
|
2655 |
} |
|
2656 |
} |
|
2657 |
|
|
2658 |
# send notification to the user and the moderator |
|
2659 |
if (!scalar(@errorMessages)) { |
|
2660 |
# send notifications |
|
2661 |
mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Accepted'); |
|
2662 |
|
|
2663 |
$$templateVars{'function'} = "deleted"; |
|
2664 |
$$templateVars{'section'} = "Deletion Status"; |
|
2665 |
$template->process( $responseTemplate, $templateVars); |
|
2666 |
} else { |
|
2667 |
############ TODO: need for proper error message |
|
2668 |
processErrorTemplate('failure', '', 'Unable to delete the document'); |
|
2669 |
} |
|
2670 |
} |
|
2671 |
|
|
2672 |
################################################################################ |
|
2673 |
# |
|
2674 |
# function to handle decline request for moderator |
|
2675 |
# |
|
2676 |
################################################################################ |
|
2677 |
sub handleModDecline(){ |
|
2678 |
|
|
2679 |
my $metacat; |
|
2680 |
$metacat = Metacat->new(); |
|
2681 |
if ($metacat) { |
|
2682 |
$metacat->set_options( metacatUrl => $metacatUrl ); |
|
2683 |
} else { |
|
2684 |
#die "failed during metacat creation\n"; |
|
2685 |
push(@errorMessages, "Failed during metacat creation."); |
|
2686 |
} |
|
2687 |
|
|
2688 |
print "Content-type: text/html\n\n"; |
|
2689 |
|
|
2690 |
# Check if the session exists |
|
2691 |
debug("Stage is mod_decline"); |
|
2692 |
|
|
2693 |
my $session = CGI::Session->load(); |
|
2694 |
if ( $session->is_empty || $session->is_expired) { |
|
2695 |
# no session found ... send back to index.html page ... |
|
2696 |
push(@errorMessages, "Failed during login.\n"); |
|
2697 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2698 |
return; |
|
2699 |
} |
|
2700 |
|
|
2701 |
# check if logged in user is moderator |
|
2702 |
my $moderator = $session->param("moderator"); |
|
2703 |
if ( $moderator ne 'true') { |
|
2704 |
# no session found ... send back to index.html page ... |
|
2705 |
debug("Logged in user is not moderator"); |
|
2706 |
push(@errorMessages, "Logged in user is not moderator. Please login again as moderator\n"); |
|
2707 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2708 |
return; |
|
2709 |
} |
|
2710 |
|
|
2711 |
# variables for contact information |
|
2712 |
my $contactEmailAddress; |
|
2713 |
my $contactName; |
|
2714 |
my $title; |
|
2715 |
|
|
2716 |
# Log into metacat |
|
2717 |
my $username = $session->param("username"); |
|
2718 |
my $password = $session->param("password"); |
|
2719 |
my $response = $metacat->login($username, $password); |
|
2720 |
|
|
2721 |
if (! $response) { |
|
2722 |
# Could not login |
|
2723 |
push(@errorMessages, $metacat->getMessage()); |
|
2724 |
push(@errorMessages, "Failed during login.\n"); |
|
2725 |
|
|
2726 |
} else { |
|
2727 |
# read the document and get the contact name and address |
|
2728 |
my $parser = XML::LibXML->new(); |
|
2729 |
my $docid = $FORM::docid; |
|
2730 |
|
|
2731 |
$response = $metacat->read($docid); |
|
2732 |
my $doc = $response->content(); |
|
2733 |
my $xmldoc = $parser->parse_string($doc); |
|
2734 |
|
|
2735 |
if ($xmldoc eq "" || $doc=~ /<error/) { |
|
2736 |
# not able to parse |
|
2737 |
push(@errorMessages, "Error in reading the docid:".$docid."\n"); |
|
2738 |
} else { |
|
2739 |
my $findNodes = $xmldoc->findnodes('//dataset/contact'); |
|
2740 |
if($findNodes->size() > 0){ |
|
2741 |
# found contact email address |
|
2742 |
my $node = ''; |
|
2743 |
foreach $node ($findNodes->get_nodelist) { |
|
2744 |
$contactEmailAddress = findValue($node,'electronicMailAddress'); |
|
2745 |
|
|
2746 |
my $surName = findValue($node,'individualName/surName'); |
|
2747 |
my $givenName = findValue($node,'individualName/givenName'); |
|
2748 |
my $organizationName = findValue($node,'organizaitionName'); |
|
2749 |
|
|
2750 |
if($surName ne ''){ |
|
2751 |
$contactName = $givenName.' '.$surName; |
|
2752 |
} else { |
|
2753 |
$contactName = $organizationName; |
|
2754 |
} |
|
2755 |
} |
|
2756 |
} else { |
|
2757 |
$contactEmailAddress = ''; |
|
2758 |
} |
|
2759 |
$findNodes = $xmldoc->findnodes('//dataset/title'); |
|
2760 |
if($findNodes->size() > 0){ |
|
2761 |
# found title |
|
2762 |
my $node = ''; |
|
2763 |
foreach $node ($findNodes->get_nodelist) { |
|
2764 |
$title = findValue($node,'../title'); |
|
2765 |
} |
|
2766 |
} else { |
|
2767 |
$title = ''; |
|
2768 |
} |
|
2769 |
|
|
2770 |
} |
|
2771 |
|
|
2772 |
#$response = $metacat->delete($docid); |
|
2773 |
if (!$response) { |
|
2774 |
debug("Error while deleting document in handleModDecline."); |
|
2775 |
push(@errorMessages, $metacat->getMessage()); |
|
2776 |
push(@errorMessages, "Failed during deleting $docid. Please check if you are authorized to delete this document.\n"); |
|
2777 |
} else { |
|
2778 |
debug("Document deleted by handleModDecline is " . $docid); |
|
2779 |
} |
|
2780 |
} |
|
2781 |
|
|
2782 |
if (!scalar(@errorMessages)) { |
|
2783 |
# send notifications |
|
2784 |
mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Rejected'); |
|
2785 |
|
|
2786 |
$$templateVars{'function'} = "deleted"; |
|
2787 |
$$templateVars{'section'} = "Deletion Status"; |
|
2788 |
$template->process( $responseTemplate, $templateVars); |
|
2789 |
} else { |
|
2790 |
############ TODO: need for proper error message |
|
2791 |
processErrorTemplate('failure', '', 'Unable to delete the document'); |
|
2792 |
} |
|
2793 |
} |
|
2794 |
|
|
2795 |
################################################################################ |
|
2796 |
# |
|
2797 |
# function to handle revise request for moderator |
|
2798 |
# |
|
2799 |
################################################################################ |
|
2800 |
sub handleModRevise(){ |
|
2801 |
|
|
2802 |
my $metacat; |
|
2803 |
$metacat = Metacat->new(); |
|
2804 |
if ($metacat) { |
|
2805 |
$metacat->set_options( metacatUrl => $metacatUrl ); |
|
2806 |
} else { |
|
2807 |
#die "failed during metacat creation\n"; |
|
2808 |
push(@errorMessages, "Failed during metacat creation."); |
|
2809 |
} |
|
2810 |
|
|
2811 |
print "Content-type: text/html\n\n"; |
|
2812 |
|
|
2813 |
# Check if the session exists |
|
2814 |
debug("Stage is mod_revise"); |
|
2815 |
|
|
2816 |
my $session = CGI::Session->load(); |
|
2817 |
if ( $session->is_empty || $session->is_expired) { |
|
2818 |
# no session found ... send back to index.html page ... |
|
2819 |
push(@errorMessages, "Failed during login.\n"); |
|
2820 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2821 |
return; |
|
2822 |
} |
|
2823 |
|
|
2824 |
# check if logged in user is moderator |
|
2825 |
my $moderator = $session->param("moderator"); |
|
2826 |
if ( $moderator ne 'true') { |
|
2827 |
# no session found ... send back to index.html page ... |
|
2828 |
debug("Logged in user is not moderator"); |
|
2829 |
push(@errorMessages, "Logged in user is not moderator. Please login again as moderator\n"); |
|
2830 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2831 |
return; |
|
2832 |
} |
|
2833 |
|
|
2834 |
# variables for contact information |
|
2835 |
my $contactEmailAddress; |
|
2836 |
my $contactName; |
|
2837 |
my $title; |
|
2838 |
|
|
2839 |
# Log into metacat |
|
2840 |
my $username = $session->param("username"); |
|
2841 |
my $password = $session->param("password"); |
|
2842 |
my $response = $metacat->login($username, $password); |
|
2843 |
|
|
2844 |
if (! $response) { |
|
2845 |
# Could not login |
|
2846 |
push(@errorMessages, $metacat->getMessage()); |
|
2847 |
push(@errorMessages, "Failed during login.\n"); |
|
2848 |
|
|
2849 |
} else { |
|
2850 |
# read the document and get the contact name and address |
|
2851 |
my $parser = XML::LibXML->new(); |
|
2852 |
my $docid = $FORM::docid; |
|
2853 |
|
|
2854 |
$response = $metacat->read($docid); |
|
2855 |
my $doc = $response->content(); |
|
2856 |
my $xmldoc = $parser->parse_string($doc); |
|
2857 |
|
|
2858 |
if ($xmldoc eq "" || $doc=~ /<error/) { |
|
2859 |
# not able to parse |
|
2860 |
push(@errorMessages, "Error in reading the docid:".$docid."\n"); |
|
2861 |
} else { |
|
2862 |
my $findNodes = $xmldoc->findnodes('//dataset/contact'); |
|
2863 |
if($findNodes->size() > 0){ |
|
2864 |
# found contact email address |
|
2865 |
my $node = ''; |
|
2866 |
foreach $node ($findNodes->get_nodelist) { |
|
2867 |
$contactEmailAddress = findValue($node,'electronicMailAddress'); |
|
2868 |
|
|
2869 |
my $surName = findValue($node,'individualName/surName'); |
|
2870 |
my $givenName = findValue($node,'individualName/givenName'); |
|
2871 |
my $organizationName = findValue($node,'organizaitionName'); |
|
2872 |
|
|
2873 |
if($surName ne ''){ |
|
2874 |
$contactName = $givenName.' '.$surName; |
|
2875 |
} else { |
|
2876 |
$contactName = $organizationName; |
|
2877 |
} |
|
2878 |
} |
|
2879 |
} else { |
|
2880 |
$contactEmailAddress = ''; |
|
2881 |
} |
|
2882 |
$findNodes = $xmldoc->findnodes('//dataset/title'); |
|
2883 |
if($findNodes->size() > 0){ |
|
2884 |
# found title |
|
2885 |
my $node = ''; |
|
2886 |
foreach $node ($findNodes->get_nodelist) { |
|
2887 |
$title = findValue($node,'../title'); |
|
2888 |
} |
|
2889 |
} else { |
|
2890 |
$title = ''; |
|
2891 |
} |
|
2892 |
|
|
2893 |
} |
|
2894 |
} |
|
2895 |
|
|
2896 |
# send notifications |
|
2897 |
mod_sendNotification($title, $contactEmailAddress, $contactName, "Revise document: ".$FORM::docid); |
|
2898 |
|
|
2899 |
$$templateVars{'function'} = "deleted"; |
|
2900 |
$$templateVars{'section'} = "Deletion Status"; |
|
2901 |
$template->process( $responseTemplate, $templateVars); |
|
2902 |
} |
|
2903 |
|
|
2904 |
|
|
2905 |
|
|
2906 |
################################################################################ |
|
2907 |
# |
|
2908 |
# send an email message to the moderator and the contact |
|
2909 |
# |
|
2910 |
################################################################################ |
|
2911 |
sub mod_sendNotification { |
|
2912 |
my $title = shift; |
|
2913 |
my $contactEmailAddress = shift; |
|
2914 |
my $contactName = shift; |
|
2915 |
my $subject = shift; |
|
2916 |
|
|
2917 |
debug($subject); |
|
2918 |
# send notification to the user and the moderator |
|
2919 |
my $templateVars = { 'stage' => $FORM::stage }; |
|
2920 |
$$templateVars{'recipient'} = $recipient; |
|
2921 |
$$templateVars{'sender'} = $sender; |
|
2922 |
$$templateVars{'docid'} = $FORM::docid; |
|
2923 |
$$templateVars{'comment'} = $FORM::comment; |
|
2924 |
$$templateVars{'contactName'} = $contactName; |
|
2925 |
$$templateVars{'dpTitle'} = $title; |
|
2926 |
|
|
2927 |
$$templateVars{'recipient_status'} = 'moderator'; |
|
2928 |
sendNotification($mailhost, $sender, $recipient, $subject, |
|
2929 |
$modNotificationTemplate, $templateVars); |
|
2930 |
if($contactEmailAddress ne ''){ |
|
2931 |
# send notification to contact email address specified in cfg |
|
2932 |
$$templateVars{'recipient'} = $contactEmailAddress; |
|
2933 |
$$templateVars{'recipient_status'} = 'user'; |
|
2934 |
sendNotification($mailhost, $sender, $contactEmailAddress, |
|
2935 |
$subject, $modNotificationTemplate, $templateVars); |
|
2936 |
} |
|
2937 |
} |
|
2938 |
|
|
2939 |
################################################################################ |
|
2940 |
# |
|
2941 |
# send an email message notifying the moderator of a new submission |
|
2942 |
# |
|
2943 |
################################################################################ |
|
2944 |
sub sendNotification { |
|
2945 |
my $mailhost = shift; |
|
2946 |
my $sender = shift; |
|
2947 |
my $recipient = shift; |
|
2948 |
my $subject = shift; |
|
2949 |
my $templateForm = shift; |
|
2950 |
my $templateVars = shift; |
|
2951 |
|
|
2952 |
debug($mailhost); |
|
2953 |
debug($sender); |
|
2954 |
debug($recipient); |
|
2955 |
debug($subject); |
|
2956 |
|
|
2957 |
my $smtp = Net::SMTP->new($mailhost); |
|
2958 |
$smtp->mail($sender); |
|
2959 |
$smtp->to($recipient); |
|
2960 |
|
|
2961 |
$smtp->data; |
|
2962 |
$smtp->datasend("From: $sender\n"); |
|
2963 |
$smtp->datasend("To: <$recipient>\n"); |
|
2964 |
$smtp->datasend("Subject: $subject\n"); |
|
2965 |
$smtp->datasend("\n"); |
|
2966 |
|
|
2967 |
my $message; |
|
2968 |
$template->process($templateForm, $templateVars,\$message); |
|
2969 |
|
|
2970 |
$smtp->datasend($message); |
|
2971 |
$smtp->dataend(); |
|
2972 |
$smtp->quit; |
|
2973 |
} |
|
2974 |
|
|
2975 |
sub processErrorTemplate(){ |
|
2976 |
my $status = shift; |
|
2977 |
my $function = shift; |
|
2978 |
my $section = shift; |
|
2979 |
|
|
2980 |
$$templateVars{'status'} = $status; |
|
2981 |
$$templateVars{'function'} = $function; |
|
2982 |
$$templateVars{'errorMessages'} = \@errorMessages; |
|
2983 |
$$templateVars{'cfg'} = $FORM::cfg; |
|
2984 |
$$templateVars{'section'} = $section; |
|
2985 |
$template->process( $responseTemplate, $templateVars); |
|
2986 |
} |
|
2987 |
|
|
2988 |
|
|
2989 |
################################################################################ |
|
2990 |
# |
|
2401 | 2991 |
# Do data validation and send the data to confirm data template. |
2402 | 2992 |
# |
2403 | 2993 |
################################################################################ |
... | ... | |
2594 | 3184 |
$$templateVars{'hasTaxonomic'} = $FORM::hasTaxonomic; |
2595 | 3185 |
$$templateVars{'hasMethod'} = $FORM::hasMethod; |
2596 | 3186 |
$$templateVars{'spatialRequired'} = $FORM::spatialRequired; |
3187 |
$$templateVars{'contactEmailAddressRequired'} = $FORM::contactEmailAddressRequired; |
|
2597 | 3188 |
$$templateVars{'temporalRequired'} = $FORM::temporalRequired; |
2598 | 3189 |
|
2599 | 3190 |
$$templateVars{'docid'} = $FORM::docid; |
... | ... | |
2791 | 3382 |
$$templateVars{'hasTaxonomic'} = $FORM::hasTaxonomic; |
2792 | 3383 |
$$templateVars{'hasMethod'} = $FORM::hasMethod; |
2793 | 3384 |
$$templateVars{'spatialRequired'} = $FORM::spatialRequired; |
3385 |
$$templateVars{'contactEmailAddressRequired'} = $FORM::contactEmailAddressRequired; |
|
2794 | 3386 |
$$templateVars{'temporalRequired'} = $FORM::temporalRequired; |
2795 | 3387 |
} |
2796 | 3388 |
|
... | ... | |
2911 | 3503 |
|
2912 | 3504 |
################################################################################ |
2913 | 3505 |
# |
3506 |
# print redirect html code |
|
3507 |
# |
|
3508 |
################################################################################ |
|
3509 |
sub redirect(){ |
|
3510 |
my $url = shift; |
|
3511 |
|
|
3512 |
print "<head>"; |
|
3513 |
print "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=".$url."\">"; |
|
3514 |
print "</head><body></body></html>"; |
|
3515 |
} |
|
3516 |
|
|
3517 |
|
|
3518 |
################################################################################ |
|
3519 |
# |
|
2914 | 3520 |
# print debugging messages to stderr |
2915 | 3521 |
# |
2916 | 3522 |
################################################################################ |
Also available in: Unified diff
New functions in the dataset registry to support moderation feature needed for ESA