r4625 - trunk/src/perl
walbridge at ecoinformatics.org
walbridge at ecoinformatics.org
Mon Nov 24 15:03:46 PST 2008
Author: walbridge
Date: 2008-11-24 15:03:46 -0800 (Mon, 24 Nov 2008)
New Revision: 4625
Modified:
trunk/src/perl/register-dataset.cgi
Log:
Number of ESA-related fixes:
- fix review panel to reference valid URL using cgiPrefix
- update ESA document creation to use XSLT methods instead of split()
- add code for ESA access rules fix (to be used in 1.9.1)
- use moderators in metacat.properties (postpone skin-based configuration till 1.9.1)
- use cgiDir instead of cgiUrl
Modified: trunk/src/perl/register-dataset.cgi
===================================================================
--- trunk/src/perl/register-dataset.cgi 2008-11-24 22:10:14 UTC (rev 4624)
+++ trunk/src/perl/register-dataset.cgi 2008-11-24 23:03:46 UTC (rev 4625)
@@ -44,10 +44,10 @@
use strict;
# Global configuration paramters
-my $cgiUrl = $ENV{'SCRIPT_FILENAME'};
+my $cgiDir = $ENV{'SCRIPT_FILENAME'};
my $workingDirectory = ".";
-if ($cgiUrl ne "") {
- my $workingDirectory = dirname($cgiUrl);
+if ($cgiDir ne "") {
+ my $workingDirectory = dirname($cgiDir);
}
my $metacatProps = "${workingDirectory}/../WEB-INF/metacat.properties";
my $properties = new Config::Properties();
@@ -122,7 +122,7 @@
}
# replacements for appconfig values using properties
-my $moderators = $properties->getProperty('ldap.moderators');
+my $moderators = $properties->getProperty('moderators');
my $config = $skinProperties->splitToTree(qr/\./, 'registry.config');
my $templates = $skinProperties->splitToTree(qr/\./, 'registry.templates');
my $modules = $skinProperties->splitToTree(qr/\./, 'registry.modules');
@@ -439,7 +439,7 @@
$docid = incrementRevision($FORM::docid);
$xmldoc =~ s/docid/$docid/;
- debugDoc($xmldoc);$
+ debugDoc($xmldoc);
my $response = $metacat->update($docid, $xmldoc);
@@ -1844,12 +1844,9 @@
my $transform = "$styleCommonPath/conversions/eml201to210.xsl";
$stylesheet = $xslt->parse_stylesheet_file($transform);
- $results = $stylesheet->transform($doc);
- #my $out = "$emldir/test-210.xml";
- #open (TFILE,">$out") || die("Can't open xml file...\n");
- #print TFILE $stylesheet->output_string($results);
- #close(TFILE);
- #print "Output $out.\n";
+ $results = $stylesheet->transform($xmldoc);
+ # if debugging is enabled, dump the transformed document to disk
+ debugDoc($stylesheet->output_string($results));
return $results;
}
@@ -2469,9 +2466,9 @@
$results = $doc->findnodes('//access/allow');
my $accessError = 0;
+
foreach $node ($results->get_nodelist) {
my @children = $node->childNodes;
- my $principal = "";
my $permission = "";
for (my $i = 0; $i < scalar(@children); $i++) {
my $child = $children[$i];
@@ -2484,7 +2481,22 @@
if ($principal eq 'public' && $permission ne 'read') { $accessError = 1; }
if ($principal eq $username && $permission ne 'all') { $accessError = 2; }
- if ($principal ne 'public' && $principal ne $username && $principal ne $moderators && $permission ne 'all') { $accessError = 3; }
+ if ($principal ne 'public' && $principal ne $username && $permission ne 'all') { $accessError = 3; }
+ # TODO: FIXME for 1.9.1
+ # The ESA skin has a separate concept of 'moderator', which is defined by a property
+ # within the configuration. This should be updated to check the user against the groups.
+ # my $isSkinModerator = 0;
+ # my $userGroups = metacat->getGroups($username');
+ #foreach my $mod (split(":", $moderators) {
+ # foreach $my $ug (split(":", $userGroups)) {
+ # if ($ug == $mod) {
+ # $isSkinModerator = 1;
+ # }
+ # }
+ #}
+ # if (!$isSkinModerator) {
+ # $accessError = 3;
+ # }
if ($accessError == 3) {
my $session = CGI::Session->load();
if (!$session->is_empty) {
@@ -2498,7 +2510,7 @@
}
if ($accessError != 0) {
- my $error ="The ACL for this document has been changed outside the registry. Please use Morpho to edit this document";
+ my $error = "The ACL for this document has been changed outside the registry. Please use Morpho to edit this document (Access Error #$accessError).";
push(@errorMessages, $error."\n");
}
@@ -2567,8 +2579,7 @@
my $pushDoc;
my $alreadyInArray;
my $findType;
- my $node;
- my $response;
+ my $node;
my $element;
push (@fileArray, $docid);
@@ -2815,7 +2826,7 @@
<frameset rows="150,*" cols="*" frameborder="NO" border="0" framespacing="0">
<frame src="$skinsDir/$skinName/header.jsp" marginwidth="40" name="topFrame" scrolling="NO" noresize>
<frameset cols="200,*" frameborder="NO" border="0" framespacing="0">
- <body></body><frame src="$cgiUrl?cfg=$skinName&stage=review_frame&docid="$docid"" name="rightFrame" scrolling="NO" noresize></frame>
+ <body></body><frame src="$cgiPrefix/register-dataset.cgi?cfg=$skinName&stage=review_frame&docid="$docid"" name="rightFrame" scrolling="NO" noresize></frame>
<frame src="$metacatUrl?action=read&qformat=$skinName&docid=$docid&insertTemplate=0" name="mainFrame">
</frameset>
</frameset>
@@ -2912,6 +2923,7 @@
my $docFromMetacat = $response->content();
my $xmldoc = $parser->parse_string($docFromMetacat);
my $dataElem = '';
+ my $results;
if ($xmldoc eq "" || $docFromMetacat=~ /<error/) {
# not able to parse
@@ -3221,10 +3233,33 @@
$userDN = '';
}
}
- # SCW TODO FIX THIS
- my ($emldoc, $temp) = split('</dataset>', $doc);
- $emldoc .= "</dataset>\n<additionalMetadata>\n<moderatorComment>Revision Requested</moderatorComment>\n</additionalMetadata>";
- $emldoc .= "\n</eml:eml>\n";
+
+ my $emldoc = '';
+ my $dataElem = '';
+ my $accessElem = '';
+
+ # pull out existing dataset entry
+ my $results = $doc->findnodes('//dataset');
+ foreach my $r ($results->get_nodelist) {
+ $dataElem .= $r->toString();
+ }
+ # also grab the access element
+ $results = $doc->findnodes('//access');
+ foreach my $r ($results->get_nodelist) {
+ $accessElem .= $r->toString();
+ }
+
+ my $addlMetadata = qq|
+ <additionalMetadata>
+ <moderatorComment>Revision Requested</moderatorComment>
+ </additionalMetadata>|;
+
+ $emldoc .= EMLStart();
+ $emldoc .= $accessElem;
+ $emldoc .= $dataElem;
+ $emldoc .= $addlMetadata;
+ $emldoc .= EMLEnd();
+
#debug("Document created by handleModAccept is " . $emldoc);
# update the document
my $newDocid = incrementRevision($docid);
@@ -3258,21 +3293,21 @@
my $action = shift;
my $metacat = shift;
my $userDN = shift;
-
+
my $gmt = gmtime($now);
+ my $docid = $FORM::docid;
my $parser = XML::LibXML->new();
# create the xml part that has to be inserted
- my $review = '';
- $review .= '<review>';
- $review .= '<packageId>'.$FORM::docid.'</packageId>';
- $review .= '<action>'.$action.'</action>';
- $review .= '<datetime>'.$gmt.'</datetime>';
- $review .= '<text>'.$FORM::review.'</text>';
- $review .= '</review>';
+ my $review = qq|
+ <review>
+ <packageId>$docid</packageId>
+ <action>$action</action>
+ <datetime>$gmt</datetime>
+ <text>$FORM::review</text>
+ </review>|;
# find out if a docid already exists...
- my $docid = $FORM::docid;
my ($x, $y, $z) = split(/\./, $docid);
my $docidWithoutRev = $x.$y;
my $reviewDocumentId = '';
More information about the Metacat-cvs
mailing list