From 428bb6c96f323783da3c498feb84e5d8a4d8434a Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Thu, 12 Jan 2023 15:15:10 +0100 Subject: [PATCH] baculum: Add endtime property and filters to source list endpoint --- .../protected/API/Modules/SourceManager.php | 5 ++-- .../protected/API/Pages/API/Sources.php | 25 ++++++++++++++++--- .../protected/API/openapi_baculum.json | 22 ++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/gui/baculum/protected/API/Modules/SourceManager.php b/gui/baculum/protected/API/Modules/SourceManager.php index 7cb0b20b4..3647e1e8c 100644 --- a/gui/baculum/protected/API/Modules/SourceManager.php +++ b/gui/baculum/protected/API/Modules/SourceManager.php @@ -38,7 +38,7 @@ class SourceManager extends APIModule { } $where = Database::getWhere($criteria, true); $sql = 'SELECT DISTINCT - sres.fileset, sres.client, sres.job, ores.starttime, ores.jobid, jres.jobstatus + sres.fileset, sres.client, sres.job, jres.starttime, jres.endtime, ores.jobid, jres.jobstatus FROM Job AS jres, ( SELECT DISTINCT @@ -50,7 +50,6 @@ class SourceManager extends APIModule { JOIN Client USING (ClientId) ) AS sres, ( SELECT - MAX(StartTime) AS starttime, MAX(JobId) AS jobid, FileSet.FileSet AS fileset, Client.Name AS client, @@ -68,7 +67,7 @@ class SourceManager extends APIModule { AND sres.fileset = ores.fileset AND jres.Type = \'B\' ' . (!empty($where['where']) ? ' AND ' . $where['where'] : '') . ' - ORDER BY sres.fileset ASC, sres.client ASC, sres.job ASC, ores.starttime ASC ' . $limit; + ORDER BY sres.fileset ASC, sres.client ASC, sres.job ASC, jres.starttime ASC ' . $limit; $connection = SourceRecord::finder()->getDbConnection(); $connection->setActive(true); diff --git a/gui/baculum/protected/API/Pages/API/Sources.php b/gui/baculum/protected/API/Pages/API/Sources.php index 450469838..81c6c503d 100644 --- a/gui/baculum/protected/API/Pages/API/Sources.php +++ b/gui/baculum/protected/API/Pages/API/Sources.php @@ -40,6 +40,8 @@ class Sources extends BaculumAPIServer { $fileset = $this->Request->contains('fileset') && $misc->isValidName($this->Request['fileset']) ? $this->Request['fileset'] : ''; $starttime_from = $this->Request->contains('starttime_from') && $misc->isValidInteger($this->Request['starttime_from']) ? (int)$this->Request['starttime_from'] : null; $starttime_to = $this->Request->contains('starttime_to') && $misc->isValidInteger($this->Request['starttime_to']) ? (int)$this->Request['starttime_to'] : null; + $endtime_from = $this->Request->contains('endtime_from') && $misc->isValidInteger($this->Request['endtime_from']) ? (int)$this->Request['endtime_from'] : null; + $endtime_to = $this->Request->contains('endtime_to') && $misc->isValidInteger($this->Request['endtime_to']) ? (int)$this->Request['endtime_to'] : null; $jobstatus = $this->Request->contains('jobstatus') && $misc->isValidState($this->Request['jobstatus']) ? $this->Request['jobstatus'] : ''; $hasobject = $this->Request->contains('hasobject') && $misc->isValidBoolean($this->Request['hasobject']) ? $this->Request['hasobject'] : null; @@ -81,21 +83,38 @@ class Sources extends BaculumAPIServer { // Start time range if (!empty($starttime_from) || !empty($starttime_to)) { - $params['ores.starttime'] = []; + $params['jres.starttime'] = []; if (!empty($starttime_from)) { - $params['ores.starttime'][] = [ + $params['jres.starttime'][] = [ 'operator' => '>=', 'vals' => date('Y-m-d H:i:s', $starttime_from) ]; } if (!empty($starttime_to)) { - $params['ores.starttime'][] = [ + $params['jres.starttime'][] = [ 'operator' => '<=', 'vals' => date('Y-m-d H:i:s', $starttime_to) ]; } } + // End time range + if (!empty($endtime_from) || !empty($endtime_to)) { + $params['jres.endtime'] = []; + if (!empty($endtime_from)) { + $params['jres.endtime'][] = [ + 'operator' => '>=', + 'vals' => date('Y-m-d H:i:s', $endtime_from) + ]; + } + if (!empty($endtime_to)) { + $params['jres.endtime'][] = [ + 'operator' => '<=', + 'vals' => date('Y-m-d H:i:s', $endtime_to) + ]; + } + } + $sources = $this->getModule('source')->getSources($params, $limit); $this->output = $sources; $this->error = SourceError::ERROR_NO_ERRORS; diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 275a9eca1..b0d38f5a4 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -7206,6 +7206,24 @@ "type": "integer" } }, + { + "name": "endtime_from", + "in": "query", + "required": false, + "description": "End time from (UNIX timestamp format, seconds)", + "schema": { + "type": "integer" + } + }, + { + "name": "endtime_to", + "in": "query", + "required": false, + "description": "End time to (UNIX timestamp format, seconds)", + "schema": { + "type": "integer" + } + }, { "name": "jobstatus", "in": "query", @@ -8738,6 +8756,10 @@ "description": "Start time latest job using this source", "type": "string" }, + "endtime": { + "description": "End time latest job using this source", + "type": "string" + }, "jobid": { "description": "Latest jobid", "type": "integer" -- 2.47.3