Skip to content

Commit

Permalink
Revert "Kavitha|add list of filters"
Browse files Browse the repository at this point in the history
This reverts commit 76ca278.
  • Loading branch information
kavitha-sundararajan committed May 30, 2024
1 parent 76ca278 commit 4367e5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,12 @@ public static class ErrorDestination extends Destination {
public static class AdditionalProperty {
private String parentPath;
private String filterKeyPath;
private List<AdditionalPropertyFilter> additionalPropertyFilters;
private String filterValue;
private LinkedHashMap<String, String> staticProperties = new LinkedHashMap<>(0);
private LinkedHashMap<String, String> dynamicProperties = new LinkedHashMap<>(0);
private LinkedHashMap<String, SplitPatternConfiguration> splitPatternConfigurations = new LinkedHashMap<>(0);
}

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class AdditionalPropertyFilter {
private String keyPath;
private String value;
}

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.bahmni.eventrouterservice.configuration.RouteDescriptionLoader.RouteDescription;
import org.bahmni.eventrouterservice.configuration.RouteDescriptionLoader.AdditionalProperty;
import org.bahmni.eventrouterservice.configuration.RouteDescriptionLoader.AdditionalPropertyFilter;
import org.bahmni.eventrouterservice.configuration.RouteDescriptionLoader.SplitPatternConfiguration;

import java.util.LinkedHashMap;
Expand Down Expand Up @@ -49,7 +47,8 @@ private String addAdditionalProperties(String payloadAsJsonString, List<Addition

for (AdditionalProperty obj : additionalProperties) {
String parentPath = obj.getParentPath();
List<AdditionalPropertyFilter> additionalPropertyFilters = obj.getAdditionalPropertyFilters();
String filterKeyPath = obj.getFilterKeyPath();
String filterValue = obj.getFilterValue();
LinkedHashMap<String, SplitPatternConfiguration> splitPatternConfigurations = obj.getSplitPatternConfigurations();
if (obj.getStaticProperties() != null && obj.getStaticProperties().size() > 0) {
obj.getStaticProperties().entrySet().forEach(entry -> {
Expand All @@ -62,19 +61,14 @@ private String addAdditionalProperties(String payloadAsJsonString, List<Addition
Object parentObj = JsonPath.read(payloadAsJsonString, parentPath);
if (parentObj instanceof List && !((List<?>) parentObj).isEmpty()) {
contextRef[0] = contextRef[0].map(parentPath, (currentValue, configuration) -> {
Object filterObj = JsonPath.read(currentValue, filterKeyPath);
Object valueObj = JsonPath.read(currentValue, entry.getValue());
DocumentContext obsContext = JsonPath.parse(currentValue);
try {
Object valueObj = JsonPath.read(currentValue, entry.getValue());
if (valueObj != null) {
if (splitPatternConfigurations != null && splitPatternConfigurations.get(entry.getKey()) != null) {
valueObj = applySplitPattern(valueObj, splitPatternConfigurations.get(entry.getKey()));
}
if (additionalPropertyFilters == null || additionalPropertyFilters.size() == 0 || applyFilter(currentValue, additionalPropertyFilters)) {
obsContext.put(JsonPath.compile("$"), entry.getKey(), valueObj);
}
}
} catch (PathNotFoundException e) {
log.info("Path not found: " + entry.getValue());
if (splitPatternConfigurations != null && splitPatternConfigurations.get(entry.getKey()) != null) {
valueObj = applySplitPattern(valueObj, splitPatternConfigurations.get(entry.getKey()));
}
if ((filterKeyPath == null && filterValue == null) || (filterObj != null && filterObj.toString().contains(filterValue))) {
obsContext.put(JsonPath.compile("$"), entry.getKey(), valueObj);
}
return obsContext.json();
});
Expand All @@ -89,18 +83,6 @@ private String addAdditionalProperties(String payloadAsJsonString, List<Addition
}
}

private boolean applyFilter(Object value, List<AdditionalPropertyFilter> additionalPropertyFilters) {
for (AdditionalPropertyFilter filter : additionalPropertyFilters) {
if (filter.getKeyPath() != null && filter.getValue() != null) {
Object filterObj = JsonPath.read(value, filter.getKeyPath());
if (filterObj == null || (filterObj != null && !filterObj.toString().contains(filter.getValue()))) {
return false;
}
}
}
return true;
}

private Object applySplitPattern(Object value, SplitPatternConfiguration splitConfig) {
if (value instanceof String) {
String[] parts = ((String) value).split(splitConfig.getSplitPattern());
Expand Down

0 comments on commit 4367e5c

Please sign in to comment.