develop #38
38
src/java/ABTProductsPUTGenerator/.gitignore
vendored
Normal file
38
src/java/ABTProductsPUTGenerator/.gitignore
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
8
src/java/ABTProductsPUTGenerator/.idea/.gitignore
vendored
Normal file
8
src/java/ABTProductsPUTGenerator/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
7
src/java/ABTProductsPUTGenerator/.idea/encodings.xml
Normal file
7
src/java/ABTProductsPUTGenerator/.idea/encodings.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
14
src/java/ABTProductsPUTGenerator/.idea/misc.xml
Normal file
14
src/java/ABTProductsPUTGenerator/.idea/misc.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
6
src/java/ABTProductsPUTGenerator/.idea/vcs.xml
Normal file
6
src/java/ABTProductsPUTGenerator/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
BIN
src/java/ABTProductsPUTGenerator/bin/ABTProductsPUTGenerator.jar
Normal file
BIN
src/java/ABTProductsPUTGenerator/bin/ABTProductsPUTGenerator.jar
Normal file
Binary file not shown.
12
src/java/ABTProductsPUTGenerator/bin/README.md
Normal file
12
src/java/ABTProductsPUTGenerator/bin/README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# ABTProducts PUT request body generator
|
||||
Simple tool to quickly edit HTM products via ABTProducts REST API.
|
||||
|
||||
- Requires JRE 21
|
||||
- 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 - 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)
|
||||
154
src/java/ABTProductsPUTGenerator/bin/input.json
Normal file
154
src/java/ABTProductsPUTGenerator/bin/input.json
Normal file
@ -0,0 +1,154 @@
|
||||
{
|
||||
"productId": 38,
|
||||
"parentProductId": null,
|
||||
"productCode": "30901-WA",
|
||||
"gboPackageTemplateId": "30901",
|
||||
"tapConnectProductCode": null,
|
||||
"productGroupMetadata": null,
|
||||
"productName": "HTM P1W Prolongatie-Test 90% Korting",
|
||||
"productDescription": "Reis je regelmatig met HTM? Activeer dan HTM 90% Korting op je betaalpas of credit card en reis met korting!",
|
||||
"validityPeriod": {
|
||||
"validityPeriodId": 148,
|
||||
"fromInclusive": "2023-12-31T23:00:00.000+00:00",
|
||||
"toInclusive": "2029-12-08T04:00:00.000+00:00"
|
||||
},
|
||||
"productTranslations": [
|
||||
{
|
||||
"language": "en",
|
||||
"name": "HTM Prolongation-Test 90% Discount",
|
||||
"description": "Are you a regular traveler? Activate HTM 90% discount on your EMV card!"
|
||||
}
|
||||
],
|
||||
"productOwner": {
|
||||
"productOwnerId": 17,
|
||||
"name": "Corneel Verstoep",
|
||||
"organization": "HTM"
|
||||
},
|
||||
"marketSegments": [
|
||||
{
|
||||
"marketSegmentId": 1,
|
||||
"name": "B2C"
|
||||
}
|
||||
],
|
||||
"customerSegments": [
|
||||
{
|
||||
"customerSegmentId": 2,
|
||||
"name": "Kind (4-11)"
|
||||
},
|
||||
{
|
||||
"customerSegmentId": 3,
|
||||
"name": "Jongere (12-18)"
|
||||
},
|
||||
{
|
||||
"customerSegmentId": 4,
|
||||
"name": "Volwassene (19-64)"
|
||||
},
|
||||
{
|
||||
"customerSegmentId": 5,
|
||||
"name": "Oudere (65+)"
|
||||
}
|
||||
],
|
||||
"productCategory": {
|
||||
"productCategoryId": 1,
|
||||
"isTravelProduct": true,
|
||||
"name": "Kortingsabonnement"
|
||||
},
|
||||
"requiredCustomerLevel": {
|
||||
"requiredCustomerLevelId": 3,
|
||||
"name": "profile"
|
||||
},
|
||||
"requiredProducts": null,
|
||||
"incompatibleProducts": null,
|
||||
"mandatoryCustomerDataItems": [
|
||||
{
|
||||
"mandatoryCustomerDataItemId": 1,
|
||||
"customerDataItem": "birthname"
|
||||
},
|
||||
{
|
||||
"mandatoryCustomerDataItemId": 2,
|
||||
"customerDataItem": "surname"
|
||||
},
|
||||
{
|
||||
"mandatoryCustomerDataItemId": 4,
|
||||
"customerDataItem": "emailAddress"
|
||||
},
|
||||
{
|
||||
"mandatoryCustomerDataItemId": 5,
|
||||
"customerDataItem": "address"
|
||||
}
|
||||
],
|
||||
"requiredGboPersonalAttributes": null,
|
||||
"tokenTypes": [
|
||||
{
|
||||
"tokenTypeId": 1,
|
||||
"name": "EMV"
|
||||
}
|
||||
],
|
||||
"paymentMoment": {
|
||||
"paymentMomentId": 1,
|
||||
"name": "prepaid"
|
||||
},
|
||||
"serviceOptions": null,
|
||||
"validityDuration": "P1W",
|
||||
"maxStartInFutureDuration": "P6W",
|
||||
"isRenewable": true,
|
||||
"sendInvoice": true,
|
||||
"imageReference": "https://web.acc.cloud.htm.nl/media/leif2leu/htm-logo-mobile.svg",
|
||||
"productPageUrl": "https://web.acc.cloud.htm.nl/webshop/htm-90-korting/",
|
||||
"termsUrl": "https://web.acc.cloud.htm.nl/reisproducten/productvoorwaarden/htm-90-korting/",
|
||||
"isSellableAtHtm": true,
|
||||
"needsSolvencyCheckConsumer": false,
|
||||
"needsSolvencyCheckBusiness": false,
|
||||
"sellingPeriods": [
|
||||
{
|
||||
"sellingPeriodId": 89,
|
||||
"fromInclusive": "2024-09-30T23:00:00.000+00:00",
|
||||
"toInclusive": "2029-12-01T23:00:00.000+00:00",
|
||||
"salesTouchpoint": {
|
||||
"salesTouchpointId": 3,
|
||||
"name": "Website (Perplex)",
|
||||
"isActive": true,
|
||||
"retailer": {
|
||||
"retailerId": 1001,
|
||||
"name": "HTM externe touchpoints",
|
||||
"street": "Koningin Julianaplein",
|
||||
"number": 10,
|
||||
"numberAddition": null,
|
||||
"postalCode": "2595 AA",
|
||||
"city": "Den Haag",
|
||||
"country": "Nederland",
|
||||
"emailAddress": "info@htm.nl",
|
||||
"phoneNumber": "070 374 9002",
|
||||
"taxId": 572309345923,
|
||||
"imageReference": "https://www.htm.nl/media/leif2leu/htm-logo-mobile.svg"
|
||||
}
|
||||
},
|
||||
"forbiddenPaymentMethods": null,
|
||||
"sellingPrices": [
|
||||
{
|
||||
"sellingPriceId": 82,
|
||||
"amountExclTax": 92,
|
||||
"amountInclTax": 100,
|
||||
"fromInclusive": "2024-09-30T23:00:00.000+00:00",
|
||||
"toInclusive": "2029-12-01T23:00:00.000+00:00",
|
||||
"internalPrice": 0.0000,
|
||||
"taxMetadata": {
|
||||
"taxMetadataId": "47C8972E-A730-4032-9BDA-AF0A5BCB2C85",
|
||||
"taxCode": "V09",
|
||||
"taxPercentageAmount": 9,
|
||||
"description": "BTW VERKOOP LAAG 9%"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"purchasePrices": null,
|
||||
"auditTrail": [
|
||||
{
|
||||
"auditTrailId": 162,
|
||||
"action": "insert",
|
||||
"user": "api",
|
||||
"timestamp": "2024-11-25T08:39:36.793+00:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
58
src/java/ABTProductsPUTGenerator/bin/output.json
Normal file
58
src/java/ABTProductsPUTGenerator/bin/output.json
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"parentProductId" : null,
|
||||
"productCode" : "30901-WA",
|
||||
"gboPackageTemplateId" : "30901",
|
||||
"tapConnectProductCode" : null,
|
||||
"productGroupMetadata" : null,
|
||||
"productName" : "HTM P1W Prolongatie-Test 90% Korting",
|
||||
"productDescription" : "Reis je regelmatig met HTM? Activeer dan HTM 90% Korting op je betaalpas of credit card en reis met korting!",
|
||||
"validityPeriod" : {
|
||||
"validityPeriodId" : 148,
|
||||
"fromInclusive" : "2023-12-31T23:00:00.000+00:00",
|
||||
"toInclusive" : "2029-12-08T04:00:00.000+00:00"
|
||||
},
|
||||
"productTranslations" : [ {
|
||||
"language" : "en",
|
||||
"name" : "HTM Prolongation-Test 90% Discount",
|
||||
"description" : "Are you a regular traveler? Activate HTM 90% discount on your EMV card!"
|
||||
} ],
|
||||
"productOwnerId" : 17,
|
||||
"marketSegmentIds" : [ 1 ],
|
||||
"customerSegmentIds" : [ 2, 3, 4, 5 ],
|
||||
"productCategoryId" : 1,
|
||||
"requiredCustomerLevelId" : 3,
|
||||
"requiredProducts" : null,
|
||||
"incompatibleProducts" : null,
|
||||
"mandatoryCustomerDataItemIds" : [ 1, 2, 4, 5 ],
|
||||
"requiredGboPersonalAttributes" : null,
|
||||
"tokenTypeIds" : [ 1 ],
|
||||
"paymentMomentId" : 1,
|
||||
"serviceOptions" : null,
|
||||
"validityDuration" : "P1W",
|
||||
"maxStartInFutureDuration" : "P6W",
|
||||
"isRenewable" : true,
|
||||
"sendInvoice" : true,
|
||||
"imageReference" : "https://web.acc.cloud.htm.nl/media/leif2leu/htm-logo-mobile.svg",
|
||||
"productPageUrl" : "https://web.acc.cloud.htm.nl/webshop/htm-90-korting/",
|
||||
"termsUrl" : "https://web.acc.cloud.htm.nl/reisproducten/productvoorwaarden/htm-90-korting/",
|
||||
"isSellableAtHtm" : true,
|
||||
"needsSolvencyCheckConsumer" : false,
|
||||
"needsSolvencyCheckBusiness" : false,
|
||||
"sellingPeriods" : [ {
|
||||
"sellingPeriodId" : 89,
|
||||
"fromInclusive" : "2024-09-30T23:00:00.000+00:00",
|
||||
"toInclusive" : "2029-12-01T23:00:00.000+00:00",
|
||||
"salesTouchpointId" : 3,
|
||||
"forbiddenPaymentMethodIds" : null,
|
||||
"sellingPrices" : [ {
|
||||
"sellingPriceId" : 82,
|
||||
"amountExclTax" : 92,
|
||||
"amountInclTax" : 100,
|
||||
"fromInclusive" : "2024-09-30T23:00:00.000+00:00",
|
||||
"toInclusive" : "2029-12-01T23:00:00.000+00:00",
|
||||
"internalPrice" : 0.0,
|
||||
"taxMetadataId" : "47C8972E-A730-4032-9BDA-AF0A5BCB2C85"
|
||||
} ]
|
||||
} ],
|
||||
"purchasePrices" : null
|
||||
}
|
||||
58
src/java/ABTProductsPUTGenerator/output.json
Normal file
58
src/java/ABTProductsPUTGenerator/output.json
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"parentProductId" : null,
|
||||
"productCode" : "30901-WA",
|
||||
"gboPackageTemplateId" : "30901",
|
||||
"tapConnectProductCode" : null,
|
||||
"productGroupMetadata" : null,
|
||||
"productName" : "HTM P1W Prolongatie-Test 90% Korting",
|
||||
"productDescription" : "Reis je regelmatig met HTM? Activeer dan HTM 90% Korting op je betaalpas of credit card en reis met korting!",
|
||||
"validityPeriod" : {
|
||||
"validityPeriodId" : 148,
|
||||
"fromInclusive" : "2023-12-31T23:00:00.000+00:00",
|
||||
"toInclusive" : "2029-12-08T04:00:00.000+00:00"
|
||||
},
|
||||
"productTranslations" : [ {
|
||||
"language" : "en",
|
||||
"name" : "HTM Prolongation-Test 90% Discount",
|
||||
"description" : "Are you a regular traveler? Activate HTM 90% discount on your EMV card!"
|
||||
} ],
|
||||
"productOwnerId" : 17,
|
||||
"marketSegmentIds" : [ 1 ],
|
||||
"customerSegmentIds" : [ 2, 3, 4, 5 ],
|
||||
"productCategoryId" : 1,
|
||||
"requiredCustomerLevelId" : 3,
|
||||
"requiredProducts" : null,
|
||||
"incompatibleProducts" : null,
|
||||
"mandatoryCustomerDataItemIds" : [ 1, 2, 4, 5 ],
|
||||
"requiredGboPersonalAttributes" : null,
|
||||
"tokenTypeIds" : [ 1 ],
|
||||
"paymentMomentId" : 1,
|
||||
"serviceOptions" : null,
|
||||
"validityDuration" : "P1W",
|
||||
"maxStartInFutureDuration" : "P6W",
|
||||
"isRenewable" : true,
|
||||
"sendInvoice" : true,
|
||||
"imageReference" : "https://web.acc.cloud.htm.nl/media/leif2leu/htm-logo-mobile.svg",
|
||||
"productPageUrl" : "https://web.acc.cloud.htm.nl/webshop/htm-90-korting/",
|
||||
"termsUrl" : "https://web.acc.cloud.htm.nl/reisproducten/productvoorwaarden/htm-90-korting/",
|
||||
"isSellableAtHtm" : true,
|
||||
"needsSolvencyCheckConsumer" : false,
|
||||
"needsSolvencyCheckBusiness" : false,
|
||||
"sellingPeriods" : [ {
|
||||
"sellingPeriodId" : 89,
|
||||
"fromInclusive" : "2024-09-30T23:00:00.000+00:00",
|
||||
"toInclusive" : "2029-12-01T23:00:00.000+00:00",
|
||||
"salesTouchpointId" : 3,
|
||||
"forbiddenPaymentMethodIds" : null,
|
||||
"sellingPrices" : [ {
|
||||
"sellingPriceId" : 82,
|
||||
"amountExclTax" : 92,
|
||||
"amountInclTax" : 100,
|
||||
"fromInclusive" : "2024-09-30T23:00:00.000+00:00",
|
||||
"toInclusive" : "2029-12-01T23:00:00.000+00:00",
|
||||
"internalPrice" : 0.0,
|
||||
"taxMetadataId" : "47C8972E-A730-4032-9BDA-AF0A5BCB2C85"
|
||||
} ]
|
||||
} ],
|
||||
"purchasePrices" : null
|
||||
}
|
||||
67
src/java/ABTProductsPUTGenerator/pom.xml
Normal file
67
src/java/ABTProductsPUTGenerator/pom.xml
Normal file
@ -0,0 +1,67 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>nl.htm.ovpay.abt</groupId>
|
||||
<artifactId>ABTProductsPUTGenerator</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>ABTProductsPUTGenerator</name>
|
||||
<description>Generate an ABTProducts PUT request body from a given ABTProducts GET response body</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- Log4j Slf4j Logging -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.23.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.23.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.23.1</version>
|
||||
</dependency>
|
||||
<!-- JSON parsing -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.17.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>nl.htm.ovpay.abt.ABTProductsPUTGenerator</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>21</source>
|
||||
<target>21</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@ -0,0 +1,272 @@
|
||||
package nl.htm.ovpay.abt;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
public class ABTProductsPUTGenerator {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ABTProductsPUTGenerator.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) {
|
||||
LOGGER.info("To modify input/output path, use: java -jar ABTProductsPUTGenerator.jar <inputPath> <outputPath>");
|
||||
}
|
||||
var inputFile = args.length > 0 ? args[0] : "input.json";
|
||||
var outputFile = args.length > 1 ? args[1] : "output.json";
|
||||
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", 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("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 {
|
||||
var externalResource = new File(filePath);
|
||||
if (externalResource.exists()) {
|
||||
LOGGER.info("Loading ABTProducts details JSON from external file {}...", externalResource.getAbsolutePath());
|
||||
return externalResource.toURI().toURL().openStream();
|
||||
} else {
|
||||
LOGGER.info("External file {} not found, using internal resource /input.json...", filePath);
|
||||
return ABTProductsPUTGenerator.class.getResourceAsStream("/input.json");
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeToFile(JsonNode jsonNode, String filePath) throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
var outputFile = new File(filePath);
|
||||
if (outputFile.exists()) {
|
||||
LOGGER.info("Deleting existing output file {}...", filePath);
|
||||
outputFile.delete();
|
||||
}
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(outputFile, jsonNode);
|
||||
LOGGER.info("Successfully wrote JSON to file {}!", outputFile.getAbsolutePath(), jsonNode.toPrettyString());
|
||||
}
|
||||
|
||||
private static JsonNode processJsonNode(JsonNode jsonNode) {
|
||||
var newJsonNode = new ObjectNode(new JsonNodeFactory(true));
|
||||
|
||||
jsonNode.fields().forEachRemaining(jsonField -> {
|
||||
if (!List.of(JsonNodeType.ARRAY, JsonNodeType.OBJECT).contains(jsonField.getValue().getNodeType())) {
|
||||
if (!jsonField.getKey().equals("productId") && !jsonField.getKey().equals("auditTrail")) {
|
||||
LOGGER.info("Keeping {} as-is...", jsonField.getKey());
|
||||
newJsonNode.put(jsonField.getKey(), jsonField.getValue());
|
||||
}
|
||||
} else {
|
||||
if (List.of("validityPeriod", "productTranslations").contains(jsonField.getKey())) {
|
||||
LOGGER.info("Keeping {} as-is...", jsonField.getKey());
|
||||
newJsonNode.set(jsonField.getKey(), jsonField.getValue());
|
||||
} else {
|
||||
rewriteObjectFields(jsonField, newJsonNode);
|
||||
rewriteArrayFields(jsonField, newJsonNode);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LOGGER.info("Successfully rewritten into PUT JSON:\n{}\n", newJsonNode.toPrettyString());
|
||||
|
||||
return newJsonNode;
|
||||
}
|
||||
|
||||
private static void rewriteObjectFields(Map.Entry<String, JsonNode> jsonField, JsonNode newJsonNode) {
|
||||
switch (jsonField.getKey()) {
|
||||
case "productOwner" -> {
|
||||
LOGGER.info("Rewriting productOwner to productOwnerId...");
|
||||
Long productOwnerId = jsonField.getValue().get("productOwnerId").asLong();
|
||||
((ObjectNode)newJsonNode).put("productOwnerId", productOwnerId);
|
||||
}
|
||||
case "productCategory" -> {
|
||||
LOGGER.info("Rewriting productCategory to productCategoryId...");
|
||||
Long productCategoryId = jsonField.getValue().get("productCategoryId").asLong();
|
||||
((ObjectNode)newJsonNode).put("productCategoryId", productCategoryId);
|
||||
}
|
||||
case "paymentMoment" -> {
|
||||
LOGGER.info("Rewriting paymentMoment to paymentMomentId...");
|
||||
Long paymentMomentId = jsonField.getValue().get("paymentMomentId").asLong();
|
||||
((ObjectNode)newJsonNode).put("paymentMomentId", paymentMomentId);
|
||||
}
|
||||
case "requiredCustomerLevel" -> {
|
||||
LOGGER.info("Rewriting requiredCustomerLevel to requiredCustomerLevelId...");
|
||||
Long requiredCustomerLevelId = jsonField.getValue().get("requiredCustomerLevelId").asLong();
|
||||
((ObjectNode)newJsonNode).put("requiredCustomerLevelId", requiredCustomerLevelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void rewriteArrayFields(Map.Entry<String, JsonNode> jsonField, JsonNode newJsonNode) {
|
||||
switch (jsonField.getKey()) {
|
||||
case "marketSegments" -> {
|
||||
LOGGER.info("Rewriting marketSegments to marketSegmentIds...");
|
||||
if (jsonField.getValue() != null) {
|
||||
ArrayNode marketSegmentIds = new ArrayNode(new JsonNodeFactory(true));
|
||||
((ArrayNode)jsonField.getValue()).elements().forEachRemaining(marketSegment -> {
|
||||
marketSegmentIds.add(marketSegment.get("marketSegmentId").asLong());
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("marketSegmentIds").addAll(marketSegmentIds);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("marketSegmentIds", null);
|
||||
}
|
||||
}
|
||||
case "customerSegments" -> {
|
||||
LOGGER.info("Rewriting customerSegments to customerSegmentIds...");
|
||||
if (jsonField.getValue() != null) {
|
||||
ArrayNode customerSegmentIds = new ArrayNode(new JsonNodeFactory(true));
|
||||
((ArrayNode)jsonField.getValue()).elements().forEachRemaining(customerSegment -> {
|
||||
customerSegmentIds.add(customerSegment.get("customerSegmentId").asLong());
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("customerSegmentIds").addAll(customerSegmentIds);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("customerSegmentIds", null);
|
||||
}
|
||||
}
|
||||
case "tokenTypes" -> {
|
||||
LOGGER.info("Rewriting tokenTypes to tokenTypeIds...");
|
||||
if (jsonField.getValue() != null) {
|
||||
ArrayNode tokenTypeIds = new ArrayNode(new JsonNodeFactory(true));
|
||||
((ArrayNode)jsonField.getValue()).elements().forEachRemaining(tokenType -> {
|
||||
tokenTypeIds.add(tokenType.get("tokenTypeId").asLong());
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("tokenTypeIds").addAll(tokenTypeIds);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("tokenTypeIds", null);
|
||||
}
|
||||
}
|
||||
case "mandatoryCustomerDataItems" -> {
|
||||
LOGGER.info("Rewriting mandatoryCustomerDataItems to mandatoryCustomerDataItemIds...");
|
||||
if (jsonField.getValue() != null) {
|
||||
ArrayNode mandatoryCustomerDataItemIds = new ArrayNode(new JsonNodeFactory(true));
|
||||
((ArrayNode)jsonField.getValue()).elements().forEachRemaining(mandatoryCustomerDataItem -> {
|
||||
mandatoryCustomerDataItemIds.add(mandatoryCustomerDataItem.get("mandatoryCustomerDataItemId").asLong());
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("mandatoryCustomerDataItemIds").addAll(mandatoryCustomerDataItemIds);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("mandatoryCustomerDataItemIds", null);
|
||||
}
|
||||
}
|
||||
case "requiredGboPersonalAttributes" -> {
|
||||
LOGGER.info("Rewriting requiredGboPersonalAttributes to requiredGboPersonalAttributeIds...");
|
||||
if (jsonField.getValue() != null) {
|
||||
ArrayNode requiredGboPersonalAttributeIds = new ArrayNode(new JsonNodeFactory(true));
|
||||
((ArrayNode)jsonField.getValue()).elements().forEachRemaining(requiredGboPersonalAttribute -> {
|
||||
requiredGboPersonalAttributeIds.add(
|
||||
requiredGboPersonalAttribute.get("requiredGboPersonalAttributeId").asLong());
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("requiredGboPersonalAttributeIds").addAll(requiredGboPersonalAttributeIds);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("requiredGboPersonalAttributeIds", null);
|
||||
}
|
||||
}
|
||||
case "serviceOptions" -> {
|
||||
LOGGER.info("Rewriting serviceOptions to serviceOptionIds...");
|
||||
if (jsonField.getValue() != null) {
|
||||
ArrayNode serviceOptionIds = new ArrayNode(new JsonNodeFactory(true));
|
||||
((ArrayNode)jsonField.getValue()).elements().forEachRemaining(serviceOption -> {
|
||||
serviceOptionIds.add(serviceOption.get("serviceOptionId").asLong());
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("serviceOptionIds").addAll(serviceOptionIds);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("serviceOptionIds", null);
|
||||
}
|
||||
}
|
||||
case "incompatibleProducts" -> {
|
||||
LOGGER.info("Rewriting incompatibleProducts to remove product names...");
|
||||
if (jsonField.getValue() != null) {
|
||||
ArrayNode incompatibleProducts = ((ArrayNode)jsonField.getValue()).deepCopy();
|
||||
incompatibleProducts.elements().forEachRemaining(incompatibleProduct -> {
|
||||
((ObjectNode)incompatibleProduct).remove("productName");
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("incompatibleProducts").addAll(incompatibleProducts);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("incompatibleProducts", null);
|
||||
}
|
||||
}
|
||||
case "requiredProducts" -> {
|
||||
LOGGER.info("Rewriting requiredProducts to remove product names...");
|
||||
if (jsonField.getValue() != null) {
|
||||
ArrayNode requiredProducts = ((ArrayNode)jsonField.getValue()).deepCopy();
|
||||
requiredProducts.elements().forEachRemaining(requiredProduct -> {
|
||||
((ObjectNode)requiredProduct).remove("productName");
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("requiredProducts").addAll(requiredProducts);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("requiredProducts", null);
|
||||
}
|
||||
}
|
||||
case "sellingPeriods" -> {
|
||||
if (jsonField.getValue() != null) {
|
||||
LOGGER.info("Rewriting salesTouchpoint in sellingPeriods to salesTouchpointId...");
|
||||
ArrayNode sellingPeriods = ((ArrayNode)jsonField.getValue()).deepCopy();
|
||||
sellingPeriods.elements().forEachRemaining(sellingPeriod -> {
|
||||
Long salesTouchpointId = sellingPeriod.get("salesTouchpoint").get("salesTouchpointId").asLong();
|
||||
((ObjectNode)sellingPeriod).put("salesTouchpointId", salesTouchpointId);
|
||||
((ObjectNode)sellingPeriod).remove("salesTouchpoint");
|
||||
if (sellingPeriod.get("forbiddenPaymentMethods") != null) {
|
||||
LOGGER.info("Rewriting forbiddenPaymentMethods to forbiddenPaymentMethodIds...");
|
||||
ArrayNode forbiddenPaymentMethodIds = new ArrayNode(new JsonNodeFactory(true));
|
||||
sellingPeriod.get("forbiddenPaymentMethods").elements().forEachRemaining(forbiddenPaymentMethod -> {
|
||||
forbiddenPaymentMethodIds.add(forbiddenPaymentMethod.get("forbiddenPaymentMethodId").asLong());
|
||||
});
|
||||
((ObjectNode)sellingPeriod).remove("forbiddenPaymentMethods");
|
||||
if (!forbiddenPaymentMethodIds.isEmpty()) {
|
||||
((ObjectNode)sellingPeriod).putArray("forbiddenPaymentMethodIds").addAll(forbiddenPaymentMethodIds);
|
||||
} else {
|
||||
((ObjectNode)sellingPeriod).putRawValue("forbiddenPaymentMethodIds", null);
|
||||
}
|
||||
}
|
||||
if (sellingPeriod.get("sellingPrices") != null) {
|
||||
LOGGER.info("Rewriting taxMetadata in sellingPrices to taxMetadataId...");
|
||||
ArrayNode sellingPrices = ((ArrayNode)sellingPeriod.get("sellingPrices")).deepCopy();
|
||||
sellingPrices.elements().forEachRemaining(sellingPrice -> {
|
||||
String taxMetadataId = sellingPrice.get("taxMetadata").get("taxMetadataId").asText();
|
||||
((ObjectNode)sellingPrice).put("taxMetadataId", taxMetadataId);
|
||||
((ObjectNode)sellingPrice).remove("taxMetadata");
|
||||
});
|
||||
((ObjectNode)sellingPeriod).remove("sellingPrices");
|
||||
if (!sellingPrices.isEmpty()) {
|
||||
((ObjectNode)sellingPeriod).putArray("sellingPrices").addAll(sellingPrices);
|
||||
} else {
|
||||
((ObjectNode)sellingPeriod).putRawValue("sellingPrices", null);
|
||||
}
|
||||
}
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("sellingPeriods").addAll(sellingPeriods);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("sellingPeriods", null);
|
||||
}
|
||||
}
|
||||
case "purchasePrices" -> {
|
||||
LOGGER.info("Rewriting taxMetadata in purchasePrices to taxMetadataId...");
|
||||
if (jsonField.getValue() != null) {
|
||||
ArrayNode purchasePrices = ((ArrayNode)jsonField.getValue()).deepCopy();
|
||||
purchasePrices.elements().forEachRemaining(purchasePrice -> {
|
||||
String taxMetadataId = purchasePrice.get("taxMetadata").get("taxMetadataId").asText();
|
||||
((ObjectNode)purchasePrice).put("taxMetadataId", taxMetadataId);
|
||||
((ObjectNode)purchasePrice).remove("taxMetadata");
|
||||
});
|
||||
((ObjectNode)newJsonNode).putArray("purchasePrices").addAll(purchasePrices);
|
||||
} else {
|
||||
((ObjectNode)newJsonNode).putRawValue("purchasePrices", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
154
src/java/ABTProductsPUTGenerator/src/main/resources/input.json
Normal file
154
src/java/ABTProductsPUTGenerator/src/main/resources/input.json
Normal file
@ -0,0 +1,154 @@
|
||||
{
|
||||
"productId": 38,
|
||||
"parentProductId": null,
|
||||
"productCode": "30901-WA",
|
||||
"gboPackageTemplateId": "30901",
|
||||
"tapConnectProductCode": null,
|
||||
"productGroupMetadata": null,
|
||||
"productName": "HTM P1W Prolongatie-Test 90% Korting",
|
||||
"productDescription": "Reis je regelmatig met HTM? Activeer dan HTM 90% Korting op je betaalpas of credit card en reis met korting!",
|
||||
"validityPeriod": {
|
||||
"validityPeriodId": 148,
|
||||
"fromInclusive": "2023-12-31T23:00:00.000+00:00",
|
||||
"toInclusive": "2029-12-08T04:00:00.000+00:00"
|
||||
},
|
||||
"productTranslations": [
|
||||
{
|
||||
"language": "en",
|
||||
"name": "HTM Prolongation-Test 90% Discount",
|
||||
"description": "Are you a regular traveler? Activate HTM 90% discount on your EMV card!"
|
||||
}
|
||||
],
|
||||
"productOwner": {
|
||||
"productOwnerId": 17,
|
||||
"name": "Corneel Verstoep",
|
||||
"organization": "HTM"
|
||||
},
|
||||
"marketSegments": [
|
||||
{
|
||||
"marketSegmentId": 1,
|
||||
"name": "B2C"
|
||||
}
|
||||
],
|
||||
"customerSegments": [
|
||||
{
|
||||
"customerSegmentId": 2,
|
||||
"name": "Kind (4-11)"
|
||||
},
|
||||
{
|
||||
"customerSegmentId": 3,
|
||||
"name": "Jongere (12-18)"
|
||||
},
|
||||
{
|
||||
"customerSegmentId": 4,
|
||||
"name": "Volwassene (19-64)"
|
||||
},
|
||||
{
|
||||
"customerSegmentId": 5,
|
||||
"name": "Oudere (65+)"
|
||||
}
|
||||
],
|
||||
"productCategory": {
|
||||
"productCategoryId": 1,
|
||||
"isTravelProduct": true,
|
||||
"name": "Kortingsabonnement"
|
||||
},
|
||||
"requiredCustomerLevel": {
|
||||
"requiredCustomerLevelId": 3,
|
||||
"name": "profile"
|
||||
},
|
||||
"requiredProducts": null,
|
||||
"incompatibleProducts": null,
|
||||
"mandatoryCustomerDataItems": [
|
||||
{
|
||||
"mandatoryCustomerDataItemId": 1,
|
||||
"customerDataItem": "birthname"
|
||||
},
|
||||
{
|
||||
"mandatoryCustomerDataItemId": 2,
|
||||
"customerDataItem": "surname"
|
||||
},
|
||||
{
|
||||
"mandatoryCustomerDataItemId": 4,
|
||||
"customerDataItem": "emailAddress"
|
||||
},
|
||||
{
|
||||
"mandatoryCustomerDataItemId": 5,
|
||||
"customerDataItem": "address"
|
||||
}
|
||||
],
|
||||
"requiredGboPersonalAttributes": null,
|
||||
"tokenTypes": [
|
||||
{
|
||||
"tokenTypeId": 1,
|
||||
"name": "EMV"
|
||||
}
|
||||
],
|
||||
"paymentMoment": {
|
||||
"paymentMomentId": 1,
|
||||
"name": "prepaid"
|
||||
},
|
||||
"serviceOptions": null,
|
||||
"validityDuration": "P1W",
|
||||
"maxStartInFutureDuration": "P6W",
|
||||
"isRenewable": true,
|
||||
"sendInvoice": true,
|
||||
"imageReference": "https://web.acc.cloud.htm.nl/media/leif2leu/htm-logo-mobile.svg",
|
||||
"productPageUrl": "https://web.acc.cloud.htm.nl/webshop/htm-90-korting/",
|
||||
"termsUrl": "https://web.acc.cloud.htm.nl/reisproducten/productvoorwaarden/htm-90-korting/",
|
||||
"isSellableAtHtm": true,
|
||||
"needsSolvencyCheckConsumer": false,
|
||||
"needsSolvencyCheckBusiness": false,
|
||||
"sellingPeriods": [
|
||||
{
|
||||
"sellingPeriodId": 89,
|
||||
"fromInclusive": "2024-09-30T23:00:00.000+00:00",
|
||||
"toInclusive": "2029-12-01T23:00:00.000+00:00",
|
||||
"salesTouchpoint": {
|
||||
"salesTouchpointId": 3,
|
||||
"name": "Website (Perplex)",
|
||||
"isActive": true,
|
||||
"retailer": {
|
||||
"retailerId": 1001,
|
||||
"name": "HTM externe touchpoints",
|
||||
"street": "Koningin Julianaplein",
|
||||
"number": 10,
|
||||
"numberAddition": null,
|
||||
"postalCode": "2595 AA",
|
||||
"city": "Den Haag",
|
||||
"country": "Nederland",
|
||||
"emailAddress": "info@htm.nl",
|
||||
"phoneNumber": "070 374 9002",
|
||||
"taxId": 572309345923,
|
||||
"imageReference": "https://www.htm.nl/media/leif2leu/htm-logo-mobile.svg"
|
||||
}
|
||||
},
|
||||
"forbiddenPaymentMethods": null,
|
||||
"sellingPrices": [
|
||||
{
|
||||
"sellingPriceId": 82,
|
||||
"amountExclTax": 92,
|
||||
"amountInclTax": 100,
|
||||
"fromInclusive": "2024-09-30T23:00:00.000+00:00",
|
||||
"toInclusive": "2029-12-01T23:00:00.000+00:00",
|
||||
"internalPrice": 0.0000,
|
||||
"taxMetadata": {
|
||||
"taxMetadataId": "47C8972E-A730-4032-9BDA-AF0A5BCB2C85",
|
||||
"taxCode": "V09",
|
||||
"taxPercentageAmount": 9,
|
||||
"description": "BTW VERKOOP LAAG 9%"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"purchasePrices": null,
|
||||
"auditTrail": [
|
||||
{
|
||||
"auditTrailId": 162,
|
||||
"action": "insert",
|
||||
"user": "api",
|
||||
"timestamp": "2024-11-25T08:39:36.793+00:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="STDOUT-COLOR">
|
||||
<PatternLayout
|
||||
pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} | %highlight{%-5level} | %cyan{%-28c{1}} - %msg %blue{[%t]}%n"
|
||||
disableAnsi="false"/>
|
||||
</Console>
|
||||
<Console name="STDOUT-NOCOLOR">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} | %-5level | %-28c{1} - %msg [%t]%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="STDOUT-NOCOLOR"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -3406,7 +3406,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/unavailable"
|
||||
example:
|
||||
examples:
|
||||
v2.0:
|
||||
summary: Order customer address create v1.2
|
||||
description: Order customer address create v1.2
|
||||
@ -3564,7 +3564,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/unavailable"
|
||||
example:
|
||||
examples:
|
||||
v2.0:
|
||||
summary: Order customer address create v1.2
|
||||
description: Order customer address create v1.2
|
||||
|
||||
Loading…
Reference in New Issue
Block a user