[ 
https://issues.apache.org/jira/browse/RANGER-1419?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Qiang Zhang updated RANGER-1419:
--------------------------------
    Attachment: 0001-RANGER-1419-Do-some-code-improvement-in-Java-method-.patch

> 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
>              Labels: patch
>         Attachments: 
> 0001-RANGER-1419-Do-some-code-improvement-in-Java-method-.patch, 
> AduitAdminSearch.jpg
>
>   Original Estimate: 0.2h
>  Remaining Estimate: 0.2h
>
> 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|https://issues.apache.org/jira/secure/attachment/12855809/AduitAdminSearch.jpg]
>  for more detail,
> so it can be tested easily.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to