Skip to content

Commit

Permalink
added improvement patch for detail query of quote and order
Browse files Browse the repository at this point in the history
  • Loading branch information
xuelianhan007 committed Nov 1, 2024
1 parent 054332b commit 81e918a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@Slf4j
public class DBCrudActionRunner extends AbstractActionRunner {
private static final String ENTITY_NOT_FOUND_ERR = "DBCrudFilterFactory: entity not found";
private static final String ENTITY_ID_ERROR = ENTITY_NOT_FOUND_ERR + ", entityId:%s";
private final HttpRequestRepository repository;
private final FilterHeaderService filterHeaderService;

Expand Down Expand Up @@ -138,10 +139,17 @@ private void onUpdate(ServerWebExchange exchange, Config config) {
}

private void onRead(ServerWebExchange exchange, Config config) {
if (StringUtils.isBlank(config.getId()) && StringUtils.isNotBlank(config.getBlankIdErrMsg())) {
throw KrakenException.badRequest(config.getBlankIdErrMsg());
}
Optional<HttpRequestEntity> optionalEntity = readRequestEntity(config.getId());
if (optionalEntity.isEmpty()) {
log.error(ENTITY_NOT_FOUND_ERR);
return;
if (StringUtils.isNotBlank(config.getNotExistedErrMsg())) {
throw KrakenException.notFound(config.getNotExistedErrMsg());
} else {
throw KrakenException.notFound(String.format(ENTITY_ID_ERROR, config.getId()));
}
}
HttpRequestEntity entity = optionalEntity.get();
exchange.getAttributes().put(KrakenFilterConstants.X_ENTITY_ID, entity.getId().toString());
Expand All @@ -156,9 +164,9 @@ private Optional<HttpRequestEntity> readRequestEntity(String entityId) {
try {
entityUUID = UUID.fromString(entityId);
} catch (Exception e) {
String error = ENTITY_NOT_FOUND_ERR + ", entityId:" + entityId;
String error = String.format(ENTITY_ID_ERROR, entityId);
log.error(error, e);
throw KrakenException.notFound(error);
return Optional.empty();
}
return repository.findById(entityUUID);
}
Expand All @@ -171,6 +179,8 @@ public static class Config {
private String id;
private List<String> properties;
private String externalId;
private String blankIdErrMsg;
private String notExistedErrMsg;

public static Config of(ComponentAPIFacets.Action action, Map<String, Object> inputs) {
Map<String, Object> with = action.getWith();
Expand All @@ -181,6 +191,12 @@ public static Config of(ComponentAPIFacets.Action action, Map<String, Object> in
if ("undefined".equalsIgnoreCase(config.getBizType())) {
config.setBizType((String) inputs.get("bizType"));
}
if (config.getBlankIdErrMsg() == null) {
config.setBlankIdErrMsg((String) inputs.getOrDefault("blankIdErrMsg", ""));
}
if (config.getNotExistedErrMsg() == null) {
config.setNotExistedErrMsg((String) inputs.getOrDefault("notExistedErrMsg", ""));
}
return config;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
description: ""
source: "@{{id}}"
sourceLocation: "PATH"
target: "}"
target: ""
targetLocation: ""
requiredMapping: true
response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
targetLocation: BODY
requiredMapping: true
replaceStar: false
- name: address.validation.country.mapper
- name: mapper.address.validation.country
title: "The country of the identified alternate Geographic Address"
description: ""
source: ""
Expand All @@ -64,7 +64,7 @@ spec:
targetLocation: BODY
requiredMapping: false
replaceStar: false
- name: address.validation.city.mapper
- name: mapper.address.validation.city
title: "The city of the identified alternate Geographic Address"
description: ""
source: ""
Expand All @@ -74,7 +74,7 @@ spec:
targetLocation: BODY
requiredMapping: false
replaceStar: false
- name: address.validation.address.mapper
- name: mapper.address.validation.address
title: "The street of the identified alternate Geographic Address"
description: ""
source: ""
Expand All @@ -84,7 +84,7 @@ spec:
targetLocation: BODY
requiredMapping: false
replaceStar: false
- name: address.validation.locality.mapper
- name: mapper.address.validation.locality
title: "The metroId of the identified alternate Geographic Address"
description: ""
source: ""
Expand All @@ -94,7 +94,7 @@ spec:
targetLocation: BODY
requiredMapping: false
replaceStar: false
- name: address.validation.bestMatch.id.mapper
- name: mapper.address.validation.bestMatch.id
title: "Unique identifier of the identified best match Address"
requiredMapping: false
description: ""
Expand All @@ -106,7 +106,7 @@ spec:
checkPath: "$.bestMatchGeographicAddress.id"
deletePath: "$.bestMatchGeographicAddress"
replaceStar: false
- name: address.validation.bestMatch.city.mapper
- name: mapper.address.validation.bestMatch.city
title: "The City of the identified best match Address"
requiredMapping: false
description: ""
Expand All @@ -116,7 +116,7 @@ spec:
targetType: string
targetLocation: BODY
replaceStar: false
- name: address.validation.bestMatch.country.mapper
- name: mapper.address.validation.bestMatch.country
title: "The Country of the identified best match Address"
requiredMapping: false
description: ""
Expand All @@ -126,7 +126,7 @@ spec:
targetType: string
targetLocation: BODY
replaceStar: false
- name: address.validation.bestMatch.streetName.mapper
- name: mapper.address.validation.bestMatch.streetName
title: "The streetName of the identified best match Address"
requiredMapping: false
description: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
actionType: buildin@db
env:
id: ${query.productOrderId}
blankIdErrMsg: "productOrderId id cannot be blank"
notExistedErrMsg: "productOrderId id does not exist"
with:
action: read
preRequest: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ spec:
actionType: buildin@db
env:
id: ${segment}
blankIdErrMsg: "order id cannot be blank"
notExistedErrMsg: "order id does not exist"
with:
action: read
preRequest: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ spec:
actionType: buildin@db
env:
id: ${segment}
blankIdErrMsg: "quote id cannot be blank"
notExistedErrMsg: "quote id does not exist"
with:
action: read
preRequest: true
Expand Down

0 comments on commit 81e918a

Please sign in to comment.