[Mapbender-commits] r9676 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jan 31 16:04:39 PST 2017


Author: armin11
Date: 2017-01-31 16:04:38 -0800 (Tue, 31 Jan 2017)
New Revision: 9676

Modified:
   trunk/mapbender/http/classes/class_cswClient.php
Log:
Some new handlings for harvesting external csw

Modified: trunk/mapbender/http/classes/class_cswClient.php
===================================================================
--- trunk/mapbender/http/classes/class_cswClient.php	2017-02-01 00:03:37 UTC (rev 9675)
+++ trunk/mapbender/http/classes/class_cswClient.php	2017-02-01 00:04:38 UTC (rev 9676)
@@ -41,11 +41,12 @@
 		$this->operationSuccessful = false;
 	}
 	
-	public function doRequest($cswId, $operationName, $recordId=false, $record=false) {
+	public function doRequest($cswId, $operationName, $recordId=false, $record=false, $recordtype=false, $maxrecords=false, $startposition=false) {
 		$this->cswId = $cswId;
 		$csw = new csw();
 		$csw->createCatObjFromDB($this->cswId);
-		$e = new mb_exception($csw->cat_op_values[$operationName]['get']);
+		$operationNameCsw = $operationName;
+		//$e = new mb_exception($csw->cat_op_values[$operationName]['post']);
 		//check for operation support
 		switch (strtolower($operationName)) {
 			case "getrecords":
@@ -80,7 +81,23 @@
 					return false;
 				}
 				break;
-			
+			//wrapped operations for internal usage
+			case "counthits":
+				if (isset($csw->cat_op_values['getrecords']['post'])) {
+					//all ok
+				} else {
+					$e = new mb_exception("classes/class_cswClient.php: Needed operation not supported by catalogue!");
+					return false;
+				}
+				break;
+			case "getrecordspaging":				
+				if (isset($csw->cat_op_values['getrecords']['post'])) {
+					//all ok
+				} else {
+					$e = new mb_exception("classes/class_cswClient.php: Needed operation not supported by catalogue!");
+					return false;
+				}
+				break;
 			default: 
 				break;
 		}
@@ -132,17 +149,69 @@
         			$postRequest .= '</csw:Delete>';
     				$postRequest .= '</csw:Transaction>';
 				break;
+				//wrapped operations for internal usage
+			case "counthits":
+				$postRequest = '<?xml version="1.0" encoding="UTF-8"?>';
+				$postRequest .= '<csw:GetRecords service="CSW" version="2.0.2" xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:apiso="http://www.opengis.net/cat/csw/apiso/1.0">';
+    				$postRequest .= '<csw:Query typeNames="csw:Record">';
+				$postRequest .= '<csw:ElementSetName>summary</csw:ElementSetName>';
+				if ($recordtype !== false) {
+            				$postRequest .= '<csw:Constraint version="1.0.0">';
+                			$postRequest .= '<ogc:Filter>';
+                    			$postRequest .= '<ogc:PropertyIsEqualTo>';
+                       			$postRequest .= '<ogc:PropertyName>Type</ogc:PropertyName>';
+                        		$postRequest .= '<ogc:Literal>'.$recordtype.'</ogc:Literal>';
+                    			$postRequest .= '</ogc:PropertyIsEqualTo>';
+                			$postRequest .= '</ogc:Filter>';
+            				$postRequest .= '</csw:Constraint>';
+				}
+        			$postRequest .= '</csw:Query>';
+    				$postRequest .= '</csw:GetRecords>';
+				//alter operationName
+				$operationNameCsw = 'getrecords';
+					break;
+			case "getrecordspaging":
+				if ($recordtype !== false && $maxrecords !== false && $startposition !== false) {				
+					$postRequest = '<?xml version="1.0" encoding="UTF-8"?>';
+					$postRequest .= '<csw:GetRecords service="CSW" version="2.0.2" xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:apiso="http://www.opengis.net/cat/csw/apiso/1.0" ';
+					$postRequest .= 'maxRecords="'.$maxrecords.'" ';
+					$postRequest .= 'startPosition="'.$startposition.'" ';
+					$postRequest .= 'resultType="results"';
+					$postRequest .= '>';
+    					$postRequest .= '<csw:Query typeNames="csw:Record">';
+					//$postRequest .= '<csw:ElementSetName>summary</csw:ElementSetName>';
+					$postRequest .= '<csw:ElementSetName>full</csw:ElementSetName>';
+					if ($recordtype !== false) {
+            					$postRequest .= '<csw:Constraint version="1.0.0">';
+                				$postRequest .= '<ogc:Filter>';
+                    				$postRequest .= '<ogc:PropertyIsEqualTo>';
+                       				$postRequest .= ' <ogc:PropertyName>Type</ogc:PropertyName>';
+                        			$postRequest .= '<ogc:Literal>'.$recordtype.'</ogc:Literal>';
+                    				$postRequest .= '</ogc:PropertyIsEqualTo>';
+                				$postRequest .= '</ogc:Filter>';
+            					$postRequest .= '</csw:Constraint>';
+					}
+        				$postRequest .= '</csw:Query>';
+    					$postRequest .= '</csw:GetRecords>';				
+					//alter operationName
+					$operationNameCsw = 'getrecords';
+				} else {
+					$e = new mb_exception("classes/class_cswClient.php: Operation getrecordspaging needs more parameters!");
+				}
+					break;
 			default: 
 				break;
 			
 		}
 		//do request and return result
 		//$e = new mb_exception($csw->cat_op_values[$operationName]['post']);
