diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PolicyRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PolicyRepository.java index c3c8aa8fed5c..373564fa4dc3 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PolicyRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PolicyRepository.java @@ -28,7 +28,9 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; +import javax.ws.rs.BadRequestException; import lombok.extern.slf4j.Slf4j; import org.jdbi.v3.sqlobject.transaction.Transaction; import org.openmetadata.schema.entity.policies.Policy; @@ -158,6 +160,15 @@ public void entitySpecificUpdate() { } private void updateRules(List origRules, List updatedRules) { + // Check if the Rules have unique names + if (!nullOrEmpty(updatedRules)) { + Set ruleNames = updatedRules.stream().map(Rule::getName).collect(Collectors.toSet()); + + if (ruleNames.size() != updatedRules.size()) { + throw new BadRequestException("Policy contains duplicate Rules. Please use unique name for Rules."); + } + } + // Record change description List deletedRules = new ArrayList<>(); List addedRules = new ArrayList<>();