You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ranger.apache.org by "Qiang Zhang (JIRA)" <ji...@apache.org> on 2017/03/03 08:59:45 UTC
[jira] [Created] (RANGER-1419) Do some code improvement in Java
method XTrxLogService.searchXTrxLogs
Qiang Zhang created RANGER-1419:
-----------------------------------
Summary: Do some code improvement in Java method XTrxLogService.searchXTrxLogs
Key: RANGER-1419
URL: https://issues.apache.org/jira/browse/RANGER-1419
Project: Ranger
Issue Type: Improvement
Components: admin
Reporter: Qiang Zhang
Assignee: Qiang Zhang
Priority: Minor
In method searchXTrxLogs of class \security-admin\src\main\java\org\apache\ranger\service\XTrxLogService.java,
there is some code can be improved:
1.When search type is SearchField.SEARCH_TYPE.PARTIAL, stringPredicate generated twice which first is redundant.
{code}
if(attr != null){
stringPredicate = criteriaBuilder.equal(rootEntityType.get(attr), paramValue);
if (searchField.getSearchType().equals(SearchField.SEARCH_TYPE.PARTIAL)) {
String val = "%" + paramValue + "%";
stringPredicate = criteriaBuilder.like(rootEntityType.get(attr), val);
}
predicate = criteriaBuilder.and(predicate, stringPredicate);
}
{code}
2."datePredicate = criteriaBuilder.equal(...)" is repeated, the first is redundant and duplicated code.
{code}
if (searchField.getCustomCondition() == null) {
datePredicate = criteriaBuilder.equal(rootEntityType.get(attr), fieldValue);
if (searchField.getSearchType().equals(SearchField.SEARCH_TYPE.LESS_THAN)) {
datePredicate = criteriaBuilder.lessThan(rootEntityType.get(attr), fieldValue);
} else if (searchField.getSearchType().equals(SearchField.SEARCH_TYPE.LESS_EQUAL_THAN)) {
datePredicate = criteriaBuilder.lessThanOrEqualTo(rootEntityType.get(attr), fieldValue);
} else if (searchField.getSearchType().equals(SearchField.SEARCH_TYPE.GREATER_THAN)) {
datePredicate = criteriaBuilder.greaterThan(rootEntityType.get(attr), fieldValue);
} else if (searchField.getSearchType().equals(SearchField.SEARCH_TYPE.GREATER_EQUAL_THAN)) {
datePredicate = criteriaBuilder.greaterThanOrEqualTo(rootEntityType.get(attr), fieldValue);
} else {
datePredicate = criteriaBuilder.equal(rootEntityType.get(attr), fieldValue);
}
predicate = criteriaBuilder.and(predicate, datePredicate);
}
{code}
3.The following code is repated in Java method XTrxLogService.searchXTrxLogsCount, it can be refactored to a method.
{code}for(String key : paramList.keySet()){...}{code}
4.Do some other code improvement in Java method XTrxLogService.searchXTrxLogs and related code.
Such as equal usage and local variable, etc.
5.XTrxLogService.searchXTrxLogs is used in Audit Admin WebPage,
please refer screenshot [AduitAdminSearch.jpg] for more detail,
so it can be tested easily.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)