vyommani commented on code in PR #671:
URL: https://github.com/apache/ranger/pull/671#discussion_r2354759741
##########
agents-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerRequestScriptEvaluator.java:
##########
@@ -443,125 +432,59 @@ public String getCurrentTagType() {
}
public Set<String> getAllTagTypes() {
- Set<String> allTagTypes = null;
- Set<RangerTagForEval> tagObjectList = getAllTags();
-
- if (CollectionUtils.isNotEmpty(tagObjectList)) {
- for (RangerTagForEval tag : tagObjectList) {
- String tagType = tag.getType();
- if (allTagTypes == null) {
- allTagTypes = new HashSet<>();
- }
- allTagTypes.add(tagType);
- }
- }
+ Set<RangerTagForEval> tags = getAllTags();
- return allTagTypes;
+ return CollectionUtils.isEmpty(tags) ? null :
tags.stream().map(RangerTagForEval::getType).collect(Collectors.toSet());
}
public Map<String, String> getTagAttributes(final String tagType) {
- Map<String, String> ret = null;
-
- if (StringUtils.isNotBlank(tagType)) {
- Set<RangerTagForEval> tagObjectList = getAllTags();
-
- // Assumption: There is exactly one tag with given tagType in the
list of tags - may not be true ***TODO***
- // This will get attributes of the first tagType that matches
- if (CollectionUtils.isNotEmpty(tagObjectList)) {
- for (RangerTagForEval tag : tagObjectList) {
- if (tag.getType().equals(tagType)) {
- ret = tag.getAttributes();
- break;
- }
- }
- }
- }
+ Set<RangerTagForEval> tags = StringUtils.isBlank(tagType) ? null :
getAllTags();
- return ret;
+ // Assumption: There is exactly one tag with given tagType in the list
of tags - may not be true ***TODO**
+ // This will get attributes of the first tagType that matches
+ return CollectionUtils.isEmpty(tags) ? null :
+ tags.stream()
+ .filter(tag -> tagType.equals(tag.getType()))
+ .findFirst()
+ .map(RangerTagForEval::getAttributes)
+ .orElse(null);
}
public List<Map<String, String>> getTagAttributesForAllMatchingTags(final
String tagType) {
- List<Map<String, String>> ret = null;
-
- if (StringUtils.isNotBlank(tagType)) {
- Set<RangerTagForEval> tagObjectList = getAllTags();
-
- // Assumption: There is exactly one tag with given tagType in the
list of tags - may not be true ***TODO***
- // This will get attributes of the first tagType that matches
- if (CollectionUtils.isNotEmpty(tagObjectList)) {
- for (RangerTagForEval tag : tagObjectList) {
- if (tag.getType().equals(tagType)) {
- Map<String, String> tagAttributes =
tag.getAttributes();
- if (tagAttributes != null) {
- if (ret == null) {
- ret = new ArrayList<>();
- }
- ret.add(tagAttributes);
- }
- break;
- }
- }
- }
- }
+ Set<RangerTagForEval> tags = StringUtils.isBlank(tagType) ? null :
getAllTags();
- return ret;
+ return CollectionUtils.isEmpty(tags) ? null :
+ tags.stream()
+ .filter(tag -> tagType.equals(tag.getType()))
+ .map(RangerTagForEval::getAttributes)
Review Comment:
don't you think we have to call findFirst() ? as you did in previous changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]