Revision 4738
Added by walbridge almost 16 years ago
register-dataset.cgi | ||
---|---|---|
63 | 63 |
my $skinsDir = "${workingDirectory}/../style/skins"; |
64 | 64 |
my $templatesDir = abs_path("${workingDirectory}/../style/common/templates"); |
65 | 65 |
my $tempDir = $properties->getProperty('application.tempDir'); |
66 |
my $dataDir = $properties->getProperty('application.datafilepath'); |
|
66 | 67 |
|
67 | 68 |
# url configuration |
68 | 69 |
my $server = $properties->splitToTree(qr/\./, 'server'); |
... | ... | |
898 | 899 |
my $fileName = param("uploadname_$fileNum"); |
899 | 900 |
my $contentType = param("uploadtype_$fileNum"); |
900 | 901 |
my $filePerm = param("uploadperm_$fileNum"); |
902 |
my $docid; |
|
903 |
my $outFile; |
|
901 | 904 |
my $cleanName = $fileName; |
902 | 905 |
|
903 |
# normalize input filenames; Windows filenames include full paths |
|
904 |
$cleanName =~ s/.*[\/\\](.*)/$1/; |
|
906 |
# process an _existing_ data file, which is already within Metacat. |
|
907 |
if ($fileHash =~ /ondisk/) { |
|
908 |
my $finfo = $fileHash; |
|
909 |
$finfo =~ s/ondisk://g; |
|
910 |
(my $docid, $fileHash) = split(":", $finfo); |
|
911 |
$outFile = $dataDir . "/" . $docid; |
|
912 |
} else { |
|
913 |
# normalize input filenames; Windows filenames include full paths |
|
914 |
$cleanName =~ s/.*[\/\\](.*)/$1/; |
|
915 |
$outFile = $tempDir . "/" . $cleanName; |
|
916 |
} |
|
917 |
debug("Registry: Reading file from disk: $outFile"); |
|
905 | 918 |
|
906 |
my $outFile = $tempDir . "/" . $cleanName; |
|
907 |
#debug("Reading file from disk: $outFile"); |
|
908 |
|
|
909 | 919 |
my $fileSize = stat($outFile)->size; |
910 | 920 |
if ($fileSize == 0) { |
911 | 921 |
push(@errorMessages, "file $fileName is zero bytes!"); |
... | ... | |
916 | 926 |
my $session = CGI::Session->load(); |
917 | 927 |
if ($session->is_empty) { |
918 | 928 |
push(@errorMessages, "Must be logged in to upload files."); |
919 |
debug("Not logged in, cannot upload files."); |
|
929 |
debug("Registry: Not logged in, cannot upload files.");
|
|
920 | 930 |
return 0; |
921 | 931 |
} |
922 | 932 |
|
923 |
my $docid = newAccessionNumber($config->{'scope'}); |
|
924 |
my $uploadReturn = uploadData($outFile, $docid); |
|
925 |
if (!$uploadReturn) { |
|
926 |
debug("Registry: uploading the data failed."); |
|
933 |
if ($fileHash !~ /ondisk/) { |
|
934 |
$docid = newAccessionNumber($config->{'scope'}); |
|
935 |
my $uploadReturn = uploadData($outFile, $docid); |
|
936 |
if (!$uploadReturn) { |
|
937 |
debug("Registry: uploading the data failed."); |
|
938 |
} |
|
927 | 939 |
} |
928 |
|
|
929 | 940 |
my $entityid = $fileHash."001"; |
930 | 941 |
my $distribid = $fileHash."002"; |
931 | 942 |
|
... | ... | |
987 | 998 |
sub writeFile { |
988 | 999 |
my $fileName = shift; |
989 | 1000 |
my $fileData; |
1001 |
my $fileName = shift; |
|
990 | 1002 |
my $length = 0; |
991 | 1003 |
my $buffer; |
1004 |
|
|
992 | 1005 |
my $cleanName = $fileName; |
993 | 1006 |
|
994 | 1007 |
# normalize input filenames; Windows filenames include full paths |
... | ... | |
1008 | 1021 |
open(OUT,">$outputName") or die "Could not open: $!"; |
1009 | 1022 |
print OUT $fileData; |
1010 | 1023 |
close(OUT); |
1011 |
debug("Registry: output is: $outputName, length is: $length");
|
|
1024 |
debug("Registry: writing output, result is: $outputName");
|
|
1012 | 1025 |
|
1013 | 1026 |
return ($outputName, $digest); |
1014 | 1027 |
} |
1015 | 1028 |
|
1016 | 1029 |
sub deleteFile { |
1017 | 1030 |
my $input = shift; |
1018 |
my $fileName = $tempDir . "/" . $input; |
|
1031 |
|
|
1032 |
if ($input =~ /ondisk/) { |
|
1033 |
my $docid = $input; |
|
1034 |
$docid =~ s/ondisk://g; |
|
1035 |
# XXX FIXME once ondisk support is enabled |
|
1036 |
#my $response = $metacat->delete($docid); |
|
1037 |
my $response; |
|
1038 |
if (!$response) { |
|
1039 |
my $msg = $metacat->getMessage(); |
|
1040 |
push(@errorMessages, "Failed to delete existing file. Error was: $msg\n"); |
|
1041 |
debug("Registry: Delete -- Error is: $msg"); |
|
1042 |
} else { |
|
1043 |
debug("Registry: Delete -- Success! Removed docid $docid"); |
|
1044 |
} |
|
1045 |
} else { |
|
1046 |
my $fileName = $tempDir . "/" . $input; |
|
1019 | 1047 |
|
1020 |
if (-e $fileName) { |
|
1021 |
unlink $fileName or |
|
1022 |
debug("Registry: failed to delete file $fileName."); |
|
1023 |
} else { |
|
1024 |
debug("Registry: unable to find file $fileName"); |
|
1048 |
if (-e $fileName) { |
|
1049 |
unlink $fileName or |
|
1050 |
debug("Registry: failed to delete file $fileName."); |
|
1051 |
} else { |
|
1052 |
debug("Registry: unable to find file $fileName"); |
|
1053 |
} |
|
1054 |
if (!-e $fileName) { |
|
1055 |
debug("Registry: successfully deleted $fileName"); |
|
1056 |
} |
|
1025 | 1057 |
} |
1026 |
if (!-e $fileName) { |
|
1027 |
debug("Registry: successfully deleted $fileName"); |
|
1028 |
} |
|
1029 | 1058 |
} |
1030 | 1059 |
|
1031 | 1060 |
sub uploadData { |
... | ... | |
2475 | 2504 |
dontOccur($doc, "./pubPlace", "pubPlace"); |
2476 | 2505 |
dontOccur($doc, "./project", "project"); |
2477 | 2506 |
|
2478 |
############ Code for checking ACL ##################### |
|
2479 |
dontOccur($doc, "//access/deny", "access/deny"); |
|
2507 |
# Code for checking ACL: with EML 2.1, we should only look within the top-level elements |
|
2480 | 2508 |
|
2481 |
$results = $doc->findnodes('//access/allow'); |
|
2509 |
dontOccur($doc, "/eml:eml/access/deny", "access/deny"); |
|
2510 |
|
|
2511 |
$results = $doc->findnodes('/eml:eml/access/allow'); |
|
2482 | 2512 |
my $accessError = 0; |
2483 | 2513 |
|
2484 | 2514 |
foreach $node ($results->get_nodelist) { |
... | ... | |
2530 | 2560 |
} |
2531 | 2561 |
|
2532 | 2562 |
# handle otherEntity objects, by populating the relevant file form elements |
2533 |
$results = $doc->findnodes('./otherEntity'); |
|
2563 |
$results = $doc->findnodes('//otherEntity/physical'); |
|
2564 |
my $upCount = 0; |
|
2534 | 2565 |
foreach $node ($results->get_nodelist) { |
2535 |
# entityName |
|
2536 |
# physical/ |
|
2537 |
# size |
|
2538 |
# authentication |
|
2539 |
# dataformat/externallyDefinedFormat/formatName |
|
2540 |
# distribution/online |
|
2541 |
# distribution/access |
|
2566 |
my $distUrl = findValue($node, 'distribution/online/url'); |
|
2567 |
debug("Registry: found distUrl of value $distUrl."); |
|
2568 |
if ($distUrl !~ /^ecogrid/) { |
|
2569 |
my $error = "The file URL referenced is not a local resource and has been changed outside the registry. Please use Morpho to edit this document."; |
|
2570 |
push(@errorMessages, $error."\n"); |
|
2571 |
} else { |
|
2572 |
# have a file with a ecogrid distUrl, use this to set up the file parameters |
|
2573 |
$distUrl =~ s/ecogrid:\/\/knb\///g; |
|
2574 |
my $accessResults = $doc->findnodes('distribution/access/allow'); |
|
2575 |
my $accessRule = 'private'; |
|
2576 |
|
|
2577 |
foreach $node ($accessResults->get_nodelist) { |
|
2578 |
my @children = $node->childNodes; |
|
2579 |
my $permission = ""; |
|
2580 |
my $principal = ""; |
|
2581 |
for (my $i = 0; $i < scalar(@children); $i++) { |
|
2582 |
my $child = $children[$i]; |
|
2583 |
if ($child->nodeName eq 'principal') { |
|
2584 |
$principal = $child->textContent(); |
|
2585 |
} elsif ($child->nodeName eq 'permission') { |
|
2586 |
$permission = $child->textContent(); |
|
2587 |
} |
|
2588 |
} |
|
2589 |
|
|
2590 |
if ($principal eq 'public' && $permission eq 'read') { |
|
2591 |
$accessRule = 'public'; |
|
2592 |
} |
|
2593 |
} |
|
2594 |
# overload the name with the ondisk status, the docid and the SHA1 sum |
|
2595 |
$$templateVars{"upload_$upCount"} = "ondisk:$distUrl:" . findValue($node, 'authentication'); |
|
2596 |
$$templateVars{"uploadname_$upCount"} = findValue($node, 'objectName'); |
|
2597 |
$$templateVars{"uploadtype_$upCount"} = findValue($node, 'dataFormat/externallyDefinedFormat/formatName'); |
|
2598 |
$$templateVars{"uploadperm_$upCount"} = $accessRule; |
|
2599 |
debug("Registry: setting upload data: " . $$templateVars{"upload_$upCount"} . ", " . $$templateVars{"uploadname_$upCount"} . ", " . $$templateVars{"uploadtype_$upCount"} . ", " . $$templateVars{"uploadperm_$upCount"}); |
|
2600 |
$upCount++; |
|
2601 |
} |
|
2542 | 2602 |
} |
2603 |
if ($upCount > 0) { |
|
2604 |
$$templateVars{"upCount"} = $upCount; |
|
2605 |
} |
|
2606 |
|
|
2543 | 2607 |
dontOccur($doc, "./dataTable", "dataTable"); |
2544 | 2608 |
dontOccur($doc, "./spatialRaster", "spatialRaster"); |
2545 | 2609 |
dontOccur($doc, "./spatialVector", "spatialVector"); |
... | ... | |
4014 | 4078 |
|
4015 | 4079 |
my $result = $node->findnodes("$value"); |
4016 | 4080 |
if ($result->size > 0) { |
4081 |
debug("Registry: error trying to find $value, $errVal."); |
|
4017 | 4082 |
$error ="One of the following tags found: $errVal. Please use Morpho to edit this document"; |
4018 | 4083 |
push(@errorMessages, $error."\n"); |
4019 | 4084 |
} |
... | ... | |
4046 | 4111 |
|
4047 | 4112 |
################################################################################ |
4048 | 4113 |
# |
4049 |
# convert coord to degrees, minutes and seconds form. |
|
4050 |
# |
|
4051 |
################################################################################ |
|
4052 |
#sub convertCoord { |
|
4053 |
# my $wx = shift; |
|
4054 |
# print $deg." ".$min." ".$sec; |
|
4055 |
# print "\n"; |
|
4056 |
#} |
|
4057 |
|
|
4058 |
|
|
4059 |
################################################################################ |
|
4060 |
# |
|
4061 | 4114 |
# print redirect html code |
4062 | 4115 |
# |
4063 | 4116 |
################################################################################ |
Also available in: Unified diff
Further fixes for allowing editing with otherEntity objects, completed deserialization and copying of file metadata from existing data objects (Bug #3319). Still needs more work.