-		if (strpos($operationName, "transaction") === false) {
-			$this->operationResult = $this->getResult($csw->cat_op_values[$operationName]['post'], $postRequest);
+		if (strpos($operationNameCsw, "transaction") === false) {
+			//$e = new mb_exception("test: ".$csw->cat_op_values[$operationNameCsw]['post']);
+			$this->operationResult = $this->getResult($csw->cat_op_values[$operationNameCsw]['post'], $postRequest);
 		} else {
 			$this->operationResult = $this->getResult($csw->cat_op_values["transaction"]['post'], $postRequest);
 		}
+		//$e = new mb_exception("test: ".$this->operationResult);
 		//parse response
 		libxml_use_internal_errors(true);
 		try {
@@ -194,6 +263,44 @@
 							return true;
 						}
 						break;
+					case "getrecords":
+						$metadataRecord = $cswResponseObject->xpath('/csw:GetRecordsResponse/csw:SearchResults at numberOfRecordsMatched');
+						$e = new mb_exception(json_encode($metadataRecord));
+						if (is_array($metadataRecord) && count($metadataRecord) <> 1 || !is_array($metadataRecord)) {
+							$this->operationResult = "No result for counting metadata records via csw query!";
+							return false;
+						} else {
+							$this->operationSuccessful = true;
+							$this->operationResult = $metadataRecord[0];
+							return true;
+						}
+						break;
+					case "counthits":
+						//$e = new mb_exception('count hits');
+						
+						$metadataRecord = $cswResponseObject->xpath('/csw:GetRecordsResponse/csw:SearchResults/@numberOfRecordsMatched');
+						//$e = new mb_exception(json_encode($metadataRecord));
+						if (is_array($metadataRecord) && count($metadataRecord) <> 1 || !is_array($metadataRecord)) {
+							$this->operationResult = "No result for counting metadata records via csw query!";
+							return false;
+						} else {
+							$this->operationSuccessful = true;
+							$this->operationResult = $metadataRecord[0];
+							return true;
+						}
+					case "getrecordspaging":
+						$metadataRecord = $cswResponseObject->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata');
+						if (is_array($metadataRecord) && count($metadataRecord) < 1 || !is_array($metadataRecord)) {
+							$this->operationResult = "No result for counting metadata records via csw query!";
+							$this->operationSuccessful = false;
+							return false;
+						} else {
+							$this->operationSuccessful = true;
+							//give back all records in json
+							$this->operationResult = $cswResponseObject;
+							return true;
+						}
+						break;
 				}
 			}
 			//handle expections if occur
@@ -215,12 +322,13 @@
 	}
 
 	private function getResult($url, $postData, $auth=false) {
-			//$e = new mb_exception("postdata: ".$postData);
+			$e = new mb_exception("postdata: ".$postData);
 			$cswInterfaceObject = new connector();
 			$cswInterfaceObject->set('httpType','POST');
 			$postData = stripslashes($postData);
 			$dataXMLObject = new SimpleXMLElement($postData);
 			$postData = $dataXMLObject->asXML();
+
 			//$e = new mb_exception($postData);
 			$cswInterfaceObject->set('curlSendCustomHeaders',true);
 			$cswInterfaceObject->set('httpPostData', $postData);
@@ -231,7 +339,6 @@
 	}
 	//insert or update - depends if record with same fileidentifier already exists in catalog and if timestamp is not newer than the timestamp of the new record
 
-	
 	public function deleteRecord($fileIdentifier, $auth=false) {
 		//check if exists before!
 		if ($this->doRequest($this->cswId, 'getrecordbyid', $fileIdentifier, false)) {



More information about the Mapbender_commits mailing list