Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bacula Community Edition
Bacula Community
Commits
e84cf590
Commit
e84cf590
authored
Nov 15, 2022
by
Marcin Haba
Browse files
baculum: Add groupby parameter to object list endpoint
parent
1560de3f
Changes
3
Hide whitespace changes
Inline
Side-by-side
gui/baculum/protected/API/Modules/ObjectManager.php
View file @
e84cf590
...
...
@@ -31,7 +31,7 @@ namespace Baculum\API\Modules;
*/
class
ObjectManager
extends
APIModule
{
public
function
getObjects
(
$criteria
=
array
(),
$limit_val
=
null
)
{
public
function
getObjects
(
$criteria
=
array
(),
$limit_val
=
null
,
$groupby
=
null
)
{
$sort_col
=
'ObjectId'
;
$db_params
=
$this
->
getModule
(
'api_config'
)
->
getConfig
(
'db'
);
if
(
$db_params
[
'type'
]
===
Database
::
PGSQL_TYPE
)
{
...
...
@@ -51,7 +51,22 @@ FROM Object
LEFT JOIN Job USING (JobId) '
.
$where
[
'where'
]
.
$order
.
$limit
;
return
ObjectRecord
::
finder
()
->
findAllBySql
(
$sql
,
$where
[
'params'
]);
$result
=
ObjectRecord
::
finder
()
->
findAllBySql
(
$sql
,
$where
[
'params'
]);
if
(
is_string
(
$groupby
)
&&
is_array
(
$result
))
{
// Group results
$new_result
=
[];
for
(
$i
=
0
;
$i
<
count
(
$result
);
$i
++
)
{
if
(
!
property_exists
(
$result
[
$i
],
$groupby
))
{
continue
;
}
if
(
!
key_exists
(
$result
[
$i
]
->
{
$groupby
},
$new_result
))
{
$new_result
[
$result
[
$i
]
->
{
$groupby
}]
=
[];
}
$new_result
[
$result
[
$i
]
->
{
$groupby
}][]
=
$result
[
$i
];
}
$result
=
$new_result
;
}
return
$result
;
}
public
function
getObjectById
(
$objectid
)
{
...
...
gui/baculum/protected/API/Pages/API/Objects.php
View file @
e84cf590
...
...
@@ -21,6 +21,7 @@
*/
use
Baculum\Common\Modules\Errors\ObjectError
;
use
Baculum\API\Modules\ObjectRecord
;
/**
* Objects endpoint.
...
...
@@ -42,6 +43,29 @@ class Objects extends BaculumAPIServer {
$objectstatus
=
$this
->
Request
->
contains
(
'objectstatus'
)
&&
$misc
->
isValidState
(
$this
->
Request
[
'objectstatus'
])
?
$this
->
Request
[
'objectstatus'
]
:
null
;
$jobname
=
$this
->
Request
->
contains
(
'jobname'
)
&&
$misc
->
isValidName
(
$this
->
Request
[
'jobname'
])
?
$this
->
Request
[
'jobname'
]
:
null
;
$jobids
=
$this
->
Request
->
contains
(
'jobids'
)
&&
$misc
->
isValidIdsList
(
$this
->
Request
[
'jobids'
])
?
explode
(
','
,
$this
->
Request
[
'jobids'
])
:
[];
$groupby
=
$this
->
Request
->
contains
(
'groupby'
)
&&
$misc
->
isValidColumn
(
$this
->
Request
[
'groupby'
])
?
strtolower
(
$this
->
Request
[
'groupby'
])
:
null
;
if
(
is_string
(
$groupby
))
{
$or
=
new
\
ReflectionClass
(
'Baculum\API\Modules\ObjectRecord'
);
$group_cols
=
$or
->
getProperties
();
$cols_excl
=
[
'jobname'
];
$columns
=
[];
foreach
(
$group_cols
as
$cols
)
{
$name
=
$cols
->
getName
();
// skip columns not existing in the catalog
if
(
in_array
(
$name
,
$cols_excl
))
{
continue
;
}
$columns
[]
=
$name
;
}
if
(
!
in_array
(
$groupby
,
$columns
))
{
$this
->
output
=
ObjectError
::
MSG_ERROR_INVALID_PROPERTY
;
$this
->
error
=
ObjectError
::
ERROR_INVALID_PROPERTY
;
return
;
}
}
$params
=
[];
if
(
!
empty
(
$objecttype
))
{
...
...
@@ -94,7 +118,7 @@ class Objects extends BaculumAPIServer {
];
}
$objects
=
$this
->
getModule
(
'object'
)
->
getObjects
(
$params
,
$limit
);
$objects
=
$this
->
getModule
(
'object'
)
->
getObjects
(
$params
,
$limit
,
$groupby
);
$this
->
output
=
$objects
;
$this
->
error
=
ObjectError
::
ERROR_NO_ERRORS
;
}
...
...
gui/baculum/protected/API/openapi_baculum.json
View file @
e84cf590
...
...
@@ -6283,7 +6283,7 @@
"error"
:
{
"type"
:
"integer"
,
"description"
:
"Error code"
,
"enum"
:
[
0
,
1
,
2
,
3
,
6
,
7
,
1000
]
"enum"
:
[
0
,
1
,
2
,
3
,
6
,
7
,
520
,
1000
]
}
}
}
...
...
@@ -6366,6 +6366,15 @@
"schema"
:
{
"type"
:
"string"
}
},
{
"name"
:
"groupby"
,
"in"
:
"query"
,
"required"
:
false
,
"description"
:
"Object property to group results. Note: it changes the result output format."
,
"schema"
:
{
"type"
:
"string"
}
}
]
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment