use of org.apache.ranger.common.SortField in project ranger by apache.
the class TestXUserREST method test24searchXUsers.
@SuppressWarnings("unchecked")
@Test
public void test24searchXUsers() {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
SearchCriteria testSearchCriteria = createsearchCriteria();
Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
Mockito.when(searchUtil.extractString(request, testSearchCriteria, "name", "User name", null)).thenReturn("");
Mockito.when(searchUtil.extractString(request, testSearchCriteria, "emailAddress", "Email Address", null)).thenReturn("");
Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "userSource", "User Source")).thenReturn(1);
Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "isVisible", "User Visibility")).thenReturn(1);
Mockito.when(searchUtil.extractInt(request, testSearchCriteria, "status", "User Status")).thenReturn(1);
Mockito.when(searchUtil.extractStringList(request, testSearchCriteria, "userRoleList", "User Role List", "userRoleList", null, null)).thenReturn(new ArrayList<String>());
Mockito.when(searchUtil.extractString(request, testSearchCriteria, "userRole", "UserRole", null)).thenReturn("");
List<VXUser> vXUsersList = new ArrayList<VXUser>();
vXUsersList.add(vxUser);
VXUserList testVXUserList = new VXUserList();
testVXUserList.setVXUsers(vXUsersList);
Mockito.when(xUserMgr.searchXUsers(testSearchCriteria)).thenReturn(testVXUserList);
VXUserList gotVXUserList = xUserRest.searchXUsers(request);
Mockito.verify(xUserMgr).searchXUsers(testSearchCriteria);
Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "name", "User name", null);
Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "emailAddress", "Email Address", null);
Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "userSource", "User Source");
Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "isVisible", "User Visibility");
Mockito.verify(searchUtil).extractInt(request, testSearchCriteria, "status", "User Status");
Mockito.verify(searchUtil).extractStringList(request, testSearchCriteria, "userRoleList", "User Role List", "userRoleList", null, null);
Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "userRole", "UserRole", null);
assertNotNull(gotVXUserList);
assertEquals(testVXUserList.getTotalCount(), gotVXUserList.getTotalCount());
assertEquals(testVXUserList.getClass(), gotVXUserList.getClass());
}
use of org.apache.ranger.common.SortField in project ranger by apache.
the class TestXUserREST method test49countXPermMaps.
@SuppressWarnings("unchecked")
@Test
public void test49countXPermMaps() {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
SearchCriteria testSearchCriteria = createsearchCriteria();
Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(testSearchCriteria);
vXLong.setValue(1);
Mockito.when(xUserMgr.getXPermMapSearchCount(testSearchCriteria)).thenReturn(vXLong);
VXLong testvxLong = xUserRest.countXPermMaps(request);
Mockito.verify(xUserMgr).getXPermMapSearchCount(testSearchCriteria);
Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
assertNotNull(testvxLong);
}
use of org.apache.ranger.common.SortField in project ranger by apache.
the class KmsKeyMgr method getFilteredKeyList.
public VXKmsKeyList getFilteredKeyList(HttpServletRequest request, VXKmsKeyList vXKmsKeyList) {
List<SortField> sortFields = new ArrayList<SortField>();
sortFields.add(new SortField(KeySearchFilter.KEY_NAME, KeySearchFilter.KEY_NAME));
KeySearchFilter filter = getKeySearchFilter(request, sortFields);
Predicate pred = getPredicate(filter);
if (pred != null) {
CollectionUtils.filter(vXKmsKeyList.getVXKeys(), pred);
}
return vXKmsKeyList;
}
use of org.apache.ranger.common.SortField in project ranger by apache.
the class KmsKeyMgr method extractCommonCriteriasForFilter.
private KeySearchFilter extractCommonCriteriasForFilter(HttpServletRequest request, KeySearchFilter ret, List<SortField> sortFields) {
int startIndex = restErrorUtil.parseInt(request.getParameter(KeySearchFilter.START_INDEX), 0, "Invalid value for parameter startIndex", MessageEnums.INVALID_INPUT_DATA, null, KeySearchFilter.START_INDEX);
ret.setStartIndex(startIndex);
int pageSize = restErrorUtil.parseInt(request.getParameter(KeySearchFilter.PAGE_SIZE), configUtil.getDefaultMaxRows(), "Invalid value for parameter pageSize", MessageEnums.INVALID_INPUT_DATA, null, KeySearchFilter.PAGE_SIZE);
ret.setMaxRows(pageSize);
ret.setGetCount(restErrorUtil.parseBoolean(request.getParameter("getCount"), true));
String sortBy = restErrorUtil.validateString(request.getParameter(KeySearchFilter.SORT_BY), StringUtil.VALIDATION_ALPHA, "Invalid value for parameter sortBy", MessageEnums.INVALID_INPUT_DATA, null, KeySearchFilter.SORT_BY);
boolean sortSet = false;
if (!StringUtils.isEmpty(sortBy)) {
for (SortField sortField : sortFields) {
if (sortField.getParamName().equalsIgnoreCase(sortBy)) {
ret.setSortBy(sortField.getParamName());
String sortType = restErrorUtil.validateString(request.getParameter("sortType"), StringUtil.VALIDATION_ALPHA, "Invalid value for parameter sortType", MessageEnums.INVALID_INPUT_DATA, null, "sortType");
ret.setSortType(sortType);
sortSet = true;
break;
}
}
}
if (!sortSet && !StringUtils.isEmpty(sortBy)) {
logger.info("Invalid or unsupported sortBy field passed. sortBy=" + sortBy, new Throwable());
}
if (ret.getParams() == null) {
ret.setParams(new HashMap<String, String>());
}
return ret;
}
use of org.apache.ranger.common.SortField in project ranger by apache.
the class AbstractBaseResourceService method setSortClause.
public void setSortClause(SearchCriteria searchCriteria, List<SortField> sortFields, CriteriaBuilder criteriaBuilder, CriteriaQuery<? extends Object> criteria, Root<? extends XXDBBase> from) {
String sortBy = searchCriteria.getSortBy();
String sortByField = null;
if (!stringUtil.isEmpty(sortBy)) {
sortBy = sortBy.trim();
for (SortField sortField : sortFields) {
if (sortBy.equalsIgnoreCase(sortField.getParamName())) {
sortByField = sortField.getFieldName();
// searchCriteria.setSortBy(sortByField);
break;
}
}
}
if (sortByField == null) {
for (SortField sortField : sortFields) {
if (sortField.isDefault()) {
sortByField = sortField.getFieldName();
// Override the sortBy using the default value
searchCriteria.setSortBy(sortField.getParamName());
searchCriteria.setSortType(sortField.getDefaultOrder().name());
break;
}
}
}
if (sortByField != null) {
int dotIndex = sortByField.indexOf(".");
if (dotIndex != -1) {
sortByField = sortByField.substring(dotIndex + 1);
}
// Add sort type
String sortType = searchCriteria.getSortType();
if (sortType != null && "desc".equalsIgnoreCase(sortType)) {
criteria.orderBy(criteriaBuilder.desc(from.get(sortByField)));
} else {
criteria.orderBy(criteriaBuilder.asc(from.get(sortByField)));
}
}
}
Aggregations