# (DD08) Business Logic — CurrencyRateAPI.getApiKeyService() [14 LOC]

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

## 1. Role

### CurrencyRateAPI.getApiKeyService()

This method is a configuration lookup utility that retrieves the Exchange Rate API key from the application classpath at runtime. Its business purpose is to externalize the secret value used for API access, so the URL construction logic can remain independent of hard-coded credentials and can be maintained through `config.properties` instead of source code changes. The method follows a simple load-and-return pattern: it opens the configuration resource, loads key/value pairs, and returns the value mapped to `API_KEY`. If the configuration file is missing or cannot be read, the method logs the failure and returns `null`, allowing the caller to detect a missing integration credential. In the larger system, this method supports outbound currency-rate integration by supplying the authentication token used by `getURL()` when building the remote service endpoint. The method has no branching business workflow beyond the two failure paths: missing resource stream and I/O error during property loading.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getApiKeyService()"])
    CREATE(["Create Properties instance"])
    OPEN(["Open config.properties resource stream"])
    CHECK{"Input stream is null?"}
    LOG_MISSING(["Log missing config.properties error"])
    RETURN_NULL_1(["Return null"])
    LOAD(["Load properties from stream"])
    GET_KEY(["Read property API_KEY = \"YOUR_API_KEY\""])
    RETURN_KEY(["Return API_KEY value"])
    CATCH(["Catch IOException"])
    LOG_IO(["Log config.properties load error"])
    RETURN_NULL_2(["Return null"])
    END_NODE(["End"])

    START --> CREATE
    CREATE --> OPEN
    OPEN --> CHECK
    CHECK -->|Yes| LOG_MISSING
    LOG_MISSING --> RETURN_NULL_1
    CHECK -->|No| LOAD
    LOAD --> GET_KEY
    GET_KEY --> RETURN_KEY
    RETURN_KEY --> END_NODE
    OPEN --> CATCH
    CATCH --> LOG_IO
    LOG_IO --> RETURN_NULL_2
    RETURN_NULL_2 --> END_NODE
```

## 3. Parameter Analysis

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

Additional state used by this method:

| State | Type | Business Description |
|------|------|---------------------|
| `config.properties` | Classpath resource | External configuration file that stores the API credential used to authenticate currency-rate requests. |
| `API_KEY` | Property key | Logical name of the secret token entry inside `config.properties`. |
| `logger` | Instance field | Logging facility used to record missing-resource and I/O failure conditions. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|-----------------------|
| R | `getProperty()` | - | `java.util.Properties` | Reads the `API_KEY` value from in-memory configuration data loaded from the resource file. |

The method does not call any SC/CBS business component or database table access method. Its only functional dependency is the Java `Properties` API used to read a configuration entry.

## 5. Dependency Trace

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

| # | Caller (Screen/Batch) | Call Chain (Full Path to Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|----------------------------------|-------------------------------|
| 1 | Controller:CurrencyRateAPI | `CurrencyRateAPI.getURL` -> `CurrencyRateAPI.getApiKeyService` | `getProperty() [R] java.util.Properties` |

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Controller:CurrencyRateAPI | `CurrencyRateAPI.getURL` -> `CurrencyRateAPI.getApiKeyService` | `getProperty() [R] java.util.Properties` |

## 6. Per-Branch Detail Blocks

**Block 1** — `TRY` `(open and load config.properties)` (L23-L31)

> Business purpose: obtain the integration credential from externalized runtime configuration.

| # | Type | Code |
|---|------|------|
| 1 | SET | `Properties properties = new Properties();` |
| 2 | EXEC | `getClass().getClassLoader().getResourceAsStream("config.properties")` |
| 3 | SET | `InputStream input = ...;` |

**Block 1.1** — `IF` `(input == null)` (L25-L28)

> Handles the case where the application cannot locate the configuration resource in the classpath.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `logger.error("Unable to find config.properties");` |
| 2 | RETURN | `return null;` |

**Block 1.2** — `ELSE` `(input != null)` (L29-L31)

> Loads the properties file and retrieves the API key used for outbound currency-rate access.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `properties.load(input);` |
| 2 | CALL | `properties.getProperty("API_KEY")` [-> `API_KEY="YOUR_API_KEY"`] |
| 3 | RETURN | `return properties.getProperty("API_KEY");` |

**Block 2** — `CATCH` `(IOException e)` (L32-L35)

> Handles any file read or property parsing failure while loading the configuration resource.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `logger.error("Error loading config.properties", e);` |
| 2 | RETURN | `return null;` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `config.properties` | Resource | External runtime configuration file containing application settings, including the currency API credential. |
| `API_KEY` | Property key | The configured secret token used to authenticate against the Exchange Rate API. |
| `logger` | Technical term | Logging component that records operational failures for support and diagnostics. |
| `Properties` | Technical term | Java configuration container that stores key/value pairs loaded from a resource file. |
| `InputStream` | Technical term | Stream used to read the configuration file contents from the classpath. |
| `classpath` | Technical term | Runtime resource location mechanism used to package and load application configuration. |
| Exchange Rate API | Business term | External currency exchange-rate service that requires an API key for access. |
| CurrencyRateAPI | Class name | Utility class that builds the remote currency-rate endpoint and retrieves the authentication key. |
| `getURL()` | Method | Companion method that concatenates the API base URL with the returned API key to form the service endpoint. |
| I/O | Acronym | Input/Output — file or resource access operations that can fail due to missing or unreadable configuration. |
| CRUD | Acronym | Create, Read, Update, Delete — data operation classification used here to describe the read-only configuration lookup. |
