|
| 1 | +# ------------------------------------------------------------------------------- |
| 2 | +# Copyright (c) 2024 Siemens |
| 3 | +# All Rights Reserved. |
| 4 | +# Authors: thomas.graf@siemens.com |
| 5 | +# |
| 6 | +# Licensed under the MIT license. |
| 7 | +# SPDX-License-Identifier: MIT |
| 8 | +# ------------------------------------------------------------------------------- |
| 9 | + |
| 10 | +from typing import Any, Dict, List, Optional |
| 11 | + |
| 12 | +from .base import BaseMixin |
| 13 | + |
| 14 | + |
| 15 | +class ModerationRequestMixin(BaseMixin): |
| 16 | + def get_all_moderation_requests(self, page: int = -1, page_size: int = -1, |
| 17 | + sort: str = "") -> List[Dict[str, Any]]: |
| 18 | + """Get information of about all moderation requests |
| 19 | +
|
| 20 | + API endpoint: GET /moderationrequest |
| 21 | +
|
| 22 | + :param page: page to retrieve |
| 23 | + :type page: int |
| 24 | + :param page_size: page size to use |
| 25 | + :type page_size: int |
| 26 | + :param sort: sort order for the packages ("name,desc"; "name,asc") |
| 27 | + :type sort: str |
| 28 | + :return: list of moderation requests |
| 29 | + :rtype: list of JSON moderation requests objects |
| 30 | + :raises SW360Error: if there is a negative HTTP response |
| 31 | + """ |
| 32 | + |
| 33 | + full_url = self.url + "resource/api/moderationrequest" |
| 34 | + if page > -1: |
| 35 | + full_url = self._add_param(full_url, "page=" + str(page)) |
| 36 | + full_url = self._add_param(full_url, "page_entries=" + str(page_size)) |
| 37 | + |
| 38 | + if sort: |
| 39 | + # ensure HTML encoding |
| 40 | + sort = sort.replace(",", "%2C") |
| 41 | + full_url = self._add_param(full_url, "sort=" + sort) |
| 42 | + |
| 43 | + resp = self.api_get(full_url) |
| 44 | + return resp |
| 45 | + |
| 46 | + def get_moderation_requests_by_state(self, state: str, all_details: bool = False, |
| 47 | + page: int = -1, page_size: int = -1, |
| 48 | + sort: str = "") -> List[Dict[str, Any]]: |
| 49 | + """Get information of about all moderation requests |
| 50 | +
|
| 51 | + API endpoint: GET /moderationrequest/byState |
| 52 | +
|
| 53 | + :param all_details: retrieve all package details (optional)) |
| 54 | + :type all_details: bool |
| 55 | + :param page: page to retrieve |
| 56 | + :type page: int |
| 57 | + :param page_size: page size to use |
| 58 | + :type page_size: int |
| 59 | + :param sort: sort order for the packages ("name,desc"; "name,asc") |
| 60 | + :type sort: str |
| 61 | + :return: list of moderation requests |
| 62 | + :rtype: list of JSON moderation requests objects |
| 63 | + :raises SW360Error: if there is a negative HTTP response |
| 64 | + """ |
| 65 | + |
| 66 | + full_url = self.url + "resource/api/moderationrequest/byState?state=" + state |
| 67 | + if all_details: |
| 68 | + full_url = self._add_param(full_url, "allDetails=true") |
| 69 | + |
| 70 | + if page > -1: |
| 71 | + full_url = self._add_param(full_url, "page=" + str(page)) |
| 72 | + full_url = self._add_param(full_url, "page_entries=" + str(page_size)) |
| 73 | + |
| 74 | + if sort: |
| 75 | + # ensure HTML encoding |
| 76 | + sort = sort.replace(",", "%2C") |
| 77 | + full_url = self._add_param(full_url, "sort=" + sort) |
| 78 | + |
| 79 | + resp = self.api_get(full_url) |
| 80 | + return resp |
| 81 | + |
| 82 | + def get_moderation_request(self, mr_id: str) -> Optional[Dict[str, Any]]: |
| 83 | + """Get information of about a moderation request |
| 84 | +
|
| 85 | + API endpoint: GET /moderationrequest/{id} |
| 86 | +
|
| 87 | + :param mr_id: the id of the moderation request to be requested |
| 88 | + :type mr_id: string |
| 89 | + :return: a moderation request |
| 90 | + :rtype: JSON moderation request object |
| 91 | + :raises SW360Error: if there is a negative HTTP response |
| 92 | + """ |
| 93 | + |
| 94 | + resp = self.api_get(self.url + "resource/api/moderationrequest/" + mr_id) |
| 95 | + return resp |
0 commit comments