Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions src/main/java/com/ly/doc/model/torna/TornaRequestInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;

import com.ly.doc.constants.TornaConstants;
Expand Down Expand Up @@ -92,25 +93,47 @@ public TornaRequestInfo setResponseInfo(String responseInfo) {
return this;
}

/**
* Builds a full log string including both request and response data.
* @return Formatted log string with request and response details
*/
public String buildInfo() {
StringBuilder sb = new StringBuilder();
sb.append("---------------------------PUSH START---------------------------\n")
return buildLogContent(true, "=============== REQUEST & RESPONSE LOG END ===============");
}

/**
* Builds a log string containing only request data (no response).
* @return Formatted log string with request details only
*/
public String buildRequestInfo() {
return buildLogContent(false, "==================== REQUEST LOG END ====================");
}

/**
* Shared method to construct log content dynamically.
* @param includeResponse Whether to include response data
* @param closingMarker Custom closing boundary marker
*/
private String buildLogContent(boolean includeResponse, String closingMarker) {
StringBuilder sb = new StringBuilder().append("==================== PUSH LOG START ====================\n")
.append("API: ")
.append(category)
.append("\n")
.append("Request Param: \n")
.append(TornaConstants.GSON.toJson(requestInfo))
.append("\n")
.append("Response: \n")
.append(TornaConstants.GSON.fromJson(responseInfo, HashMap.class))
.append("\n")
.append("---------------------------PUSH END---------------------------\n");
.append("\n");

if (includeResponse) {
sb.append("Response: \n").append(TornaConstants.GSON.fromJson(responseInfo, HashMap.class)).append("\n");
}

sb.append(closingMarker).append("\n"); // Custom closing marker

try {
return URLDecoder.decode(sb.toString(), "utf-8");
return URLDecoder.decode(sb.toString(), StandardCharsets.UTF_8.name());
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
return "";
return ""; // In production, log this error (e.g., via SLF4J)
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/ly/doc/utils/JavaClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public static Object getDefaultEnumValue(JavaClass javaClass, ProjectDocConfigBu
}

// Default handling for enum values
return processDefaultEnumFields(enumConstant);
return processDefaultEnumFields(enumConstant, builder);
}

/**
Expand Down Expand Up @@ -501,7 +501,12 @@ private static Optional<JavaField> findFieldWithJsonValue(JavaClass javaClass) {
* @param javaField The JavaField object representing the enum constant
* @return The value based on the enum field processing logic
*/
private static Object processDefaultEnumFields(JavaField javaField) {
private static Object processDefaultEnumFields(JavaField javaField, ProjectDocConfigBuilder builder) {
ApiConfig apiConfig = builder.getApiConfig();
if (!apiConfig.isEnumConvertor()) {
return javaField.getName();
}

String initializationExpression = javaField.getInitializationExpression();

if (StringUtils.isBlank(initializationExpression)) {
Expand Down
39 changes: 31 additions & 8 deletions src/main/java/com/ly/doc/utils/TornaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public static void pushToTorna(TornaApi tornaApi, ApiConfig apiConfig, JavaProje
private static void pushToTornaAll(TornaApi tornaApi, ApiConfig apiConfig, JavaProjectBuilder builder) {
// Build push document information
Map<String, String> requestJson = TornaConstants.buildParams(PUSH, new Gson().toJson(tornaApi), apiConfig);
TornaUtil.printDebugInfo(apiConfig, null, requestJson, PUSH, true);
// Push dictionary information
Map<String, Object> dicMap = new HashMap<>(2);
List<TornaDic> docDicts = TornaUtil.buildTornaDic(DocUtil.buildDictionary(apiConfig, builder));
Expand Down Expand Up @@ -190,23 +191,45 @@ public static boolean setDebugEnv(ApiConfig apiConfig, TornaApi tornaApi) {
*/
public static void printDebugInfo(ApiConfig apiConfig, String responseMsg, Map<String, String> requestJson,
String category) {
printDebugInfo(apiConfig, responseMsg, requestJson, category, false);
}

/**
* Prints debug information with mode support.
* @param apiConfig The API configuration object containing OpenUrl, appToken, etc.
* @param responseMsg The response message, null for pre-request mode.
* @param requestJson The request JSON object in key-value pairs.
* @param category The category of the request or response for classifying debug
* information.
* @param isPreRequest true for pre-request mode, false for post-request mode.
*/
public static void printDebugInfo(ApiConfig apiConfig, String responseMsg, Map<String, String> requestJson,
String category, boolean isPreRequest) {
if (apiConfig.isTornaDebug()) {
String sb = "Configuration information : \n" + "OpenUrl: " + apiConfig.getOpenUrl() + "\n" + "appToken: "
+ apiConfig.getAppToken() + "\n";
System.out.println(sb);
try {
JsonElement element = JsonParser.parseString(responseMsg);
if (isPreRequest) {
TornaRequestInfo info = new TornaRequestInfo().of()
.setCategory(category)
.setCode(element.getAsJsonObject().get(TornaConstants.CODE).getAsString())
.setMessage(element.getAsJsonObject().get(TornaConstants.MESSAGE).getAsString())
.setRequestInfo(requestJson)
.setResponseInfo(responseMsg);
System.out.println(info.buildInfo());
System.out.println(info.buildRequestInfo());
}
catch (Exception e) {
// Ex : Nginx Error,Tomcat Error
System.out.println("Response Error : \n" + responseMsg);
else {
try {
JsonElement element = JsonParser.parseString(responseMsg);
TornaRequestInfo info = new TornaRequestInfo().of()
.setCategory(category)
.setCode(element.getAsJsonObject().get(TornaConstants.CODE).getAsString())
.setMessage(element.getAsJsonObject().get(TornaConstants.MESSAGE).getAsString())
.setRequestInfo(requestJson)
.setResponseInfo(responseMsg);
System.out.println(info.buildInfo());
}
catch (Exception e) {
System.out.println("Response Error : \n" + responseMsg);
}
}
}
}
Expand Down
Loading