Skip to content

Commit

Permalink
Cover edge case of object instead of list
Browse files Browse the repository at this point in the history
  • Loading branch information
romulets committed Oct 30, 2024
1 parent 689f771 commit 3c0dda2
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ processors:
drop(ctx);
- script:
description: Populate related.entity
description: Populate related.entity
lang: painless
on_failure:
- set:
description: Add error reason
field: error.message
value: "{{{ _ingest.on_failure_message }}}"
source: |
boolean addValue(Set entities, String value) {
if (value == null || value == "" || value == "unknown") {
Expand All @@ -51,13 +56,22 @@ processors:
// Using tree set to ensure a sorting is kept (testing purposes)
TreeSet related = new TreeSet();
addValue(related, field("json.actor.id").get(null));
addValue(related, field("json.actor.alternateId").get(null));
addValue(related, ctx?.json?.actor?.id);
addValue(related, ctx?.json?.actor?.alternateId);
field("json.target").get(new ArrayList()).stream().forEach(target -> {
addValue(related, target.id);
addValue(related, target.relatedId);
});
def oktaTarget = ctx?.json?.target;
if (oktaTarget != null) {
if (oktaTarget instanceof List) {
oktaTarget.stream().forEach(target -> {
addValue(related, target.id);
addValue(related, target.relatedId);
});
} else if (oktaTarget instanceof Map) {
addValue(related, oktaTarget.id);
addValue(related, oktaTarget.alternateId);
}
}
field("related.entity").set(related);
- convert:
Expand Down

0 comments on commit 3c0dda2

Please sign in to comment.