kumaab commented on code in PR #741:
URL: https://github.com/apache/ranger/pull/741#discussion_r2562223735
##########
agents-common/src/main/java/org/apache/ranger/plugin/util/SearchFilter.java:
##########
@@ -48,6 +48,8 @@ public class SearchFilter {
public static final String CREATE_TIME = "createTime"; // sort
public static final String UPDATE_TIME = "updateTime"; // sort
public static final String START_INDEX = "startIndex";
+ public static final String BEGIN_INDEX = "beginIndex";
+ public static final String OFFSET_INDEX = "offsetIndex";
Review Comment:
Update vertical alignment for `=`, see other references.
##########
security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java:
##########
@@ -3889,6 +3900,45 @@ private RangerPolicyList
toRangerPolicyList(List<RangerPolicy> policyList, Searc
return ret;
}
+ private List<RangerPolicy> cutRangerPolicyList(List<RangerPolicy>
policyList, SearchFilter filter) {
Review Comment:
Suggested name: `getRangerPoliciesInRange`
##########
security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java:
##########
@@ -3889,6 +3900,45 @@ private RangerPolicyList
toRangerPolicyList(List<RangerPolicy> policyList, Searc
return ret;
}
+ private List<RangerPolicy> cutRangerPolicyList(List<RangerPolicy>
policyList, SearchFilter filter) {
+ List<RangerPolicy> retList = null;
+ if (CollectionUtils.isNotEmpty(policyList)) {
+ int totalCount = policyList.size();
+ int startIndex = filter.getBeginIndex();
+ int pageSize = filter.getOffsetIndex();
+ int toIndex = Math.min(startIndex + pageSize,
totalCount);
+ LOG.info("==>totalCount: " + totalCount + "
startIndex: " + startIndex + " pageSize: " +pageSize + " toIndex: " + toIndex);
Review Comment:
Avoid string concatenation, use `String.format()`
##########
security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java:
##########
@@ -3889,6 +3900,45 @@ private RangerPolicyList
toRangerPolicyList(List<RangerPolicy> policyList, Searc
return ret;
}
+ private List<RangerPolicy> cutRangerPolicyList(List<RangerPolicy>
policyList, SearchFilter filter) {
+ List<RangerPolicy> retList = null;
+ if (CollectionUtils.isNotEmpty(policyList)) {
+ int totalCount = policyList.size();
+ int startIndex = filter.getBeginIndex();
+ int pageSize = filter.getOffsetIndex();
+ int toIndex = Math.min(startIndex + pageSize,
totalCount);
+ LOG.info("==>totalCount: " + totalCount + "
startIndex: " + startIndex + " pageSize: " +pageSize + " toIndex: " + toIndex);
+ String sortType = filter.getSortType();
+ String sortBy = filter.getSortBy();
+
+ if (StringUtils.isNotEmpty(sortBy) &&
StringUtils.isNotEmpty(sortType)) {
+ // By default policyList is sorted by policyId
in asc order, So handling only desc case.
+ if
(SearchFilter.POLICY_ID.equalsIgnoreCase(sortBy)) {
+ if
(SORT_ORDER.DESC.name().equalsIgnoreCase(sortType)) {
+
policyList.sort(this.getPolicyComparator(sortBy, sortType));
+ }
+ } else if
(SearchFilter.POLICY_NAME.equalsIgnoreCase(sortBy)) {
+ if
(SORT_ORDER.ASC.name().equalsIgnoreCase(sortType)) {
+
policyList.sort(this.getPolicyComparator(sortBy, sortType));
+ } else if
(SORT_ORDER.DESC.name().equalsIgnoreCase(sortType)) {
+
policyList.sort(this.getPolicyComparator(sortBy, sortType));
+ } else {
+ LOG.info("Invalid or
Unsupported sortType : " + sortType);
+ }
+ } else {
+ LOG.info("Invalid or Unsupported sortBy
property : " + sortBy);
Review Comment:
Avoid string concat, check all references.
See:
https://cwiki.apache.org/confluence/display/RANGER/Apache+Ranger+Java+Style+Guide
--
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]