In your terminal:
mvnw spring-boot:run
There are several files that make up this sample:
DomController.java: The class that parses the.rdashfiles and returns a JSON list to the client app.VisualizationChartInfo.java: The model class that represents a Visualization.DashboardNameInfo.java: The model class that represents the simplified dashboard information.
The DomController class is a JAX-RS-based RESTful controller that exposes endpoints to retrieve visualizations and dashboard names from .rdash files. It processes the dashboards to extract relevant information and format it into JSON responses.
- Core Java Libraries: Used for file handling (
File), I/O operations (BufferedReader,InputStream), and handling ZIP files. - JSON Libraries: For JSON parsing and object manipulation.
- Jakarta RESTful Web Services (JAX-RS): For REST API annotations and functionality.
Defines the base path for all endpoints in this controller.
- HTTP Method:
GET - Path:
/visualizations - Response Format:
application/json - Description: Retrieves all visualizations from
.rdashfiles stored in thedashboardsfolder.
- HTTP Method:
GET - Path:
/names - Response Format:
application/json - Description: Retrieves the names and titles of all dashboards from
.rdashfiles stored in thedashboardsfolder.
- Purpose: Main function to process
.rdashfiles and extract visualization data. - Steps:
- Scans the
dashboardsfolder for.rdashfiles. - Reads each
.rdashfile as a ZIP archive to find and extract its.jsoncontent. - Parses the extracted JSON to retrieve dashboard and widget information.
- Formats the data into
VisualizationChartInfoobjects.
- Scans the
- Purpose: Retrieves the names and titles of all dashboards.
- Steps:
- Scans the
dashboardsfolder for.rdashfiles. - Reads each
.rdashfile as a ZIP archive to find and extract its.jsoncontent. - Parses the extracted JSON to retrieve the dashboard
Title. - Formats the data into
DashboardNameInfoobjects.
- Scans the
- Purpose: Extracts the JSON content from a
.rdashfile, treating it as a ZIP archive. - Steps:
- Opens the
.rdashfile as aZipFile. - Finds entries ending with
.json. - Reads and returns the content of the
.jsonentry as a string.
- Opens the
- Purpose: Extracts the
Titlefield from the JSON content of a dashboard. - Default Behavior: Returns
"Untitled"if noTitlefield exists.
- Purpose: Parses the widgets array in the JSON content and maps it to a list of
VisualizationChartInfoobjects. - Steps:
- Checks for the presence of a
Widgetsarray in the JSON. - Iterates through the widgets to extract:
- Widget ID
- Title
- Visualization settings (e.g., type, view type, chart type)
- Determines the appropriate visualization chart type based on the settings.
- Generates the image URL for the chart type.
- Constructs and returns a list of
VisualizationChartInfoobjects.
- Checks for the presence of a
- Purpose: Constructs an image URL for a given visualization chart type.
- Default Behavior: Appends
.pngto the chart type name, removing the suffix "Visualization" if present.
The project includes the following supporting classes:
- Purpose: Represents information about a single visualization chart.
- Fields:
dashboardFileName: The name of the dashboard file.dashboardTitle: The title of the dashboard.vizId: The unique ID of the visualization widget.vizTitle: The title of the widget.vizChartType: The type of the chart (e.g., Line, Bar, Gauge).vizImageUrl: URL for the visualization chart image.
- Purpose: Represents simplified information about a dashboard.
- Fields:
dashboardFileName: The name of the dashboard file.dashboardTitle: The title of the dashboard.
-
Dynamic Parsing:
- Automatically discovers
.rdashfiles and extracts their visualization and name data without hardcoding file paths.
- Automatically discovers
-
Flexible Chart Type Handling:
- Supports multiple visualization types with fallbacks for unknown types.
-
Error Handling:
- Logs errors when
.rdashfiles are missing or malformed JSON is encountered.
- Logs errors when
-
Extensibility:
- Easily extendable to handle additional visualization settings, dashboard metadata, or customization.
-
RESTful Design:
- Simplifies integration with frontend or other services by providing structured JSON data.