Skip to main content

πŸ“Œ API Detail Design Document

1. API Information​

  • API Name: Collect sonar all data
  • Module/Service: amdp-ags-dashboard-backend
  • Author: Reus
  • Created Date: 2025/08/18
  • Last Updated: 2025/08/18

2. Overview​

  • Purpose: API collect data sonar on sonar server
  • Description: Collect branch data

3. Endpoint Specification​

  • Method: POST
  • URL: /dashboard/collect/sonar/all-data
  • Headers:
    • Authorization: Bearer <token user>
    • Content-Type: application/json

Query Params​

NameTypeRequiredDescriptionExample

Path Params​

NameTypeRequiredDescriptionExample

Request Body​

{
"applicationId": "app-67890",
"applicationName": "My Application",
"collectFrom": "2024-01-01T00:00:00Z",
"collectTo": "2024-12-31T23:59:59Z",
"componentKey": "component-123",
"componentName": "Main Component",
"host": "http://sonar.example.com",
"password": "securePassword",
"profileId": 12345,
"profileName": "My Sonar Profile",
"projectId": 14245,
"projectName": "My Project",
"token": "abc123token",
"tool": "SONAR",
"username": "user123"
}


4. Response Specification​

Success Response (200/201)​

{"code": 200,"message": "Success"}

Error Response (400/401/404/500)​

{"code": 400,"message": "Bad Request"}

5. Sequence / Flow (Source)​

@startuml
actor Client
participant "Dashboard Service" as DS
queue "Request Queue" as Q
participant "Scheduler (5s)" as Sch
database "MongoDB\nstatusManagerCollection" as StatusDB
participant "Worker Pool (max=5)" as Worker
participant "SonarQube API" as Sonar
database "MongoDB\nsonarMeasureComponentCollection" as SonarDB


Client -> DS: POST /collectSonarData\n{projectKey, metrics, collectFrom, collectTo, ...}
activate DS
DS -> Q: Push collect request
DS -> StatusDB: Insert status = "waiting for sync"
DS --> Client: 200 OK\n{ "message": "Request queued" }
deactivate DS


Sch -> Q: Poll request (FIFO)
Q --> Sch: Request (if available)


alt If request found
Sch -> Worker: Dispatch request (max 5 parallel)
activate Worker
Worker -> StatusDB: Update status = "in sync"
Worker -> Sonar: Fetch measure component data\\n(using token, projectKey, metrics)
activate Sonar
Sonar --> Worker: Measure component data (JSON)
deactivate Sonar
Worker -> SonarDB: Insert measure component data
Worker -> StatusDB: Update status = "success"
deactivate Worker

else No request
Sch -> Sch: Wait 5s
end


'--- Error handling ---
Worker -> StatusDB: Update status = "failed" (on error)

@enduml

6. Sequence / Flow (Image)​


7. Dependencies​

  • DB tables:

    • sonarMeasureComponentCollection
  • External service call:

  • Message broker/topic:


8. Security & Performance Considerations​

  • Authentication & Authorization
  • Rate limit / Throttling
  • Caching
  • Timeout & Retry logic

9. Test Cases (basic)​

CaseInputExpected OutputNotes
Valid request{...}200 + data
Missing param{}400 error
Unauthorized401 error

10. Change History​

VersionDateAuthorChange