Revision 2847
Added by sgarg about 19 years ago
src/perl/register-dataset.cgi | ||
---|---|---|
210 | 210 |
print "Content-type: text/html\n\n"; |
211 | 211 |
# Send back the login form..... |
212 | 212 |
my $session = CGI::Session->load() or die CGI::Session->errstr(); |
213 |
|
|
214 |
|
|
215 |
$$templateVars{'submission'} = $FORM::submission; |
|
216 |
|
|
213 | 217 |
if ( $session->is_empty ) { |
214 | 218 |
# no session found ... redirect to login page template |
215 | 219 |
$template->process( $loginFormTemplate, $templateVars); |
... | ... | |
234 | 238 |
} elsif ($FORM::stage =~ "mod_revise") { |
235 | 239 |
handleModRevise(); |
236 | 240 |
exit(0); |
241 |
} elsif ($FORM::stage =~ "read") { |
|
242 |
handleRead(); |
|
243 |
exit(0); |
|
244 |
} elsif ($FORM::stage =~ "review_frame"){ |
|
245 |
handleReviewFrame(); |
|
246 |
exit(0); |
|
237 | 247 |
} |
238 | 248 |
|
239 | 249 |
print "Content-type: text/html\n\n"; |
... | ... | |
388 | 398 |
my $userPass = $FORM::password; |
389 | 399 |
my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org"; |
390 | 400 |
|
401 |
if($FORM::userLoggedIn eq 'true'){ |
|
402 |
my $session = CGI::Session->load(); |
|
403 |
if (!( $session->is_empty || $session->is_expired)) { |
|
404 |
$dname = $session->param("username"); |
|
405 |
$userPass = $session->param("password"); |
|
406 |
} |
|
407 |
} |
|
408 |
|
|
391 | 409 |
my $xmldocWithDocID = $xmldoc; |
392 | 410 |
|
393 | 411 |
my $errorMessage = ""; |
... | ... | |
407 | 425 |
exit(0); |
408 | 426 |
} else { |
409 | 427 |
|
410 |
if($adminIsDocOwner == 'true'){
|
|
428 |
if($adminIsDocOwner eq 'true'){
|
|
411 | 429 |
$response = $metacat->login($username, $password); |
412 | 430 |
if (! $response) { |
413 | 431 |
push(@errorMessages, $metacat->getMessage()); |
... | ... | |
1381 | 1399 |
$cov .= "<boundingCoordinates>\n"; |
1382 | 1400 |
# if the second latitude is missing, then set the second lat/long pair |
1383 | 1401 |
# equal to the first this makes a point appear like a rectangle |
1384 |
if ($FORM::useSiteCoord || ($FORM::latDeg2 == "" && $FORM::latMin2 == "" && $FORM::latSec2 == "")) {
|
|
1402 |
if ($FORM::useSiteCoord || ($FORM::latDeg2 eq "" && $FORM::latMin2 eq "" && $FORM::latSec2 eq "")) {
|
|
1385 | 1403 |
|
1386 | 1404 |
$latDeg2 = $latDeg1; |
1387 | 1405 |
$latMin2 = $latMin1; |
... | ... | |
1498 | 1516 |
$doc .= "</allow>\n"; |
1499 | 1517 |
|
1500 | 1518 |
if($moderators eq ''){ |
1501 |
$doc .= "<allow>\n"; |
|
1502 |
$doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n"; |
|
1503 |
$doc .= "<permission>all</permission>\n"; |
|
1504 |
$doc .= "</allow>\n"; |
|
1519 |
if($FORM::username ne ''){ |
|
1520 |
$doc .= "<allow>\n"; |
|
1521 |
$doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n"; |
|
1522 |
$doc .= "<permission>all</permission>\n"; |
|
1523 |
$doc .= "</allow>\n"; |
|
1524 |
} else { |
|
1525 |
my $session = CGI::Session->load(); |
|
1526 |
if ( !$session->is_empty ) { |
|
1527 |
my $username = $session->param("username"); |
|
1528 |
$doc .= "<allow>\n"; |
|
1529 |
$doc .= "<principal>$username</principal>\n"; |
|
1530 |
$doc .= "<permission>all</permission>\n"; |
|
1531 |
$doc .= "</allow>\n"; |
|
1532 |
} |
|
1533 |
} |
|
1505 | 1534 |
} else { |
1506 | 1535 |
foreach(split(":",$moderators)){ |
1507 | 1536 |
$doc .= "<allow>\n"; |
... | ... | |
1509 | 1538 |
$doc .= "<permission>all</permission>\n"; |
1510 | 1539 |
$doc .= "</allow>\n"; |
1511 | 1540 |
} |
1512 |
|
|
1513 |
$doc .= "<allow>\n"; |
|
1514 |
$doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n"; |
|
1515 |
$doc .= "<permission>read</permission>\n"; |
|
1516 |
$doc .= "<permission>write</permission>\n"; |
|
1517 |
$doc .= "</allow>\n"; |
|
1541 |
|
|
1542 |
if($FORM::username ne ''){ |
|
1543 |
$doc .= "<allow>\n"; |
|
1544 |
$doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n"; |
|
1545 |
$doc .= "<permission>read</permission>\n"; |
|
1546 |
$doc .= "<permission>write</permission>\n"; |
|
1547 |
$doc .= "</allow>\n"; |
|
1548 |
} else { |
|
1549 |
my $session = CGI::Session->load(); |
|
1550 |
if ( !$session->is_empty ) { |
|
1551 |
my $username = $session->param("username"); |
|
1552 |
$doc .= "<allow>\n"; |
|
1553 |
$doc .= "<principal>$username</principal>\n"; |
|
1554 |
$doc .= "<permission>read</permission>\n"; |
|
1555 |
$doc .= "<permission>write</permission>\n"; |
|
1556 |
$doc .= "</allow>\n"; |
|
1557 |
} |
|
1558 |
} |
|
1518 | 1559 |
} |
1519 | 1560 |
|
1520 | 1561 |
if($publicReadable eq "true"){ |
... | ... | |
1556 | 1597 |
#die "failed during metacat creation\n"; |
1557 | 1598 |
push(@errorMessages, "Failed during metacat creation."); |
1558 | 1599 |
} |
1559 |
|
|
1600 |
|
|
1601 |
my $session = CGI::Session->load(); |
|
1602 |
if ( !$session->is_empty ) { |
|
1603 |
my $username = $session->param("username"); |
|
1604 |
my $password = $session->param("password"); |
|
1605 |
$metacat->login($username, $password); |
|
1606 |
} |
|
1607 |
|
|
1608 |
|
|
1560 | 1609 |
$httpMessage = $metacat->read($docid); |
1561 | 1610 |
$doc = $httpMessage->content(); |
1562 | 1611 |
$xmldoc = $parser->parse_string($doc); |
... | ... | |
2296 | 2345 |
|
2297 | 2346 |
if ($principal eq 'public' && $permission ne 'read') { $accessError = 1; } |
2298 | 2347 |
if ($principal eq $username && $permission ne 'all') { $accessError = 2; } |
2299 |
if ($principal ne 'public' && $principal ne $username && $permission ne 'all') { $accessError = 3; } |
|
2348 |
if ($principal ne 'public' && $principal ne $username && $principal ne $moderators && $permission ne 'all') { $accessError = 3; } |
|
2349 |
if ($accessError == 3){ |
|
2350 |
my $session = CGI::Session->load(); |
|
2351 |
if ( !$session->is_empty ) { |
|
2352 |
my $username = $session->param("username"); |
|
2353 |
my $password = $session->param("password"); |
|
2354 |
if($principal eq $username){ |
|
2355 |
$accessError = 0; |
|
2356 |
} |
|
2357 |
} |
|
2358 |
} |
|
2300 | 2359 |
} |
2301 | 2360 |
|
2302 | 2361 |
if ($accessError != 0) { |
... | ... | |
2318 | 2377 |
dontOccur($doc, "//citation", "citation"); |
2319 | 2378 |
dontOccur($doc, "//software", "software"); |
2320 | 2379 |
dontOccur($doc, "//protocol", "protocol"); |
2321 |
dontOccur($doc, "//additionalMetadata", "additionalMetadata"); |
|
2380 |
$results = $doc->findnodes( |
|
2381 |
'//additionalMetadata/moderatorComment'); |
|
2382 |
if($results->size == 0){ |
|
2383 |
dontOccur($doc, "//additionalMetadata", "additionalMetadata"); |
|
2384 |
} |
|
2322 | 2385 |
} |
2323 | 2386 |
|
2324 | 2387 |
################################################################################ |
... | ... | |
2587 | 2650 |
return $returnValue; |
2588 | 2651 |
} |
2589 | 2652 |
|
2653 |
sub handleRead { |
|
2654 |
my $docid = $FORM::docid; |
|
2655 |
my $errorMessage; |
|
2656 |
|
|
2657 |
print "Content-type: text/html\n\n"; |
|
2658 |
|
|
2659 |
# Check if the session exists |
|
2660 |
my $session = CGI::Session->load(); |
|
2661 |
if ( $session->is_empty || $session->is_expired) { |
|
2662 |
# no session found ... send back the regular read page ... |
|
2663 |
my $url = "@systemidserver@@style-skins-path@/".$FORM::cfg."/index.html"; |
|
2664 |
redirect($url); |
|
2665 |
} else { |
|
2666 |
my $htmldoc = ""; |
|
2667 |
$htmldoc .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">"; |
|
2668 |
$htmldoc .= "<html><head><title>Dataset Description: ".$docid."</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>"; |
|
2669 |
$htmldoc .= "<frameset rows=\"150,*\" cols=\"*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">"; |
|
2670 |
$htmldoc .= "<frame src=\"@systemidserver@@style-skins-path@/".$FORM::cfg."/header.html\" marginwidth=\"40\" name=\"topFrame\" scrolling=\"NO\" noresize>"; |
|
2671 |
$htmldoc .= "<frameset cols=\"200,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">"; |
|
2672 |
$htmldoc .= "<body></body><frame src=\"@cgi-prefix@/register-dataset.cgi?cfg=".$FORM::cfg."&stage=review_frame&docid=".$docid."\" name=\"rightFrame\" scrolling=\"NO\" noresize></frame>"; |
|
2673 |
$htmldoc .= "<frame src=\"@systemidserver@@servlet-path@?action=read&qformat=".$FORM::cfg."&docid=".$docid."&insertTemplate=0\" name=\"mainFrame\">"; |
|
2674 |
$htmldoc .= "</frameset></frameset></html>"; |
|
2675 |
|
|
2676 |
print $htmldoc; |
|
2677 |
} |
|
2678 |
} |
|
2679 |
|
|
2680 |
sub handleReviewFrame { |
|
2681 |
print "Content-type: text/html\n\n"; |
|
2682 |
my $session = CGI::Session->load(); |
|
2683 |
if ( $session->is_empty || $session->is_expired) { |
|
2684 |
return; |
|
2685 |
} |
|
2686 |
|
|
2687 |
my $moderator = $session->param("moderator"); |
|
2688 |
if ( $moderator ne 'true') { |
|
2689 |
my $reviewHistory = getReviewHistoryHTML($session->param("username"), $session->param("password")); |
|
2690 |
if($reviewHistory eq ''){ |
|
2691 |
print "<br><br><br>No comments found"; |
|
2692 |
} else { |
|
2693 |
print $reviewHistory; |
|
2694 |
} |
|
2695 |
return; |
|
2696 |
} |
|
2697 |
|
|
2698 |
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"; |
|
2699 |
print "<html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"; |
|
2700 |
print "<link href=\"/style/skins/esa/esa.css\" type=\"text/css\" rel=\"stylesheet\"></head><body>"; |
|
2701 |
print getReviewHistoryHTML($session->param("username"), $session->param("password")); |
|
2702 |
print "<br><br><center><p class=\"sectionnames\">Moderator Actions</p>"; |
|
2703 |
print "<form target=\"_top\" id=\"reviewForm\" method=\"POST\" action=\"@cgi-prefix@/register-dataset.cgi\">"; |
|
2704 |
print "<input value=\"mod_accept\" name=\"stage\" type=\"hidden\">"; |
|
2705 |
print "<input value=\"esa\" name=\"cfg\" type=\"hidden\">"; |
|
2706 |
print "<input name=\"docid\" type=\"hidden\" value=\"".$FORM::docid."\">"; |
|
2707 |
print "<p>Comments:<br><textarea name=\"review\" rows=\"10\"></textarea></p>"; |
|
2708 |
print "<br><br><input name=\"Accept\" value=\" Accept \" type=\"SUBMIT\" onClick=\"this.parentNode.stage.value='mod_accept';\">"; |
|
2709 |
print "<br><br><input name=\"Decline\" value=\"Decline\" type=\"SUBMIT\" onClick=\"this.parentNode.stage.value='mod_decline';\">"; |
|
2710 |
print "<br><br><input name=\"Revise\" value=\" Revise \" type=\"SUBMIT\" onClick=\"this.parentNode.stage.value='mod_revise';\">"; |
|
2711 |
print "</form></center></body></html>"; |
|
2712 |
} |
|
2713 |
|
|
2714 |
sub getReviewHistoryHTML { |
|
2715 |
my $username = shift; |
|
2716 |
my $password = shift; |
|
2717 |
|
|
2718 |
my $metacat; |
|
2719 |
$metacat = Metacat->new(); |
|
2720 |
if ($metacat) { |
|
2721 |
$metacat->set_options( metacatUrl => $metacatUrl ); |
|
2722 |
} |
|
2723 |
$metacat->login($username, $password); |
|
2724 |
my $parser = XML::LibXML->new(); |
|
2725 |
my $docid = $FORM::docid; |
|
2726 |
my ($x, $y, $z) = split(/\./, $docid); |
|
2727 |
my $docidWithoutRev = $x.".".$y; |
|
2728 |
my $reviewDocumentId = ''; |
|
2729 |
my $response = $metacat->squery("<pathquery><querytitle>Moderator-Search</querytitle><querygroup operator='INTERSECT'><queryterm searchmode='contains' casesensitive='false'><value>$docidWithoutRev</value><pathexpr>/reviewHistory/review/packageId</pathexpr></queryterm></querygroup></pathquery>"); |
|
2730 |
my $doc = $response->content(); |
|
2731 |
my $xmldoc = $parser->parse_string($doc); |
|
2732 |
my $reviewHTML = ''; |
|
2733 |
|
|
2734 |
if ($xmldoc eq "" || $doc=~ /<error/) { |
|
2735 |
# not able to parse |
|
2736 |
return " Unable to search for review for the docid:".$docid; |
|
2737 |
} else { |
|
2738 |
my $findNodes = $xmldoc->findnodes('//resultset/document'); |
|
2739 |
if($findNodes->size() > 0){ |
|
2740 |
# found contact email address |
|
2741 |
my $node = ''; |
|
2742 |
foreach $node ($findNodes->get_nodelist) { |
|
2743 |
$reviewDocumentId = findValue($node,'docid'); |
|
2744 |
} |
|
2745 |
|
|
2746 |
#update the old document |
|
2747 |
$response = $metacat->read($reviewDocumentId); |
|
2748 |
$doc = $response->content(); |
|
2749 |
$xmldoc = $parser->parse_string($doc); |
|
2750 |
|
|
2751 |
if ($xmldoc eq "" || $doc=~ /<error/){ |
|
2752 |
return " Unable to read the document from Metacat which has old reviews for the docid:".$docid; |
|
2753 |
} else { |
|
2754 |
my $findNodes = $xmldoc->findnodes('//reviewHistory/review'); |
|
2755 |
if($findNodes->size() > 0){ |
|
2756 |
# found contact email address |
|
2757 |
my $node = ''; |
|
2758 |
my $text = ''; |
|
2759 |
my $datetime = ''; |
|
2760 |
foreach $node ($findNodes->get_nodelist) { |
|
2761 |
$text = findValue($node,'text'); |
|
2762 |
$datetime = findValue($node,'datetime'); |
|
2763 |
|
|
2764 |
$reviewHTML .= "<tr><td>".$datetime."</td><td>".$text."</td></tr>"; |
|
2765 |
} |
|
2766 |
|
|
2767 |
$reviewHTML = "<table width=\"90%\" border=\"0\"> <tr><td>Time</td><td>Review</td></tr>".$reviewHTML."</table>"; |
|
2768 |
} |
|
2769 |
} |
|
2770 |
} |
|
2771 |
} |
|
2772 |
if ($reviewHTML ne ''){ |
|
2773 |
$reviewHTML = "<center>".$reviewHTML."</center>"; |
|
2774 |
} |
|
2775 |
|
|
2776 |
return $reviewHTML; |
|
2777 |
} |
|
2778 |
|
|
2590 | 2779 |
################################################################################ |
2591 | 2780 |
# |
2592 | 2781 |
# function to handle accept request for moderator |
... | ... | |
2639 | 2828 |
my $title = ''; |
2640 | 2829 |
my $contactEmailAddress = ''; |
2641 | 2830 |
my $contactName = ''; |
2831 |
my $userDN = ''; |
|
2642 | 2832 |
# Log into metacat |
2643 | 2833 |
my $response = $metacat->login($modUsername, $modPassword); |
2644 | 2834 |
|
... | ... | |
2671 | 2861 |
|
2672 | 2862 |
($x, $y, $z) = split(/\./, $docid); |
2673 | 2863 |
$z++; |
2674 |
$docid = "$x.$y.$z";
|
|
2864 |
my $newDocid = "$x.$y.$z";
|
|
2675 | 2865 |
|
2676 |
$emldoc =~ s/packageId=\"docid\"/packageId=\"$docid\"/;
|
|
2677 |
$response = $metacat->update($docid, $emldoc);
|
|
2866 |
$emldoc =~ s/packageId=\"$docid\"/packageId=\"$newDocid\"/;
|
|
2867 |
$response = $metacat->update($newDocid, $emldoc);
|
|
2678 | 2868 |
|
2679 | 2869 |
if (! $response) { |
2680 | 2870 |
debug("Error while updating in handleModAccept."); |
... | ... | |
2718 | 2908 |
} else { |
2719 | 2909 |
$title = ''; |
2720 | 2910 |
} |
2911 |
|
|
2912 |
$findNodes = $xmldoc->findnodes('//dataset/access/allow'); |
|
2913 |
if($findNodes->size() > 0){ |
|
2914 |
# found title |
|
2915 |
my $node = ''; |
|
2916 |
foreach $node ($findNodes->get_nodelist) { |
|
2917 |
my $perm = findValue($node,'permission'); |
|
2918 |
if($perm ne 'all'){ |
|
2919 |
$userDN = findValue($node,'principal'); |
|
2920 |
} |
|
2921 |
} |
|
2922 |
} else { |
|
2923 |
$userDN = ''; |
|
2924 |
} |
|
2925 |
|
|
2721 | 2926 |
} |
2722 | 2927 |
} |
2723 | 2928 |
} |
2724 | 2929 |
# send notification to the user and the moderator |
2725 | 2930 |
if ($errorMessage eq '') { |
2931 |
mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Accepted'); |
|
2932 |
if($FORM::review ne ''){ |
|
2933 |
$errorMessage = mod_storeReview('accept', $metacat, $userDN); |
|
2934 |
if ($errorMessage ne '') { |
|
2935 |
processResultTemplate('accept', 'failure', $errorMessage); |
|
2936 |
return; |
|
2937 |
} |
|
2938 |
} |
|
2726 | 2939 |
# send notifications |
2727 |
mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Accepted'); |
|
2728 | 2940 |
processResultTemplate('accept', 'success', $errorMessage); |
2729 | 2941 |
} else { |
2730 | 2942 |
processResultTemplate('accept', 'failure', $errorMessage); |
... | ... | |
2739 | 2951 |
sub handleModDecline(){ |
2740 | 2952 |
|
2741 | 2953 |
my $errorMessage = ''; |
2954 |
my $userDN = ''; |
|
2742 | 2955 |
my $metacat; |
2743 | 2956 |
$metacat = Metacat->new(); |
2744 | 2957 |
if ($metacat) { |
... | ... | |
2778 | 2991 |
my $xmldoc = $parser->parse_string($doc); |
2779 | 2992 |
|
2780 | 2993 |
if ($xmldoc eq "" || $doc=~ /<error/) { |
2781 |
# not able to parse
|
|
2994 |
# not able to parse
|
|
2782 | 2995 |
$errorMessage = $errorMessage." Error in reading the docid:".$docid; |
2783 | 2996 |
} else { |
2784 | 2997 |
my $findNodes = $xmldoc->findnodes('//dataset/contact'); |
... | ... | |
2810 | 3023 |
} else { |
2811 | 3024 |
$title = ''; |
2812 | 3025 |
} |
3026 |
|
|
3027 |
$findNodes = $xmldoc->findnodes('//dataset/access/allow'); |
|
3028 |
if($findNodes->size() > 0){ |
|
3029 |
# found title |
|
3030 |
my $node = ''; |
|
3031 |
foreach $node ($findNodes->get_nodelist) { |
|
3032 |
my $perm = findValue($node,'permission'); |
|
3033 |
if($perm ne 'all'){ |
|
3034 |
$userDN = findValue($node,'principal'); |
|
3035 |
} |
|
3036 |
} |
|
3037 |
} else { |
|
3038 |
$userDN = ''; |
|
3039 |
} |
|
2813 | 3040 |
} |
2814 | 3041 |
|
2815 | 3042 |
$response = $metacat->delete($docid); |
... | ... | |
2823 | 3050 |
} |
2824 | 3051 |
|
2825 | 3052 |
if ($errorMessage eq '') { |
2826 |
# send notifications |
|
2827 | 3053 |
mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Rejected'); |
3054 |
if($FORM::review ne ''){ |
|
3055 |
$errorMessage = mod_storeReview('decline', $metacat, $userDN); |
|
3056 |
if ($errorMessage ne '') { |
|
3057 |
processResultTemplate('decline', 'failure', $errorMessage); |
|
3058 |
return; |
|
3059 |
} |
|
3060 |
} |
|
3061 |
# send notifications |
|
2828 | 3062 |
processResultTemplate('decline', 'success', $errorMessage); |
2829 | 3063 |
} else { |
2830 | 3064 |
processResultTemplate('decline', 'failure', $errorMessage); |
... | ... | |
2859 | 3093 |
my $contactEmailAddress; |
2860 | 3094 |
my $contactName; |
2861 | 3095 |
my $title; |
2862 |
|
|
3096 |
my $userDN = ''; |
|
3097 |
|
|
2863 | 3098 |
# Log into metacat |
2864 | 3099 |
my $response = $metacat->login($modUsername, $modPassword); |
2865 | 3100 |
|
... | ... | |
2901 | 3136 |
} else { |
2902 | 3137 |
$contactEmailAddress = ''; |
2903 | 3138 |
} |
2904 |
$findNodes = $xmldoc->findnodes('//dataset/title'); |
|
3139 |
|
|
3140 |
$findNodes = $xmldoc->findnodes('//dataset/title'); |
|
2905 | 3141 |
if($findNodes->size() > 0){ |
2906 | 3142 |
# found title |
2907 | 3143 |
my $node = ''; |
... | ... | |
2912 | 3148 |
$title = ''; |
2913 | 3149 |
} |
2914 | 3150 |
|
3151 |
$findNodes = $xmldoc->findnodes('//dataset/access/allow'); |
|
3152 |
if($findNodes->size() > 0){ |
|
3153 |
# found title |
|
3154 |
my $node = ''; |
|
3155 |
foreach $node ($findNodes->get_nodelist) { |
|
3156 |
my $perm = findValue($node,'permission'); |
|
3157 |
if($perm ne 'all'){ |
|
3158 |
$userDN = findValue($node,'principal'); |
|
3159 |
} |
|
3160 |
} |
|
3161 |
} else { |
|
3162 |
$userDN = ''; |
|
3163 |
} |
|
3164 |
|
|
2915 | 3165 |
} |
2916 | 3166 |
|
2917 | 3167 |
my ($emldoc, $temp) = split('</dataset>', $doc); |
2918 | 3168 |
$emldoc .= "</dataset>\n<additionalMetadata>\n<moderatorComment>Revision Requested</moderatorComment>\n</additionalMetadata>"; |
2919 | 3169 |
$emldoc .= "\n</eml:eml>\n"; |
2920 |
debug($emldoc); |
|
2921 | 3170 |
#debug("Document created by handleModAccept is " . $emldoc); |
2922 | 3171 |
# update the document |
2923 | 3172 |
my $docid = $FORM::docid; |
... | ... | |
2928 | 3177 |
|
2929 | 3178 |
($x, $y, $z) = split(/\./, $docid); |
2930 | 3179 |
$z++; |
2931 |
$docid = "$x.$y.$z";
|
|
3180 |
my $newDocid = "$x.$y.$z";
|
|
2932 | 3181 |
|
2933 |
$emldoc =~ s/packageId=\"docid\"/packageId=\"$docid\"/;
|
|
2934 |
$response = $metacat->update($docid, $emldoc);
|
|
3182 |
$emldoc =~ s/packageId=\"$docid\"/packageId=\"$newDocid\"/;
|
|
3183 |
$response = $metacat->update($newDocid, $emldoc);
|
|
2935 | 3184 |
|
2936 | 3185 |
if (! $response) { |
2937 | 3186 |
debug("Error while updating in handleModAccept.".$metacat->getMessage()); |
... | ... | |
2941 | 3190 |
|
2942 | 3191 |
} |
2943 | 3192 |
if ($errorMessage eq '') { |
3193 |
mod_sendNotification($title, $contactEmailAddress, $contactName, "Revise document: ".$FORM::docid); |
|
3194 |
if($FORM::review ne ''){ |
|
3195 |
$errorMessage = mod_storeReview('revise', $metacat, $userDN); |
|
3196 |
if ($errorMessage ne '') { |
|
3197 |
processResultTemplate('revise', 'failure', $errorMessage); |
|
3198 |
return; |
|
3199 |
} |
|
3200 |
} |
|
2944 | 3201 |
# send notifications |
2945 |
mod_sendNotification($title, $contactEmailAddress, $contactName, "Revise document: ".$FORM::docid); |
|
2946 | 3202 |
processResultTemplate('revise', 'success', $errorMessage); |
2947 | 3203 |
} else { |
2948 | 3204 |
processResultTemplate('revise', 'failure', $errorMessage); |
2949 | 3205 |
} |
2950 | 3206 |
} |
2951 | 3207 |
|
3208 |
sub mod_storeReview { |
|
3209 |
my $action = shift; |
|
3210 |
my $metacat = shift; |
|
3211 |
my $userDN = shift; |
|
2952 | 3212 |
|
3213 |
my $gmt = gmtime($now); |
|
3214 |
my $parser = XML::LibXML->new(); |
|
3215 |
|
|
3216 |
# create the xml part that has to be inserted |
|
3217 |
my $review = ''; |
|
3218 |
$review .= '<review>'; |
|
3219 |
$review .= '<packageId>'.$FORM::docid.'</packageId>'; |
|
3220 |
$review .= '<action>'.$action.'</action>'; |
|
3221 |
$review .= '<datetime>'.$gmt.'</datetime>'; |
|
3222 |
$review .= '<text>'.$FORM::review.'</text>'; |
|
3223 |
$review .= '</review>'; |
|
2953 | 3224 |
|
3225 |
# find out if a docid already exists... |
|
3226 |
my $docid = $FORM::docid; |
|
3227 |
my ($x, $y, $z) = split(/\./, $docid); |
|
3228 |
my $docidWithoutRev = $x.$y; |
|
3229 |
my $reviewDocumentId = ''; |
|
3230 |
my $response = $metacat->squery("<pathquery><querytitle>Moderator-Search</querytitle><querygroup operator='INTERSECT'><queryterm searchmode='contains' casesensitive='false'><value>".$x.".".$y."</value><pathexpr>/reviewHistory/review/packageId</pathexpr></queryterm></querygroup></pathquery>"); |
|
3231 |
|
|
3232 |
my $doc = $response->content(); |
|
3233 |
my $xmldoc = $parser->parse_string($doc); |
|
3234 |
|
|
3235 |
if ($xmldoc eq "" || $doc=~ /<error/) { |
|
3236 |
# not able to parse |
|
3237 |
return " Unable to store review for the docid:".$docid; |
|
3238 |
} else { |
|
3239 |
my $findNodes = $xmldoc->findnodes('//resultset/document'); |
|
3240 |
if($findNodes->size() > 0){ |
|
3241 |
# found contact email address |
|
3242 |
my $node = ''; |
|
3243 |
foreach $node ($findNodes->get_nodelist) { |
|
3244 |
$reviewDocumentId = findValue($node,'docid'); |
|
3245 |
} |
|
3246 |
|
|
3247 |
#update the old document |
|
3248 |
$response = $metacat->read($reviewDocumentId); |
|
3249 |
$doc = $response->content(); |
|
3250 |
$xmldoc = $parser->parse_string($doc); |
|
3251 |
|
|
3252 |
|
|
3253 |
if ($xmldoc eq "" || $doc=~ /<error/){ |
|
3254 |
return " Unable to read the document from Metacat which has the old reviews for the docid:".$docid; |
|
3255 |
} else { |
|
3256 |
my ($reviewdoc, $temp) = split('</reviewHistory>', $doc); |
|
3257 |
$reviewdoc .= $review."\n</reviewHistory>\n"; |
|
3258 |
($x, $y, $z) = split(/\./, $reviewDocumentId); |
|
3259 |
$z++; |
|
3260 |
$reviewDocumentId = "$x.$y.$z"; |
|
3261 |
$response = $metacat->update($reviewDocumentId, $reviewdoc); |
|
3262 |
if ($response != '1') { |
|
3263 |
return " Unable to update the review on Metacat for the docid:".$docid; |
|
3264 |
} else { |
|
3265 |
$response = $metacat->setaccess($reviewDocumentId, $userDN, "read", "allow", "denyFirst"); |
|
3266 |
if ($response != '1') { |
|
3267 |
return " Unable to set access for the review document in Metacat for the docid:".$docid; |
|
3268 |
} |
|
3269 |
} |
|
3270 |
} |
|
3271 |
} else { |
|
3272 |
#insert a new document |
|
3273 |
my $id = $metacat->getLastId('esa_reviews'); |
|
3274 |
if ($id eq "null"){ |
|
3275 |
$id = 'esa_reviews.1.1'; |
|
3276 |
} else { |
|
3277 |
($x, $y, $z) = split(/\./, $id); |
|
3278 |
$y++; |
|
3279 |
$id = "$x.$y.1"; |
|
3280 |
} |
|
3281 |
|
|
3282 |
my $reviewDoc = ''; |
|
3283 |
$reviewDoc .= "<?xml version=\"1.0\"?>"; |
|
3284 |
$reviewDoc .= "<reviewHistory registryName=\"".$FORM::cfg."\">"; |
|
3285 |
$reviewDoc .= $review; |
|
3286 |
$reviewDoc .= "</reviewHistory>"; |
|
3287 |
$response = $metacat->insert($id, $reviewDoc); |
|
3288 |
if ($response != '1') { |
|
3289 |
return " Unable to insert the review on Metacat for the docid:".$docid; |
|
3290 |
} else { |
|
3291 |
# set access |
|
3292 |
$response = $metacat->setaccess($id, $userDN, "read", "allow", "denyFirst"); |
|
3293 |
if ($response != '1') { |
|
3294 |
return " Unable to set access for the review document in Metacat for the docid:".$docid; |
|
3295 |
} |
|
3296 |
} |
|
3297 |
} |
|
3298 |
} |
|
3299 |
|
|
3300 |
return ''; |
|
3301 |
# find out if a document already exist. if not then insert a new one. otherwise update the old one |
|
3302 |
# the owner of the document is the moderator |
|
3303 |
} |
|
3304 |
|
|
2954 | 3305 |
################################################################################ |
2955 | 3306 |
# |
2956 | 3307 |
# send an email message to the moderator and the contact |
... | ... | |
2968 | 3319 |
$$templateVars{'recipient'} = $recipient; |
2969 | 3320 |
$$templateVars{'sender'} = $sender; |
2970 | 3321 |
$$templateVars{'docid'} = $FORM::docid; |
2971 |
$$templateVars{'comment'} = $FORM::comment;
|
|
3322 |
$$templateVars{'comment'} = $FORM::review;
|
|
2972 | 3323 |
$$templateVars{'contactName'} = $contactName; |
2973 | 3324 |
$$templateVars{'dpTitle'} = $title; |
2974 | 3325 |
|
... | ... | |
3057 | 3408 |
|
3058 | 3409 |
my $invalidParams; |
3059 | 3410 |
if (! $error) { |
3060 |
$invalidParams = validateParameters(0); |
|
3061 |
if (scalar(@$invalidParams)) { |
|
3062 |
$$templateVars{'status'} = 'failure'; |
|
3063 |
$$templateVars{'invalidParams'} = $invalidParams; |
|
3064 |
$error = 1; |
|
3411 |
$invalidParams = validateParameters(0); |
|
3412 |
if (scalar(@$invalidParams)) { |
|
3413 |
$$templateVars{'status'} = 'failure'; |
|
3414 |
$$templateVars{'invalidParams'} = $invalidParams; |
|
3415 |
$error = 1; |
|
3416 |
} |
|
3065 | 3417 |
} |
3066 |
} |
|
3067 | 3418 |
|
3068 | 3419 |
|
3069 | 3420 |
$$templateVars{'providerGivenName'} = normalizeCD($FORM::providerGivenName); |
... | ... | |
3250 | 3601 |
|
3251 | 3602 |
$$templateVars{'docid'} = $FORM::docid; |
3252 | 3603 |
|
3604 |
# Check if the session exists |
|
3605 |
my $session = CGI::Session->load(); |
|
3606 |
if ( !($session->is_empty || $session->is_expired)) { |
|
3607 |
$$templateVars{'userLoggedIn'} = 'true'; |
|
3608 |
} |
|
3609 |
|
|
3610 |
|
|
3253 | 3611 |
if (! $error) { |
3254 | 3612 |
# If no errors, then print out data in confirm Data template |
3255 | 3613 |
|
Also available in: Unified diff
bugfixes in previous code and added functionality to store reviews on various documents...