From f511eea54c6245da41cd0f0264e77c135de353b4 Mon Sep 17 00:00:00 2001 From: Joanne Wang Date: Tue, 2 Jul 2024 18:42:40 -0700 Subject: [PATCH] make variables final Signed-off-by: Joanne Wang --- .../services/STIX2IOCFeedStore.java | 24 ++++--------------- .../model/DefaultIocStoreConfig.java | 17 +++---------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java b/src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java index bb55bd770..eb5751fa4 100644 --- a/src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java +++ b/src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java @@ -152,26 +152,10 @@ public void indexIocs(List iocs) throws IOException { if (saTifSourceConfig.getIocStoreConfig() instanceof DefaultIocStoreConfig) { List listOfIocToIndexDetails = ((DefaultIocStoreConfig) saTifSourceConfig.getIocStoreConfig()).getIocToIndexDetails(); - - boolean containsType = false; - DefaultIocStoreConfig.IocToIndexDetails newIoctoIndexDetails = null; - - for (DefaultIocStoreConfig.IocToIndexDetails iocToIndexDetails: listOfIocToIndexDetails) { - if (iocToIndexDetails.getIocType() == iocType) { - containsType = true; - newIoctoIndexDetails = iocToIndexDetails; - break; - } - } - - if (containsType) { - newIoctoIndexDetails.setWriteIndex(writeIndex); - } else { - DefaultIocStoreConfig.IocToIndexDetails iocToIndexDetails = - new DefaultIocStoreConfig.IocToIndexDetails(iocType, iocIndexPattern, writeIndex); - listOfIocToIndexDetails.add(iocToIndexDetails); - } - + listOfIocToIndexDetails.removeIf(iocToIndexDetails -> iocToIndexDetails.getIocType() == iocType); + DefaultIocStoreConfig.IocToIndexDetails iocToIndexDetails = + new DefaultIocStoreConfig.IocToIndexDetails(iocType, iocIndexPattern, writeIndex); + listOfIocToIndexDetails.add(iocToIndexDetails); } }); bulkIndexIocs(iocs, iocAlias); diff --git a/src/main/java/org/opensearch/securityanalytics/threatIntel/model/DefaultIocStoreConfig.java b/src/main/java/org/opensearch/securityanalytics/threatIntel/model/DefaultIocStoreConfig.java index fd48a7a1d..608d6761b 100644 --- a/src/main/java/org/opensearch/securityanalytics/threatIntel/model/DefaultIocStoreConfig.java +++ b/src/main/java/org/opensearch/securityanalytics/threatIntel/model/DefaultIocStoreConfig.java @@ -90,9 +90,9 @@ public static class IocToIndexDetails implements Writeable, ToXContent { public static final String IOC_TYPE_FIELD = "ioc_type"; public static final String INDEX_PATTERN_FIELD = "index_pattern"; public static final String WRITE_INDEX_FIELD = "write_index"; - IOCType iocType; - String indexPattern; - String writeIndex; + private final IOCType iocType; + private final String indexPattern; + private final String writeIndex; public IocToIndexDetails(IOCType iocType, String indexPattern, String writeIndex) { this.iocType = iocType; @@ -161,24 +161,13 @@ public IOCType getIocType() { return iocType; } - public void setIocType(IOCType iocType) { - this.iocType = iocType; - } - public String getIndexPattern() { return indexPattern; } - public void setIndexPattern(String indexPattern) { - this.indexPattern = indexPattern; - } - public String getWriteIndex() { return writeIndex; } - public void setWriteIndex(String writeIndex) { - this.writeIndex = writeIndex; - } } }