-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement paging for releases and components
- Loading branch information
Showing
8 changed files
with
75 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Copyright (c) 2019-2022 Siemens | ||
# Copyright (c) 2019-2023 Siemens | ||
# Copyright (c) 2022 BMW CarIT GmbH | ||
# All Rights Reserved. | ||
# Authors: [email protected], [email protected] | ||
|
@@ -15,24 +15,40 @@ | |
|
||
|
||
class ComponentsMixin: | ||
def get_all_components(self, fields=None, page=-1, page_size=-1): | ||
def get_all_components(self, fields=None, page=-1, page_size=-1, all_details: bool = False, sort: str = ""): | ||
"""Get information of about all components | ||
API endpoint: GET /components | ||
:param page: page to retrieve | ||
:type page: int | ||
:param page_size: page size to use | ||
:type page_size: int | ||
:param all_details: retrieve all component details (optional)) | ||
:type all_details: bool | ||
:param sort: sort order for the components ("name,desc"; "name,asc") | ||
:type sort: str | ||
:return: list of components | ||
:rtype: list of JSON component objects | ||
:raises SW360Error: if there is a negative HTTP response | ||
""" | ||
|
||
url = self.url + "resource/api/components" | ||
|
||
if all_details: | ||
url = self._add_param(url, "allDetails=true") | ||
|
||
if fields: | ||
url = self.url + "resource/api/components?fields=" + fields | ||
else: | ||
url = self.url + "resource/api/components" | ||
url = self._add_param(url, "fields=" + fields) | ||
|
||
if page > -1: | ||
url = url + "?page=" + str(page) + "&page_entries=" | ||
url = url + str(page_size) + "&sort=name%2Cdesc" | ||
url = self._add_param(url, "page=" + str(page)) | ||
url = self._add_param(url, "page_entries=" + str(page_size)) | ||
|
||
if sort: | ||
# ensure HTML encoding | ||
sort = sort.replace(",", "%2C") | ||
url = self._add_param(url, "sort=" + sort) | ||
|
||
resp = self.api_get(url) | ||
if not resp: | ||
|
@@ -44,7 +60,8 @@ def get_all_components(self, fields=None, page=-1, page_size=-1): | |
if "sw360:components" not in resp["_embedded"]: | ||
return None | ||
|
||
resp = resp["_embedded"]["sw360:components"] | ||
if page == -1: | ||
resp = resp["_embedded"]["sw360:components"] | ||
return resp | ||
|
||
def get_components_by_type(self, component_type): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Copyright (c) 2019-2022 Siemens | ||
# Copyright (c) 2019-2023 Siemens | ||
# Copyright (c) 2022 BMW CarIT GmbH | ||
# All Rights Reserved. | ||
# Authors: [email protected], [email protected] | ||
|
@@ -60,27 +60,42 @@ def get_releases_by_name(self, name): | |
resp = resp["_embedded"]["sw360:releases"] | ||
return resp | ||
|
||
def get_all_releases(self, fields=None, all_details=False): | ||
def get_all_releases(self, fields=None, all_details=False, page: int = -1, page_size: int = -1, sort: str = ""): | ||
"""Get information of about all releases | ||
API endpoint: GET /releases | ||
:param all_details: retrieve all project details (optional)) | ||
:type all_details: bool | ||
:param page: page to retrieve | ||
:type page: int | ||
:param page_size: page size to use | ||
:type page_size: int | ||
:param sort: sort order for the releases ("name,desc"; "name,asc") | ||
:type sort: str | ||
:return: list of releases | ||
:rtype: list of JSON release objects | ||
:raises SW360Error: if there is a negative HTTP response | ||
""" | ||
full_url = self.url + "resource/api/releases" | ||
if all_details: | ||
full_url = full_url + "?allDetails=true" | ||
full_url = self._add_param(full_url, "allDetails=true") | ||
|
||
if fields: | ||
full_url = full_url + "?fields=" + fields | ||
full_url = self._add_param(full_url, "fields=" + fields) | ||
|
||
if page > -1: | ||
full_url = self._add_param(full_url, "page=" + str(page)) | ||
full_url = self._add_param(full_url, "page_entries=" + str(page_size)) | ||
|
||
if sort: | ||
# ensure HTML encoding | ||
sort = sort.replace(",", "%2C") | ||
full_url = self._add_param(full_url, "sort=" + sort) | ||
|
||
resp = self.api_get(full_url) | ||
|
||
if resp and ("_embedded" in resp) and ("sw360:releases" in resp["_embedded"]): | ||
if page == -1 and resp and ("_embedded" in resp) and ("sw360:releases" in resp["_embedded"]): | ||
resp = resp["_embedded"]["sw360:releases"] | ||
return resp | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Copyright (c) 2020 Siemens | ||
# Copyright (c) 2023 Siemens | ||
# All Rights Reserved. | ||
# Author: [email protected] | ||
# | ||
|
@@ -191,7 +191,7 @@ def test_get_all_releases_with_fields_and_all_details(self): | |
|
||
responses.add( | ||
method=responses.GET, | ||
url=self.MYURL + "resource/api/releases?allDetails=true?fields=releaseDate", | ||
url=self.MYURL + "resource/api/releases?allDetails=true&fields=releaseDate", | ||
body='{"_embedded": {"sw360:releases": [{"name": "Tethys.Logging", "version": "1.3.0", "releaseDate": "2018-03-04"}]}}', # noqa | ||
status=200, | ||
content_type="application/json", | ||
|