Commit 15fe0531 authored by Marcin Haba's avatar Marcin Haba
Browse files

baculum: Add offset parameter to jobs, objects and volumes endpoints

parent 49d63d7d
......@@ -34,7 +34,7 @@ use Prado\Data\ActiveRecord\TActiveRecordCriteria;
*/
class JobManager extends APIModule {
public function getJobs($criteria = array(), $limit_val = null, $sort_col = 'JobId', $sort_order = 'ASC') {
public function getJobs($criteria = array(), $limit_val = null, $offset_val = 0, $sort_col = 'JobId', $sort_order = 'ASC') {
$db_params = $this->getModule('api_config')->getConfig('db');
if ($db_params['type'] === Database::PGSQL_TYPE) {
$sort_col = strtolower($sort_col);
......@@ -44,6 +44,10 @@ class JobManager extends APIModule {
if(is_int($limit_val) && $limit_val > 0) {
$limit = ' LIMIT ' . $limit_val;
}
$offset = '';
if (is_int($offset_val) && $offset_val > 0) {
$offset = ' OFFSET ' . $offset_val;
}
$where = Database::getWhere($criteria);
......@@ -55,7 +59,7 @@ FROM Job
LEFT JOIN Client USING (ClientId)
LEFT JOIN Pool USING (PoolId)
LEFT JOIN FileSet USING (FilesetId)'
. $where['where'] . $order . $limit;
. $where['where'] . $order . $limit . $offset;
return JobRecord::finder()->findAllBySql($sql, $where['params']);
}
......
......@@ -37,13 +37,14 @@ class ObjectManager extends APIModule
*
* @param array $criteria criteria in nested array format (@see Databaes::getWhere)
* @param integer $limit_val maximum number of elements to return
* @param integer $offset_val query offset number
* @param string $sort_col column to sort
* @param string $sort_order sort order (asc - ascending, desc - descending)
* @param string $group_by column to group
* @param integer $group_limit maximum number of elements in one group
* @return array object list
*/
public function getObjects($criteria = array(), $limit_val = null, $sort_col = 'ObjectId', $sort_order = 'DESC', $group_by = null, $group_limit = 0) {
public function getObjects($criteria = array(), $limit_val = null, $offset_val = 0, $sort_col = 'ObjectId', $sort_order = 'DESC', $group_by = null, $group_limit = 0) {
$db_params = $this->getModule('api_config')->getConfig('db');
if ($db_params['type'] === Database::PGSQL_TYPE) {
$sort_col = strtolower($sort_col);
......@@ -56,10 +57,17 @@ class ObjectManager extends APIModule
$limit = '';
if(is_int($limit_val) && $limit_val > 0) {
$limit = sprintf(
' LIMIT %s',
' LIMIT %d',
$limit_val
);
}
$offset = '';
if (is_int($offset_val) && $offset_val > 0) {
$offset = sprintf(
' OFFSET %d',
$offset_val
);
}
$where = Database::getWhere($criteria);
......@@ -67,7 +75,7 @@ class ObjectManager extends APIModule
Job.Name as jobname
FROM Object
LEFT JOIN Job USING (JobId) '
. $where['where'] . $order . $limit;
. $where['where'] . $order . $limit . $offset;
$result = ObjectRecord::finder()->findAllBySql($sql, $where['params']);
Database::groupBy($group_by, $result, $group_limit);
......
......@@ -31,7 +31,7 @@ namespace Baculum\API\Modules;
*/
class VolumeManager extends APIModule {
public function getVolumes($criteria = array(), $limit_val = 0) {
public function getVolumes($criteria = array(), $limit_val = 0, $offset_val = 0) {
$order_pool_id = 'PoolId';
$order_volume = 'VolumeName';
$db_params = $this->getModule('api_config')->getConfig('db');
......@@ -45,6 +45,10 @@ class VolumeManager extends APIModule {
if(is_int($limit_val) && $limit_val > 0) {
$limit = " LIMIT $limit_val ";
}
$offset = '';
if (is_int($offset_val) && $offset_val > 0) {
$offset = ' OFFSET ' . $offset_val;
}
$where = Database::getWhere($criteria);
......@@ -58,7 +62,7 @@ LEFT JOIN Pool AS pool1 USING (PoolId)
LEFT JOIN Pool AS pool2 ON Media.ScratchPoolId = pool2.PoolId
LEFT JOIN Pool AS pool3 ON Media.RecyclePoolId = pool3.PoolId
LEFT JOIN Storage USING (StorageId)
' . $where['where'] . $order . $limit;
' . $where['where'] . $order . $limit . $offset;
$volumes = VolumeRecord::finder()->findAllBySql($sql, $where['params']);
$this->setExtraVariables($volumes);
return $volumes;
......
......@@ -35,7 +35,8 @@ class Jobs extends BaculumAPIServer {
public function get() {
$misc = $this->getModule('misc');
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
$limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0;
$offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
$jobstatus = $this->Request->contains('jobstatus') ? $this->Request['jobstatus'] : '';
$level = $this->Request->contains('level') && $misc->isValidJobLevel($this->Request['level']) ? $this->Request['level'] : '';
$type = $this->Request->contains('type') && $misc->isValidJobType($this->Request['type']) ? $this->Request['type'] : '';
......@@ -248,6 +249,7 @@ class Jobs extends BaculumAPIServer {
$result = $this->getModule('job')->getJobs(
$params,
$limit,
$offset,
$order_by,
$order_direction
);
......
......@@ -34,7 +34,8 @@ class Objects extends BaculumAPIServer {
public function get() {
$misc = $this->getModule('misc');
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
$limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0;
$offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
$objecttype = $this->Request->contains('objecttype') && $misc->isValidName($this->Request['objecttype']) ? $this->Request['objecttype'] : null;
$objectname = $this->Request->contains('objectname') && $misc->isValidName($this->Request['objectname']) ? $this->Request['objectname'] : null;
$objectcategory = $this->Request->contains('objectcategory') && $misc->isValidName($this->Request['objectcategory']) ? $this->Request['objectcategory'] : null;
......@@ -224,6 +225,7 @@ class Objects extends BaculumAPIServer {
$objects = $this->getModule('object')->getObjects(
$params,
$limit,
$offset,
$order_by_lc,
$order_direction,
$group_by,
......
......@@ -32,8 +32,10 @@ use Baculum\Common\Modules\Errors\VolumeError;
*/
class Volumes extends BaculumAPIServer {
public function get() {
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
$result = $this->getModule('volume')->getVolumes(array(), $limit);
$misc = $this->getModule('misc');
$limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0;
$offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
$result = $this->getModule('volume')->getVolumes(array(), $limit, $offset);
$this->output = $result;
$this->error = VolumeError::ERROR_NO_ERRORS;
}
......
......@@ -179,6 +179,15 @@
"type": "integer"
}
},
"Offset": {
"name": "offset",
"in": "query",
"description": "Items offset",
"required": false,
"schema": {
"type": "integer"
}
},
"ClientId": {
"name": "clientid",
"in": "path",
......@@ -832,6 +841,9 @@
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
},
{
"name": "name",
"in": "query",
......@@ -2978,9 +2990,14 @@
}
}
},
"parameters": [{
"$ref": "#/components/parameters/Limit"
}]
"parameters": [
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
}
]
}
},
"/api/v2/volumes/{mediaid}": {
......@@ -6432,6 +6449,9 @@
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
},
{
"name": "objecttype",
"in": "query",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment