Revision 4744
Added by walbridge almost 16 years ago
register-dataset.cgi | ||
---|---|---|
432 | 432 |
debug("NO SUCCESS"); |
433 | 433 |
debug("Message is: $docStatus"); |
434 | 434 |
push(@errorMessages, $docStatus); |
435 |
} else { |
|
436 |
deleteRemovedData(); |
|
435 | 437 |
} |
436 | 438 |
|
437 | 439 |
debug("B3"); |
438 | 440 |
} else { |
441 |
debug("M1"); |
|
442 |
|
|
439 | 443 |
# document is being modified |
440 | 444 |
$docid = incrementRevision($FORM::docid); |
441 | 445 |
|
... | ... | |
447 | 451 |
if (! $response) { |
448 | 452 |
push(@errorMessages, $metacat->getMessage()); |
449 | 453 |
push(@errorMessages, "Failed while updating.\n"); |
450 |
} |
|
451 |
|
|
454 |
} |
|
455 |
|
|
456 |
debug("M2, $docid"); |
|
452 | 457 |
if (scalar(@errorMessages)) { |
453 |
debug("ErrorMessages defined in modify.");
|
|
458 |
debug("Errors defined in modify."); |
|
454 | 459 |
|
455 | 460 |
$$templateVars{'docid'} = $FORM::docid; |
456 | 461 |
copyFormToTemplateVars(); |
... | ... | |
458 | 463 |
$$templateVars{'errorMessages'} = \@errorMessages; |
459 | 464 |
$error = 1; |
460 | 465 |
} else { |
466 |
deleteRemovedData(); |
|
461 | 467 |
$$templateVars{'docid'} = $docid; |
462 | 468 |
$$templateVars{'cfg'} = $skinName; |
463 | 469 |
} |
... | ... | |
884 | 890 |
for (my $fileNum = 0; $fileNum <= $FORM::upCount; $fileNum++) { |
885 | 891 |
my $fn = 'upload_' . $fileNum; |
886 | 892 |
if (hasContent(param($fn))) { |
887 |
debug("Retrieving metadata for file: $fn"); |
|
888 |
($docid, $fileInfo) = fileMetadata($fileNum); |
|
889 |
$uploadedFiles{ $docid } = $fileInfo; |
|
893 |
# ignore data which is scheduled for deletion |
|
894 |
if (grep {$_ eq ("uploadname_$fileNum")} @FORM::deletefile) { |
|
895 |
debug("Not generating metadata for file scheduled for deletion: $fn"); |
|
896 |
} else { |
|
897 |
debug("Retrieving metadata for file: $fn"); |
|
898 |
($docid, $fileInfo) = fileMetadata($fileNum); |
|
899 |
$uploadedFiles{ $docid } = $fileInfo; |
|
900 |
} |
|
890 | 901 |
} |
891 | 902 |
} |
892 | 903 |
|
... | ... | |
905 | 916 |
|
906 | 917 |
# process an _existing_ data file, which is already within Metacat. |
907 | 918 |
if ($fileHash =~ /ondisk/) { |
908 |
my $finfo = $fileHash; |
|
909 |
$finfo =~ s/ondisk://g; |
|
910 |
($docid, $fileHash) = split(":", $finfo); |
|
919 |
($docid, $fileHash) = datafileInfo($fileHash); |
|
911 | 920 |
$outFile = $dataDir . "/" . $docid; |
912 | 921 |
} else { |
913 | 922 |
# normalize input filenames; Windows filenames include full paths |
... | ... | |
960 | 969 |
return ($docid, \%dataInfo); |
961 | 970 |
} |
962 | 971 |
|
972 |
sub datafileInfo { |
|
973 |
my $finfo = shift; |
|
974 |
$finfo =~ s/ondisk://g; |
|
975 |
return my ($docid, $fileHash) = split (":", $finfo); |
|
976 |
} |
|
963 | 977 |
|
964 | 978 |
sub processFile { |
965 | 979 |
my $fileName = shift; |
... | ... | |
1025 | 1039 |
return ($outputName, $digest); |
1026 | 1040 |
} |
1027 | 1041 |
|
1042 |
sub deleteRemovedData { |
|
1043 |
# if we have any associated datafiles which are scheduled for deletion, remove them now |
|
1044 |
for (my $delNum = 0; $delNum <= $FORM::delCount; $delNum++) { |
|
1045 |
# need to look up the actual upload number, which is contained in the name |
|
1046 |
my $upNum = param("deletefile_$delNum"); |
|
1047 |
$upNum =~ s/uploadname_//; |
|
1048 |
my $upn = param("upload_$upNum"); |
|
1049 |
if (hasContent($upn)) { |
|
1050 |
debug("Deleting upload_$upNum, $upn"); |
|
1051 |
if (grep {$_ eq ("uploadname_$upNum")} @FORM::deletefile) { |
|
1052 |
if (param("upload_$upNum") =~ /ondisk/) { |
|
1053 |
debug("got a file which is ondisk, proceeding with deletion"); |
|
1054 |
deleteFileData(param("upload_$upNum")); |
|
1055 |
} else { |
|
1056 |
debug("got an old reference, not yet in EML, remove from tempdir"); |
|
1057 |
deleteFile(param("uploadname_$upNum")); |
|
1058 |
} |
|
1059 |
} else { |
|
1060 |
debug("Name didn't match in deletefile list"); |
|
1061 |
} |
|
1062 |
} |
|
1063 |
} |
|
1064 |
} |
|
1065 |
|
|
1028 | 1066 |
sub deleteFile { |
1029 | 1067 |
my $input = shift; |
1030 |
|
|
1031 |
if ($input =~ /ondisk/) { |
|
1032 |
my $docid = $input; |
|
1033 |
$docid =~ s/ondisk://g; |
|
1034 |
# XXX FIXME once ondisk support is enabled |
|
1035 |
#my $response = $metacat->delete($docid); |
|
1036 |
my $response; |
|
1068 |
my $fileName = $tempDir . "/" . $input; |
|
1069 |
|
|
1070 |
if (-e $fileName) { |
|
1071 |
unlink $fileName or |
|
1072 |
debug("Failed to delete file $fileName."); |
|
1073 |
} else { |
|
1074 |
debug("Unable to find file $fileName"); |
|
1075 |
} |
|
1076 |
if (!-e $fileName) { |
|
1077 |
debug("Successfully deleted $fileName"); |
|
1078 |
} |
|
1079 |
} |
|
1080 |
|
|
1081 |
sub deleteFileData { |
|
1082 |
my $input = shift; |
|
1083 |
my ($docid, $fileHash) = datafileInfo($input); |
|
1084 |
my $metacat = Metacat->new($metacatUrl); |
|
1085 |
|
|
1086 |
my ($username, $password) = getCredentials(); |
|
1087 |
my $response = $metacat->login($username, $password); |
|
1088 |
if (!$response) { |
|
1089 |
my $msg = $metacat->getMessage(); |
|
1090 |
push(@errorMessages, "Failed to login with credentials for `$username`. Error was $msg"); |
|
1091 |
debug("Failed to login with given credentials for username $username, Error is: $msg"); |
|
1092 |
} else { |
|
1093 |
$response = $metacat->delete($docid); |
|
1037 | 1094 |
if (!$response) { |
1038 | 1095 |
my $msg = $metacat->getMessage(); |
1039 |
push(@errorMessages, "Failed to delete existing file. Error was: $msg\n");
|
|
1096 |
push(@errorMessages, "Failed to delete existing file. Error was: $msg"); |
|
1040 | 1097 |
debug("Delete -- Error is: $msg"); |
1041 | 1098 |
} else { |
1042 | 1099 |
debug("Delete -- Success! Removed docid $docid"); |
1043 | 1100 |
} |
1044 |
} else { |
|
1045 |
my $fileName = $tempDir . "/" . $input; |
|
1046 |
|
|
1047 |
if (-e $fileName) { |
|
1048 |
unlink $fileName or |
|
1049 |
debug("Failed to delete file $fileName."); |
|
1050 |
} else { |
|
1051 |
debug("Unable to find file $fileName"); |
|
1052 |
} |
|
1053 |
if (!-e $fileName) { |
|
1054 |
debug("Successfully deleted $fileName"); |
|
1055 |
} |
|
1056 | 1101 |
} |
1057 | 1102 |
} |
1058 | 1103 |
|
... | ... | |
1933 | 1978 |
my $node; |
1934 | 1979 |
my $tempResult; |
1935 | 1980 |
my $tempNode; |
1936 |
my $aoCount = 1;
|
|
1981 |
my $aoCount = 0;
|
|
1937 | 1982 |
my $foundDSO; |
1938 | 1983 |
|
1939 | 1984 |
# set variable values |
... | ... | |
2239 | 2284 |
my $temp = findValue($tempNode, "mediumName"); |
2240 | 2285 |
if (substr($temp, 0, 5) eq "other") { |
2241 | 2286 |
$$templateVars{'dataMedium'} = substr($temp, 0, 5); |
2242 |
$$templateVars{'dataMediumOther'} = substr($temp, 5);
|
|
2287 |
$$templateVars{'dataMediumOther'} = substr($temp, 6);
|
|
2243 | 2288 |
} else { |
2244 | 2289 |
$$templateVars{'dataMedium'} = $temp; |
2245 | 2290 |
} |
... | ... | |
2838 | 2883 |
my $userPass = $FORM::password; |
2839 | 2884 |
my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org"; |
2840 | 2885 |
|
2841 |
if ($FORM::userLoggedIn eq 'true') { |
|
2842 |
my $session = CGI::Session->load(); |
|
2843 |
if (!($session->is_empty || $session->is_expired)) { |
|
2844 |
$dname = $session->param("username"); |
|
2845 |
$userPass = $session->param("password"); |
|
2846 |
} |
|
2886 |
my $session = CGI::Session->load(); |
|
2887 |
if (!($session->is_empty || $session->is_expired)) { |
|
2888 |
$dname = $session->param("username"); |
|
2889 |
$userPass = $session->param("password"); |
|
2847 | 2890 |
} |
2848 | 2891 |
|
2849 | 2892 |
return ($dname, $userPass); |
... | ... | |
3016 | 3059 |
} |
3017 | 3060 |
|
3018 | 3061 |
$emldoc .= EMLStart(); |
3019 |
# TODO SCW: make sure this replacement works as expected |
|
3020 | 3062 |
$emldoc .= accessElement("true"); |
3021 | 3063 |
$emldoc .= $dataElem; |
3022 | 3064 |
$emldoc .= EMLEnd(); |
... | ... | |
3026 | 3068 |
my $newDocid = incrementRevision($docid); |
3027 | 3069 |
|
3028 | 3070 |
$emldoc =~ s/packageId=\"$docid\"/packageId=\"$newDocid\"/; |
3029 |
$response = $metacat->update($newDocid, $emldoc);
|
|
3071 |
$response = $metacat->update($docid, $emldoc);
|
|
3030 | 3072 |
|
3031 | 3073 |
if (! $response) { |
3032 | 3074 |
debug("Error while updating in handleModAccept."); |
... | ... | |
3741 | 3783 |
$$templateVars{'taxaCount'} = $taxonCount-1; |
3742 | 3784 |
$$templateVars{'taxaAuth'} = normalizeCD($FORM::taxaAuth); |
3743 | 3785 |
my $deleteCount = 0; |
3786 |
|
|
3787 |
for (my $i = 0; $i <= scalar(@FORM::deletefile); $i++) { |
|
3788 |
my $delfile = pop(@FORM::deletefile); |
|
3789 |
$$templateVars{"deletefile_$deleteCount"} = $delfile; |
|
3790 |
debug(" creating deletefile_$deleteCount = $delfile"); |
|
3791 |
$deleteCount++; |
|
3792 |
} |
|
3793 |
$$templateVars{"delCount"} = $deleteCount; |
|
3744 | 3794 |
for (my $upNum = 0; $upNum <= $FORM::upCount; $upNum++) { |
3745 | 3795 |
my $upn = "upload_$upNum"; |
3746 | 3796 |
if (hasContent(param($upn))) { |
3747 |
if (grep {$_ eq ("uploadname_$upNum")} @FORM::deletefile) { |
|
3748 |
deleteFile(param("uploadname_$upNum")); |
|
3749 |
$deleteCount++; |
|
3750 |
} else { |
|
3751 |
debug("Processing existing file: $upn"); |
|
3752 |
$$templateVars{"upload_$upNum"} = param("upload_$upNum"); |
|
3753 |
$$templateVars{"uploadname_$upNum"} = param("uploadname_$upNum"); |
|
3754 |
$$templateVars{"uploadtype_$upNum"} = param("uploadtype_$upNum"); |
|
3755 |
$$templateVars{"uploadperm_$upNum"} = param("uploadperm_$upNum"); |
|
3756 |
} |
|
3797 |
debug("Processing existing file: $upn"); |
|
3798 |
$$templateVars{"upload_$upNum"} = param("upload_$upNum"); |
|
3799 |
$$templateVars{"uploadname_$upNum"} = param("uploadname_$upNum"); |
|
3800 |
$$templateVars{"uploadtype_$upNum"} = param("uploadtype_$upNum"); |
|
3801 |
$$templateVars{"uploadperm_$upNum"} = param("uploadperm_$upNum"); |
|
3757 | 3802 |
} |
3758 | 3803 |
} |
3759 | 3804 |
|
... | ... | |
3763 | 3808 |
if (hasContent(param($fn))) { |
3764 | 3809 |
my $fileName = eval "\$FORM::file_$fileNum"; |
3765 | 3810 |
debug("Processing file: $fn"); |
3766 |
# Upload the file object itself to a temporary file, copy file |
|
3767 |
# metadata to form |
|
3811 |
# Upload the file object itself to a temporary file, copy file metadata to form |
|
3768 | 3812 |
my $fileInfo = processFile($fileName); |
3769 | 3813 |
# if we have existing uploads, increment the counter to avoid overwriting |
3770 | 3814 |
my $totalFileNum = $fileNum + $FORM::upCount; |
... | ... | |
3776 | 3820 |
} |
3777 | 3821 |
} |
3778 | 3822 |
# total uploads are: new uploads - deleted files + original uploads |
3779 |
$$templateVars{'upCount'} = $uploadCount - $deleteCount + $FORM::upCount;
|
|
3823 |
$$templateVars{'upCount'} = $uploadCount + $FORM::upCount; |
|
3780 | 3824 |
$$templateVars{'methodTitle'} = normalizeCD($FORM::methodTitle); |
3781 | 3825 |
|
3782 | 3826 |
my @tempMethodPara; |
... | ... | |
3787 | 3831 |
$$templateVars{'studyExtentDescription'} = normalizeCD($FORM::studyExtentDescription); |
3788 | 3832 |
$$templateVars{'samplingDescription'} = normalizeCD($FORM::samplingDescription); |
3789 | 3833 |
$$templateVars{'origStateContact'} = $FORM::origState; |
3790 |
|
|
3791 | 3834 |
$$templateVars{'modules'} = $modules; |
3792 | 3835 |
$$templateVars{'required'} = $required; |
3793 | 3836 |
$$templateVars{'show'} = $show; |
3794 | 3837 |
$$templateVars{'site'} = $FORM::site; |
3795 |
|
|
3796 | 3838 |
$$templateVars{'docid'} = $FORM::docid; |
3797 | 3839 |
|
3798 | 3840 |
# Check if the session exists |
... | ... | |
3800 | 3842 |
if (!($session->is_empty || $session->is_expired)) { |
3801 | 3843 |
$$templateVars{'userLoggedIn'} = 'true'; |
3802 | 3844 |
} |
3845 |
|
|
3846 |
# Errors from validation function. print the errors out using the response template |
|
3847 |
if (scalar(@errorMessages)) { |
|
3848 |
debug("Error messages found when confirming data."); |
|
3849 |
$$templateVars{'status'} = 'failure'; |
|
3850 |
$$templateVars{'errorMessages'} = \@errorMessages; |
|
3851 |
$error = 1; |
|
3852 |
} |
|
3803 | 3853 |
|
3804 |
if (! $error) {
|
|
3854 |
if (!$error) { |
|
3805 | 3855 |
# If no errors, then print out data in confirm Data template |
3806 | 3856 |
$$templateVars{'section'} = "Confirm Data"; |
3807 | 3857 |
$template->process($templates->{'confirmData'}, $templateVars); |
3808 | 3858 |
|
3809 | 3859 |
} else { |
3810 |
# Errors from validation function. print the errors out using the response template |
|
3811 |
if (scalar(@errorMessages)) { |
|
3812 |
$$templateVars{'status'} = 'failure'; |
|
3813 |
$$templateVars{'errorMessages'} = \@errorMessages; |
|
3814 |
$error = 1; |
|
3815 |
} |
|
3816 | 3860 |
# Create our HTML response and send it back |
3817 |
$$templateVars{'function'} = "submitted"; |
|
3818 |
$$templateVars{'section'} = "Submission Status"; |
|
3819 |
$template->process($templates->{'response'}, $templateVars); |
|
3861 |
$$templateVars{'function'} = "submitted";
|
|
3862 |
$$templateVars{'section'} = "Submission Status";
|
|
3863 |
$template->process($templates->{'response'}, $templateVars);
|
|
3820 | 3864 |
} |
3821 | 3865 |
} |
3822 | 3866 |
|
Also available in: Unified diff
Complete implementation of otherEntity editing and deletion, syncronizing changes to EML document. Now all elements which are created by the form can also be edited (Bug #3319). Also prevented associated party duplication on modification.