[Mapbender-commits] r9420 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Mar 9 09:13:56 PST 2016


Author: armin11
Date: 2016-03-09 09:13:56 -0800 (Wed, 09 Mar 2016)
New Revision: 9420

Modified:
   trunk/mapbender/http/php/mod_dataISOMetadata.php
Log:
Handling of predefined licenses. Need to be tested with validators

Modified: trunk/mapbender/http/php/mod_dataISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_dataISOMetadata.php	2016-03-09 17:13:18 UTC (rev 9419)
+++ trunk/mapbender/http/php/mod_dataISOMetadata.php	2016-03-09 17:13:56 UTC (rev 9420)
@@ -261,8 +261,6 @@
 	$wmsId = $mb_metadata_coupling['fkey_wms_id'];
 	$e = new mb_notice("mod_dataISOMetadata.php: Found coupled layer with id: ".$layerId);
 
-
-
 	//featuretype and wfs information:
 	$sql = <<<SQL
 SELECT featuretype_id, fkey_wfs_id FROM wfs_featuretype INNER JOIN ows_relation_metadata ON 
@@ -304,7 +302,7 @@
 			$sql .= "wms.wms_title, wms.wms_abstract, wms.wms_id, wms.fees, wms.accessconstraints, wms.contactperson, ";
 			$sql .= "wms.contactposition, wms.contactorganization, wms.address, wms.city, wms_timestamp, wms_owner, ";
 			$sql .= "wms.stateorprovince, wms.postcode, wms.contactvoicetelephone, wms.contactfacsimiletelephone, wms.wms_owsproxy,";
-			$sql .= "wms.contactelectronicmailaddress, wms.country, wms.fkey_mb_group_id, ";
+			$sql .= "wms.contactelectronicmailaddress, wms.country, wms.fkey_mb_group_id, wms.wms_license_source_note,";
 			$sql .= "layer_epsg.minx || ',' || layer_epsg.miny || ',' || layer_epsg.maxx || ',' || layer_epsg.maxy  as bbox ";
 			$sql .= "FROM wms, layer, layer_epsg WHERE layer_id = $1 and layer.fkey_wms_id = wms.wms_id";
 			$sql .= " and layer_epsg.fkey_layer_id=layer.layer_id and layer_epsg.epsg='EPSG:4326'";
@@ -674,7 +672,7 @@
 
 	#Create date elements B5.2-5.4
 	#Do things for B 5.2 date of publication - maybe the date when the first metadata was generated or it should not be available at all
