Tweak logging and readme

This commit is contained in:
Max Martens 2025-03-17 10:00:46 +01:00
parent 35f9cccc05
commit d1a9cb4cd0
3 changed files with 9 additions and 5 deletions

View File

@ -5,6 +5,8 @@ Simple tool to quickly edit HTM products via ABTProducts REST API.
- Run via: `java -jar ABTProductsPUTGenerator.jar`
- Specify custom input/output path via: `java -jar ABTProductsPUTGenerator.jar <inputPath> <outputPath>`
- Takes a ABTProducts GET response body in JSON format (product details)
- Generates the equivalent PUT request body
- Generates the equivalent PUT request body - send via either:
- Postman WSO2 ABTProducts collection
- `curl -X PUT -H 'Content-Type: application/json' {baseUrl}/abt/abtproducts/1.0/38 --data @output.json`
- Default input path: /input.json
- Default output path: /output.json (output is overwritten if it exists)

View File

@ -24,18 +24,20 @@ public class ABTProductsPUTGenerator {
}
var inputFile = args.length > 0 ? args[0] : "input.json";
var outputFile = args.length > 1 ? args[1] : "output.json";
try(InputStream is = getInputStream(inputFile)) {
try (InputStream is = getInputStream(inputFile)) {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(is);
Long productId = jsonNode.get("productId").asLong();
LOGGER.info("Successfully parsed product with productId {} from JSON:\n{}\n", jsonNode.get("productId").asLong(), jsonNode.toPrettyString());
LOGGER.info("Successfully parsed product with productId {} from JSON:\n{}\n", productId, jsonNode.toPrettyString());
JsonNode putJsonNode = processJsonNode(jsonNode);
writeToFile(putJsonNode, outputFile);
}
LOGGER.info("DONE! Modify the output JSON as desired and send it as ABTProducts PUT request body.");
LOGGER.info("DONE! Modify the output JSON as desired and send it as ABTProducts PUT request body:");
LOGGER.info("curl -X PUT -H 'Content-Type: application/json' {baseUrl}/abt/abtproducts/1.0/products/{} --data @{}", productId, outputFile);
}
}
private static InputStream getInputStream(String filePath) throws IOException {