Ver código fonte

added wps relations api - todo

Piotr Labudda 8 anos atrás
pai
commit
844e052e00

+ 35 - 0
SE/se-lib/Api/Process/P5/CreateRelation.php

@@ -0,0 +1,35 @@
+<?php
+
+Lib::loadClass('Relations');
+
+class Api_Process_P5_CreateRelation { // TODO: extends Api_ProcessBase
+
+	static function run($args, $responseForm) {
+		$typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
+		if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
+		$primaryKey = (!empty($args['primaryKey'][0])) ? $args['primaryKey'][0] : '';
+		if (!$primaryKey) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
+		$remoteTypeName = (!empty($args['remoteTypeName'][0])) ? $args['remoteTypeName'][0] : '';
+		if (!$remoteTypeName) throw new Api_OwsException("Missing value for 'remoteTypeName'", 501, null, 'MissingParameterValue', 'request');
+		$listRemotePrimaryKeys = (!empty($args['primaryKey'])) ? $args['remotePrimaryKey'] : [];
+		if (empty($listRemotePrimaryKeys)) throw new Api_OwsException("Missing value for 'remotePrimaryKey'", 501, null, 'MissingParameterValue', 'request');
+
+		if (!Relations::isAllowedToCreateRelation($userLogin, $typeName, $primaryKey, $remoteTypeName)) {
+			throw new Api_OwsException("User is not allowed to create relation from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}' ", 501, null, 'AccessDenied', 'request');
+		}
+		Relations::createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys);
+		$listSelectedState = Relations::getRelations($typeName, $primaryKey);
+
+		header('Content-Type: application/json');
+		echo json_encode([
+			'type' => "success",
+			'msg' => "done",
+			// 'body' => [
+			// 	'relations' => $listRelations,
+			// 	'total' => $total,
+			// ]
+		]);
+		exit;
+	}
+
+}

+ 39 - 0
SE/se-lib/Api/Process/P5/DeleteRelation.php

@@ -0,0 +1,39 @@
+<?php
+
+Lib::loadClass('Relations');
+
+class Api_Process_P5_DeleteRelation { // TODO: extends Api_ProcessBase
+
+	static function run($args, $responseForm) {
+		$typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
+		if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
+		$primaryKey = (!empty($args['primaryKey'][0])) ? $args['primaryKey'][0] : '';
+		if (!$primaryKey) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
+		$remoteTypeName = (!empty($args['remoteTypeName'][0])) ? $args['remoteTypeName'][0] : '';
+		if (!$remoteTypeName) throw new Api_OwsException("Missing value for 'remoteTypeName'", 501, null, 'MissingParameterValue', 'request');
+		$listRemotePrimaryKeys = (!empty($args['primaryKey'])) ? $args['remotePrimaryKey'] : [];
+		if (empty($listRemotePrimaryKeys)) throw new Api_OwsException("Missing value for 'remotePrimaryKey'", 501, null, 'MissingParameterValue', 'request');
+
+		if (!Relations::isAllowedToDeleteRelation($userLogin, $typeName, $primaryKey, $remoteTypeName)) {
+			throw new Api_OwsException("User is not allowed to create relation from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}' ", 501, null, 'AccessDenied', 'request');
+		}
+		try {
+			Relations::deleteRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys);
+		} catch (Exception $e) {
+			DBG::log($e);
+			throw new Api_OwsException($e->getMessage(), 501, null, 'AccessDenied', 'request');
+		}
+
+		header('Content-Type: application/json');
+		echo json_encode([
+			'type' => "success",
+			'msg' => "done",
+			// 'body' => [
+			// 	'relations' => $listRelations,
+			// 	'total' => $total,
+			// ]
+		]);
+		exit;
+	}
+
+}

+ 32 - 0
SE/se-lib/Api/Process/P5/GetRelations.php

@@ -0,0 +1,32 @@
+<?php
+
+Lib::loadClass('Relations');
+
+class Api_Process_P5_GetRelations { // TODO: extends Api_ProcessBase
+
+	static function run($args, $responseForm) {
+		$typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
+		if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
+		$primaryKey = (!empty($args['primaryKey'][0])) ? $args['primaryKey'][0] : '';
+		if (!$primaryKey) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
+		$remoteTypeName = (!empty($args['remoteTypeName'][0])) ? $args['remoteTypeName'][0] : '';
+		if (!$remoteTypeName) throw new Api_OwsException("Missing value for 'remoteTypeName'", 501, null, 'MissingParameterValue', 'request');
+
+		if (!Relations::isAllowedToGetRelation($userLogin, $typeName, $primaryKey, $remoteTypeName)) {
+			throw new Api_OwsException("User is not allowed to view relations from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}' ", 501, null, 'AccessDenied', 'request');
+		}
+		$listRelations = Relations::getRelations($typeName, $primaryKey);
+
+		header('Content-Type: application/json');
+		echo json_encode([
+			'type' => "success",
+			'msg' => "done",
+			'body' => [
+				'relations' => $listRelations,
+				// 'total' => $total,
+			]
+		]);
+		exit;
+	}
+
+}

