fix: refactor ToolScaffolder to use generic MciClient for MCI tools
All checks were successful
Deploy Tools / deploy (push) Successful in 1m32s

This commit is contained in:
jade
2026-08-19 14:06:45 +09:00
parent 9dcf06ae95
commit a8363fae1e

View File

@@ -268,25 +268,37 @@ public class ToolScaffolder {
StringBuilder methods = new StringBuilder(); StringBuilder methods = new StringBuilder();
for (ToolMethodDefinition tool : tools) { for (ToolMethodDefinition tool : tools) {
String baseName = toPascalCase(tool.baseName()); String baseName = toPascalCase(tool.baseName());
String clientVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Client"; String clientClassName;
String converterVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Converter"; String clientVariable;
boolean mci = "MCI".equalsIgnoreCase(tool.routingType()); boolean mci = "MCI".equalsIgnoreCase(tool.routingType());
if (mci) {
String sysCode = tool.clientSystemCode().toLowerCase(Locale.ROOT);
clientClassName = "Mci" + sysCode.substring(0, 1).toUpperCase(Locale.ROOT) + sysCode.substring(1) + "Client";
clientVariable = "mci" + sysCode.substring(0, 1).toUpperCase(Locale.ROOT) + sysCode.substring(1) + "Client";
} else {
clientClassName = baseName + "Client";
clientVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Client";
}
String converterVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Converter";
String integrationPackage = BASE_PACKAGE + (mci ? ".infra.itrf.mci." + tool.clientSystemCode().toLowerCase(Locale.ROOT) String integrationPackage = BASE_PACKAGE + (mci ? ".infra.itrf.mci." + tool.clientSystemCode().toLowerCase(Locale.ROOT)
: ".infra.itrf.http." + toPackageSegment(tool.httpApiName())); : ".infra.itrf.http." + toPackageSegment(tool.httpApiName()));
imports.append("import ").append(bizPackage).append(".dto.").append(baseName).append("Request;\n") imports.append("import ").append(bizPackage).append(".dto.").append(baseName).append("Request;\n")
.append("import ").append(bizPackage).append(".dto.").append(baseName).append("Response;\n") .append("import ").append(bizPackage).append(".dto.").append(baseName).append("Response;\n")
.append("import ").append(bizPackage).append(".converter.").append(baseName).append("Converter;\n") .append("import ").append(bizPackage).append(".converter.").append(baseName).append("Converter;\n")
.append("import ").append(integrationPackage).append(".").append(baseName).append("Client;\n") .append("import ").append(integrationPackage).append(".").append(clientClassName).append(";\n")
.append("import ").append(integrationPackage).append(".io.").append(baseName) .append("import ").append(integrationPackage).append(".io.").append(baseName)
.append(mci ? "_I;\n" : "HttpRequest;\n") .append(mci ? "_I;\n" : "HttpRequest;\n")
.append("import ").append(integrationPackage).append(".io.").append(baseName) .append("import ").append(integrationPackage).append(".io.").append(baseName)
.append(mci ? "_O;\n" : "HttpResponse;\n"); .append(mci ? "_O;\n" : "HttpResponse;\n");
fields.append(" private final ").append(baseName).append("Client ").append(clientVariable).append(";\n"); if (!fields.toString().contains(" " + clientVariable + ";")) {
fields.append(" private final ").append(clientClassName).append(" ").append(clientVariable).append(";\n");
}
fields.append(" private final ").append(baseName).append("Converter ").append(converterVariable).append(";\n"); fields.append(" private final ").append(baseName).append("Converter ").append(converterVariable).append(";\n");
methods.append(" @Override\n public ").append(baseName).append("Response ").append(tool.methodName()) methods.append(" @Override\n public ").append(baseName).append("Response ").append(tool.methodName())
.append("(").append(baseName).append("Request req) {\n") .append("(").append(baseName).append("Request req) {\n")
.append(" ").append(baseName).append(mci ? "_I" : "HttpRequest").append(" request = ").append(converterVariable).append(".toRequest(req);\n") .append(" ").append(baseName).append(mci ? "_I" : "HttpRequest").append(" request = ").append(converterVariable).append(".toRequest(req);\n")
.append(" ").append(baseName).append(mci ? "_O" : "HttpResponse").append(" response = ").append(clientVariable).append(mci ? ".call" + baseName + "(request);\n" : ".call(request, " + baseName + "HttpResponse.class);\n") .append(" ").append(baseName).append(mci ? "_O" : "HttpResponse").append(" response = ").append(clientVariable)
.append(mci ? ".call(\"" + tool.interfaceId() + "\", request, " + baseName + "_O.class);\n" : ".call(request, " + baseName + "HttpResponse.class);\n")
.append(" ").append(baseName).append("Response toolResponse = ").append(converterVariable).append(".toResponse(response);\n") .append(" ").append(baseName).append("Response toolResponse = ").append(converterVariable).append(".toResponse(response);\n")
.append(" if (toolResponse == null) toolResponse = new ").append(baseName).append("Response();\n") .append(" if (toolResponse == null) toolResponse = new ").append(baseName).append("Response();\n")
.append(" toolResponse.setResultCode(\"SUCCESS\");\n") .append(" toolResponse.setResultCode(\"SUCCESS\");\n")
@@ -354,8 +366,6 @@ public class ToolScaffolder {
String responseType = baseName + "Response"; String responseType = baseName + "Response";
String requestIo = baseName + (mci ? "_I" : "HttpRequest"); String requestIo = baseName + (mci ? "_I" : "HttpRequest");
String responseIo = baseName + (mci ? "_O" : "HttpResponse"); String responseIo = baseName + (mci ? "_O" : "HttpResponse");
String clientVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Client";
String converterVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Converter";
useCase = addImport(useCase, "import " + bizPackage + ".dto." + requestType + ";") ; useCase = addImport(useCase, "import " + bizPackage + ".dto." + requestType + ";") ;
useCase = addImport(useCase, "import " + bizPackage + ".dto." + responseType + ";") ; useCase = addImport(useCase, "import " + bizPackage + ".dto." + responseType + ";") ;
@@ -402,20 +412,34 @@ public class ToolScaffolder {
String declaration = declBuilder.toString(); String declaration = declBuilder.toString();
useCase = insertBeforeLastBrace(useCase, declaration); useCase = insertBeforeLastBrace(useCase, declaration);
String clientClassName;
String clientVariable;
if (mci) {
String sysCode = tool.clientSystemCode().toLowerCase(Locale.ROOT);
clientClassName = "Mci" + sysCode.substring(0, 1).toUpperCase(Locale.ROOT) + sysCode.substring(1) + "Client";
clientVariable = "mci" + sysCode.substring(0, 1).toUpperCase(Locale.ROOT) + sysCode.substring(1) + "Client";
} else {
clientClassName = baseName + "Client";
clientVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Client";
}
String converterVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Converter";
implementation = addImport(implementation, "import " + bizPackage + ".dto." + requestType + ";"); implementation = addImport(implementation, "import " + bizPackage + ".dto." + requestType + ";");
implementation = addImport(implementation, "import " + bizPackage + ".dto." + responseType + ";"); implementation = addImport(implementation, "import " + bizPackage + ".dto." + responseType + ";");
implementation = addImport(implementation, "import " + bizPackage + ".converter." + baseName + "Converter;"); implementation = addImport(implementation, "import " + bizPackage + ".converter." + baseName + "Converter;");
implementation = addImport(implementation, "import " + integrationPackage + "." + baseName + "Client;"); implementation = addImport(implementation, "import " + integrationPackage + "." + clientClassName + ";");
implementation = addImport(implementation, "import " + integrationPackage + ".io." + requestIo + ";"); implementation = addImport(implementation, "import " + integrationPackage + ".io." + requestIo + ";");
implementation = addImport(implementation, "import " + integrationPackage + ".io." + responseIo + ";"); implementation = addImport(implementation, "import " + integrationPackage + ".io." + responseIo + ";");
implementation = addImport(implementation, "import lombok.RequiredArgsConstructor;"); implementation = addImport(implementation, "import lombok.RequiredArgsConstructor;");
if (!implementation.contains("@RequiredArgsConstructor")) { if (!implementation.contains("@RequiredArgsConstructor")) {
implementation = implementation.replaceFirst("public class ", "@RequiredArgsConstructor\npublic class "); implementation = implementation.replaceFirst("public class ", "@RequiredArgsConstructor\npublic class ");
} }
implementation = insertConstructorField(implementation, " private final " + baseName + "Client " + clientVariable + ";"); if (!implementation.contains(" " + clientVariable + ";")) {
implementation = insertConstructorField(implementation, " private final " + clientClassName + " " + clientVariable + ";");
}
implementation = insertConstructorField(implementation, " private final " + baseName + "Converter " + converterVariable + ";"); implementation = insertConstructorField(implementation, " private final " + baseName + "Converter " + converterVariable + ";");
String call = mci String call = mci
? clientVariable + ".call" + baseName + "(request)" ? clientVariable + ".call(\"" + tool.interfaceId() + "\", request, " + responseIo + ".class)"
: clientVariable + ".call(request, " + responseIo + ".class)"; : clientVariable + ".call(request, " + responseIo + ".class)";
String method = "\n @Override\n public " + responseType + " " + methodName + "(" + requestType + " req) {\n" String method = "\n @Override\n public " + responseType + " " + methodName + "(" + requestType + " req) {\n"
+ " " + requestIo + " request = " + converterVariable + ".toRequest(req);\n" + " " + requestIo + " request = " + converterVariable + ".toRequest(req);\n"