Skip to content

Add Dashboard Config API for managing dashboard configurations#1

Merged
odtorres merged 3 commits into
trunkfrom
based/configjson-wescript-management
Mar 18, 2026
Merged

Add Dashboard Config API for managing dashboard configurations#1
odtorres merged 3 commits into
trunkfrom
based/configjson-wescript-management

Conversation

@odtorres

@odtorres odtorres commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Implement DashboardConfigService and its implementation, DashboardConfigServiceImpl, to handle retrieval and storage of dashboard configurations. Create DashboardConfigWebscript to expose the API for getting and saving configurations via web requests. Update service and webscript contexts for dependency injection. Add XML descriptor for webscript and unit tests for the webscript functionality.

Summary by CodeRabbit

  • New Features

    • Added a dashboard configuration API to fetch and save dashboard layout JSON for sites, with input validation, clear JSON responses, and proper HTTP error codes.
  • Tests

    • Added tests covering get, save, missing config, and unknown-action error handling to validate API behavior.
  • Chores

    • Project version updated to 0.0.1.

Implement DashboardConfigService and its implementation, DashboardConfigServiceImpl, to handle retrieval and storage of dashboard configurations. Create DashboardConfigWebscript to expose the API for getting and saving configurations via web requests. Update service and webscript contexts for dependency injection. Add XML descriptor for webscript and unit tests for the webscript functionality.
@odtorres odtorres self-assigned this Mar 13, 2026
@coderabbitai

coderabbitai Bot commented Mar 13, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0b756bc2-9be8-4921-a4e2-36f8767d0e40

📥 Commits

Reviewing files that changed from the base of the PR and between 5252d4b and 71ef95a.

📒 Files selected for processing (2)
  • pom.xml
  • src/main/java/com/microboxlabs/dashboards/dashboard/webscript/DashboardConfigWebscript.java

📝 Walkthrough

Walkthrough

This pull request adds dashboard configuration management: a new service interface and Alfresco-backed implementation, a web script REST endpoint for get/save actions, Spring bean wiring, a webscript descriptor, and unit tests for the webscript behaviors.

Changes

Cohort / File(s) Summary
Service Layer
src/main/java/com/microboxlabs/dashboards/dashboard/service/DashboardConfigService.java, src/main/java/com/microboxlabs/dashboards/dashboard/service/DashboardConfigServiceImpl.java
Adds DashboardConfigService interface and DashboardConfigServiceImpl implementing getConfig/saveConfig. Implementation interacts with Alfresco services (SiteService, NodeService, FileFolderService, ContentService) to locate/create document library and dashboard folder, and read/write JSON files.
Web Script
src/main/java/com/microboxlabs/dashboards/dashboard/webscript/DashboardConfigWebscript.java, src/main/resources/alfresco/extension/templates/webscripts/microboxlabs/dashboards/dashboard-config/api.post.desc.xml
Introduces DashboardConfigWebscript handling POST actions get and save, validates JSON request body, delegates to service, and returns JSON responses with proper HTTP status codes. Descriptor registers URL pattern and auth/transaction settings.
Spring Configuration
src/main/resources/alfresco/module/miot-dashboards/context/service-context.xml, src/main/resources/alfresco/module/miot-dashboards/context/webscript-context.xml
Registers dashboardConfigService bean wired with Alfresco services and a webscript bean webscript.microboxlabs.dashboards.dashboard-config.api.post referencing the service.
Tests
src/test/java/com/microboxlabs/dashboards/dashboard/webscript/DashboardConfigWebscriptTest.java
Adds unit tests for webscript: get returns config, get returns null, save invokes service, and unknown action returns 400.
Build
pom.xml
Bumps project version to 0.0.1.

Sequence Diagram(s)

sequenceDiagram
    participant Client as HTTP Client
    participant WebScript as DashboardConfigWebscript
    participant Service as DashboardConfigServiceImpl
    participant SiteService as SiteService
    participant FileFolderService as FileFolderService
    participant ContentService as ContentService
    participant FileSystem as AlfrescoFS

    rect rgba(100,150,200,0.5)
    Note over Client,WebScript: GET flow
    Client->>WebScript: POST {action: "get", site, slug}
    WebScript->>Service: getConfig(site, slug)
    Service->>SiteService: getSite(site)
    SiteService-->>Service: site info
    Service->>FileFolderService: getContainer(site, DOCUMENT_LIBRARY)
    FileFolderService-->>Service: docLib NodeRef
    Service->>FileFolderService: searchSimple(docLib, "dashboard")
    alt dashboard folder exists
        FileFolderService-->>Service: dashboard NodeRef
    else missing
        Service-->>WebScript: null
        WebScript-->>Client: {data: null}
    end
    Service->>FileFolderService: searchSimple(dashboard, filename)
    FileFolderService-->>Service: file NodeRef
    Service->>ContentService: getReader(file)
    ContentService->>FileSystem: read JSON
    FileSystem-->>ContentService: JSON
    ContentService-->>Service: content string
    Service-->>WebScript: config JSON
    WebScript-->>Client: {data: config}
    end
Loading
sequenceDiagram
    participant Client as HTTP Client
    participant WebScript as DashboardConfigWebscript
    participant Service as DashboardConfigServiceImpl
    participant SiteService as SiteService
    participant FileFolderService as FileFolderService
    participant ContentService as ContentService
    participant FileSystem as AlfrescoFS

    rect rgba(150,200,100,0.5)
    Note over Client,WebScript: SAVE flow
    Client->>WebScript: POST {action: "save", site, slug, config}
    WebScript->>Service: saveConfig(site, slug, configJson)
    Service->>SiteService: getSite(site)
    SiteService-->>Service: site info
    Service->>FileFolderService: getContainer(site, DOCUMENT_LIBRARY)
    FileFolderService-->>Service: docLib NodeRef
    Service->>FileFolderService: getOrCreateFolder(docLib, "dashboard")
    FileFolderService-->>Service: dashboard NodeRef
    Service->>FileFolderService: getOrCreateFile(dashboard, filename)
    FileFolderService-->>Service: file NodeRef
    Service->>ContentService: getWriter(file)
    ContentService->>FileSystem: write JSON (application/json, UTF-8)
    FileSystem-->>ContentService: write complete
    ContentService-->>Service: success
    Service-->>WebScript: void
    WebScript-->>Client: {success: true}
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I'm a little rabbit, nibbling code with cheer,
Folders hop in order, JSON held so near,
Beans are sewn in Springtime, webscripts hum and play,
Configs snug in Alfresco, saved to hop away. 🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly summarizes the main change: adding a Dashboard Config API for managing dashboard configurations, which is the primary objective reflected across all file changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch based/configjson-wescript-management
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@korutx korutx added this to the MIOT-0.4.4 milestone Mar 13, 2026
@korutx korutx self-requested a review March 13, 2026 19:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/test/java/com/microboxlabs/dashboards/dashboard/webscript/DashboardConfigWebscriptTest.java (1)

42-101: Consider adding test coverage for error handling paths.

The current tests cover the happy paths well. However, the webscript has several error-handling branches that aren't tested:

  • Missing required parameters (site/slug) → 400 response
  • IllegalStateException from service → 404 response
  • General exceptions → 500 response

Would you like me to generate additional test cases for these error scenarios?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/com/microboxlabs/dashboards/dashboard/webscript/DashboardConfigWebscriptTest.java`
around lines 42 - 101, Add unit tests in DashboardConfigWebscriptTest to cover
the error branches: create a test for missing required params by setting
req.getContent().getContent() to JSON missing "site" or "slug" and assert
webscript.execute(req,res) results in res.setStatus(400), response contains
"error", and that service.getConfig/saveConfig is not called; create a test
where service.getConfig (or saveConfig for save action) is mocked to throw new
IllegalStateException(...) and assert webscript.execute sets res.setStatus(404)
and response contains the exception message; and create a test where the service
throws a generic RuntimeException and assert webscript.execute sets
res.setStatus(500) and response contains "error" — use existing helpers/objects
(Match, req, res, responseWriter, service, webscript) and verify interactions
with service and response status for each case.
src/main/java/com/microboxlabs/dashboards/dashboard/service/DashboardConfigServiceImpl.java (2)

18-18: Unused constant.

MIMETYPE_JSON is defined but not used. Line 83 uses a hardcoded "application/json" string instead.

Use the constant consistently
         var writer = contentService.getWriter(configFile, ContentModel.PROP_CONTENT, true);
-        writer.setMimetype("application/json");
+        writer.setMimetype(MIMETYPE_JSON);
         writer.setEncoding("UTF-8");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/com/microboxlabs/dashboards/dashboard/service/DashboardConfigServiceImpl.java`
at line 18, The MIMETYPE_JSON constant in DashboardConfigServiceImpl is defined
but not used; replace the hardcoded "application/json" occurrences (e.g., the
usage at the method around the current line that sets the response/content type)
with the MIMETYPE_JSON constant to use it consistently, and if after replacing
all occurrences the constant ends up unused elsewhere remove the now-unnecessary
constant declaration.

