---

# (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()

`CurrencyRateAPI.getCurrencyCode()` is a read-oriented utility method that retrieves the list of supported currency codes from an external exchange-rate endpoint and returns them as a `String[]`. In business terms, it acts as a currency master discovery function: instead of maintaining a local currency list, it asks the remote rate service for the current `conversion_rates` keys and exposes those keys to the rest of the application. The method is designed as a lightweight data retrieval and transformation routine, using a simple delegation pattern to reuse `getURL()` and `getJsonObject()` for endpoint construction and JSON parsing. Its role in the system is to provide a shared currency-code source that can be consumed by UI or higher-level application flows when currency selection or display needs to be dynamically populated. The method has two outcome branches: when the response contains a non-empty `conversion_rates` object, it returns all available currency codes; otherwise, it returns `null` to signal that no usable currency list was obtained.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["getCurrencyCode()"]
    CALL_GETJSON["Call getJsonObject(new URI(getURL() + latest + USD).toURL())"]
    CHECK_JSON{"jsonObject != null and has conversion_rates"}
    GET_CODE["jsonObject.getAsJsonObject(conversion_rates)"]
    CHECK_KEYSET{"code != null and !code.keySet().isEmpty()"}
    RETURN_CODES["Return code.keySet().toArray(new String[0])"]
    RETURN_NULL["Return null"]
    END_NODE["End"]
    START --> CALL_GETJSON
    CALL_GETJSON --> CHECK_JSON
    CHECK_JSON -- "true" --> GET_CODE
    CHECK_JSON -- "false" --> RETURN_NULL
    GET_CODE --> CHECK_KEYSET
    CHECK_KEYSET -- "true" --> RETURN_CODES
    CHECK_KEYSET -- "false" --> RETURN_NULL
    RETURN_CODES --> END_NODE
    RETURN_NULL --> END_NODE
```

**CRITICAL — Constant Resolution:**
The method hard-codes the base currency segment as `"USD"` in the request path `getURL() + "/latest/" + "USD"`. No repository constant file was referenced for this value, so the resolved business value is the literal U.S. dollar base currency code.

## 3. Parameter Analysis

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

This method takes no input parameters. It relies on internal instance behavior through `getURL()` and `getJsonObject()` and on the external HTTP response from the currency-rate service. The returned content is entirely determined by the remote service payload and by the fixed base currency code `USD` used in the request path.

## 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 | - | Resolves the external API base URL used to request the latest exchange-rate dataset |
| R | `getJsonObject()` | CurrencyRateAPI | - | Performs HTTP access and JSON parsing for the latest currency-rate response |
| R | `has("conversion_rates")` | - | - | Checks whether the response contains the currency-rate map payload |
| R | `getAsJsonObject("conversion_rates")` | - | - | Extracts the currency-rate object from the JSON response |
| R | `keySet()` | - | - | Reads the available currency code keys from the response object |
| R | `toArray(new String[0])` | - | - | Converts the discovered currency-code set into a string array for caller consumption |

## 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] -` ; `getURL [R] -` |

## 6. Per-Branch Detail Blocks

**Block 1** — [CALL] `(build external request and load latest exchange-rate JSON)` `(L61)`

> This block creates the request URL for the latest exchange-rate payload using the fixed base currency `USD` and delegates HTTP/JSON retrieval to the shared API helper.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getURL()` |
| 2 | SET | `new java.net.URI(getURL() + "/latest/" + "USD").toURL()` [-> `USD`="USD"] |
| 3 | CALL | `getJsonObject(...)` |
| 4 | SET | `JsonObject jsonObject = ...;` |

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

> This block validates that the external service returned a usable currency-rate map before attempting to enumerate codes.

| # | Type | Code |
|---|------|------|
| 1 | IF | `jsonObject != null && jsonObject.has("conversion_rates")` |

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

> This branch confirms that the conversion-rates object contains at least one supported currency code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JsonObject code = jsonObject.getAsJsonObject("conversion_rates");` |
| 2 | IF | `code != null && !code.keySet().isEmpty()` |
| 3 | CALL | `code.keySet()` |
| 4 | CALL | `toArray(new String[0])` |
| 5 | RETURN | `return code.keySet().toArray(new String[0]);` |

**Block 2.2** — [ELSE] `(conversion_rates missing or empty)` `(L62-L68)`

> This branch handles incomplete or unusable API responses and signals failure to the caller.

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `CurrencyRateAPI` | Class | API helper responsible for retrieving currency-rate data from an external service |
| `getCurrencyCode` | Method | Retrieves the list of supported currency codes from the latest exchange-rate response |
| `getURL` | Method | Resolves the base endpoint used for the external currency-rate request |
| `getJsonObject` | Method | Executes the remote request and converts the response into a JSON object |
| `conversion_rates` | JSON field | Map of currency codes to exchange-rate values returned by the remote service |
| `USD` | Business term | U.S. dollar, used here as the fixed base currency for the latest-rate lookup |
| currency code | Business term | Standard ISO-style code used to identify a currency in the application |
| latest | Business term | The most recent exchange-rate dataset exposed by the external API |
| `String[]` | Technical type | Array of currency-code strings returned to the caller for display or selection |
| `UI` | Class | Presentation-layer caller that consumes the available currency codes |
