From ca6edb730eead33bb66ca183de3349e0be4a47d2 Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Wed, 28 Jun 2023 16:45:12 +0200 Subject: [PATCH] baculum: Add objecttype filter to objects names endpoint --- .../protected/API/Modules/ObjectManager.php | 7 +++++-- .../protected/API/Pages/API/ObjectNames.php | 15 ++++++++++++++- gui/baculum/protected/API/openapi_baculum.json | 9 +++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/gui/baculum/protected/API/Modules/ObjectManager.php b/gui/baculum/protected/API/Modules/ObjectManager.php index f3b45a507..1b0146fb0 100644 --- a/gui/baculum/protected/API/Modules/ObjectManager.php +++ b/gui/baculum/protected/API/Modules/ObjectManager.php @@ -732,10 +732,11 @@ JOIN Job USING (JobId) ' /** * Get existing object names. * + * @param array $criteria SQL criteria in nested array format (@see Databaes::getWhere) * @param integer $limit_val maximum number of elements to return * @return array object names */ - public function getObjectNames($limit_val = null) { + public function getObjectNames($criteria = [], $limit_val = null) { $limit = ''; if(is_int($limit_val) && $limit_val > 0) { $limit = sprintf( @@ -743,10 +744,12 @@ JOIN Job USING (JobId) ' $limit_val ); } + $where = Database::getWhere($criteria); $sql = 'SELECT DISTINCT ObjectName as objectname FROM Object + ' . $where['where'] . ' ORDER BY ObjectName ' . $limit; - $statement = Database::runQuery($sql); + $statement = Database::runQuery($sql, $where['params']); $result = $statement->fetchAll(\PDO::FETCH_GROUP); $values = array_keys($result); return $values; diff --git a/gui/baculum/protected/API/Pages/API/ObjectNames.php b/gui/baculum/protected/API/Pages/API/ObjectNames.php index eb81e20ca..af95d2e96 100644 --- a/gui/baculum/protected/API/Pages/API/ObjectNames.php +++ b/gui/baculum/protected/API/Pages/API/ObjectNames.php @@ -33,9 +33,22 @@ use Baculum\Common\Modules\Errors\ObjectError; class ObjectNames extends BaculumAPIServer { public function get() { + $misc = $this->getModule('misc'); $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : null; + $objecttype = $this->Request->contains('objecttype') && $misc->isValidName($this->Request['objecttype']) ? $this->Request['objecttype'] : null; - $this->output = $this->getModule('object')->getObjectNames($limit); + $params = []; + if (!empty($objecttype)) { + $params['Object.ObjectType'] = []; + $params['Object.ObjectType'][] = [ + 'vals' => $objecttype + ]; + } + + $this->output = $this->getModule('object')->getObjectNames( + $params, + $limit + ); $this->error = ObjectError::ERROR_NO_ERRORS; } } diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 6f5d05a89..d3ed43572 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -8642,6 +8642,15 @@ "parameters": [ { "$ref": "#/components/parameters/Limit" + }, + { + "name": "objecttype", + "in": "query", + "required": false, + "description": "Object type, ex. 'm365' or 'PostgreSQL'", + "schema": { + "type": "string" + } } ] } -- 2.47.3