Project

General

Profile

« Previous | Next » 

Revision 4758

Added by walbridge almost 16 years ago

A slew of fixes in the process of fixing bug #3679:
- omit port number from the contextUrl if running on 80, looks bad in exposed URLs
- explicitly pass the metacat object to newAccessionNumber, the global definition of the object had introduced a difficult to track bug
- fix a few variable name esacaping issues
- provide review-related error messages back to the user on the ESA skin (also see related checkin in r4756)
- more EML 2.1 fixes to ESA-specific EML documents

View differences:

src/perl/register-dataset.cgi
67 67

  
68 68
# url configuration
69 69
my $server = $properties->splitToTree(qr/\./, 'server');
70
my $contextUrl = 'http://' . $properties->getProperty('server.name') . ':' . 
71
                 $properties->getProperty('server.httpPort') . '/' . 
72
                 $properties->getProperty('application.context');
70
my $contextUrl = 'http://' . $properties->getProperty('server.name');
71
if ($properties->getProperty('server.httpPort') ne '80') {
72
    $contextUrl = $contextUrl . ':' . $properties->getProperty('server.httpPort');
73
}
74
$contextUrl = $contextUrl . '/' .  $properties->getProperty('application.context');
73 75

  
74 76
my $metacatUrl = $contextUrl . "/metacat";
75 77
my $cgiPrefix = "/" . $properties->getProperty('application.context') . "/cgi-bin";
......
428 430
            # document is being inserted 
429 431
            my $docStatus = "INCOMPLETE";
