Project

General

Profile

Revision 9780

Added by Chris Jones over 4 years ago

Merge changes from the 2.6.0 release.

View differences:

register-dataset.cgi
109 109
my $userManagementUrl = $properties->getProperty('auth.userManagementUrl');
110 110

  
111 111
my $now = time;
112
# The party param index of the first creator role encountered
113
my $firstCreatorIndex = -1;
114
# Was a contact submitted in the form?
115
my $hasContact = 0;
116
# Was a metadataProvider submitted in the form?
117
my $hasMetadataProvider = 0;
112 118

  
119

  
113 120
# Import all of the HTML form fields as variables
114 121
import_names('FORM');
115 122

  
......
549 556
                deleteRemovedData();
550 557
            }
551 558

  
552
		}
553
		else {
559
		} else {
554 560
			debug("The form has an existing docid: " . $FORM::docid);
555 561

  
556 562
			# document is being modified
......
865 871

  
866 872
	push( @invalidParams, "Name of the Project is not selected in the form." )
867 873
	  if ( scalar(@FORM::wg) == 0 && $required->{'wgList'} eq 'true' );
868
	push( @invalidParams, "First name of person entering the form is missing." )
869
	  unless hasContent($FORM::providerGivenName);
870
	push( @invalidParams, "Last name of person entering the form is missing." )
871
	  unless hasContent($FORM::providerSurName);
872
	push( @invalidParams, "Dataset title is missing." )
874
	
875
	push( @invalidParams, "Please provide a dataset title." )
873 876
	  unless hasContent($FORM::title);
877
	
874 878
	if ( $show->{'siteList'} eq 'true' ) {
875 879
		push( @invalidParams, ucfirst( $config->{'site'} ) . " name is missing." )
876 880
		  unless ( ( hasContent($FORM::site) && !( $FORM::site =~ /^Select/ ) )
877 881
			|| $skinName eq "nceas" );
878 882
	}
879
	push( @invalidParams, "First name of principal data set owner is missing." )
880
	  unless hasContent($FORM::origNamefirst0);
881
	push( @invalidParams, "Last name of principal data set owner is missing." )
882
	  unless hasContent($FORM::origNamelast0);
883
	push( @invalidParams, "Dataset abstract is missing." )
883
    
884
    if ( $required->{'funding'} eq 'true' ) {
885
    	push( @invalidParams, "Please provide an award number." )
886
    	  unless hasContent($FORM::funding);
887
        
888
    }
889

  
890
	push( @invalidParams, "Please provide a person's first name, last name, and role, or an organization name and it's role.")
891
	  unless ((hasContent($FORM::partyFirstName) && 
892
		         hasContent($FORM::partyLastName) &&
893
						 hasContent($FORM::partyRole)) 
894
						 ||
895
		         (hasContent($FORM::partyOrgName) && 
896
						  hasContent($FORM::partyRole)));
897
	
898
    my @partyRoles = param('partyRole');
899
    my $hasCreator = 0;
900
    foreach  my $partyRole (@partyRoles) {
901
        if ( $partyRole eq 'creator' ) {
902
            $hasCreator = 1;
903
            last;
904
            
905
        }
906
    }
907
	push( @invalidParams, "Please provide a party entry with a 'Creator' role." )
908
	  unless $hasCreator == 1;
909
    
910
	push( @invalidParams, "Please provide a dataset abstract." )
884 911
	  unless hasContent($FORM::abstract);
885 912

  
886 913
	if ( $modules->{'temporal'} eq 'true' ) {
887
		push( @invalidParams, "Year of start date is missing." )
914
		push( @invalidParams, "Please provide a start date year." )
888 915
		  unless ( hasContent($FORM::beginningYear)
889 916
			|| $required->{'temporal'} ne 'true' );
890
		push( @invalidParams,
891
"Year of stop date has been specified but year of start date is missing."
917
		
918
		push( @invalidParams, "Year of stop date has been specified but year of start date is missing."
892 919
		  )
893 920
		  if ( ( !hasContent($FORM::beginningYear) )
894 921
			&& hasContent($FORM::endingYear) );
895 922
	}
896
	push( @invalidParams, "Geographic description is missing." )
897
	  unless ( hasContent($FORM::geogdesc)
898
		|| $required->{'spatial'} ne 'true' );
923
	
924
	push( @invalidParams, "Please provide a geographic description." )
925
	  unless ( hasContent($FORM::geogdesc) || $required->{'spatial'} ne 'true' );
899 926

  
900 927
	if ( $FORM::beginningMonth eq "MM" ) {
901 928
		$FORM::beginningMonth = "";
......
911 938
	}
912 939

  
913 940
	if ( hasContent($FORM::beginningYear)
914
		&& !( $FORM::beginningYear =~ /[0-9]{4}/ ) )
915
	{
916
		push( @invalidParams, "Invalid year of start date specified." );
941
		&& !( $FORM::beginningYear =~ /[0-9]{4}/ ) ) {
942
		push( @invalidParams, "Please provide a four digit start date." );
917 943
	}
918 944

  
919
	if ( hasContent($FORM::endingYear) && !( $FORM::endingYear =~ /[0-9]{4}/ ) )
920
	{
921
		push( @invalidParams, "Invalid year of stop date specified." );
945
	if ( hasContent($FORM::endingYear) && !( $FORM::endingYear =~ /[0-9]{4}/ ) ) {
946
		push( @invalidParams, "Please provide a four digit stop date." );
922 947
	}
923 948

  
924 949
	# If the "use site" coord. box is checked and if the site is in
......
1012 1037

  
1013 1038
	if ( $modules->{'spatial'} eq 'true' && $required->{'spatial'} eq 'true' ) {
1014 1039
		if ($FORM::useSiteCoord) {
1015
			push( @invalidParams,
1016
"The Data Registry doesn't have latitude and longitude information for the site that you chose. Please go back and enter the spatial information."
1040
			push( @invalidParams, "The Data Registry doesn't have latitude and longitude information for the site that you chose. Please go back and enter the spatial information."
1017 1041
			) unless ( hasContent($latDeg1) && hasContent($longDeg1) );
1018 1042
		}
1019 1043
		else {
......
1024 1048
			  unless ( hasContent($longDeg1)
1025 1049
				|| $required->{'spatial'} ne 'true' );
1026 1050
		}
1027
		push( @invalidParams,
1028
"You must provide a geographic description if you provide latitude and longitude information."
1051
		push( @invalidParams, "You must provide a geographic description if you provide latitude and longitude information."
1029 1052
		  )
1030 1053
		  if ( ( hasContent($latDeg1) || ( hasContent($longDeg1) ) )
1031 1054
			&& ( !hasContent($FORM::geogdesc) ) );
1032 1055
	}
1033 1056

  
1034 1057
	if ( $modules->{'method'} eq 'true' ) {
1035
		push( @invalidParams,
1036
"You must provide a method description if you provide a method title."
1058
		push( @invalidParams, "You must provide a method description if you provide a method title."
1037 1059
		  )
1038 1060
		  if (
1039 1061
			hasContent($FORM::methodTitle)
1040 1062
			&& (  !( scalar(@FORM::methodPara) > 0 )
1041 1063
				|| ( !hasContent( $FORM::methodPara[0] ) ) )
1042 1064
		  );
1043
		push( @invalidParams,
1044
"You must provide a method description if you provide an extent of study description."
1065
		push( @invalidParams, "You must provide a method description if you provide an extent of study description."
1045 1066
		  )
1046 1067
		  if (
1047 1068
			hasContent($FORM::studyExtentDescription)
1048 1069
			&& (  !( scalar(@FORM::methodPara) > 0 )
1049 1070
				|| ( !hasContent( $FORM::methodPara[0] ) ) )
1050 1071
		  );
1051
		push( @invalidParams,
1052
"You must provide both an extent of study description and a sampling description, or neither."
1072
		push( @invalidParams, "You must provide both an extent of study description and a sampling description, or neither."
1053 1073
		  )
1054 1074
		  if (
1055 1075
			(
......
1075 1095
		}
1076 1096
	}
1077 1097

  
1078
	push( @invalidParams, "First name of data set contact is missing." )
1079
	  unless ( hasContent($FORM::origNamefirstContact)
1080
		|| $FORM::useOrigAddress );
1081
	push( @invalidParams, "Last name of data set contact is missing." )
1082
	  unless ( hasContent($FORM::origNamelastContact)
1083
		|| $FORM::useOrigAddress );
1084
	if ( $required->{'contactEmailAddress'} eq 'true' ) {
1085
		if ($FORM::useOrigAddress) {
1086
			push( @invalidParams,
1087
"Email address of data set owner is missing. This is required as it will be used as contact email address as specified by you."
1088
			) unless ( hasContent($FORM::origEmail) );
1089
		}
1090
		else {
1091
			push( @invalidParams,
1092
				"Email address of data set contact is missing." )
1093
			  unless ( hasContent($FORM::origEmailContact) );
1094
		}
1095
	}
1096

  
1097
	# check required distribution elements
1098
	push( @invalidParams, "Data medium is required." )
1099
	  unless ( hasContent($FORM::dataMedium) );
1100
	if ( $FORM::dataMedium eq 'other' ) {
1101
		push( @invalidParams,
1102
			"Must enter custom data medium when 'other' is selected." )
1103
		  unless ( hasContent($FORM::dataMediumOther) );
1104
	}
1105
	push( @invalidParams, "Usage rights are required." )
1098
	push( @invalidParams, "Please provide the data medium." )
1099
	  unless ( hasContent($FORM::dataMedium));
1100
	
1101
	push( @invalidParams, "Please provide usage rights." )
1106 1102
	  unless ( hasContent($FORM::useConstraints) );
1107 1103
	if ( $FORM::useConstraints eq 'other' ) {
1108 1104
		push( @invalidParams,
......
1236 1232
#
1237 1233
################################################################################
1238 1234
sub allFileData {
1235
	if ( $debug_enabled ) {
1236
	    debug("allFileData() called. ");
1237
		
1238
	}
1239

  
1239 1240
	my %uploadedFiles = ();
1240 1241
	my $fileInfo;
1241 1242
	my $docid;
......
1246 1247

  
1247 1248
			# ignore data which is scheduled for deletion
1248 1249
			if ( grep { $_ eq ("uploadname_$fileNum") } @FORM::deletefile ) {
1249
				debug(
1250
"Not generating metadata for file scheduled for deletion: $fn"
1251
				);
1252
			}
1253
			else {
1250
				debug("Not generating metadata for file scheduled for deletion: $fn");
1251
			
1252
			} else {
1254 1253
				debug("Retrieving metadata for file: $fn");
1255 1254
				( $docid, $fileInfo ) = fileMetadata($fileNum);
1256 1255
				$uploadedFiles{$docid} = $fileInfo;
......
1261 1260
	return %uploadedFiles;
1262 1261
}
1263 1262

  
1263
# Returns minimal metadata about an uploaded file: hash, name, content-type, permissions
1264 1264
sub fileMetadata {
1265
	if ( $debug_enabled ) {
1266
		debug("fileMetadata() called.");
1267
		
1268
	}
1269
	
1265 1270
	my $fileNum     = shift;
1266 1271
	my $fileHash    = param("upload_$fileNum");
1267 1272
	my $fileName    = param("uploadname_$fileNum");
......
1276 1281
		( $docid, $fileHash ) = datafileInfo($fileHash);
1277 1282
		$outFile = $dataDir . "/" . $docid;
1278 1283

  
1279
	}
1280
	else {
1284
	} else {
1281 1285

  
1282 1286
		# normalize input filenames; Windows filenames include full paths
1283 1287
		$cleanName =~ s/.*[\/\\](.*)/$1/;
......
1299 1303
	}
1300 1304

  
1301 1305
	# remove the uniqueness of the filename
1302
	# 'tempXXXXX'
1303
	$cleanName = substr($cleanName, 9);
1306
	# 'tempXXXXX' if it exists
1307
	if ( $cleanName =~ /^temp[A-Za-z0-9_]{5}/ && length($cleanName) > 9 ) {
1308
		$cleanName = substr($cleanName, 9);
1309
		
1310
	}
1304 1311

  
1305 1312
	if ( !$docid ) {
1306 1313

  
......
1343 1350
	return ( $docid, \%dataInfo );
1344 1351
}
1345 1352

  
1353
# Returns the docid and SHA1 hash from the colon-delimited string
1346 1354
sub datafileInfo {
1347 1355
	my $finfo = shift;
1348 1356
	$finfo =~ s/ondisk://g;
......
1537 1545
#
1538 1546
################################################################################
1539 1547
sub createXMLDocument {
1540
    if ( $debug_enabled ) {
1541
        debug("createXMLDocument() called.");
1542

  
1543
    }
1544

  
1545

  
1548
	if ( $debug_enabled ) {
1549
	    debug("createXMLDocument() called.");
1550
	
1551
	}
1552
	
1546 1553
	#FIXME placeholder for $FORM element, should be determined by config
1547 1554

  
1548 1555
	if ( $skinName eq "ebm" ) {
......
1558 1565
	$doc .= accessElement();
1559 1566
	$doc .= datasetStart();
1560 1567
	$doc .= titleElement();
1561
	$doc .= creatorNameElement();
1562
	$doc .= creatorElement();
1563

  
1568
	$doc .= createParties('creator');
1569
	if ( $hasMetadataProvider > 0 ) {
1570
		$doc .= createParties('metadataProvider');
1571
		
1572
	} else {
1573
		copyFirstCreator('metadataProvider');
1574
		$doc .= createParties('metadataProvider');
1575
		
1576
	}
1564 1577
	$doc .= pubElement();
1565 1578
	$doc .= setDisplayType('project');
1566 1579
	$doc .= keywordElement();
1567
	$doc .= contactElement();
1580
	if ( $hasContact > 0 ) {
1581
		$doc .= createParties('contact');
1582
		
1583
	} else {
1584
		copyFirstCreator('contact');
1585
		$doc .= createParties('contact');
1586
		
1587
	}
1568 1588

  
1569 1589
	# putting everything else under project
1570 1590
	$doc .= "<project>";
1571 1591
	$doc .= titleElement();
1572
	my %originators = personnelCreate('personnel');
1573
	$doc .= personnelList( \%originators );
1592
	$doc .= createParties('personnel');
1574 1593
	$doc .= abstractElement();
1575 1594
	$doc .= "<studyAreaDescription>\n";
1576 1595
	$doc .= coverageElement();
1577 1596
	$doc .= "</studyAreaDescription>\n";
1578

  
1579 1597
	$doc .= "</project>";
1580 1598
	$doc .= datasetEnd();
1581 1599
	$doc .= EMLEnd();
......
1584 1602

  
1585 1603
sub createDatasetDocument {
1586 1604

  
1587
    if ( $debug_enabled ) {
1588
        debug("createDatasetDocument() called.");
1605
	if ( $debug_enabled ) {
1606
		debug("createDatasetDocument() called.");
1607
	
1608
	}
1589 1609

  
1590
    }
1591

  
1592
    my $doc = EMLStart();
1610
	my $doc = EMLStart();		
1593 1611
	$doc .= accessElement();
1594 1612
	$doc .= datasetStart();
1595 1613
	$doc .= titleElement();
1596
	$doc .= creatorElement();
1597
	$doc .= creatorContactElement();
1598
	my %originators = personnelCreate('associatedParty');
1599
	$doc .= personnelList( \%originators );
1600

  
1614
	$doc .= createParties('creator');
1615
	if ( $hasMetadataProvider > 0 ) {
1616
		$doc .= createParties('metadataProvider');
1617
		
1618
	} else {
1619
		copyFirstCreator('metadataProvider');
1620
		$doc .= createParties('metadataProvider');
1621
		
1622
	}
1623
	$doc .= createParties('associatedParty');
1601 1624
	$doc .= pubElement();
1602 1625
	$doc .= abstractElement();
1603

  
1604
	#    $doc .= setDisplayType('dataset');
1605 1626
	$doc .= keywordElement();
1606 1627
	$doc .= distributionElement();
1607 1628
	$doc .= coverageElement();
1608
	$doc .= contactElement();
1629
	if ( $hasContact > 0 ) {
1630
		$doc .= createParties('contact');
1631
		
1632
	} else {
1633
		copyFirstCreator('contact');
1634
		$doc .= createParties('contact');
1635
		
1636
	}
1637
	$doc .= createParties('publisher');
1609 1638
	$doc .= methodsElement();
1610 1639
	$doc .= fundingElement();
1611 1640
	my %fileData = allFileData();
......
1616 1645

  
1617 1646
# EML document creation functions
1618 1647

  
1619
sub personnelCreate {
1648
# Build a party element based on the party type passed in and the submitted party form fields.
1649
# Party types are limited to:
1650
#     creator, contact, metadataProvider, publisher, personnel, and associatedParty
1651
sub createParties {
1620 1652

  
1621
	# passed parameter defines default role for individuals
1622
	my $defaultRole = shift;
1653
	my $partyType = shift;
1654
	my $partiesStr = "";
1655
	my $partyStr = "";
1656
	my @associatedPartyRoles = [
1657
		'principalInvestigator',
1658
		'coPrincipalInvestigator',
1659
		'collaboratingPrincipalInvestigator',
1660
		'custodianSteward',
1661
		'user'];
1662
	
1663
	# Process the party* parameters, first getting the indexed number
1664
  foreach my $paramName ( param() ) {
1623 1665

  
1624
	# element name => objects of that type
1625
	my %orig = (
1626
		'creator'          => [],
1627
		'metadataProvider' => [],
1628
		'publisher'        => [],
1629
		$defaultRole       => [],
1630
	);
1666
		$partyStr = "";
1667
		my $partyNumber = $paramName;
1668
		$partyNumber =~ s/partyRole//; # indexed number 1, 2, 3, etc
1669
		
1670
		# Check that the party number is valid
1671
		if ( $partyNumber =~ /^([0-9]+)$/) {
1631 1672

  
1632
	# form name => EML element name
1633
	my %roles = (
1634
		'Originator'        => 'creator',
1635
		'Metadata Provider' => 'metadataProvider',
1636
		'Publisher'         => 'publisher',
1637
	);
1673
			# The role we're processing
1674
			my $partyRole = normalize(param("partyRole" . $partyNumber));
1675
			
1676
			# Find the first creator index in the parties if present
1677
			if ( $partyRole eq "creator" && $firstCreatorIndex == -1 ) {
1678
				$firstCreatorIndex = $partyNumber;
1679
			} 
1638 1680

  
1639
	push(
1640
		@{ $orig{'metadataProvider'} },
1641
		[ $FORM::providerGivenName, $FORM::providerSurName ]
1642
	);
1681
			# Find the first metadataProvider in the parties if present
1682
			if ( $partyRole eq "metadataProvider" ) {
1683
				$hasMetadataProvider = 1;
1684
			} 
1643 1685

  
1644
	# Additional originators
1645
	foreach my $origName ( param() ) {
1646
		my $origNum = $origName;
1647
		$origNum =~ s/origNamelast//;   # get the index of the parameter 0 to 10
1648
		if ( $origNum =~ /^([0-9]+)$/ ) {
1686
			# Find the first contact in the parties if present
1687
			if ( $partyRole eq "contact" ) {
1688
				$hasContact = 1;
1689
			} 
1649 1690

  
1650
			# do not generate EML for empty originator fields
1651
			if ( hasContent( param( "origNamefirst" . $origNum ) ) ) {
1652
				my $first    = normalize( param( "origNamefirst" . $origNum ) );
1653
				my $last     = normalize( param( "origNamelast" . $origNum ) );
1654
				my $origRole = param( "origRole" . $origNum );
1655
				my $roleName = $roles{$origRole};
1656
				if ( !hasContent($roleName) ) {
1657
					$roleName = $defaultRole;
1658
				}
1659

  
1660
				push( @{ $orig{$roleName} }, [ $first, $last, $origRole ] );
1691
			# Process roles corresponding to specific EML elements
1692
			if ( $partyRole eq $partyType ) {
1693
                debug("Role: " . $partyRole . " matches Type: " . $partyType );
1694
				$partyStr = createParty( $partyType, $partyRole, $partyNumber); 
1695
			# handle associated parties
1696
			} elsif ( $partyType eq "associatedParty" && $partyRole ~~ @associatedPartyRoles ) {
1697
				$partyStr = createParty( $partyType, $partyRole, $partyNumber); 
1698
                debug("Asscociated Party Type: " . $partyType . " and Role: " . $partyRole . " is in @associatedPartyRoles");
1699
				
1700
			# handle personnel
1701
			} elsif ( $partyType eq "personnel" && $partyRole ~~ @associatedPartyRoles ) {
1702
				$partyStr = createParty( $partyType, $partyRole, $partyNumber); 
1703
                debug("Personnel Type: " . $partyType . " and Role: " . $partyRole . " is in @associatedPartyRoles");
1704
			
1661 1705
			}
1662 1706
		}
1663
	}
1664
	return %orig;
1707
		$partiesStr .= $partyStr;
1708
  }	
1709
	
1710
	return $partiesStr;
1665 1711
}
1666 1712

  
1667
sub personnelList {
1668
	my ( $orig, $type ) = @_;
1669
	my %orig = %$orig;
1713
# Build an EML party based on the given element type (creator, associatedParty, contact, publisher, personnel)
1714
sub createParty() {
1715
	my $partyType = shift;
1716
	my $partyRole = shift;
1717
	my $partyNumber = shift;
1718
	
1719
	my $partyStr         = "";
1720
	my $partyRole        = "";						
1721
	my $partyId          = "";		
1722
	my $partyFirstName   = "";		
1723
	my $partyLastName    = "";		
1724
	my $partyOrgName     = "";		
1725
	my $partyPositionName = "";		
1726
	my $partyEmail       = "";		
1727
	my $partyURL         = "";		
1728
	my $partyPhone       = "";		
1729
	my $partyFAX         = "";		
1730
	my $partyDelivery    = "";		
1731
	my $partyCity        = "";		
1732
	my $partyState       = "";		
1733
	my $partyStateOther  = "";		
1734
	my $partyZIP         = "";		
1735
	my $partyCountry     = "";		
1736
	my $individualName   = "";
1737
	my $organizationName = "";
1738
	my $positionName     = "";
1739
	my $address          = "";
1740
	my $phone            = "";
1741
	my $fax              = ""; 
1742
	my $email            = "";
1743
	my $onlineUrl        = "";
1744
	my $role             = "";
1745
	
1746
	if ( hasContent(param("partyRole" . $partyNumber))) {
1747
		$partyRole = normalize(param("partyRole" . $partyNumber));
1748
		$role .= "<role>";
1749
		$role .= $partyRole;
1750
		$role .= "</role>\n";
1751
	}
1752
							
1753
	if ( hasContent(param("partyId" . $partyNumber))) {
1754
		$partyId = normalize(param("partyId" . $partyNumber));
1755
		
1756
	} else {
1757
		$partyId = int(rand(10000000000000000));
1758
	}
1759
			
1760
	if ( hasContent(param("partyLastName" . $partyNumber))) {
1761
		$individualName .= "<individualName>\n";
1762
		if ( hasContent(param("partyFirstName" . $partyNumber))) {
1763
			$partyFirstName = normalize(param("partyFirstName" . $partyNumber));
1764
			$individualName .= "<givenName>";
1765
			$individualName .= $partyFirstName;
1766
			$individualName .= "</givenName>\n";
1767
			
1768
		}
1769
		$partyLastName = normalize(param("partyLastName" . $partyNumber));
1770
		$individualName .= "<surName>";
1771
		$individualName .= $partyLastName;
1772
		$individualName .= "</surName>\n";
1773
		$individualName .= "</individualName>\n";
1774
			
1775
	}
1776
			
1777
	if ( hasContent(param("partyOrgName" . $partyNumber))) {
1778
		$organizationName .= "<organizationName>";
1779
		$partyOrgName = normalize(param("partyOrgName" . $partyNumber));
1780
		$organizationName .= $partyOrgName;
1781
		$organizationName .= "</organizationName>\n";
1782
		
1783
	}
1784
	
1785
	if ( hasContent(param("partyPositionName" . $partyNumber))) {
1786
		$positionName .= "<positionName>";
1787
		$partyPositionName = normalize(param("partyPositionName" . $partyNumber));
1788
		$positionName .= $partyPositionName;
1789
		$positionName .= "</positionName>\n";
1790
		
1791
	}
1792
	
1793
	$address .= "<address>";
1794
	
1795
	if ( hasContent(param("partyDelivery" . $partyNumber))) {
1796
		$partyDelivery = normalize(param("partyDelivery" . $partyNumber));
1797
		$address .= "<deliveryPoint>";
1798
		$address .= $partyDelivery;
1799
		$address .= "</deliveryPoint>\n";
1800
		
1801
	}
1802
			
1803
	if ( hasContent(param("partyCity" . $partyNumber))) {
1804
		$partyCity = normalize(param("partyCity" . $partyNumber));
1805
		$address .= "<city>";
1806
		$address .= $partyCity;
1807
		$address .= "</city>\n";
1808
		
1809
	}
1810
			
1811
	if ( hasContent(param("partyState" . $partyNumber))) {
1812
		$partyState = normalize(param("partyState" . $partyNumber));
1813
		$address .= "<administrativeArea>";
1814
		$address .= $partyState;
1815
		$address .= "</administrativeArea>\n";
1816
		
1817
	} elsif ( hasContent(param("partyStateOther" . $partyNumber))) {
1818
		$partyStateOther = normalize(param("partyStateOther" . $partyNumber));
1819
		$address .= "<administrativeArea>";
1820
		$address .= $partyStateOther;
1821
		$address .= "</administrativeArea>\n";
1822
	}
1823
			
1824
	if ( hasContent(param("partyZIP" . $partyNumber))) {
1825
		$partyZIP = normalize(param("partyZIP" . $partyNumber));
1826
		$address .= "<postalCode>";
1827
		$address .= $partyZIP;
1828
		$address .= "</postalCode>\n";
1829
		
1830
	}
1831
		
1832
	if ( hasContent(param("partyCountry" . $partyNumber))) {
1833
		$partyCountry = normalize(param("partyCountry" . $partyNumber));
1834
		$address .= "<country>";
1835
		$address .= $partyCountry;
1836
		$address .= "</country>\n";
1837
		
1838
	}
1839
	
1840
	$address .= "</address>\n";
1670 1841

  
1671
	my $elemList = "";
1672
	foreach my $role ( keys %orig ) {
1673
		foreach my $v ( @{ $orig->{$role} } ) {
1674
			my ( $first, $last, $origRole ) = @$v;
1675
			my $elem = "<individualName>\n";
1676
			$elem .= "<givenName>" . normalize($first) . "</givenName>\n";
1677
			$elem .= "<surName>" . normalize($last) . "</surName>\n";
1678
			$elem .= "</individualName>\n";
1842
	if ( hasContent(param("partyPhone" . $partyNumber))) {
1843
		$partyPhone = normalize(param("partyPhone" . $partyNumber));
1844
		$phone .= "<phone phonetype=\"voice\">";
1845
		$phone .= $partyPhone;
1846
		$phone .= "</phone>\n";
1847
	}
1848
			
1849
	if ( hasContent(param("partyFAX" . $partyNumber))) {
1850
		$partyFAX = normalize(param("partyFAX" . $partyNumber));
1851
		$fax .= "<phone phonetype=\"facsimile\">";
1852
		$fax .= $partyFAX;
1853
		$fax .= "</phone>\n";
1854
		
1855
	}
1856
	
1857
	if ( hasContent(param("partyEmail" . $partyNumber))) {
1858
		$partyEmail = normalize(param("partyEmail" . $partyNumber));
1859
		$email .= "<electronicMailAddress>";
1860
		$email .= $partyEmail;
1861
		$email .= "</electronicMailAddress>\n";
1862
	}
1863
					
1864
	if ( hasContent(param("partyURL" . $partyNumber))) {
1865
		$partyURL = normalize(param("partyURL" . $partyNumber));
1866
		$onlineUrl .= "<onlineUrl>";
1867
		$onlineUrl .= $partyURL;
1868
		$onlineUrl .= "</onlineUrl>\n";
1869
	}
1870
					
1871
	# add the party begin tag (like <creator>)
1872
	$partyStr .= "<" . $partyType . " id=\"" . $partyId ."\">\n";
1873
	
1874
	# add in the person
1875
	if ( $individualName ne "" ) {
1876
		$partyStr .= $individualName;
1877
		
1878
	} 
1679 1879

  
1680
			if ( ( $role eq 'personnel' ) && ($FORM::origNameOrgContact) ) {
1681
				$elem .= "<organizationName>$FORM::origNameOrgContact</organizationName>\n";
1682
			}
1880
	# add in the organization
1881
	if ( $organizationName ne "" ) {
1882
		$partyStr .= $organizationName;
1883
		
1884
	} 
1683 1885

  
1684
			if ( ( $role eq 'personnel' ) || ( $role eq 'associatedParty' ) ) {
1685
				my $roleElem = $role;
1686
				if ( hasContent($origRole) ) {
1687
					$roleElem = $origRole;
1688
				}
1689
				$elem .= "<role>" . normalize($roleElem) . "</role>\n";
1690
			}
1691
                        # Ensure the metadataProvider is added before additionalParty
1692
                        my $fullElement = "<$role>$elem</$role>\n";
1693
                        if ( $role eq "metadataProvider" ) {
1694
				$fullElement .= $elemList;
1695
				$elemList = $fullElement;
1886
	# add in the position
1887
	if ( $positionName ne "" ) {
1888
		$partyStr .= $positionName;
1889
		
1890
	} 
1696 1891

  
1697
                        } else {
1698
				$elemList .= $fullElement;
1892
	# add in the address
1893
	if ( $address ne "" || $address ne "<address></address>\n") {
1894
		$partyStr .= $address;
1895
		
1896
	} 
1699 1897

  
1700
			}
1701
		}
1898
	# add in the phone
1899
	if ( $phone ne "") {
1900
		$partyStr .= $phone;
1901
		
1902
	} 
1903

  
1904
	# add in the fax
1905
	if ( $fax ne "") {
1906
		$partyStr .= $fax;
1907
		
1908
	} 
1909

  
1910
	# add in the email
1911
	if ( $email ne "") {
1912
		$partyStr .= $email;
1913
		
1702 1914
	}
1703
	return $elemList;
1915
	
1916
	# add in the online URL
1917
	if ( $onlineUrl ne "") {
1918
		$partyStr .= $onlineUrl;
1919
		
1920
	}
1921
	
1922
	if ( $partyType eq "associatedParty" || $partyType eq "personnel" ) {
1923
			$partyStr .= $role;
1924
			
1925
	}
1926

  
1927
	# add the party end tag (like </creator>)
1928
	$partyStr .= "</" . $partyType . ">\n";
1929
			
1704 1930
}
1705 1931

  
1706 1932
sub entityElement() {
......
1899 2125
	  . "</para>\n</abstract>\n";
1900 2126
}
1901 2127

  
1902
sub creatorElement() {
2128
sub partyElement() {
1903 2129
	my $creators;
1904 2130
	if ( $skinName eq 'nceas' ) {
1905 2131
		for ( my $i = 0 ; $i < scalar(@FORM::wg) ; $i++ ) {
......
1943 2169

  
1944 2170
	$creator .= "<individualName>\n";
1945 2171
	$creator .=
1946
	  "<givenName>" . normalize($FORM::origNamefirst0) . "</givenName>\n";
1947
	$creator .= "<surName>" . normalize($FORM::origNamelast0) . "</surName>\n";
2172
	  "<givenName>" . normalize($FORM::partyFirstName0) . "</givenName>\n";
2173
	$creator .= "<surName>" . normalize($FORM::partyLastName0) . "</surName>\n";
1948 2174
	$creator .= "</individualName>\n";
1949 2175

  
1950 2176
	return "<$role>\n$creator</$role>\n";
......
1983 2209
}
1984 2210

  
1985 2211
sub fundingElement() {
1986
    my $project = "";
2212
	if ( $debug_enabled ) {
2213
		debug("fundingElement() called.");
2214
	}
2215
		
2216
		my $project = "";
1987 2217

  
1988 2218
    if ( hasContent($FORM::funding) ) {
1989 2219

  
......
1997 2227
        $project .= "<personnel>\n" .
1998 2228
                    "<individualName>\n" .
1999 2229
                    "<givenName>" .
2000
                    normalize($FORM::origNamefirst0) .
2230
                    normalize($FORM::partyFirstName0) .
2001 2231
                    "</givenName>\n" .
2002 2232
                    "<surName>" .
2003
                    normalize($FORM::origNamelast0) .
2233
                    normalize($FORM::partyLastName0) .
2004 2234
                    "</surName>\n" .
2005 2235
                    "</individualName>\n";
2006 2236
        # Add a default role
......
2008 2238
                    "</personnel>\n";
2009 2239

  
2010 2240
        # Add the funding info (grant number)
2011
        $project .= "<funding>" .
2012
                    normalize($FORM::funding) .
2013
                    "</funding>\n";
2241
        $project .= "<funding>\n";                    
2242

  
2243
        # split funding by comma delimiter
2244
        my $funding = normalize($FORM::funding);
2245
        foreach my $para (split(',', $funding)) {
2246
        	$project .= "<para>" .
2247
                    $para .
2248
                    "</para>\n";
2249
        }
2250
                    
2251
        $project .= "</funding>\n";                    
2014 2252
        $project .= "</project>\n";
2015 2253
    }
2016 2254

  
2017 2255
    return $project;
2018 2256
}
2019 2257

  
2020
sub creatorContactElement() {
2258
sub partyElement() {
2021 2259
	my $cont = "";
2260
	if ( hasContent($FORM::partyLastName) ) {
2261
		$cont .= "<individualName>\n";
2262
		if ( hasContent($FORM::partyFirstName) ) {
2263
			$cont .= "<givenName>" . normalize($FORM::partyFirstName) . "</givenName>\n";
2264
		}
2265
		$cont .= "<surName>" . normalize($FORM::partyLastName) . "</surName>\n";
2266
		$cont .= "</individualName>\n";
2267
	}
2022 2268

  
2023
	$cont .= "<individualName>\n";
2024
	$cont .=
2025
	  "<givenName>" . normalize($FORM::origNamefirst0) . "</givenName>\n";
2026
	$cont .=
2027
	  "<surName>" . normalize($FORM::origNamelast0) . "</surName>\n";
2028
	$cont .= "</individualName>\n";
2029

  
2030
	if ( hasContent($FORM::origNameOrg) ) {
2269
	if ( hasContent($FORM::partyOrgName) ) {
2031 2270
		$cont .=
2032 2271
		    "<organizationName>"
2033
		  . normalize($FORM::origNameOrg)
2272
		  . normalize($FORM::partyOrgName)
2034 2273
		  . "</organizationName>\n";
2035 2274
	}
2036 2275

  
2037
	if (   hasContent($FORM::origDelivery)
2038
		|| hasContent($FORM::origCity)
2039
		|| hasContent($FORM::origState)
2040
		|| hasContent($FORM::origStateOther)
2041
		|| hasContent($FORM::origZIP)
2042
		|| hasContent($FORM::origCountry) )
2276
	if (   hasContent($FORM::partyDelivery)
2277
		|| hasContent($FORM::partyCity)
2278
		|| hasContent($FORM::partyState)
2279
		|| hasContent($FORM::partyStateOther)
2280
		|| hasContent($FORM::partyZIP)
2281
		|| hasContent($FORM::partyCountry) )
2043 2282
	{
2044 2283
		$cont .= "<address>\n";
2045
		if ( hasContent($FORM::origDelivery) ) {
2046
			$cont .= "<deliveryPoint>" . normalize($FORM::origDelivery);
2284
		if ( hasContent($FORM::partyDelivery) ) {
2285
			$cont .= "<deliveryPoint>" . normalize($FORM::partyDelivery);
2047 2286
			$cont .= "</deliveryPoint>\n";
2048 2287
		}
2049
		if ( hasContent($FORM::origCity) ) {
2050
			$cont .= "<city>" . normalize($FORM::origCity) . "</city>\n";
2288
		if ( hasContent($FORM::partyCity) ) {
2289
			$cont .= "<city>" . normalize($FORM::partyCity) . "</city>\n";
2051 2290
		}
2052
		if ( hasContent($FORM::origState)
2053
			&& ( $FORM::origState !~ /select state/i ) )
2291
		if ( hasContent($FORM::partyState)
2292
			&& ( $FORM::partyState !~ /select state/i ) )
2054 2293
		{
2055 2294
			$cont .=
2056
			  "<administrativeArea>" . normalize($FORM::origState);
2295
			  "<administrativeArea>" . normalize($FORM::partyState);
2057 2296
			$cont .= "</administrativeArea>\n";
2058 2297
		}
2059
		elsif ( hasContent($FORM::origStateOther) ) {
2298
		elsif ( hasContent($FORM::partyStateOther) ) {
2060 2299
			$cont .=
2061
			  "<administrativeArea>" . normalize($FORM::origStateOther);
2300
			  "<administrativeArea>" . normalize($FORM::partyStateOther);
2062 2301
			$cont .= "</administrativeArea>\n";
2063 2302
		}
2064
		if ( hasContent($FORM::origZIP) ) {
2303
		if ( hasContent($FORM::partyZIP) ) {
2065 2304
			$cont .=
2066 2305
			    "<postalCode>"
2067
			  . normalize($FORM::origZIP)
2306
			  . normalize($FORM::partyZIP)
2068 2307
			  . "</postalCode>\n";
2069 2308
		}
2070
		if ( hasContent($FORM::origCountry) ) {
2309
		if ( hasContent($FORM::partyCountry) ) {
2071 2310
			$cont .=
2072 2311
			    "<country>"
2073
			  . normalize($FORM::origCountry)
2312
			  . normalize($FORM::partyCountry)
2074 2313
			  . "</country>\n";
2075 2314
		}
2076 2315
		$cont .= "</address>\n";
2077 2316
	}
2078
	if ( hasContent($FORM::origPhone) ) {
2079
		$cont .= "<phone>" . normalize($FORM::origPhone) . "</phone>\n";
2317
	if ( hasContent($FORM::partyPhone) ) {
2318
		$cont .= "<phone>" . normalize($FORM::partyPhone) . "</phone>\n";
2080 2319
	}
2081
	if ( hasContent($FORM::origFAXContact) ) {
2320
	if ( hasContent($FORM::partyFAXContact) ) {
2082 2321
		$cont .=
2083 2322
		    "<phone phonetype=\"Fax\">"
2084
		  . normalize($FORM::origFAXContact)
2323
		  . normalize($FORM::partyFAXContact)
2085 2324
		  . "</phone>\n";
2086 2325
	}
2087
	if ( hasContent($FORM::origEmail) ) {
2088
		$cont .= "<electronicMailAddress>" . normalize($FORM::origEmail);
2326
	if ( hasContent($FORM::partyEmail) ) {
2327
		$cont .= "<electronicMailAddress>" . normalize($FORM::partyEmail);
2089 2328
		$cont .= "</electronicMailAddress>\n";
2090 2329
	}
2091 2330

  
2331
	if ( hasContent($FORM::partyURL) ) {
2332
		$cont .= "<onlineUrl>" . normalize($FORM::partyURL);
2333
		$cont .= "</onlineUrl>\n";
2334
	}
2335

  
2092 2336
	return "<creator>\n$cont</creator>\n";
2093 2337
}
2094 2338

  
......
2102 2346

  
2103 2347
	$cont .= "<individualName>\n";
2104 2348
	$cont .=
2105
	  "<givenName>" . normalize($FORM::origNamefirstContact) . "</givenName>\n";
2349
	  "<givenName>" . normalize($FORM::partyFirstNameContact) . "</givenName>\n";
2106 2350
	$cont .=
2107
	  "<surName>" . normalize($FORM::origNamelastContact) . "</surName>\n";
2351
	  "<surName>" . normalize($FORM::partyLastNameContact) . "</surName>\n";
2108 2352
	$cont .= "</individualName>\n";
2109 2353

  
2110
	if ( hasContent($FORM::origNameOrgContact) ) {
2354
	if ( hasContent($FORM::partyOrgNameContact) ) {
2111 2355
		$cont .=
2112 2356
		    "<organizationName>"
2113
		  . normalize($FORM::origNameOrgContact)
2357
		  . normalize($FORM::partyOrgNameContact)
2114 2358
		  . "</organizationName>\n";
2115 2359
	}
2116 2360

  
......
2699 2943

  
2700 2944
################################################################################
2701 2945
#
2946
# Parse getaccesscontrol XML response
2947
# from Metacat and return the allow elements
2948
#
2949
################################################################################
2950
sub getAllowAccess {
2951
	
2952
	my $docid = shift;
2953
	debug("looking up access control block for docid: $docid");
2954
	
2955
	# read the access control block
2956
	my $parser = XML::LibXML->new();
2957

  
2958
	my $metacat = Metacat->new($metacatUrl);
2959
    setAuthToken($metacat);
2960
    
2961
	my $response = $metacat->getaccess($docid);
2962
	my $doc    = $response->content();
2963
	debug("Retrieved access control block: $doc");
2964
	my $xmldoc = $parser->parse_string($doc);
2965
	if ( $xmldoc eq "" || $doc =~ /<error/ ) {
2966

  
2967
		# not able to parse
2968
		my $errorMessage =
2969
		  "Error in retrieving access control for docid:" . $docid;
2970
		  
2971
	}
2972
	
2973
	# return the allow access nodes
2974
	my $results = $xmldoc->findnodes('/access/allow');
2975

  
2976
	return $results;
2977
}
2978

  
2979
################################################################################
2980
#
2702 2981
# Parse an EML 2.x file and extract the metadata into perl variables for
2703 2982
# processing and returning to the template processor
2704 2983
#
......
2712 2991
	my $node;
2713 2992
	my $tempResult;
2714 2993
	my $tempNode;
2715
	my $aoCount = 0;
2994
	my $partyCount = 0;
2716 2995
	my $foundDSO;
2717 2996

  
2718 2997
	# set variable values
......
2724 3003
	# perform any required transformation
2725 3004
	$doc = transformEml($doc);
2726 3005

  
2727
	# find out the tag <alternateIdentifier>.
3006
	# Find <alternateIdentifier>.
2728 3007
	$results = $doc->findnodes('//dataset/alternateIdentifier');
2729 3008
	if ( $results->size() > 0 ) {		
2730 3009
		# handle multiple alternate identifiers
......
2740 3019
	}
2741 3020
	
2742 3021

  
2743
	# find out the tag <title>.
3022
	# Find <title>.
2744 3023
	$results = $doc->findnodes('//dataset/title');
2745 3024
	if ( $results->size() > 1 ) {
2746 3025
		errMoreThanOne("title");
2747
	}
2748
	elsif ( $results->size() < 1 ) {
3026
		
3027
	} elsif ( $results->size() < 1 ) {
2749 3028
		$error = "Following tag not found: title. Please use Morpho to edit this document";
2750 3029
		push( @errorMessages, $error . "\n" );
2751
	}
2752
	else {
3030
		
3031
	} else {
2753 3032
		foreach $node ( $results->get_nodelist ) {
2754 3033
			$$templateVars{'title'} = findValue( $node, '../title' );
2755 3034
		}
3035
		
2756 3036
	}
2757 3037

  
2758
	# find out the tag <creator>.
2759
	$results = $doc->findnodes('//dataset/creator/individualName');
2760
	debug( "Creators: " . $results->size() );
2761
	foreach $node ( $results->get_nodelist ) {
2762
		dontOccur(
2763
			$node,
2764
			"../positionName|../onlineURL|../userId",
2765
			"positionName, onlineURL, userId"
2766
		);
3038
	# Find <creator>s 
3039
	populatePartyFields(\$doc, "//dataset/creator", \$partyCount);
3040
	
3041
	# Find <metadataProvider>s 
3042
	populatePartyFields(\$doc, "//dataset/metadataProvider", \$partyCount);
2767 3043

  
2768
		dontOccur( $node, "./salutation", "salutation" );
3044
	# Find <associatedParty>s 
3045
	populatePartyFields(\$doc, "//dataset/associatedParty", \$partyCount);
2769 3046

  
2770
		debug("Checking a creator in loop 1...");
2771
		$tempResult = $node->findnodes(
2772
			'../address|../phone|../electronicmailAddress|../organizationName');
2773
		if ( $tempResult->size > 0 ) {
2774
			if ( $foundDSO == 0 ) {
2775
				$foundDSO = 1;
3047
	# Find <publisher>s 
3048
	populatePartyFields(\$doc, "//dataset/publisher", \$partyCount);
2776 3049

  
2777
				debug("Recording a creator in loop 1...");
2778
				$$templateVars{'origNamefirst0'} =
2779
				  findValue( $node, 'givenName' );
2780
				$$templateVars{'origNamelast0'} = findValue( $node, 'surName' );
3050
	# Find <contact>s 
3051
	populatePartyFields(\$doc, "//dataset/contact", \$partyCount);
2781 3052

  
2782
				my $tempResult2 = $node->findnodes('../address');
2783
				if ( $tempResult2->size > 1 ) {
2784
					errMoreThanOne("address");
2785
				}
2786
				else {
2787
					foreach my $tempNode2 ( $tempResult2->get_nodelist ) {
2788
						$$templateVars{'origDelivery'} =
2789
						  findValue( $tempNode2, 'deliveryPoint' );
2790
						$$templateVars{'origCity'} =
2791
						  findValue( $tempNode2, 'city' );
2792
						$$templateVars{'origState'} =
2793
						  findValue( $tempNode2, 'administrativeArea' );
2794
						$$templateVars{'origZIP'} =
2795
						  findValue( $tempNode2, 'postalCode' );
2796
						$$templateVars{'origCountry'} =
2797
						  findValue( $tempNode2, 'country' );
2798
					}
2799
				}
3053
	$$templateVars{'partyCount'} = $partyCount;
2800 3054

  
2801
				my $tempResult3 = $node->findnodes('../phone');
2802
				if ( $tempResult3->size > 2 ) {
2803
					errMoreThanN("phone");
2804
				}
2805
				else {
2806
					foreach my $tempNode2 ( $tempResult3->get_nodelist ) {
2807
						if ( $tempNode2->hasAttributes() ) {
2808
							my @attlist = $tempNode2->attributes();
2809
							if ( $attlist[0]->value eq "Fax" ) {
2810
								$$templateVars{'origFAX'} =
2811
								  $tempNode2->textContent();
2812
							}
2813
							else {
2814
								$$templateVars{'origPhone'} =
2815
								  $tempNode2->textContent();
2816
							}
2817
						}
2818
						else {
2819
							$$templateVars{'origPhone'} =
2820
							  $tempNode2->textContent();
2821
						}
2822
					}
2823
				}
2824
				$$templateVars{'origEmail'} =
2825
				  findValue( $node, '../electronicMailAddress' );
2826
				$$templateVars{'origNameOrg'} =
2827
				  findValue( $node, '../organizationName' );
2828
			}
2829
			else {
2830
				errMoreThanN("address, phone and electronicMailAddress");
2831
			}
2832
		}
2833
	}
2834
	foreach $node ( $results->get_nodelist ) {
2835
		debug("Checking a creator in loop 2...");
2836
		$tempResult = $node->findnodes(
2837
			'../address|../phone|../electronicmailAddress|../organizationName');
2838
		if ( $tempResult->size == 0 ) {
2839
			if ( $foundDSO == 0 ) {
2840
				debug("Recording a creator in loop 2 block A...");
2841
				$foundDSO = 1;
2842
				$$templateVars{'origNamefirst0'} =
2843
				  findValue( $node, 'givenName' );
2844
				$$templateVars{'origNamelast0'} = findValue( $node, 'surName' );
2845
				$$templateVars{'origNameOrg'} =
2846
				  findValue( $node, '../organizationName' );
2847
			}
2848
			else {
2849
				debug("Recording a creator in loop 2 block B...");
2850
				$$templateVars{"origNamefirst$aoCount"} =
2851
				  findValue( $node, './givenName' );
2852
				$$templateVars{"origNamelast$aoCount"} =
2853
				  findValue( $node, './surName' );
2854
				$$templateVars{"origRole$aoCount"} = "Originator";
2855
				$aoCount++;
2856
			}
2857
		}
2858
	}
2859

  
2860
	$results = $doc->findnodes('//dataset/creator/organizationName');
2861
	my $wgroups = $doc->findnodes(
2862
		"//dataset/creator/organizationName[contains(text(),'(NCEAS ')]");
2863
	debug( "Number Org: " . $results->size() );
2864
	debug( " Number WG: " . $wgroups->size() );
2865
	if ( $results->size() - $wgroups->size() > 3 ) {
2866
		errMoreThanN("creator/organizationName");
2867
	}
2868
	else {
2869
		foreach $node ( $results->get_nodelist ) {
2870
			my $tempValue = findValue( $node, '../organizationName' );
2871
			$tempResult = $node->findnodes('../individualName');
2872
			if (   $tempResult->size == 0
2873
				&& $tempValue ne $config->{'organization'} )
2874
			{
2875
				$$templateVars{'site'} = $tempValue;
2876
			}
2877
		}
2878
		if ( $skinName eq 'nceas' ) {
2879
			my @wg;
2880
			foreach $node ( $results->get_nodelist ) {
2881
				my $tempValue = findValue( $node, '../organizationName' );
2882
				$wg[ scalar(@wg) ] = $tempValue;
2883
			}
2884
			my $projects = getProjectList($properties);
2885
			$$templateVars{'projects'} = $projects;
2886
			$$templateVars{'wg'}       = \@wg;
2887
		}
2888
	}
2889

  
2890
	$results = $doc->findnodes('//dataset/metadataProvider');
2891
	foreach $node ( $results->get_nodelist ) {
2892
		dontOccur(
2893
			$node,
2894
"./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address",
2895
"organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in metadataProvider"
2896
		);
2897

  
2898
		$tempResult = $node->findnodes('./individualName');
2899
		if ( $tempResult->size > 1 ) {
2900
			errMoreThanOne("metadataProvider/indvidualName");
2901
		}
2902
		else {
2903
			foreach $tempNode ( $tempResult->get_nodelist ) {
2904
				if ( $$templateVars{'providerGivenName'} ne "" ) {
2905
					$$templateVars{"origNamefirst$aoCount"} =
2906
					  findValue( $tempNode, './givenName' );
2907
					$$templateVars{"origNamelast$aoCount"} =
2908
					  findValue( $tempNode, './surName' );
2909
					$$templateVars{"origRole$aoCount"} = "Metadata Provider";
2910
					$aoCount++;
2911
				}
2912
				else {
2913
					$$templateVars{'providerGivenName'} =
2914
					  findValue( $tempNode, './givenName' );
2915
					$$templateVars{'providerSurName'} =
2916
					  findValue( $tempNode, './surName' );
2917
				}
2918
			}
2919
		}
2920
	}
2921

  
2922
	$results = $doc->findnodes('//dataset/associatedParty');
2923
	foreach $node ( $results->get_nodelist ) {
2924
		dontOccur(
2925
			$node,
2926
"./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address",
2927
"organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in associatedParty"
2928
		);
2929

  
2930
		$tempResult = $node->findnodes('./individualName');
2931
		if ( $tempResult->size > 1 ) {
2932
			errMoreThanOne("associatedParty/indvidualName");
2933
		}
2934
		else {
2935
			foreach $tempNode ( $tempResult->get_nodelist ) {
2936
				$$templateVars{"origNamefirst$aoCount"} =
2937
				  findValue( $tempNode, './givenName' );
2938
				$$templateVars{"origNamelast$aoCount"} =
2939
				  findValue( $tempNode, './surName' );
2940
				$$templateVars{"origRole$aoCount"} =
2941
				  findValue( $tempNode, '../role' );
2942
				$aoCount++;
2943
			}
2944
		}
2945
	}
2946

  
2947
	$results = $doc->findnodes('//dataset/publisher');
2948

  
2949
	#    if ($results->size() > 10) {
2950
	#       errMoreThanN("publisher");
2951
	#   } else {
2952
	foreach $node ( $results->get_nodelist ) {
2953
		dontOccur(
2954
			$node,
2955
			"./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address",
2956
			"organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in associatedParty"
2957
		);
2958

  
2959
		$tempResult = $node->findnodes('./individualName');
2960
		if ( $tempResult->size > 1 ) {
2961
			errMoreThanOne("publisher/indvidualName");
2962
		}
2963
		else {
2964
			foreach $tempNode ( $tempResult->get_nodelist ) {
2965
				$$templateVars{"origNamefirst$aoCount"} =
2966
				  findValue( $tempNode, './givenName' );
2967
				$$templateVars{"origNamelast$aoCount"} =
2968
				  findValue( $tempNode, './surName' );
2969
				$$templateVars{"origRole$aoCount"} = "Publisher";
2970
				$aoCount++;
2971
			}
2972
		}
2973
	}
2974

  
2975
	#  }
2976

  
2977
	#  if ($aoCount > 11) {
2978
	#      errMoreThanN("Additional Originators");
2979
	#   }
2980

  
2981
	$$templateVars{'aoCount'} = $aoCount;
2982

  
2983 3055
	dontOccur( $doc, "./pubDate",  "pubDate" );
2984 3056
	dontOccur( $doc, "./language", "language" );
2985 3057
	dontOccur( $doc, "./series",   "series" );
......
3043 3115
			dontOccur( $node, "./section", "section in intellectualRights" );
3044 3116

  
3045 3117
			$tempResult = $node->findnodes("para");
3046
			if ( $tempResult->size > 2 ) {
3118
			if ( $tempResult->size() > 2 ) {
3047 3119
				errMoreThanN("para");
3048 3120
			}
3049 3121
			else {
......
3129 3201
		foreach $node ( $results->get_nodelist ) {
3130 3202
			dontOccur(
3131 3203
				$node,
3132
				"./temporalCoverage/rangeOfDates/beginDate/time|./temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale|./temporalCoverage/rangeOfDates/endDate/time|./temporalCoverage/rangeOfDates/endDate/alternativeTimeScale|./taxonomicCoverage/taxonomicSystem|./taxonomicCoverage/taxonomicClassification/commonName|./taxonomicCoverage/taxonomicClassification/taxonomicClassification|./geographicCoverage/datasetGPolygon|./geographicCoverage/boundingCoordinates/boundingAltitudes",
3133
				"temporalCoverage/rangeOfDates/beginDate/time, /temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale, /temporalCoverage/rangeOfDates/endDate/time, /temporalCoverage/rangeOfDates/endDate/alternativeTimeScale, /taxonomicCoverage/taxonomicSystem, /taxonomicCoverage/taxonomicClassification/commonName, /taxonomicCoverage/taxonomicClassification/taxonomicClassification, /geographicCoverage/datasetGPolygon, /geographicCoverage/boundingCoordinates/boundingAltitudes"
3204
				"./temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale|./temporalCoverage/rangeOfDates/endDate/alternativeTimeScale|./taxonomicCoverage/taxonomicSystem|./taxonomicCoverage/taxonomicClassification/commonName|./taxonomicCoverage/taxonomicClassification/taxonomicClassification|./geographicCoverage/datasetGPolygon|./geographicCoverage/boundingCoordinates/boundingAltitudes",
3205
				"/temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale, /temporalCoverage/rangeOfDates/endDate/alternativeTimeScale, /taxonomicCoverage/taxonomicSystem, /taxonomicCoverage/taxonomicClassification/commonName, /taxonomicCoverage/taxonomicClassification/taxonomicClassification, /geographicCoverage/datasetGPolygon, /geographicCoverage/boundingCoordinates/boundingAltitudes"
3134 3206
			);
3135 3207

  
3136 3208
			$tempResult = $node->findnodes('./temporalCoverage');
3137
			if ( $tempResult->size > 1 ) {
3209
			if ( $tempResult->size() > 1 ) {
3138 3210
				errMoreThanOne("temporalCoverage");
3139 3211
			}
3140 3212
			else {
......
3171 3243
			}
3172 3244

  
3173 3245
			$tempResult = $node->findnodes('./geographicCoverage');
3174
			if ( $tempResult->size > 1 ) {
3246
			if ( $tempResult->size() > 1 ) {
3175 3247
				errMoreThanOne("geographicCoverage");
3176 3248
			}
3177 3249
			else {
......
3282 3354
	dontOccur( $doc, "./purpose",     "purpose" );
3283 3355
	dontOccur( $doc, "./maintenance", "maintnance" );
3284 3356

  
3285
	$results = $doc->findnodes('//dataset/contact/individualName');
3286
	if ( $results->size() > 1 ) {
3287
		errMoreThanOne("contact/individualName");
3288
	}
3289
	else {
3290
		foreach $node ( $results->get_nodelist ) {
3291
			dontOccur(
3292
				$node,
3293
				"../positionName|../onlineURL|../userId",
3294
				"positionName, onlineURL, userId in contact tag"
3295
			);
3296
			dontOccur( $node, "./saluation", "saluation in contact tag" );
3297

  
3298
			$tempResult = $node->findnodes(
3299
'../address|../phone|../electronicmailAddress|../organizationName'
3300
			);
3301
			if ( $tempResult->size > 0 ) {
3302
				$$templateVars{'origNamefirstContact'} =
3303
				  findValue( $node, 'givenName' );
3304
				$$templateVars{'origNamelastContact'} =
3305
				  findValue( $node, 'surName' );
3306

  
3307
				my $tempResult2 = $node->findnodes('../address');
3308
				if ( $tempResult2->size > 1 ) {
3309
					errMoreThanOne("address");
3310
				}
3311
				else {
3312
					foreach my $tempNode2 ( $tempResult2->get_nodelist ) {
3313
						$$templateVars{'origDeliveryContact'} =
3314
						  findValue( $tempNode2, 'deliveryPoint' );
3315
						$$templateVars{'origCityContact'} =
3316
						  findValue( $tempNode2, 'city' );
3317
						$$templateVars{'origStateContact'} =
3318
						  findValue( $tempNode2, 'administrativeArea' );
3319
						$$templateVars{'origZIPContact'} =
3320
						  findValue( $tempNode2, 'postalCode' );
3321
						$$templateVars{'origCountryContact'} =
3322
						  findValue( $tempNode2, 'country' );
3323
					}
3324
				}
3325

  
3326
				my $tempResult3 = $node->findnodes('../phone');
3327
				if ( $tempResult3->size > 2 ) {
3328
					errMoreThanN("phone");
3329
				}
3330
				else {
3331
					foreach my $tempNode2 ( $tempResult3->get_nodelist ) {
3332
						if ( $tempNode2->hasAttributes() ) {
3333
							my @attlist = $tempNode2->attributes();
3334
							if ( $attlist[0]->value eq "Fax" ) {
3335
								$$templateVars{'origFAXContact'} =
3336
								  $tempNode2->textContent();
3337
							}
3338
							else {
3339
								$$templateVars{'origPhoneContact'} =
3340
								  $tempNode2->textContent();
3341
							}
3342
						}
3343
						else {
3344
							$$templateVars{'origPhoneContact'} =
3345
							  $tempNode2->textContent();
3346
						}
3347
					}
3348
				}
3349
				$$templateVars{'origEmailContact'} =
3350
				  findValue( $node, '../electronicMailAddress' );
3351
				$$templateVars{'origNameOrgContact'} =
3352
				  findValue( $node, '../organizationName' );
3353
			}
3354
			else {
3355
				$$templateVars{'origNamefirstContact'} =
3356
				  findValue( $node, 'givenName' );
3357
				$$templateVars{'origNamelastContact'} =
3358
				  findValue( $node, 'surName' );
3359
				$$templateVars{'origNameOrgContact'} =
3360
				  findValue( $node, '../organizationName' );
3361
			}
3362
		}
3363
	}
3364

  
3365 3357
	$results =
3366 3358
	  $doc->findnodes('//dataset/methods/methodStep/description/section');
3367 3359
	debug( "Number methods: " . $results->size() );
......
3440 3432

  
3441 3433
	# Code for checking ACL: with EML 2.1, we should only look within the top-level elements
3442 3434
	#debug("checking user access");
3435
	
3436
	# deny rules have been discontinued in metacat, but we'll keep this in here
3443 3437
	dontOccur( $doc, "/eml:eml/access/deny", "access/deny" );
3444 3438

  
3445
	$results = $doc->findnodes('/eml:eml/access/allow');
3439
	#  check access from Metacat API instead of eml-embedded rules
3440
	my $docid   = $FORM::docid;
3441
	$results = getAllowAccess($docid);
3442
	# $results = $doc->findnodes('/eml:eml/access/allow');
3443
	
3446 3444
	my $accessError = 0;
3447 3445
	my $accessGranted = 0;
3448 3446
	my $docOwner;
......
3455 3453
	}
3456 3454
	push( @admins, $adminUsername );
3457 3455

  
3458
	#debug("getting user groups for current user");
3456
	debug("getting user groups for current user");
3459 3457

  
3460 3458
	my @userGroups = getUserGroups();
3461 3459

  
......
3480 3478
			$accessError = 1;
3481 3479
			debug($errorMessage);
3482 3480
		}
3483
		if (($principal eq $adminUsername) && ($permission ne 'all')) {
3484
			# If the principal is the admin and permission is not 'all' then this document
3485
	    	# could not have been created in the registry.
3486
			$errorMessage = "The ACL for this document has been changed outside the registry. Please use Morpho to edit this document (Access Error: admin principal cannot have $permission permission).\n";
3487
			$accessError = 1;
3488
			debug($errorMessage);
3489
		}
3481
		#if (($principal eq $adminUsername) && ($permission ne 'all' || $permission ne 'chmod' || $permission ne 'write')) {
3482
		#	# If the principal is the admin and permission is not 'all' then this document
3483
	    #	# could not have been created in the registry.
3484
		#	$errorMessage = "The ACL for this document has been changed outside the registry. Please use Morpho to edit this document (Access Error: admin principal cannot have $permission permission).\n";
3485
		#	$accessError = 1;
3486
		#	debug($errorMessage);
3487
		#}
3490 3488

  
3491 3489
		# no access error in doc, if principal is not equal to public and permission is
3492 3490
		# 'all' (requirements in registry) then try and determine if user has access
3493
		if (!$accessError && ($principal ne 'public') && ($permission eq 'all' || $permission eq 'write')) {
3491
		if (!$accessError && ($principal ne 'public') && ($permission eq 'all' || $permission eq 'write' || $permission eq 'chmod')) {
3494 3492
			my ($username, $password) = getCredentials();
3495 3493

  
3496 3494
			# 1) check if user matches principal
3497
			#debug("does user $username match principal $principal?");
3495
			debug("does user $username match principal $principal?");
3498 3496
			if ($principal eq $username) {
3499 3497
				$accessGranted = 1;
3500
				#debug("Access granted: user $username matches principal");
3498
				debug("Access granted: user $username matches principal");
3501 3499
			}
3502 3500

  
3503 3501
			# 2) if access not granted, check if user group matches principal
3504 3502
			if (!$accessGranted) {
3505
				#debug("is one of the user groups @userGroups the principal $principal?");
3503
				debug("is one of the user groups @userGroups the principal $principal?");
3506 3504
				for my $userGroup (@userGroups) {
3507
      				if ($userGroup == $principal) {
3508
           				$accessGranted = 1;
3509
           				#debug("Access granted: user group $userGroup matches principal");
3510
           				last;
3511
       				}
3505
					my $lowercaseUserGroup = lc $userGroup;
3506
					my $lowercasePrincipal = lc $principal;
3507
					if ($lowercaseUserGroup eq $lowercasePrincipal) {
3508
							$accessGranted = 1;
3509
							debug("Access granted: user group $userGroup matches principal");
3510
							last;
3511
					}
3512 3512
				}
3513 3513
			}
3514 3514
		}
......
3526 3526

  
3527 3527
		# 3) if access not granted, check if the user is a moderator or admin
3528 3528
		if (!$accessGranted) {
3529
			#debug("is user $username in admins @admins?");
3529
			debug("is user $username in admins @admins?");
3530 3530
			if (grep { $_ eq $username } @admins) {
3531 3531
				$accessGranted = 1;
3532 3532
				#debug("Access granted: user $username is an admin or moderator");
......
3535 3535

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff