get value by patter for reference

This commit is contained in:
Efstratios Giannopoulos 2024-04-17 10:23:56 +03:00
parent 56efe184c9
commit a158e78101
1 changed files with 21 additions and 2 deletions

View File

@ -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 {
Object value = JsonPath.parse(resultItem).read(field.getResponsePath());
map.put(field.getCode(), normalizeJsonValue(value));
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())) {