-	if (isset($mb_metadata['createdate'])) {
+	/*if (isset($mb_metadata['createdate'])) {
 		$date1=$iso19139->createElement("gmd:date");
 		$CI_Date=$iso19139->createElement("gmd:CI_Date");
 		$date2=$iso19139->createElement("gmd:date");
@@ -693,7 +691,7 @@
 		$CI_Date->appendChild($dateType);
 		$date1->appendChild($CI_Date);
 		$CI_Citation->appendChild($date1);
-	}
+	}*/
 	#Do things for B 5.3 date of revision
 	//this should be created from the information of maintenance if available
 	//some initialization for the temporal extent:
@@ -1054,38 +1052,157 @@
 	#Part B 3 INSPIRE Category
 	#do this only if an INSPIRE keyword (Annex I-III) is set
 	#Resource Constraints B 8
+	//check for predefined license for datasets / or for service if available
+	$sql = "SELECT * FROM termsofuse WHERE termsofuse_id IN (SELECT fkey_termsofuse_id FROM md_termsofuse WHERE fkey_metadata_id = $1)";
+	$v = array((integer)$mb_metadata['metadata_id']);
+	$t = array('i');
+	$predefinedLicenseFound = false;
+	$licenseOrigin = "metadata";
+	$res = db_prep_query($sql,$v,$t);
+	if (db_num_rows($res) == 0) {
+		$licenseOrigin = "service";
+		//check service for predefined license
+		$sql = "SELECT * FROM termsofuse WHERE termsofuse_id IN (SELECT fkey_termsofuse_id FROM wms_termsofuse WHERE fkey_wms_id = $1)";
+		$v = array((integer)$wmsId);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+	}
+	if (db_num_rows($res) > 0) {
+		$predefinedLicenseFound = true;
+		while ($row = db_fetch_array($res)) {
+			$license_id = $row['name'];
+			$license_name = $row['description'];
+			$license_link = $row['descriptionlink'];
+			$license_require_source = $row['source_required'];
+			if ($license_require_source == 't') {
+				switch ($licenseOrigin) {
+					case "metadata":
+						if (isset($mb_metadata['md_license_source_note']) && $mb_metadata['md_license_source_note'] !==  "") {
+							$license_source = $mb_metadata['md_license_source_note'];
+						} else {
+							$license_source = "Source note required by license, but not given!";
+						}
+					break;
+					case "service":
+						if (isset($mapbenderMetadata['wms_license_source_note']) && $mapbenderMetadata['wms_license_source_note'] !==  "") {
+							$license_source = $mapbenderMetadata['wms_license_source_note'];
+						} else {
+							$license_source = "Source note required by license, but not given!";
+						}
+					break;
+				}
+			} else {
+				$license_source = false;
+			}
+	
+		}
+	}
+	$predefinedLicenseText = "";
+	if ($predefinedLicenseFound == true) {
+		//generate json string (id, name , url, quelle) - see german standard gdi-de
+		$jsonLicense = new stdClass();
+		$jsonLicense->id = $license_id;
+		$jsonLicense->name = $license_name;
+		$jsonLicense->link = $license_link;
+		$predefinedLicenseText = " "._mb('License').": ".$license_id." - ".$license_name." - ".$license_link;
+		if ($license_source !== false) {
+			$jsonLicense->quelle = $license_source;
+			$predefinedLicenseText .= _mb("Source note: ").$license_source;
+		}
+	}
+	
 	$resourceConstraints=$iso19139->createElement("gmd:resourceConstraints");
-	$MD_LegalConstraints=$iso19139->createElement("gmd:MD_Constraints");
+	$MD_LegalConstraints=$iso19139->createElement("gmd:MD_LegalConstraints");
 	$useLimitation=$iso19139->createElement("gmd:useLimitation");
 	$useLimitation_cs=$iso19139->createElement("gco:CharacterString");
-	if(isset($mapbenderMetadata['accessconstraints'])){
-		$useLimitationText=$iso19139->createTextNode($mapbenderMetadata['accessconstraints']);
+	//check if useLimitations are stored at mb_metadata table level (maybe they are inherited from services)
+	//if so, give them - otherwise use the information from the service (if exists!)
+	if (isset($mb_metadata['fees']) && $mb_metadata['fees'] !== '') {
+			$useLimitationTextString = $mb_metadata['fees']." ".$predefinedLicenseText;
+	} else {
+		if(isset($mapbenderMetadata['fees'])){
+			$useLimitationTextString = $mapbenderMetadata['fees']." ".$predefinedLicenseText;
+		} else {
+			$useLimitationTextString = "no conditions apply";
+		}
 	}
-	else
-	{
-		$useLimitationText=$iso19139->createTextNode("no conditions apply");
-	}
+	$useLimitationText = $iso19139->createTextNode($useLimitationTextString);
  	//TODO: Mapping of constraints between OWS/registry and INSPIRE 
 	$useLimitation_cs->appendChild($useLimitationText);
 	$useLimitation->appendChild($useLimitation_cs);
 	$MD_LegalConstraints->appendChild($useLimitation);
 	$resourceConstraints->appendChild($MD_LegalConstraints);
 	$MD_DataIdentification->appendChild($resourceConstraints);
+	
+	//Also add useConstraints field with same content!
+	
+	if ($predefinedLicenseFound == true) {
+		//TODO useConstraints for license/otherConstraints
+	
+		$resourceConstraints=$iso19139->createElement("gmd:resourceConstraints");
+		$MD_LegalConstraints=$iso19139->createElement("gmd:MD_LegalConstraints");
 
+		$useConstraints=$iso19139->createElement("gmd:useConstraints");
+		$MD_RestrictionCode=$iso19139->createElement("gmd:MD_RestrictionCode");
+		$MD_RestrictionCode->setAttribute("codeList", "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/gmxCodelists.xml#MD_RestrictionCode");
+		$MD_RestrictionCode->setAttribute("codeListValue", "license");
+		$useConstraints->appendChild($MD_RestrictionCode);
+		$MD_LegalConstraints->appendChild($useConstraints);
+		
+		
+		//and otherConstraints for text
+		$useConstraints=$iso19139->createElement("gmd:useConstraints");
+		$MD_RestrictionCode=$iso19139->createElement("gmd:MD_RestrictionCode");
+		$MD_RestrictionCode->setAttribute("codeList", "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/gmxCodelists.xml#MD_RestrictionCode");
+		$MD_RestrictionCode->setAttribute("codeListValue", "otherConstraints");
+		$useConstraints->appendChild($MD_RestrictionCode);
+		$MD_LegalConstraints->appendChild($useConstraints);
+
+		//text element
+		$otherConstraints=$iso19139->createElement("gmd:otherConstraints");
+		$otherConstraints_cs=$iso19139->createElement("gco:CharacterString");
+		//copy from above
+		$otherConstraintsText = $iso19139->createTextNode($useLimitationTextString);
+		$otherConstraints_cs->appendChild($otherConstraintsText);
+		$otherConstraints->appendChild($otherConstraints_cs);
+		$MD_LegalConstraints->appendChild($otherConstraints);
+		//json representation
+		$otherConstraints=$iso19139->createElement("gmd:otherConstraints");
+		$otherConstraints_cs=$iso19139->createElement("gco:CharacterString");
+		//copy from above
+		$otherConstraintsText = $iso19139->createTextNode(json_encode($jsonLicense));
+		$otherConstraints_cs->appendChild($otherConstraintsText);
+		$otherConstraints->appendChild($otherConstraints_cs);
+		$MD_LegalConstraints->appendChild($otherConstraints);
+		
+		
+	}
+	$resourceConstraints->appendChild($MD_LegalConstraints);
+	$MD_DataIdentification->appendChild($resourceConstraints);
+
+	//Add useLimitations field with json representation
+	if (isset($jsonLicense)) {
+		
+	}
+
+
 	$resourceConstraints=$iso19139->createElement("gmd:resourceConstraints");
 	$MD_LegalConstraints=$iso19139->createElement("gmd:MD_LegalConstraints");
 	$accessConstraints=$iso19139->createElement("gmd:accessConstraints");
 	$MD_RestrictionCode=$iso19139->createElement("gmd:MD_RestrictionCode");
-	$MD_RestrictionCode->setAttribute("codeList", "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_RetrictionCode");
+	$MD_RestrictionCode->setAttribute("codeList", "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/ML_gmxCodelists.xml#MD_RestrictionCode");
 	$MD_RestrictionCode->setAttribute("codeListValue", "otherRestrictions");
 	$MD_RestrictionCodeText=$iso19139->createTextNode("otherRestrictions");
 	$otherConstraints=$iso19139->createElement("gmd:otherConstraints");
 	$otherConstraints_cs=$iso19139->createElement("gco:CharacterString");
-	if (isset($mapbenderMetadata['accessconstraints']) & strtoupper($mapbenderMetadata['accessconstraints']) != 'NONE'){
+	if (isset($mb_metadata['constraints']) && $mb_metadata['constraints'] !== '') {
+			$otherConstraintsText=$iso19139->createTextNode($mb_metadata['constraints']);
+		} else {
+		if (isset($mapbenderMetadata['accessconstraints']) & strtoupper($mapbenderMetadata['accessconstraints']) != 'NONE'){
 			$otherConstraintsText=$iso19139->createTextNode($mapbenderMetadata['accessconstraints']);
-	}
-	else {
+		} else {
 			$otherConstraintsText=$iso19139->createTextNode("no constraints");
+		}
 	}
 	$otherConstraints_cs->appendChild($otherConstraintsText);
 	$otherConstraints->appendChild($otherConstraints_cs);



More information about the Mapbender_commits mailing list