get value by patter for reference
This commit is contained in:
parent
56efe184c9
commit
a158e78101
|
@ -33,6 +33,8 @@ import reactor.netty.http.client.HttpClient;
|
|||
|
||||
import javax.net.ssl.SSLException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
@ -302,9 +304,26 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService {
|
|||
boolean isValid = true;
|
||||
for(ResultFieldsMappingConfiguration field : resultsConfigurationEntity.getFieldsMapping()) {
|
||||
if (this.conventionService.isNullOrEmpty(field.getResponsePath()) || this.conventionService.isNullOrEmpty(field.getCode())) continue;
|
||||
|
||||
try {
|
||||
if (field.getResponsePath().contains("@{{")){
|
||||
String rePattern = "@\\{\\{(.*?)}}";
|
||||
Pattern p = Pattern.compile(rePattern);
|
||||
Matcher m = p.matcher(field.getResponsePath());
|
||||
String value = field.getResponsePath();
|
||||
while (m.find()) {
|
||||
if (m.groupCount() < 1) continue;
|
||||
Object partValue = JsonPath.parse(resultItem).read(m.group(1));
|
||||
String normalizedValue = normalizeJsonValue(partValue);
|
||||
|
||||
if (normalizedValue != null) value = value.replace("@{{" + m.group(1) + "}}", normalizedValue);
|
||||
else value = value.replace("@{{" + m.group(1) + "}}","");
|
||||
}
|
||||
map.put(field.getCode(), normalizeJsonValue(value));
|
||||
} else {
|
||||
Object value = JsonPath.parse(resultItem).read(field.getResponsePath());
|
||||
map.put(field.getCode(), normalizeJsonValue(value));
|
||||
}
|
||||
}catch (PathNotFoundException e){
|
||||
logger.debug("Json Path Error: " + e.getMessage() + " on source " + jsonHandlingService.toJsonSafe(resultItem));
|
||||
if (ReferenceEntity.KnownFields.ReferenceId.equals(field.getCode())) {
|
||||
|
|
Loading…
Reference in New Issue