Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void validate(String expected, String input) {

StateValueMappingDto responseTargetMapperDto = new StateValueMappingDto();
for (ComponentAPITargetFacets.Endpoint endpoint : facets.getEndpoints()) {
String transformedResp = transform(endpoint, responseTargetMapperDto);
String transformedResp = transform(endpoint, responseTargetMapperDto, new HashMap<>());
log.info("expected resp:{}", expected);
log.info("transformed resp:{}", transformedResp);
Assertions.assertEquals(expected, transformedResp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ spec:
mappers:
request:
- name: mapper.quote.uni.add.sync.duration.amount
source: "@{{quoteItem[0].requestedQuoteItemTerm.duration.amount}}"
source: "@{{quoteItem[*].requestedQuoteItemTerm.duration.amount}}"
sourceLocation: BODY
sourceType: constantNumber
target: "1"
targetLocation: BODY
requiredMapping: true
mappingType: array
- name: mapper.quote.uni.add.sync.duration.units
source: "@{{quoteItem[0].requestedQuoteItemTerm.duration.units}}"
source: "@{{quoteItem[*].requestedQuoteItemTerm.duration.units}}"
sourceLocation: BODY
sourceType: enum
sourceValues:
Expand All @@ -42,8 +43,9 @@ spec:
target: "@{{ports[*].durationUnit}}"
targetLocation: BODY
requiredMapping: true
mappingType: array
- name: mapper.quote.uni.add.sync.endOfTermAction
source: "@{{quoteItem[0].requestedQuoteItemTerm.endOfTermAction}}"
source: "@{{quoteItem[*].requestedQuoteItemTerm.endOfTermAction}}"
sourceLocation: BODY
sourceType: enum
sourceValues:
Expand All @@ -54,15 +56,17 @@ spec:
target: "roll"
targetLocation: BODY
requiredMapping: true
mappingType: array
- name: mapper.quote.uni.add.sync.rollInterval.amount
source: "@{{quoteItem[0].requestedQuoteItemTerm.rollInterval.amount}}"
source: "@{{quoteItem[*].requestedQuoteItemTerm.rollInterval.amount}}"
sourceLocation: BODY
sourceType: constantNumber
target: "1"
targetLocation: BODY
requiredMapping: false
mappingType: array
- name: mapper.quote.uni.add.sync.rollInterval.units
source: "@{{quoteItem[0].requestedQuoteItemTerm.rollInterval.units}}"
source: "@{{quoteItem[*].requestedQuoteItemTerm.rollInterval.units}}"
sourceLocation: BODY
sourceType: enum
sourceValues:
Expand All @@ -77,22 +81,24 @@ spec:
target: "calendarMonths"
targetLocation: BODY
requiredMapping: false
mappingType: array
- name: mapper.quote.uni.add.sync.place.id
source: "@{{quoteItem[0].product.place[0].id}}"
source: "@{{quoteItem[*].product.place[0].id}}"
sourceLocation: BODY
sourceType: discreteStr
target: "@{{ports[*].dcf}}"
targetLocation: BODY
requiredMapping: true
mappingType: array
- name: mapper.quote.uni.add.sync.place.keyName
source: "@{{quoteItem[0].product.place[0].keyName}}"
source: "@{{quoteItem[*].product.place[0].keyName}}"
sourceLocation: BODY
sourceType: discreteStr
target: ""
targetLocation: BODY
requiredMapping: false
- name: mapper.quote.uni.add.sync.productConfiguration.bandwidth
source: "@{{quoteItem[0].product.productConfiguration.bandwidth}}"
source: "@{{quoteItem[*].product.productConfiguration.bandwidth}}"
sourceLocation: BODY
sourceType: discreteInt
sourceValues:
Expand All @@ -101,8 +107,9 @@ spec:
target: "@{{ports[*].speed}}"
targetLocation: BODY
requiredMapping: true
mappingType: array
- name: mapper.quote.uni.add.sync.productConfiguration.bandwidthUnit
source: "@{{quoteItem[0].product.productConfiguration.bandwidthUnit}}"
source: "@{{quoteItem[*].product.productConfiguration.bandwidthUnit}}"
sourceLocation: BODY
sourceType: enum
sourceValues:
Expand All @@ -112,76 +119,85 @@ spec:
target: "MBPS"
targetLocation: BODY
requiredMapping: true
mappingType: array
- name: mapper.quote.uni.add.sync.productOffering.id
source: "@{{quoteItem[0].product.productOffering.id}}"
source: "@{{quoteItem[*].product.productOffering.id}}"
sourceLocation: BODY
sourceType: discreteStr
target: "UNI"
targetLocation: BODY
requiredMapping: false
mappingType: array
response:
- name: mapper.quote.uni.add.sync.unitOfMeasure
title: Quote unitOfMeasure Mapping
description: quote unitOfMeasure mapping
source: "Gb"
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].unitOfMeasure}}"
target: "@{{quoteItem[*].quoteItemPrice[0].unitOfMeasure}}"
targetLocation: BODY
requiredMapping: false
mappingType: array
- name: mapper.quote.uni.add.sync.price.unit
title: Quote Price Unit Mapping
description: quote price mapping
source: "USD"
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].price.dutyFreeAmount.unit}}"
target: "@{{quoteItem[*].quoteItemPrice[0].price.dutyFreeAmount.unit}}"
targetLocation: BODY
requiredMapping: true
mappingType: array
- name: mapper.quote.uni.add.sync.price.value
title: Quote Price Value Mapping
description: quote price mapping
source: "@{{responseBody.results[*].price}}"
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].price.dutyFreeAmount.value}}"
target: "@{{quoteItem[*].quoteItemPrice[0].price.dutyFreeAmount.value}}"
targetLocation: BODY
requiredMapping: true
mappingType: array
- name: mapper.quote.uni.add.sync.taxRate
title: Quote taxRate Mapping
description: quote taxRate mapping
source: "16"
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].price.taxRate}}"
target: "@{{quoteItem[*].quoteItemPrice[0].price.taxRate}}"
targetLocation: BODY
requiredMapping: false
mappingType: array
- name: mapper.quote.uni.add.sync.taxIncludedAmount.unit
title: Quote taxIncludedAmount unit Mapping
description: quote taxIncludedAmount unit mapping
source: "USD"
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].price.taxIncludedAmount.unit}}"
target: "@{{quoteItem[*].quoteItemPrice[0].price.taxIncludedAmount.unit}}"
targetLocation: BODY
requiredMapping: false
mappingType: array
- name: mapper.quote.uni.add.sync.taxIncludedAmount.value
title: Quote taxIncludedAmount value Mapping
description: quote taxIncludedAmount value mapping
source: "100"
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].price.taxIncludedAmount.value}}"
target: "@{{quoteItem[*].quoteItemPrice[0].price.taxIncludedAmount.value}}"
targetLocation: BODY
requiredMapping: false
mappingType: array
- name: mapper.quote.uni.add.sync.quoteItemPrice.name
title: Quote quoteItemPrice name Mapping
description: quote quoteItemPrice name mapping
source: "name-here"
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].name}}"
target: "@{{quoteItem[*].quoteItemPrice[0].name}}"
targetLocation: BODY
requiredMapping: false
mappingType: array
- name: mapper.quote.uni.add.sync.quoteItemPrice.priceType
title: Quote quoteItemPrice priceType Mapping
description: quote quoteItemPrice priceType mapping
source: "recurring"
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].priceType}}"
target: "@{{quoteItem[*].quoteItemPrice[0].priceType}}"
targetType: enum
targetLocation: BODY
requiredMapping: false
Expand All @@ -190,20 +206,22 @@ spec:
- nonRecurring
- usageBased
valueMapping: {}
mappingType: array
- name: mapper.quote.uni.add.sync.quoteItemPrice.description
title: Quote quoteItemPrice description Mapping
description: quote quoteItemPrice description mapping
source: ""
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].description}}"
target: "@{{quoteItem[*].quoteItemPrice[0].description}}"
targetLocation: BODY
requiredMapping: false
mappingType: array
- name: mapper.quote.uni.add.sync.quoteItemPrice.recurringChargePeriod
title: Quote quoteItemPrice recurringChargePeriod Mapping
description: quote quoteItemPrice recurringChargePeriod mapping
source: "month"
sourceLocation: BODY
target: "@{{quoteItem[0].quoteItemPrice[*].recurringChargePeriod}}"
target: "@{{quoteItem[*].quoteItemPrice[0].recurringChargePeriod}}"
targetType: enum
targetLocation: BODY
requiredMapping: false
Expand All @@ -213,4 +231,5 @@ spec:
- week
- month
- year
valueMapping: {}
valueMapping: {}
mappingType: array
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static class Mapper {
private String deletePath;
private Boolean customizedField = false;
private String convertValue;
private String mappingType;

@Override
public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ public static List<String> extractParam(String param, String patternStr) {
return contents;
}

public static String convertToJsonPointer(String path) {
public static String convertPathToJsonPointer(String path) {
return convertPathToJsonPointer(path, "[0]");
}

public static String convertPathToJsonPointer(String path, String arrayReplacement) {
List<String> params = extractMapperParam(path);
String param = params.get(0);
if (StringUtils.isNotBlank(param) && param.startsWith(ARRAY_ROOT_PREFIX)) {
param = param.substring(ARRAY_ROOT_PREFIX.length(), param.length());
param = param.substring(ARRAY_ROOT_PREFIX.length());
}
return "/"
+ param
.replaceAll("\\[(\\*)\\]", "[0]")
.replaceAll("\\[(\\*)\\]", arrayReplacement)
.replaceAll("(?)\\[", "\\/")
.replaceAll("(?)\\].", "\\/")
.replaceAll("(\\.)", "\\/");
Expand All @@ -64,6 +68,21 @@ public static String constructBody(String source) {
return source.replace("@{{", "${body.").replace("}}", "}");
}

public static String constructBodyOfArray(String source, int indexOfArray) {
return constructBodyOfArray(source, indexOfArray, "${body.");
}

public static String constructBodyOfArray(String source, int indexOfArray, String arrayPrefix) {
return source
.replace("@{{", arrayPrefix)
.replace("}}", "}")
.replace("[*]", "[" + indexOfArray + "]");
}

public static String constructJsonPath(String prefix, String source) {
return source.replace("@{{", prefix).replace("}}", "");
}

public static String constructJsonPathBody(String source) {
return source.replace("@{{", "$.body.").replace("}}", "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void givenExpression_whenConvert_thenResponseOK() {
assertThat(s3).contains("body");
List<String> pathParam = ConstructExpressionUtil.extractOriginalPathParam("/{path}/a/b/c");
assertThat(pathParam).contains("path");
String s4 = ConstructExpressionUtil.convertToJsonPointer("@{{a[*].b.c[1]}}");
String s4 = ConstructExpressionUtil.convertPathToJsonPointer("@{{a[*].b.c[1]}}");
String s5 = ConstructExpressionUtil.constructOriginalDBParam("abc");
assertThat(s5).contains("entity");
assertThat(s4).doesNotContain("*");
Expand All @@ -42,7 +42,7 @@ void givenExpression_whenConvert_thenResponseOK() {
@Test
void givenStatusInArray_whenConvert_thenOK() {
String target = "@{{[*].status}}";
String result = ConstructExpressionUtil.convertToJsonPointer(target);
String result = ConstructExpressionUtil.convertPathToJsonPointer(target);
String expected = "/status";
Assertions.assertEquals(expected, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Publisher<String> transform(ServerWebExchange exchange, String s, boolean
context.put("responseStatus", responseStatus);
}
String engine = (String) context.get(INPUT_ENGINE);
log.info("engine:{}", engine);
log.info("postRequest:{}, engine:{}", postRequest, engine);
String retJsonString = null;
if (ENGINE_JAVASCRIPT.equals(engine)) {
String script = (String) context.get(SpelEngineActionRunner.INPUT_CODE);
Expand All @@ -88,7 +88,7 @@ public Publisher<String> transform(ServerWebExchange exchange, String s, boolean
retJsonString = JsonToolkit.toJson(expression);
}
}
log.info("retJsonString:{}", retJsonString);
log.info("postRequest:{}, retJsonString:{}", postRequest, retJsonString);

if (postRequest) {
exchange.getAttributes().put(KrakenFilterConstants.X_KRAKEN_RESPONSE_BODY, s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public Optional<ServerWebExchange> runIt(
}

StateValueMappingDto stateValueMappingDto = new StateValueMappingDto();
renderRequestService.parseRequest(facets, stateValueMappingDto);
renderRequestService.handlePath(facets);
renderRequestService.handleBody(facets, stateValueMappingDto, inputs);

if (render != null && render) {
facets
Expand All @@ -92,8 +93,9 @@ public Optional<ServerWebExchange> runIt(
endpoint.setRequestBody(renderedRequest);
}
if (Objects.nonNull(endpoint.getResponseBody())) {
String transformedResp = transform(endpoint, stateValueMappingDto);
String transformedResp = transform(endpoint, stateValueMappingDto, inputs);
endpoint.setResponseBody(SpELEngine.evaluate(transformedResp, inputs));
log.info("After rendering, the response body is:{}", endpoint.getResponseBody());
}
if (Objects.nonNull(endpoint.getPath())) {
String evaluate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public void checkMapperConstraints(String targetKey, Map<String, Object> inputs)
log.info("Skipped mapper due to blank target, source:{}", mapper.getSource());
continue;
}
String source = replaceStar(mapper.getSource());
if (MappingTypeEnum.ENUM.getKind().equals(mapper.getSourceType())
|| MappingTypeEnum.DISCRETE_STR.getKind().equals(mapper.getSourceType())
|| MappingTypeEnum.DISCRETE_INT.getKind().equals(mapper.getSourceType())
Expand Down
Loading
Loading