107-109: Add slug validation before constructing filename.

The slug parameter is used directly to construct filenames without validation. Alfresco's FileFolderService enforces a cm:filename constraint that rejects characters like /, \, :, *, ", <, >, |, ?, and trailing spaces. If the slug contains these characters, FileFolderService.create() and searchSimple() will fail with a constraint violation.

Add validation to reject or sanitize invalid characters before calling toFileName(), or implement pre-sanitization in the method itself.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/com/microboxlabs/dashboards/dashboard/service/DashboardConfigServiceImpl.java`
around lines 107 - 109, The toFileName method currently concatenates the slug
into a filename without validation; update DashboardConfigServiceImpl.toFileName
to either validate the incoming slug and throw a clear IllegalArgumentException
when it contains any forbidden cm:filename characters (/ \ : * " < > | ? or
trailing spaces) or to sanitize the slug by removing or replacing those
characters and trimming trailing spaces before appending "-config.json"; ensure
you perform this check/sanitization wherever toFileName is called (or centralize
it inside toFileName) so FileFolderService.create() and searchSimple() receive
only valid filenames.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/com/microboxlabs/dashboards/dashboard/webscript/DashboardConfigWebscript.java`:
- Around line 85-87: The error thrown in DashboardConfigWebscript.java currently
says "Missing required fields: site, slug, and config" even though site and slug
were already validated; update the WebScriptException thrown in the block that
checks body.has("config") to only mention the missing "config" field (e.g.,
"Missing required field: config") so the exception message accurately reflects
the validation that failed in the method where the check occurs.

---

Nitpick comments:
In
`@src/main/java/com/microboxlabs/dashboards/dashboard/service/DashboardConfigServiceImpl.java`:
- Line 18: The MIMETYPE_JSON constant in DashboardConfigServiceImpl is defined
but not used; replace the hardcoded "application/json" occurrences (e.g., the
usage at the method around the current line that sets the response/content type)
with the MIMETYPE_JSON constant to use it consistently, and if after replacing
all occurrences the constant ends up unused elsewhere remove the now-unnecessary
constant declaration.
- Around line 107-109: The toFileName method currently concatenates the slug
into a filename without validation; update DashboardConfigServiceImpl.toFileName
to either validate the incoming slug and throw a clear IllegalArgumentException
when it contains any forbidden cm:filename characters (/ \ : * " < > | ? or
trailing spaces) or to sanitize the slug by removing or replacing those
characters and trimming trailing spaces before appending "-config.json"; ensure
you perform this check/sanitization wherever toFileName is called (or centralize
it inside toFileName) so FileFolderService.create() and searchSimple() receive
only valid filenames.

In
`@src/test/java/com/microboxlabs/dashboards/dashboard/webscript/DashboardConfigWebscriptTest.java`:
- Around line 42-101: Add unit tests in DashboardConfigWebscriptTest to cover
the error branches: create a test for missing required params by setting
req.getContent().getContent() to JSON missing "site" or "slug" and assert
webscript.execute(req,res) results in res.setStatus(400), response contains
"error", and that service.getConfig/saveConfig is not called; create a test
where service.getConfig (or saveConfig for save action) is mocked to throw new
IllegalStateException(...) and assert webscript.execute sets res.setStatus(404)
and response contains the exception message; and create a test where the service
throws a generic RuntimeException and assert webscript.execute sets
res.setStatus(500) and response contains "error" — use existing helpers/objects
(Match, req, res, responseWriter, service, webscript) and verify interactions
with service and response status for each case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 62ae9600-2284-483a-821d-1f94cf51c889

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac4109 and 5252d4b.

📒 Files selected for processing (7)
  • src/main/java/com/microboxlabs/dashboards/dashboard/service/DashboardConfigService.java
  • src/main/java/com/microboxlabs/dashboards/dashboard/service/DashboardConfigServiceImpl.java
  • src/main/java/com/microboxlabs/dashboards/dashboard/webscript/DashboardConfigWebscript.java
  • src/main/resources/alfresco/extension/templates/webscripts/microboxlabs/dashboards/dashboard-config/api.post.desc.xml
  • src/main/resources/alfresco/module/miot-dashboards/context/service-context.xml
  • src/main/resources/alfresco/module/miot-dashboards/context/webscript-context.xml
  • src/test/java/com/microboxlabs/dashboards/dashboard/webscript/DashboardConfigWebscriptTest.java

@odtorres odtorres merged commit 302d6aa into trunk Mar 18, 2026
1 of 2 checks passed
@odtorres odtorres deleted the based/configjson-wescript-management branch March 18, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants