Skip to content

Refactor DeploymentHandler data mapping; introduce element name constants #33

@Schmarvinius

Description

@Schmarvinius

Summary

Replace the 17-parameter buildDeploymentData method with a typed record. Introduce element name constants to eliminate hardcoded strings across all handlers.

Problem

  1. DeploymentHandler.buildDeploymentData() has 17 positional parameters — a severe maintenance hazard where parameter order mistakes cause silent bugs.
  2. Two toMap() overloads duplicate the same extraction logic (marked CPD-OFF/CPD-ON) because SDK types AiDeploymentResponseWithDetails and AiDeployment share no common interface.
  3. All handlers use hardcoded string keys ("id", "deploymentUrl", "configurationId", etc.) — if an element is renamed in the CDS model, Java code silently breaks at runtime.

Plan

Part A: Element Name Constants

Create AICoreElements.java with inner classes per entity:

public final class AICoreElements {
  private AICoreElements() {}

  public static final class Deployment {
    public static final String ID = "id";
    public static final String DEPLOYMENT_URL = "deploymentUrl";
    public static final String CONFIGURATION_ID = "configurationId";
    public static final String CONFIGURATION_NAME = "configurationName";
    public static final String EXECUTABLE_ID = "executableId";
    public static final String SCENARIO_ID = "scenarioId";
    public static final String STATUS = "status";
    public static final String STATUS_MESSAGE = "statusMessage";
    public static final String TARGET_STATUS = "targetStatus";
    public static final String LAST_OPERATION = "lastOperation";
    public static final String LATEST_RUNNING_CONFIGURATION_ID = "latestRunningConfigurationId";
    public static final String TTL = "ttl";
    public static final String CREATED_AT = "createdAt";
    public static final String MODIFIED_AT = "modifiedAt";
    public static final String SUBMISSION_TIME = "submissionTime";
    public static final String START_TIME = "startTime";
    public static final String COMPLETION_TIME = "completionTime";
    public static final String RESOURCE_GROUP = "resourceGroup";
  }

  public static final class ResourceGroup { ... }
  public static final class Configuration { ... }
}

Replace string literals in all handlers.

Part B: DeploymentHandler Record Refactor

private record DeploymentFields(
    String id, String deploymentUrl, String configurationId,
    String configurationName, String executableId, String scenarioId,
    String status, String statusMessage, String targetStatus,
    String lastOperation, String latestRunningConfigurationId,
    String ttl, Object createdAt, Object modifiedAt,
    Object submissionTime, Object startTime, Object completionTime) {}

private static DeploymentFields extractFields(AiDeploymentResponseWithDetails d) { ... }
private static DeploymentFields extractFields(AiDeployment d) { ... }
private static CdsData toCdsData(DeploymentFields f, String resourceGroupId) { ... }

Remove CPD-OFF/CPD-ON markers.

Files

  • New: AICoreElements.java
  • Modified: DeploymentHandler.java (major refactor)
  • Modified: ConfigurationHandler.java (replace ~10 string literals)
  • Modified: ResourceGroupHandler.java (replace ~10 string literals)
  • Modified: MockEntityHandler.java (replace ~15 string literals)
  • Modified: ActionHandler.java (replace ~3 string literals)

Rationale

Mirrors the generated *_.CDS_NAME constant pattern used in cds4j and cds-services. Eliminates the code smell of a 17-parameter method and removes the need for CPD suppression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions