"""Report enumeration and metadata for Web Intelligence documents."""
from typing import List, Dict, TYPE_CHECKING
if TYPE_CHECKING:
from .client import BOAPIClient
[docs]
class ReportsManager:
"""Manager for the reports of a BusinessObjects document.
Reports correspond to the views and tables configured in Web Intelligence
documents.
"""
def __init__(self, client: 'BOAPIClient'):
"""Initialize the manager.
:param client: BO client instance
:type client: BOAPIClient
"""
self.client = client
[docs]
def get_reports(self, doc_id: str) -> List[Dict]:
"""Return the list of reports of a document.
:param doc_id: Document identifier
:type doc_id: str
:return: List of reports, each report being a dictionary
:rtype: List[Dict]
:raises Exception: If the API returns an error other than 404
"""
response = self.client.session.get(
f"{self.client.base_url}/raylight/v1/documents/{doc_id}/reports",
headers=self.client.get_headers(use_quotes=True)
)
if response.status_code == 200:
reports = response.json()
report_list = reports.get("reports", {}).get("report", [])
if not isinstance(report_list, list):
report_list = [report_list]
return report_list
elif response.status_code == 404:
# The document has no reports (this is normal)
return []
else:
raise Exception(f"Failed to fetch reports: {response.status_code} - {response.text}")
[docs]
def list_reports(self, doc_id: str, show_details: bool = True) -> List[Dict]:
"""Print the list of reports of a document.
:param doc_id: Document identifier
:type doc_id: str
:param show_details: Enable detail output
:type show_details: bool
:return: List of reports
:rtype: List[Dict]
"""
reports = self.get_reports(doc_id)
if not reports:
print("No report found in this document")
return []
print(f"\nAvailable reports ({len(reports)}):")
for report in reports:
name = report.get('name', 'Unnamed')
report_id = report.get('id', 'N/A')
print(f" - {name}")
if show_details:
print(f" - ID: {report_id}")
return reports