|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
Lib::loadClass('Relations');
|
|
|
|
|
|
-class Api_Process_P5_CreateRelation { // TODO: extends Api_ProcessBase
|
|
|
+class Api_Process_P5_CreateRelations { // TODO: extends Api_ProcessBase
|
|
|
|
|
|
static function run($args, $responseForm) {
|
|
|
$typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
|
|
|
@@ -14,11 +14,18 @@ class Api_Process_P5_CreateRelation { // TODO: extends Api_ProcessBase
|
|
|
$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');
|
|
|
+ try {
|
|
|
+ Relations::isAllowedToCreateRelation($userLogin = User::getLogin(), $typeName, $primaryKey, $remoteTypeName);
|
|
|
+ Relations::createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys);
|
|
|
+ // $listRelations = Relations::getRelations($typeName, $primaryKey, $remoteTypeName);
|
|
|
+ // $totalRelations = count($listRelations);
|
|
|
+ } catch (HttpException $e) {
|
|
|
+ DBG::log($e);
|
|
|
+ throw new Api_OwsException($e->getMessage(), $e->getCode(), null, Http::getStatusText($e->getCode()), 'request');
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DBG::log($e);
|
|
|
+ throw new Api_OwsException("User is not allowed to read relations from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}'.\n" . $e->getMessage(), 501, null, 'AccessDenied', 'request');
|
|
|
}
|
|
|
- Relations::createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys);
|
|
|
- $listSelectedState = Relations::getRelations($typeName, $primaryKey);
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
echo json_encode([
|