Revision 8812
Added by Lauren Walker over 10 years ago
src/perl/register-dataset.cgi | ||
---|---|---|
42 | 42 |
use File::stat; |
43 | 43 |
use File::Basename; |
44 | 44 |
use File::Temp; |
45 |
use File::Copy; |
|
46 |
use Fcntl qw(:flock); |
|
45 | 47 |
use strict; |
46 | 48 |
|
47 | 49 |
#debug("running register-dataset.cgi"); |
... | ... | |
499 | 501 |
|
500 | 502 |
# document is being inserted |
501 | 503 |
my $docStatus = "INCOMPLETE"; |
502 |
while ( $docStatus eq "INCOMPLETE" ) { |
|
503 |
$docid = newAccessionNumber( $config->{'scope'}, $metacat ); |
|
504 |
|
|
505 |
$xmldocWithDocID =~ s/docid/$docid/; |
|
506 |
debugDoc($xmldocWithDocID); |
|
507 |
$docStatus = insertMetadata( $xmldocWithDocID, $docid ); |
|
504 |
|
|
505 |
#Lock a local file while we are creating a new docid |
|
506 |
my $lockFilePath = "docids.lock"; |
|
507 |
open my $lock, '>', $lockFilePath; |
|
508 |
flock($lock, LOCK_EX); |
|
509 |
|
|
510 |
my $logFilePath = "log.txt"; |
|
511 |
open my $log, '>>', $logFilePath; |
|
512 |
print $log "\n----next doc---\n"; |
|
513 |
|
|
514 |
my $tries = 0; |
|
515 |
my $configScope = $config->{'scope'}; |
|
516 |
|
|
517 |
while ($docStatus eq "INCOMPLETE") { |
|
518 |
|
|
519 |
my $docidsFilePath = "docids.txt"; |
|
520 |
my $docidsFilePathNew = "docids.txt.new"; |
|
521 |
|
|
522 |
#Open/create a local file while we are creating a new docid |
|
523 |
open my $docidsFile, '+<', $docidsFilePath; |
|
524 |
open my $docidsNewFile, '>', $docidsFilePathNew; |
|
525 |
|
|
526 |
#Read each docid scope,num in the file |
|
527 |
while( <$docidsFile> ) { |
|
528 |
my @line = split /,/; |
|
529 |
my $scope = $line[0]; |
|
530 |
|
|
531 |
if($scope eq $configScope){ |
|
532 |
|
|
533 |
my $newDocId = $line[1] + 1; |
|
534 |
$docid = "$configScope.$newDocId.1"; |
|
535 |
|
|
536 |
print $docidsNewFile "$configScope,$newDocId \n"; |
|
537 |
|
|
538 |
} |
|
539 |
else{ |
|
540 |
print $docidsNewFile $_; |
|
541 |
} |
|
542 |
} |
|
543 |
|
|
544 |
#Close the file and replace the old docids file with this new one |
|
545 |
close $docidsNewFile; |
|
546 |
close $docidsFile; |
|
547 |
move($docidsFilePathNew, $docidsFilePath); |
|
548 |
|
|
549 |
if((!$docid) || ($tries > 5)){ |
|
550 |
print $log "We DID NOT create a docid from the local file\n"; |
|
551 |
|
|
552 |
#Create the docid |
|
553 |
#$docid = newAccessionNumber( $config->{'scope'}, $metacat ); |
|
554 |
$docid = newAccessionNumber( "walker", $metacat ); |
|
555 |
|
|
556 |
print $log "newAccessionNum: $docid\n"; |
|
557 |
|
|
558 |
$xmldocWithDocID =~ s/docid/$docid/; |
|
559 |
debugDoc($xmldocWithDocID); |
|
560 |
$docStatus = insertMetadata( $xmldocWithDocID, $docid ); |
|
561 |
print $log "docStatus: $docStatus\n------------\n"; |
|
562 |
|
|
563 |
#Append the new docid |
|
564 |
#my @line = split(/\./, $docid); |
|
565 |
#my $scope = $line[0]; |
|
566 |
#my $num = $line[1]; |
|
567 |
|
|
568 |
#open my $docidsFile, '>>', $docidsFilePath; |
|
569 |
|
|
570 |
#print $docidsFile "$scope,$num\n"; |
|
571 |
|
|
572 |
#close $docidsFile; |
|
573 |
} |
|
574 |
else{ |
|
575 |
print $log "We created a docid: $docid\n"; |
|
576 |
$xmldocWithDocID =~ s/docid/$docid/; |
|
577 |
|
|
578 |
debugDoc($xmldocWithDocID); |
|
579 |
|
|
580 |
$docStatus = insertMetadata( $xmldocWithDocID, $docid ); |
|
581 |
print $log "docStatus: $docStatus\n------------\n"; |
|
582 |
|
|
583 |
$tries++; |
|
584 |
} |
|
585 |
|
|
586 |
debug("B2"); |
|
508 | 587 |
} |
509 |
debug("B2"); |
|
510 |
if ( $docStatus ne "SUCCESS" ) { |
|
511 |
debug("NO SUCCESS"); |
|
512 |
debug("Message is: $docStatus"); |
|
513 |
push( @errorMessages, $docStatus ); |
|
514 |
} |
|
515 |
else { |
|
516 |
deleteRemovedData(); |
|
517 |
} |
|
588 |
|
|
589 |
close $log; |
|
590 |
close $lock; |
|
591 |
|
|
592 |
if ( $docStatus ne "SUCCESS" ) { |
|
593 |
debug("NO SUCCESS"); |
|
594 |
debug("Message is: $docStatus"); |
|
595 |
|
|
596 |
push( @errorMessages, $docStatus ); |
|
597 |
} |
|
598 |
else{ |
|
599 |
deleteRemovedData(); |
|
600 |
} |
|
518 | 601 |
|
519 | 602 |
debug("B3"); |
520 | 603 |
} |
... | ... | |
697 | 780 |
if ( !$response ) { |
698 | 781 |
debug("Response gotten (D2)"); |
699 | 782 |
my $errormsg = $metacat->getMessage(); |
700 |
i debug( "Error is (D3): " . $errormsg );
|
|
783 |
debug( "Error is (D3): " . $errormsg ); |
|
701 | 784 |
if ( $errormsg =~ /is already in use/ ) { |
702 | 785 |
$docStatus = "INCOMPLETE"; |
703 | 786 |
} |
... | ... | |
4842 | 4925 |
} |
4843 | 4926 |
|
4844 | 4927 |
if ( !$error ) { |
4845 |
|
|
4846 |
# If no errors, then print out data in confirm Data template |
|
4928 |
# If no errors, then print out data in confirm Data template |
|
4847 | 4929 |
$$templateVars{'section'} = "Confirm Data"; |
4848 |
$template->process( $templates->{'confirmData'}, $templateVars ); |
|
4930 |
|
|
4931 |
#Just return the data file upload details, if specified |
|
4932 |
if(param("justGetUploadDetails")){ |
|
4933 |
$template->process( $templates->{'dataUploadDetails'}, $templateVars ); |
|
4934 |
} |
|
4935 |
else{ |
|
4936 |
$template->process( $templates->{'confirmData'}, $templateVars ); |
|
4937 |
} |
|
4849 | 4938 |
|
4850 | 4939 |
} |
4851 | 4940 |
else { |
Also available in: Unified diff
Lock a local file while docids are being created so multiple docs can be uploaded at once