430 432
            while ($docStatus eq "INCOMPLETE") {
431
                $docid = newAccessionNumber($config->{'scope'});
433
                $docid = newAccessionNumber($config->{'scope'}, $metacat);
432 434

  
433 435
                $xmldocWithDocID =~ s/docid/$docid/;
434 436
                debugDoc($xmldocWithDocID);
......
554 556
################################################################################
555 557
sub newAccessionNumber {
556 558
    my $scope = shift;
559
    my $metacat = shift;
557 560
    my $errormsg = 0;
558 561

  
559 562
    my $docid = $metacat->getLastId($scope);
560

  
561 563
    if (!$docid) {
562 564
        $docid = "$scope.1.1";
563 565
        debug("Error in newAccessionNumber: " . $metacat->getMessage());
......
957 959
    }
958 960

  
959 961
    if (!$docid) {
960
        $docid = newAccessionNumber($config->{'scope'});
962
        $docid = newAccessionNumber($config->{'scope'}, $metacat);
961 963
        my $uploadReturn = uploadData($outFile, $docid);
962 964
        if (!$uploadReturn) {
963 965
            debug("Uploading the data failed.");
......
2950 2952
          <frameset rows="150,*" cols="*" frameborder="NO" border="0" framespacing="0">
2951 2953
            <frame src="$skinsDir/$skinName/header.jsp" marginwidth="40" name="topFrame" scrolling="NO" noresize>
2952 2954
            <frameset cols="200,*" frameborder="NO" border="0" framespacing="0">
2953
              <body></body><frame src="$cgiPrefix/register-dataset.cgi?cfg=$skinName&stage=review_frame&docid="$docid"" name="rightFrame" scrolling="NO" noresize></frame>
2955
              <body></body><frame src="$cgiPrefix/register-dataset.cgi?cfg=$skinName&stage=review_frame&docid=$docid" name="rightFrame" scrolling="NO" noresize></frame>
2954 2956
              <frame src="$metacatUrl?action=read&qformat=$skinName&docid=$docid&insertTemplate=0" name="mainFrame">
2955 2957
            </frameset>
2956 2958
          </frameset>
......
2968 2970
    }
2969 2971

  
2970 2972
    my $moderator = $session->param("moderator");
2971

  
2972 2973
    $$templateVars{'reviewdocid'} = getReviewHistoryHTML();
2973 2974
    $$templateVars{'docid'} = $FORM::docid;
2974 2975
    if ($moderator eq 'true') {
......
2984 2985
    my $parser = XML::LibXML->new();
2985 2986
    my $docid = $FORM::docid;
2986 2987
    my ($x, $y, $z) = split(/\./, $docid);
2988
    if ($x eq "") {
2989
        return "Error: Unable to find review for invalid docid.";
2990
    }
2987 2991
    my $docidWithoutRev = $x.".".$y;
2988 2992
    my $reviewDocumentId = '';
2989
    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>");
2993
    my $reviewQuery = "<pathquery><querytitle>Moderator-Search</querytitle><querygroup operator='INTERSECT'><queryterm searchmode='contains' casesensitive='false'><value>$docidWithoutRev</value><pathexpr>/reviewHistory/review/packageId</pathexpr></queryterm></querygroup></pathquery>";
2994
    my $response = $metacat->squery($reviewQuery);
2990 2995
    my $doc = $response->content();
2991 2996
    my $xmldoc = $parser->parse_string($doc);
2992 2997
    my $reviewHTML = '';
2993 2998

  
2994 2999
    if ($xmldoc eq "" || $doc=~ /<error/) {
2995 3000
        # not able to parse
2996
        return " Unable to search for review for the docid:".$docid;
3001
        return "Error: Unable to search for review for the docid:".$docid;
2997 3002
    } else {
2998 3003
        my $findNodes = $xmldoc->findnodes('//resultset/document');
2999 3004
        if ($findNodes->size() > 0) {
......
3067 3072

  
3068 3073
            #debug("Document created by handleModAccept is " . $emldoc);
3069 3074
            # update the document
3070
            my $newDocid = incrementRevision($docid);
3075
            my $docid = incrementRevision($docid);
3071 3076

  
3072
            $emldoc =~ s/packageId=\"$docid\"/packageId=\"$newDocid\"/;
3077
            $emldoc =~ s/packageId="docid"/packageId=\"$docid\"/;
3073 3078
            debugDoc($emldoc);
3074 3079
            $response = $metacat->update($docid, $emldoc);
3075 3080

  
......
3304 3309
        $response = $metacat->read($docid);
3305 3310
        my $doc = $response->content();
3306 3311
        my $xmldoc = $parser->parse_string($doc);
3307
        
3312
        $xmldoc = transformEml($xmldoc); 
3308 3313
        if ($xmldoc eq "" || $doc=~ /<error/) {
3309 3314
            # not able to parse
3310 3315
            $errorMessage = $errorMessage." Error in reading the docid:".$docid;
......
3362 3367
        my $accessElem = '';
3363 3368

  
3364 3369
        # pull out existing dataset entry 
3365
        my $results = $xmldoc->findnodes('//dataset');
3370
        my $results = $xmldoc->findnodes('/eml:eml/dataset');
3366 3371
        foreach my $r ($results->get_nodelist) {
3367 3372
            $dataElem .= $r->toString();
3368 3373
        }
3369 3374
        # also grab the access element
3370
        $results = $xmldoc->findnodes('//access');
3375
        $results = $xmldoc->findnodes('/eml:eml/access');
3371 3376
        foreach my $r ($results->get_nodelist) {
3372 3377
          $accessElem .= $r->toString();
3373 3378
        }
......
3385 3390
        $emldoc .= $addlMetadata;
3386 3391
        $emldoc .= EMLEnd();
3387 3392
        
3388
        debugDoc($emldoc);
3389 3393
        # update the document
3390
        my $newDocid = incrementRevision($docid);
3394
        my $docid = incrementRevision($docid);
3391 3395

  
3392
        $emldoc =~ s/packageId=\"$docid\"/packageId=\"$newDocid\"/;
3393
        $response = $metacat->update($newDocid, $emldoc);
3396
        $emldoc =~ s/packageId="docid"/packageId="$docid"/;
3397
        debugDoc($emldoc);
3398
        $response = $metacat->update($docid, $emldoc);
3394 3399

  
3395 3400
        if (!$response) {
3396 3401
            debug("Error while updating in handleModAccept.".$metacat->getMessage());
3397
            $errorMessage = $errorMessage." Failed while updating the document with additional Metadata.";
3402
            $errorMessage = $errorMessage." Failed while updating the document with additional metadata.";
3398 3403
        }
3399 3404

  
3400 3405
    }
......
3434 3439

  
3435 3440
    # find out if a docid already exists...
3436 3441
    my ($x, $y, $z) = split(/\./, $docid);
3437
    my $docidWithoutRev = $x.$y;
3442
    my $docidWithoutRev = $x . "." . $y;
3443
    debug("docid without rev: $docidWithoutRev");
3438 3444
    my $reviewDocumentId = '';
3439
    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>"); 
3445
    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>"); 
3440 3446

  
3441 3447
    my $doc = $response->content();
3442 3448
    my $xmldoc = $parser->parse_string($doc);
3443 3449

  
3444 3450
    if ($xmldoc eq "" || $doc=~ /<error/) {
3445 3451
        # not able to parse
3446
        return " Unable to store review for the docid:".$docid;
3452
        debug("Unable to parse results for $docidWithoutRev query.");
3453
        return "Error: Unable to store review for the docid:".$docid;
3447 3454
    } else {
3448 3455
        my $findNodes = $xmldoc->findnodes('//resultset/document');
3449 3456
        if ($findNodes->size() > 0) {
......
3464 3471
                my ($reviewdoc, $temp) = split('</reviewHistory>', $doc);
3465 3472
                $reviewdoc .= $review."\n</reviewHistory>\n";
3466 3473
                $reviewDocumentId = incrementRevision($reviewDocumentId);
3474
                debug("Generating review history document for $reviewDocumentId");
3475
                debugDoc($reviewdoc);
3467 3476
                $response = $metacat->update($reviewDocumentId, $reviewdoc);
3468 3477
                if ($response != '1') {
3469 3478
                    return " Unable to update the review on Metacat for the docid:".$docid;
......
3482 3491
            }
3483 3492
        } else {
3484 3493
            #insert a new document
3485
            my $id = newAccessionNumber('esa_reviews');
3494
            debug("no review history document found, generating a new one.");
3495

  
3496
            my $id = newAccessionNumber('esa_reviews', $metacat);
3486 3497
            my $reviewDoc = '';
3487 3498
            my $failMessage = " Unable to insert the review on Metacat for the docid:".$docid;
3488 3499

  
......
3541 3552
    $$templateVars{'comment'} = $FORM::review;
3542 3553
    $$templateVars{'contactName'} = $contactName;
3543 3554
    $$templateVars{'dpTitle'} = $title;
3544

  
3555
    $$templateVars{'registryUrl'} = $contextUrl . "/cgi-bin/register-dataset.cgi";
3545 3556
    $$templateVars{'recipient_status'} = 'moderator';
3546 3557
    sendNotification($email->{'sender'}, $email->{'recipient'}, $subject, 
3547 3558
                            $templates->{'modEmailNotification'}, $templateVars);
......
3564 3575
    my $subject = shift;
3565 3576
    my $templateForm = shift;
3566 3577
    my $templateVars = shift;
3567

  
3578
    
3579
    # When testing, set recipient to your email address
3580
    # $recipient = 'walbridge@nceas.ucsb.edu';
3568 3581
    my $smtp = Net::SMTP->new($email->{'mailhost'});
3569 3582
    $smtp->mail($sender);
3570 3583
    $smtp->to($recipient);

Also available in: Unified diff