---
# (DD09) Business Logic — CurrencyRateAPI.getCurrencyCode() [10 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.github.blaxk3.api.CurrencyRateAPI` |
| Layer | Utility |
| Module | `api` (Package: `com.github.blaxk3.api`) |

## 1. Role

### CurrencyRateAPI.getCurrencyCode()

This method retrieves the list of available currency codes from the external ExchangeRate API by calling the USD latest-rate endpoint and extracting the keys from the `conversion_rates` payload. Business-wise, it acts as a currency master lookup helper: instead of calculating a conversion value, it exposes the set of supported foreign currency codes that the UI or other consumers can present to the user as selectable options. The method follows a lightweight delegation pattern, combining URL construction, HTTP retrieval, JSON inspection, and final conversion of the response map keys into a `String[]`. It is therefore a read-only integration method used as a shared gateway to a third-party currency reference service. If the API response is missing, or if the `conversion_rates` object is absent or empty, the method returns `null` to signal that no currency code list could be resolved.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getCurrencyCode()"])
    CALL_URL(["Call getURL()"])
    BUILD_URI(["Build URI /latest/USD"])
    CALL_JSON(["Call getJsonObject(URL)"])
    COND_JSON{"jsonObject != null and has conversion_rates?"}
    GET_CODE(["Get conversion_rates object"])
    COND_CODE{"code != null and keySet not empty?"}
    RETURN_CODES(["Return String[] from keySet"])
    RETURN_NULL(["Return null"])

    START --> CALL_URL
    CALL_URL --> BUILD_URI
    BUILD_URI --> CALL_JSON
    CALL_JSON --> COND_JSON
    COND_JSON -- "Yes" --> GET_CODE
    COND_JSON -- "No" --> RETURN_NULL
    GET_CODE --> COND_CODE
    COND_CODE -- "Yes" --> RETURN_CODES
    COND_CODE -- "No" --> RETURN_NULL
```

**CRITICAL — Constant Resolution:**
No project constant files were present in the repository search results. This method uses only inline string literals, so there are no external constant values to resolve.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

Instance fields and external state read by the method:
- `getURL()` uses the API key loaded from `config.properties` via `getApiKeyService()`.
- `getJsonObject(URL)` performs the outbound HTTP GET and reads the remote ExchangeRate API response.

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|-----------------------|
| R | `CurrencyRateAPI.getJsonObject` | CurrencyRateAPI | - | Calls `getJsonObject` in `CurrencyRateAPI` |
| R | `CurrencyRateAPI.getURL` | CurrencyRateAPI | - | Calls `getURL` in `CurrencyRateAPI` |

Analyze all method calls within this method and classify each as a CRUD operation.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|-----------------------|
| R | `getURL` | CurrencyRateAPI | External ExchangeRate API endpoint URL | Builds the authenticated base URL used for currency code retrieval |
| R | `getJsonObject` | CurrencyRateAPI | External ExchangeRate API response JSON | Executes the HTTP request and reads the latest USD rates payload |
| R | `JsonObject.has` | - | JSON object field `conversion_rates` | Checks whether the response contains the currency-rate map |
| R | `JsonObject.getAsJsonObject` | - | JSON object field `conversion_rates` | Extracts the nested currency-rate map from the response |
| R | `JsonObject.keySet` | - | JSON keys under `conversion_rates` | Reads the set of available currency codes |
| R | `Set.toArray` | - | In-memory array result | Converts the key set into the returned `String[]` |

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `getJsonObject` [R], `getURL` [R]

Trace who calls this method and what this method ultimately calls.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `UI` | `UI` -> `CurrencyRateAPI.getCurrencyCode` | `getJsonObject [R] External ExchangeRate API response JSON` |

## 6. Per-Branch Detail Blocks

**Block 1** — [CALL] `(method entry)` (L61)

> Entry point for retrieving the supported currency code list.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getURL()` // builds the authenticated API base URL |
| 2 | CALL | `new java.net.URI(...).toURL()` // creates the HTTP endpoint for `/latest/USD` |
| 3 | CALL | `getJsonObject(...)` // executes the remote API request |

**Block 2** — [IF] `(jsonObject != null && jsonObject.has("conversion_rates"))` (L62)

> Confirms that the remote response is present and contains the rate map needed for code extraction.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `jsonObject.has("conversion_rates")` // checks whether the response includes the currency-rate collection |
| 2 | CALL | `jsonObject.getAsJsonObject("conversion_rates")` // extracts the nested rate object |

**Block 2.1** — [IF] `(code != null && !code.keySet().isEmpty())` (L64)

> Ensures that at least one currency code exists before returning the list.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `code.keySet()` // reads all available currency code keys |
| 2 | CALL | `code.keySet().toArray(new String[0])` // converts the set of codes into a `String[]` |
| 3 | RETURN | `return code.keySet().toArray(new String[0]);` |

**Block 3** — [ELSE] `(response missing or currency list empty)` (L62-L64)

> Handles the failure or no-data path by returning `null` to the caller.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return null;` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `CurrencyRateAPI` | Class | Integration utility that accesses the external exchange-rate service |
| `getCurrencyCode` | Method | Retrieves the set of supported currency codes from the latest USD exchange-rate response |
| `getURL` | Method | Builds the authenticated base URL for the ExchangeRate API |
| `getJsonObject` | Method | Executes an HTTP GET request and converts the JSON response into a `JsonObject` |
| `conversion_rates` | JSON field | Map of currency codes to exchange-rate values returned by the provider |
| `USD` | Business term | United States dollar, used here as the base currency for the latest-rates lookup |
| `API_KEY` | Configuration key | Secret token used to authenticate requests to the external currency-rate provider |
| `config.properties` | Configuration file | Local property file containing runtime settings such as the API key |
| `ExchangeRate API` | External service | Third-party service that provides foreign exchange rates and supported currency codes |
| `currency code` | Business term | Standardized short code such as USD, JPY, or EUR used to identify a currency |
| `JSON` | Technical term | Data format used by the external API response |
| `HTTP GET` | Technical term | Read-only network request used to retrieve the latest exchange-rate payload |
| `URI` | Technical term | Uniform Resource Identifier used to construct the endpoint before conversion to URL |
| `URL` | Technical term | Network address used by the HTTP client to reach the external API |
| `null` | Technical term | Indicates that no valid currency-code list could be resolved from the response |