+ 33 - 33
SE/se-lib/Api/WpsHelper.php

@@ -109,39 +109,39 @@ class Api_WpsHelper {
 			]);
 		}
 
-		// { // Relations (ref's)
-		// 	$wpsArgTypeName = [
-		// 		'minOccurs' => "1", 'maxOccurs' => "1", // 1 arg is required
-		// 		'identifier' => 'typeName',
-		// 		'title' => "Feature typeName",
-		// 		'description' => "Feature typeName eg.: 'default_db/PROBLEMS'",
-		// 		'dataType' => 'literal',
-		// 		'xsdType' => 'p5:typeName',
-		// 	];
-		//
-		// 	$relationsBase = [
-		// 		'dataInputs' => [
-		// 			$wpsArgTypeName,
-		// 			array_merge($wpsArgPrimaryKey, [ 'maxOccurs' => 1 ]),
-		// 			$wpsArgRemoteTypeName,
-		// 			$wpsArgRemotePrimaryKey,
-		// 		],
-		// 		// 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
-		// 		'defaultOutput' => [ 'MimeType' => "application/json" ],
-		// 		'supportedOutput' => [
-		// 			[ 'MimeType' => "application/json" ],
-		// 		]
-		// 	];
-		// 	$defaultWpsProcessList['p5:getRelations'] = array_merge([ 'title' => "Fetch relations between features" ], $relationsBase, [
-		// 		'dataInputs' => [
-		// 			$wpsArgTypeName,
-		// 			array_merge($wpsArgPrimaryKey, [ 'maxOccurs' => 1 ]),
-		// 			$wpsArgRemoteTypeName,
-		// 		],
-		// 	]);
-		// 	$defaultWpsProcessList['p5:createRelation'] = array_merge([ 'title' => "Create relation between features" ], $relationsBase);
-		// 	$defaultWpsProcessList['p5:deleteRelation'] = array_merge([ 'title' => "Delete relation between features" ], $relationsBase);
-		// }
+		{ // Relations (ref's)
+			$wpsArgTypeName = [
+				'minOccurs' => "1", 'maxOccurs' => "1", // 1 arg is required
+				'identifier' => 'typeName',
+				'title' => "Feature typeName",
+				'description' => "Feature typeName eg.: 'default_db/PROBLEMS'",
+				'dataType' => 'literal',
+				'xsdType' => 'p5:typeName',
+			];
+
+			$relationsBase = [
+				'dataInputs' => [
+					$wpsArgTypeName,
+					array_merge($wpsArgPrimaryKey, [ 'maxOccurs' => 1 ]),
+					$wpsArgRemoteTypeName,
+					$wpsArgRemotePrimaryKey,
+				],
+				// 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
+				'defaultOutput' => [ 'MimeType' => "application/json" ],
+				'supportedOutput' => [
+					[ 'MimeType' => "application/json" ],
+				]
+			];
+			$defaultWpsProcessList['p5:getRelations'] = array_merge([ 'title' => "Fetch relations between features" ], $relationsBase, [
+				'dataInputs' => [
+					$wpsArgTypeName,
+					array_merge($wpsArgPrimaryKey, [ 'maxOccurs' => 1 ]),
+					$wpsArgRemoteTypeName,
+				],
+			]);
+			$defaultWpsProcessList['p5:createRelation'] = array_merge([ 'title' => "Create relation between features" ], $relationsBase);
+			$defaultWpsProcessList['p5:deleteRelation'] = array_merge([ 'title' => "Delete relation between features" ], $relationsBase);
+		}
 
 		array_walk($defaultWpsProcessList, function (&$wpsFunction, $identifier) {
 			$wpsFunction['identifier'] = $identifier;

+ 35 - 0
SE/se-lib/Relations.php

@@ -0,0 +1,35 @@
+<?php
+
+Lib::loadClass('ACL');
+Lib::loadClass('Api_WfsNs');
+
+class Relations {
+
+	static function isAllowedToCreateRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
+		return false;
+	}
+
+	static function isAllowedToGetRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
+		return false;
+	}
+
+	static function isAllowedToDeleteRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
+		return false;
+	}
+
+	static function getRelations($typeName, $primaryKey) {
+		$acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
+		throw new Exception("TODO: Relations::getRelations");
+	}
+
+	static function createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
+		$acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
+		throw new Exception("TODO: Relations::createRelation");
+	}
+
+	static function deleteRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
+		$acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
+		throw new Exception("TODO: Relations::getRelations");
+	}
+
+}