|
|
|
|
@@ -94,7 +94,11 @@ public class ToolScaffolder {
|
|
|
|
|
if (tools == null || tools.isEmpty()) {
|
|
|
|
|
throw new IllegalArgumentException("At least one Tool method is required.");
|
|
|
|
|
}
|
|
|
|
|
boolean hasMci = tools.stream().anyMatch(t -> "MCI".equalsIgnoreCase(t.routingType()));
|
|
|
|
|
String useCaseBaseName = toPascalCase(useCaseName);
|
|
|
|
|
if (hasMci) {
|
|
|
|
|
useCaseBaseName = abbreviatedMciSourceBaseName(useCaseBaseName);
|
|
|
|
|
}
|
|
|
|
|
String group = tools.getFirst().group().toLowerCase(Locale.ROOT);
|
|
|
|
|
validateToolMethods(tools, group);
|
|
|
|
|
|
|
|
|
|
@@ -128,8 +132,10 @@ public class ToolScaffolder {
|
|
|
|
|
} else {
|
|
|
|
|
writeUtf8(useCaseFile, groupedUseCaseContent(bizPackage, useCaseBaseName, moduleName, tools));
|
|
|
|
|
writeUtf8(useCaseImplFile, groupedUseCaseImplContent(bizPackage, useCaseBaseName, tools));
|
|
|
|
|
if (!hasMci) {
|
|
|
|
|
writeUtf8(converterFile, groupedConverterContent(bizPackage, useCaseBaseName, tools));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder log = new StringBuilder("\n=========================================\n")
|
|
|
|
|
.append(" Multi Tool Scaffolding Complete\n")
|
|
|
|
|
@@ -145,7 +151,9 @@ public class ToolScaffolder {
|
|
|
|
|
log.append("[HTTP Config] ").append(glowConfig).append("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!hasMci) {
|
|
|
|
|
log.append("[Converter] ").append(converterFile).append("\n");
|
|
|
|
|
}
|
|
|
|
|
return log.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -206,8 +214,9 @@ public class ToolScaffolder {
|
|
|
|
|
private static void writeGroupedToolFiles(Path moduleRoot, Path sourceRoot, Path dtoDir, Path definitionDir,
|
|
|
|
|
String bizPackage, ToolMethodDefinition tool,
|
|
|
|
|
String moduleName, StringBuilder log) throws IOException {
|
|
|
|
|
String baseName = toPascalCase(tool.baseName());
|
|
|
|
|
boolean mci = "MCI".equalsIgnoreCase(tool.routingType());
|
|
|
|
|
String toolBaseName = toPascalCase(tool.baseName());
|
|
|
|
|
String baseName = mci ? abbreviatedMciSourceBaseName(toolBaseName) : toolBaseName;
|
|
|
|
|
String code = mci ? formatClientSystemCode(tool.clientSystemCode(), "/") : toPackageSegment(tool.httpApiName());
|
|
|
|
|
String ioPackage = BASE_PACKAGE + (mci ? ".infra.itrf.mci." : ".infra.itrf.http.") + code.replace("/", ".");
|
|
|
|
|
Path clientDir = sourceRoot.resolve(Paths.get("infra", "itrf", mci ? "mci" : "http", code));
|
|
|
|
|
@@ -258,8 +267,20 @@ public class ToolScaffolder {
|
|
|
|
|
} else {
|
|
|
|
|
writeUtf8(clientDir.resolve(baseName + "Client.java"), groupedMciClientContent(ioPackage, baseName, tool.interfaceId()));
|
|
|
|
|
}
|
|
|
|
|
writeUtf8(sourceRoot.resolve(Paths.get("biz", tool.group().toLowerCase(Locale.ROOT), "converter", baseName + "Converter.java")),
|
|
|
|
|
groupedMciConverterContent(bizPackage, baseName, ioPackage, ioPrefix));
|
|
|
|
|
String targetPkg = mciTargetSystemPackage(tool.clientSystemCode());
|
|
|
|
|
String converterPkg = bizPackage + ".converter" + (targetPkg != null ? "." + targetPkg : "");
|
|
|
|
|
Path targetConverterDir = sourceRoot.resolve(Paths.get("biz", tool.group().toLowerCase(Locale.ROOT), "converter"));
|
|
|
|
|
if (targetPkg != null) {
|
|
|
|
|
for (String seg : targetPkg.split("\\.")) {
|
|
|
|
|
targetConverterDir = targetConverterDir.resolve(seg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Files.createDirectories(targetConverterDir);
|
|
|
|
|
String converterName = (tool.clientSystemCode() != null && !tool.clientSystemCode().isBlank())
|
|
|
|
|
? tool.clientSystemCode().toUpperCase(Locale.ROOT) + "Converter"
|
|
|
|
|
: baseName + "Converter";
|
|
|
|
|
writeUtf8(targetConverterDir.resolve(converterName + ".java"),
|
|
|
|
|
groupedMciConverterContent(converterPkg, bizPackage, baseName, ioPackage, ioPrefix, converterName));
|
|
|
|
|
} else {
|
|
|
|
|
writeUtf8(ioDir.resolve(baseName + "HttpRequest.java"),
|
|
|
|
|
dtoContent(ioPackage + ".io", baseName + "HttpRequest", tool.inputFields(), "", "", true));
|
|
|
|
|
@@ -273,7 +294,7 @@ public class ToolScaffolder {
|
|
|
|
|
groupedHttpConverterContent(bizPackage, baseName, ioPackage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String toolName = toToolName(moduleName, tool.group(), baseName);
|
|
|
|
|
String toolName = toToolName(moduleName, tool.group(), toolBaseName);
|
|
|
|
|
log.append("[Tool] ").append(toolName).append(" -> ").append(clientDir.resolve(baseName + "Client.java")).append("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -282,13 +303,15 @@ public class ToolScaffolder {
|
|
|
|
|
StringBuilder imports = new StringBuilder();
|
|
|
|
|
StringBuilder methods = new StringBuilder();
|
|
|
|
|
for (ToolMethodDefinition tool : tools) {
|
|
|
|
|
String baseName = toPascalCase(tool.baseName());
|
|
|
|
|
boolean mci = "MCI".equalsIgnoreCase(tool.routingType());
|
|
|
|
|
String toolBaseName = toPascalCase(tool.baseName());
|
|
|
|
|
String baseName = mci ? abbreviatedMciSourceBaseName(toolBaseName) : toolBaseName;
|
|
|
|
|
imports.append("import ").append(bizPackage).append(".dto.").append(baseName).append("Request;\n")
|
|
|
|
|
.append("import ").append(bizPackage).append(".dto.").append(baseName).append("Response;\n");
|
|
|
|
|
boolean isMutation = isMutationTool(baseName);
|
|
|
|
|
ToolDefinitionOptions opts = tool.definitionOptions() == null ? new ToolDefinitionOptions(null, null, null, null, null, null, null, null) : tool.definitionOptions();
|
|
|
|
|
|
|
|
|
|
methods.append(" @McpTool(name = \"").append(toToolName(moduleName, tool.group(), baseName))
|
|
|
|
|
methods.append(" @McpTool(name = \"").append(toToolName(moduleName, tool.group(), toolBaseName))
|
|
|
|
|
.append("\", title = \"").append(javaText(option(tool.title(), baseName)))
|
|
|
|
|
.append("\", description = \"").append(javaText(option(tool.description(), ""))).append("\")\n")
|
|
|
|
|
.append(" @GrowToolHint(\n")
|
|
|
|
|
@@ -339,10 +362,11 @@ public class ToolScaffolder {
|
|
|
|
|
StringBuilder fields = new StringBuilder();
|
|
|
|
|
StringBuilder methods = new StringBuilder();
|
|
|
|
|
for (ToolMethodDefinition tool : tools) {
|
|
|
|
|
String baseName = toPascalCase(tool.baseName());
|
|
|
|
|
boolean mci = "MCI".equalsIgnoreCase(tool.routingType());
|
|
|
|
|
String toolBaseName = toPascalCase(tool.baseName());
|
|
|
|
|
String baseName = mci ? abbreviatedMciSourceBaseName(toolBaseName) : toolBaseName;
|
|
|
|
|
String clientClassName;
|
|
|
|
|
String clientVariable;
|
|
|
|
|
boolean mci = "MCI".equalsIgnoreCase(tool.routingType());
|
|
|
|
|
String ioPrefix = (tool.clientSystemCode() != null && !tool.clientSystemCode().isBlank()) ? tool.clientSystemCode().toUpperCase() : tool.interfaceId();
|
|
|
|
|
if (mci) {
|
|
|
|
|
clientClassName = mciClientClassName(tool.clientSystemCode());
|
|
|
|
|
@@ -351,12 +375,17 @@ public class ToolScaffolder {
|
|
|
|
|
clientClassName = baseName + "Client";
|
|
|
|
|
clientVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Client";
|
|
|
|
|
}
|
|
|
|
|
String targetPkg = mci ? mciTargetSystemPackage(tool.clientSystemCode()) : null;
|
|
|
|
|
String converterPkg = bizPackage + ".converter" + (targetPkg != null ? "." + targetPkg : "");
|
|
|
|
|
String converterName = (mci && tool.clientSystemCode() != null && !tool.clientSystemCode().isBlank())
|
|
|
|
|
? tool.clientSystemCode().toUpperCase(Locale.ROOT) + "Converter"
|
|
|
|
|
: baseName + "Converter";
|
|
|
|
|
String converterVariable = "converter";
|
|
|
|
|
String integrationPackage = BASE_PACKAGE + (mci ? ".infra.itrf.mci." + formatClientSystemCode(tool.clientSystemCode(), ".")
|
|
|
|
|
: ".infra.itrf.http." + toPackageSegment(tool.httpApiName()));
|
|
|
|
|
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(".converter.").append(baseName).append("Converter;\n")
|
|
|
|
|
.append("import ").append(converterPkg).append(".").append(converterName).append(";\n")
|
|
|
|
|
.append("import ").append(integrationPackage).append(".").append(clientClassName).append(";\n")
|
|
|
|
|
.append("import ").append(integrationPackage).append(".io.").append(mci ? ioPrefix + "_I;\n" : baseName + "HttpRequest;\n")
|
|
|
|
|
.append("import ").append(integrationPackage).append(".io.").append(mci ? ioPrefix + "_O;\n" : baseName + "HttpResponse;\n");
|
|
|
|
|
@@ -368,7 +397,7 @@ public class ToolScaffolder {
|
|
|
|
|
fields.append(" private final ").append(clientClassName).append(" ").append(clientVariable).append(";\n");
|
|
|
|
|
}
|
|
|
|
|
if (!fields.toString().contains(" " + converterVariable + ";")) {
|
|
|
|
|
fields.append(" private final ").append(baseName).append("Converter ").append(converterVariable).append(";\n");
|
|
|
|
|
fields.append(" private final ").append(converterName).append(" ").append(converterVariable).append(";\n");
|
|
|
|
|
}
|
|
|
|
|
methods.append(groupedToolMethodContent(tool, baseName, converterVariable, clientVariable, ioPrefix, mci));
|
|
|
|
|
}
|
|
|
|
|
@@ -444,15 +473,15 @@ public class ToolScaffolder {
|
|
|
|
|
+ "public interface " + useCaseBaseName + "Converter {\n}\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String groupedMciConverterContent(String bizPackage, String baseName, String ioPackage, String interfaceId) {
|
|
|
|
|
return "package " + bizPackage + ".converter;\n\n"
|
|
|
|
|
private static String groupedMciConverterContent(String converterPackage, String bizPackage, String baseName, String ioPackage, String interfaceId, String converterName) {
|
|
|
|
|
return "package " + converterPackage + ";\n\n"
|
|
|
|
|
+ "import " + bizPackage + ".dto." + baseName + "Request;\n"
|
|
|
|
|
+ "import " + bizPackage + ".dto." + baseName + "Response;\n"
|
|
|
|
|
+ "import " + ioPackage + ".io." + interfaceId + "_I;\n"
|
|
|
|
|
+ "import " + ioPackage + ".io." + interfaceId + "_O;\n"
|
|
|
|
|
+ "import org.mapstruct.Mapper;\nimport org.mapstruct.ReportingPolicy;\n\n"
|
|
|
|
|
+ "@Mapper(componentModel = \"spring\", unmappedTargetPolicy = ReportingPolicy.IGNORE)\n"
|
|
|
|
|
+ "public interface " + baseName + "Converter {\n"
|
|
|
|
|
+ "public interface " + converterName + " {\n"
|
|
|
|
|
+ " " + interfaceId + "_I toRequest(" + baseName + "Request request);\n"
|
|
|
|
|
+ " " + baseName + "Response toResponse(" + interfaceId + "_O response);\n}\n";
|
|
|
|
|
}
|
|
|
|
|
@@ -479,14 +508,15 @@ public class ToolScaffolder {
|
|
|
|
|
String useCase = Files.readString(useCaseFile, StandardCharsets.UTF_8);
|
|
|
|
|
String implementation = Files.readString(useCaseImplFile, StandardCharsets.UTF_8);
|
|
|
|
|
for (ToolMethodDefinition tool : tools) {
|
|
|
|
|
String baseName = toPascalCase(tool.baseName());
|
|
|
|
|
boolean mci = "MCI".equalsIgnoreCase(tool.routingType());
|
|
|
|
|
String toolBaseName = toPascalCase(tool.baseName());
|
|
|
|
|
String baseName = mci ? abbreviatedMciSourceBaseName(toolBaseName) : toolBaseName;
|
|
|
|
|
String methodName = tool.methodName();
|
|
|
|
|
String toolName = toToolName(moduleName, tool.group(), baseName);
|
|
|
|
|
String toolName = toToolName(moduleName, tool.group(), toolBaseName);
|
|
|
|
|
if (useCase.matches("(?s).*\\b" + java.util.regex.Pattern.quote(methodName) + "\\s*\\(.*")
|
|
|
|
|
|| useCase.contains("name = \"" + toolName + "\"")) {
|
|
|
|
|
throw new IllegalArgumentException("Tool method or MCP Tool name already exists: " + methodName);
|
|
|
|
|
}
|
|
|
|
|
boolean mci = "MCI".equalsIgnoreCase(tool.routingType());
|
|
|
|
|
String integrationPackage = BASE_PACKAGE + (mci ? ".infra.itrf.mci." + formatClientSystemCode(tool.clientSystemCode(), ".")
|
|
|
|
|
: ".infra.itrf.http." + toPackageSegment(tool.httpApiName()));
|
|
|
|
|
String requestType = baseName + "Request";
|
|
|
|
|
@@ -551,11 +581,16 @@ public class ToolScaffolder {
|
|
|
|
|
clientClassName = baseName + "Client";
|
|
|
|
|
clientVariable = Character.toLowerCase(baseName.charAt(0)) + baseName.substring(1) + "Client";
|
|
|
|
|
}
|
|
|
|
|
String targetPkg = mci ? mciTargetSystemPackage(tool.clientSystemCode()) : null;
|
|
|
|
|
String converterPkg = bizPackage + ".converter" + (targetPkg != null ? "." + targetPkg : "");
|
|
|
|
|
String converterName = (mci && tool.clientSystemCode() != null && !tool.clientSystemCode().isBlank())
|
|
|
|
|
? tool.clientSystemCode().toUpperCase(Locale.ROOT) + "Converter"
|
|
|
|
|
: baseName + "Converter";
|
|
|
|
|
String converterVariable = "converter";
|
|
|
|
|
|
|
|
|
|
implementation = addImport(implementation, "import " + bizPackage + ".dto." + requestType + ";");
|
|
|
|
|
implementation = addImport(implementation, "import " + bizPackage + ".dto." + responseType + ";");
|
|
|
|
|
implementation = addImport(implementation, "import " + bizPackage + ".converter." + baseName + "Converter;");
|
|
|
|
|
implementation = addImport(implementation, "import " + converterPkg + "." + converterName + ";");
|
|
|
|
|
implementation = addImport(implementation, "import " + integrationPackage + "." + clientClassName + ";");
|
|
|
|
|
implementation = addImport(implementation, "import " + integrationPackage + ".io." + requestIo + ";");
|
|
|
|
|
implementation = addImport(implementation, "import " + integrationPackage + ".io." + responseIo + ";");
|
|
|
|
|
@@ -574,14 +609,15 @@ public class ToolScaffolder {
|
|
|
|
|
implementation = insertConstructorField(implementation, " private final " + clientClassName + " " + clientVariable + ";");
|
|
|
|
|
}
|
|
|
|
|
if (!implementation.contains(" " + converterVariable + ";")) {
|
|
|
|
|
implementation = insertConstructorField(implementation, " private final " + baseName + "Converter " + converterVariable + ";");
|
|
|
|
|
implementation = insertConstructorField(implementation, " private final " + converterName + " " + converterVariable + ";");
|
|
|
|
|
}
|
|
|
|
|
String method = groupedToolMethodContent(tool, baseName, converterVariable, clientVariable, ioPrefix, mci);
|
|
|
|
|
implementation = insertBeforeLastBrace(implementation, method);
|
|
|
|
|
}
|
|
|
|
|
writeUtf8(useCaseFile, useCase);
|
|
|
|
|
writeUtf8(useCaseImplFile, implementation);
|
|
|
|
|
if (!Files.exists(converterFile)) {
|
|
|
|
|
boolean hasMci = tools.stream().anyMatch(t -> "MCI".equalsIgnoreCase(t.routingType()));
|
|
|
|
|
if (!hasMci && !Files.exists(converterFile)) {
|
|
|
|
|
writeUtf8(converterFile, groupedConverterContent(bizPackage, useCaseBaseName, tools));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -736,13 +772,35 @@ public class ToolScaffolder {
|
|
|
|
|
String outputSchemaResource, List<FieldDefinition> inputFields,
|
|
|
|
|
List<FieldDefinition> outputFields, String httpApiName,
|
|
|
|
|
ToolDefinitionOptions definitionOptions) throws IOException {
|
|
|
|
|
baseName = toPascalCase(baseName);
|
|
|
|
|
title = title == null || title.isBlank() ? baseName : title.trim();
|
|
|
|
|
return scaffoldWithAbbreviatedMciSources(baseName, interfaceId, title, description, group, routingType,
|
|
|
|
|
moduleName, author, createDate, register, clientSystemCode, inputSchemaResource,
|
|
|
|
|
outputSchemaResource, inputFields, outputFields, httpApiName, definitionOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates MCI source files from an abbreviation derived from the Base Name. The Base Name remains the MCP Tool name.
|
|
|
|
|
*/
|
|
|
|
|
private static String scaffoldWithAbbreviatedMciSources(String baseName, String interfaceId, String title,
|
|
|
|
|
String description, String group, String routingType,
|
|
|
|
|
String moduleName, String author, String createDate,
|
|
|
|
|
boolean register, String clientSystemCode,
|
|
|
|
|
String inputSchemaResource, String outputSchemaResource,
|
|
|
|
|
List<FieldDefinition> inputFields,
|
|
|
|
|
List<FieldDefinition> outputFields, String httpApiName,
|
|
|
|
|
ToolDefinitionOptions definitionOptions) throws IOException {
|
|
|
|
|
boolean isMci = "MCI".equalsIgnoreCase(routingType);
|
|
|
|
|
boolean isHttp = "HTTP".equalsIgnoreCase(routingType);
|
|
|
|
|
if (!isMci && !isHttp) {
|
|
|
|
|
throw new IllegalArgumentException("Unsupported routing type: " + routingType + ". Only MCI and HTTP are supported.");
|
|
|
|
|
}
|
|
|
|
|
String toolBaseName = toPascalCase(baseName);
|
|
|
|
|
baseName = isMci ? abbreviatedMciSourceBaseName(toolBaseName) : toolBaseName;
|
|
|
|
|
title = title == null || title.isBlank() ? toolBaseName : title.trim();
|
|
|
|
|
description = description == null ? "" : description.trim();
|
|
|
|
|
definitionOptions = definitionOptions == null
|
|
|
|
|
? new ToolDefinitionOptions(null, null, null, null, null, List.of(), List.of(), null)
|
|
|
|
|
: definitionOptions;
|
|
|
|
|
httpApiName = httpApiName == null || httpApiName.isBlank() ? toKebabCase(baseName) : httpApiName.trim();
|
|
|
|
|
httpApiName = httpApiName == null || httpApiName.isBlank() ? toKebabCase(toolBaseName) : httpApiName.trim();
|
|
|
|
|
String envSourceDir = System.getProperty("AXHUB_SOURCE_DIR");
|
|
|
|
|
if (envSourceDir == null) {
|
|
|
|
|
envSourceDir = System.getenv("AXHUB_SOURCE_DIR");
|
|
|
|
|
@@ -754,11 +812,10 @@ public class ToolScaffolder {
|
|
|
|
|
Path dtoDir = rootDir.resolve(Paths.get(moduleName, BASE_PACKAGE_PATH, "biz", group.toLowerCase(), "dto"));
|
|
|
|
|
|
|
|
|
|
Path legacyDtoDir = rootDir.resolve(Paths.get(moduleName, BASE_PACKAGE_PATH, "biz", group.toLowerCase(), "legacy"));
|
|
|
|
|
Path converterDir = rootDir.resolve(Paths.get(moduleName, BASE_PACKAGE_PATH, "biz", group.toLowerCase(), "converter"));
|
|
|
|
|
|
|
|
|
|
// Schema Resource 파일 경로(useSchemaResource=true일 때만 생성)
|
|
|
|
|
boolean useSchemaResource = (inputSchemaResource != null && !inputSchemaResource.trim().isEmpty()) || (outputSchemaResource != null && !outputSchemaResource.trim().isEmpty());
|
|
|
|
|
String schemaBaseName = toKebabCase(baseName);
|
|
|
|
|
String schemaBaseName = toKebabCase(toolBaseName);
|
|
|
|
|
String inputSchemaFileName = schemaBaseName + "-resource-input-schema.json";
|
|
|
|
|
String outputSchemaFileName = schemaBaseName + "-resource-output-schema.json";
|
|
|
|
|
Path schemaDir = rootDir.resolve(Paths.get(moduleName, "src/main/resources/tool-schemas", group.toLowerCase()));
|
|
|
|
|
@@ -767,11 +824,6 @@ public class ToolScaffolder {
|
|
|
|
|
String outputSchemaClasspath = "classpath:tool-schemas/" + group.toLowerCase() + "/" + outputSchemaFileName;
|
|
|
|
|
|
|
|
|
|
String bizPackage = BASE_PACKAGE + ".biz." + group.toLowerCase();
|
|
|
|
|
boolean isMci = "MCI".equalsIgnoreCase(routingType);
|
|
|
|
|
boolean isHttp = "HTTP".equalsIgnoreCase(routingType);
|
|
|
|
|
if (!isMci && !isHttp) {
|
|
|
|
|
throw new IllegalArgumentException("Unsupported routing type: " + routingType + ". Only MCI and HTTP are supported.");
|
|
|
|
|
}
|
|
|
|
|
String ioPrefix = (clientSystemCode != null && !clientSystemCode.isBlank()) ? clientSystemCode.toUpperCase() : interfaceId;
|
|
|
|
|
String mciGroupPath = "infra/itrf/mci/" + group.toLowerCase();
|
|
|
|
|
String clientPrefixCap = "";
|
|
|
|
|
@@ -784,6 +836,21 @@ public class ToolScaffolder {
|
|
|
|
|
mciClientDir = rootDir.resolve(Paths.get(moduleName, BASE_PACKAGE_PATH, mciGroupPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String converterPackage = bizPackage + ".converter";
|
|
|
|
|
String targetSystemPackage = isMci ? mciTargetSystemPackage(clientSystemCode) : null;
|
|
|
|
|
if (targetSystemPackage != null) {
|
|
|
|
|
converterPackage += "." + targetSystemPackage;
|
|
|
|
|
}
|
|
|
|
|
String converterClassName = (isMci && clientSystemCode != null && !clientSystemCode.isBlank())
|
|
|
|
|
? clientSystemCode.toUpperCase(Locale.ROOT) + "Converter"
|
|
|
|
|
: baseName + "Converter";
|
|
|
|
|
Path converterDir = rootDir.resolve(Paths.get(moduleName, BASE_PACKAGE_PATH, "biz", group.toLowerCase(), "converter"));
|
|
|
|
|
if (targetSystemPackage != null) {
|
|
|
|
|
for (String segment : targetSystemPackage.split("\\.")) {
|
|
|
|
|
converterDir = converterDir.resolve(segment);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Path mciIoDir = rootDir.resolve(Paths.get(moduleName, BASE_PACKAGE_PATH, mciGroupPath, "io"));
|
|
|
|
|
String httpApiPackage = toPackageSegment(httpApiName);
|
|
|
|
|
String httpApiClass = toPascalCase(httpApiName);
|
|
|
|
|
@@ -886,9 +953,9 @@ public class ToolScaffolder {
|
|
|
|
|
writeUtf8(dtoDir.resolve(baseName + "Response.java"), resContent);
|
|
|
|
|
writeStructuredFieldTypes(dtoDir, bizPackage + ".dto", baseName + "Response", outputFields);
|
|
|
|
|
|
|
|
|
|
String toolName = toToolName(moduleName, group, baseName);
|
|
|
|
|
String toolName = toToolName(moduleName, group, toolBaseName);
|
|
|
|
|
|
|
|
|
|
boolean isMutation = isMutationTool(baseName);
|
|
|
|
|
boolean isMutation = isMutationTool(toolBaseName);
|
|
|
|
|
StringBuilder sb = new StringBuilder(" @GrowToolHint(\n");
|
|
|
|
|
if (useSchemaResource) {
|
|
|
|
|
sb.append(" inputSchemaResource = \"").append(inputSchemaClasspath).append("\",\n");
|
|
|
|
|
@@ -988,7 +1055,7 @@ public class ToolScaffolder {
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import %s.converter.%sConverter;
|
|
|
|
|
import %s.%s;
|
|
|
|
|
import %s.%s.io.%s_I;
|
|
|
|
|
import %s.%s.io.%s_O;
|
|
|
|
|
%s
|
|
|
|
|
@@ -1013,7 +1080,7 @@ public class ToolScaffolder {
|
|
|
|
|
public class %sUseCaseImpl implements %sUseCase {
|
|
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
private final %sConverter converter;
|
|
|
|
|
private final %s converter;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public %sResponse execute(%sRequest req) {
|
|
|
|
|
@@ -1062,7 +1129,7 @@ public class ToolScaffolder {
|
|
|
|
|
bizPackage, baseName,
|
|
|
|
|
bizPackage, baseName,
|
|
|
|
|
bizPackage, baseName,
|
|
|
|
|
bizPackage, baseName,
|
|
|
|
|
converterPackage, converterClassName,
|
|
|
|
|
BASE_PACKAGE, mciGroupPath.replace("/", "."), ioPrefix,
|
|
|
|
|
BASE_PACKAGE, mciGroupPath.replace("/", "."), ioPrefix,
|
|
|
|
|
(clientPrefixCap.isEmpty() ? "" : "import " + BASE_PACKAGE + "." + mciGroupPath.replace("/", ".") + ".Mci" + clientPrefixCap + "Client;\n"),
|
|
|
|
|
@@ -1074,7 +1141,7 @@ public class ToolScaffolder {
|
|
|
|
|
baseName,
|
|
|
|
|
baseName,
|
|
|
|
|
(clientPrefixCap.isEmpty() ? "private final AxhubMciComponent mci;" : "private final Mci" + clientPrefixCap + "Client mci;"),
|
|
|
|
|
baseName,
|
|
|
|
|
converterClassName,
|
|
|
|
|
baseName,
|
|
|
|
|
baseName,
|
|
|
|
|
toolName,
|
|
|
|
|
@@ -1279,8 +1346,8 @@ public class ToolScaffolder {
|
|
|
|
|
baseName, ioPrefix,
|
|
|
|
|
baseName, ioPrefix
|
|
|
|
|
);
|
|
|
|
|
converterContent = mciConverterContent(bizPackage, baseName, mciGroupPath.replace("/", "."), ioPrefix);
|
|
|
|
|
writeUtf8(converterDir.resolve(baseName + "Converter.java"), converterContent);
|
|
|
|
|
converterContent = mciConverterContent(converterPackage, bizPackage, baseName, mciGroupPath.replace("/", "."), ioPrefix, converterClassName);
|
|
|
|
|
writeUtf8(converterDir.resolve(converterClassName + ".java"), converterContent);
|
|
|
|
|
|
|
|
|
|
log.append("\n=========================================\n");
|
|
|
|
|
log.append(" Scaffolding Complete! (Routing: " + routingType + ")\n");
|
|
|
|
|
@@ -1291,7 +1358,7 @@ public class ToolScaffolder {
|
|
|
|
|
log.append("[Response DTO] ").append(dtoDir.resolve(baseName + "Response.java")).append("\n");
|
|
|
|
|
log.append("[MCI Request IO] ").append(mciIoDir.resolve(interfaceId + "_I.java")).append("\n");
|
|
|
|
|
log.append("[MCI Response IO] ").append(mciIoDir.resolve(interfaceId + "_O.java")).append("\n");
|
|
|
|
|
log.append("[MCI Converter] ").append(converterDir.resolve(baseName + "Converter.java")).append("\n");
|
|
|
|
|
log.append("[MCI Converter] ").append(converterDir.resolve(converterClassName + ".java")).append("\n");
|
|
|
|
|
|
|
|
|
|
if (!clientPrefixCap.isEmpty()) {
|
|
|
|
|
String receiveServiceId = (clientSystemCode != null && !clientSystemCode.isBlank()) ? clientSystemCode.toUpperCase() : "";
|
|
|
|
|
@@ -2140,9 +2207,10 @@ public class ToolScaffolder {
|
|
|
|
|
.replaceAll("^_+|_+$", "");
|
|
|
|
|
return normalized.isBlank() ? "http_api" : normalized;
|
|
|
|
|
}
|
|
|
|
|
private static String mciConverterContent(String bizPackage, String baseName, String mciPackage, String interfaceId) {
|
|
|
|
|
private static String mciConverterContent(String converterPackage, String bizPackage, String baseName,
|
|
|
|
|
String mciPackage, String interfaceId, String converterClassName) {
|
|
|
|
|
return """
|
|
|
|
|
package %s.converter;
|
|
|
|
|
package %s;
|
|
|
|
|
|
|
|
|
|
import %s.dto.%sRequest;
|
|
|
|
|
import %s.dto.%sResponse;
|
|
|
|
|
@@ -2153,16 +2221,24 @@ public class ToolScaffolder {
|
|
|
|
|
import org.mapstruct.ReportingPolicy;
|
|
|
|
|
|
|
|
|
|
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
|
|
|
|
public interface %sConverter {
|
|
|
|
|
public interface %s {
|
|
|
|
|
// Field names differ? Add mappings like this before the method.
|
|
|
|
|
// @Mapping(source = "sourceField", target = "targetField")
|
|
|
|
|
%s_I toLegacyRequest(%sRequest request);
|
|
|
|
|
%sRequest toRequest(%s_I mciRequest);
|
|
|
|
|
%sResponse toResponse(%s_O mciRes);
|
|
|
|
|
}
|
|
|
|
|
""".formatted(bizPackage, bizPackage, baseName, bizPackage, baseName,
|
|
|
|
|
""".formatted(converterPackage, bizPackage, baseName, bizPackage, baseName,
|
|
|
|
|
BASE_PACKAGE, mciPackage, interfaceId, BASE_PACKAGE, mciPackage, interfaceId,
|
|
|
|
|
baseName, interfaceId, baseName, baseName, interfaceId, baseName, interfaceId);
|
|
|
|
|
converterClassName, interfaceId, baseName, baseName, interfaceId, baseName, interfaceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String mciTargetSystemPackage(String clientSystemCode) {
|
|
|
|
|
if (clientSystemCode == null || clientSystemCode.length() != 9) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String prefix = clientSystemCode.substring(1, 5).toLowerCase(Locale.ROOT);
|
|
|
|
|
return prefix.substring(0, 3) + "." + prefix.substring(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String legacyConverterContent(String bizPackage, String baseName) {
|
|
|
|
|
@@ -2364,6 +2440,19 @@ public class ToolScaffolder {
|
|
|
|
|
action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String abbreviatedMciSourceBaseName(String baseName) {
|
|
|
|
|
String[] words = baseName.split("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])");
|
|
|
|
|
if (words.length < 3) {
|
|
|
|
|
return baseName;
|
|
|
|
|
}
|
|
|
|
|
return abbreviatedWord(words[0], 4) + abbreviatedWord(words[1], 6);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String abbreviatedWord(String word, int maximumLength) {
|
|
|
|
|
int length = Math.min(word.length(), maximumLength);
|
|
|
|
|
return toPascalCase(word.substring(0, length).toLowerCase(Locale.ROOT));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String toPascalCase(String str) {
|
|
|
|
|
if (str == null || str.isEmpty()) {
|
|
|
|
|
return str;
|
|
|
|
|
|