Skip to content

Commit

Permalink
RANGER-4542: updated zone search API to support search by zoneNamePar…
Browse files Browse the repository at this point in the history
…tial

Signed-off-by: Madhan Neethiraj <[email protected]>
  • Loading branch information
prashantdev88 authored and mneethiraj committed Dec 4, 2023
1 parent 2e4a8c1 commit 1d09117
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ public void applyFilter(List<? extends RangerBaseModelObject> objList, SearchFil
}

Comparator<RangerBaseModelObject> sorter = getSorter(filter);
boolean isDesc = (filter.getSortType() != null) && "desc".equalsIgnoreCase(filter.getSortType());

if (sorter != null) {
boolean isDesc = "desc".equalsIgnoreCase(filter.getSortType());

if (sorter != null){
Collections.sort(objList, isDesc ? new ReverseComparator(sorter) : sorter);
}else if(isDesc) {
Collections.reverse(objList);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void addPredicates(SearchFilter filter, List<Predicate> predicates) {
addPredicateForMatchingZoneId(filter.getParam(SearchFilter.ZONE_ID), predicates);
addPredicateForMatchingZoneName(filter.getParam(SearchFilter.ZONE_NAME), predicates);
addPredicateForNonMatchingZoneName(filter.getParam(SearchFilter.NOT_ZONE_NAME), predicates);
addPredicateForMatchingZoneNamePartial(filter.getParam(SearchFilter.ZONE_NAME_PARTIAL), predicates);
}

private Predicate addPredicateForServiceName(final String serviceName, List<Predicate> predicates) {
Expand Down Expand Up @@ -170,5 +171,38 @@ public boolean evaluate(Object object) {

return ret;
}

private Predicate addPredicateForMatchingZoneNamePartial(final String zoneName, List<Predicate> predicates) {
if (StringUtils.isEmpty(zoneName)) {
return null;
}

Predicate ret = new Predicate() {
@Override
public boolean evaluate(Object object) {
if (object == null) {
return false;
}

boolean ret = false;

if (object instanceof RangerSecurityZone) {
RangerSecurityZone securityZone = (RangerSecurityZone) object;

if (StringUtils.contains(securityZone.getName(), zoneName)) {
ret = true;
}
}

return ret;
}
};

if (predicates != null) {
predicates.add(ret);
}

return ret;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public List<RangerSecurityZone> getSecurityZones(SearchFilter filter) throws Exc
}
}

if (CollectionUtils.isNotEmpty(ret) && filter != null && !filter.isEmpty()) {
if (CollectionUtils.isNotEmpty(ret) && filter != null) {
List<RangerSecurityZone> copy = new ArrayList<>(ret);

predicateUtil.applyFilter(copy, filter);
Expand Down

0 comments on commit 1d09117

Please sign in to comment.