Search in sources :

Example 11 with SortField

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXUserList(org.apache.ranger.view.VXUserList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 12 with SortField

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXLong(org.apache.ranger.view.VXLong) SortField(org.apache.ranger.common.SortField) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 13 with SortField

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;
}
Also used : ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) KeySearchFilter(org.apache.ranger.plugin.util.KeySearchFilter) Predicate(org.apache.commons.collections.Predicate)

Example 14 with SortField

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;
}
Also used : SortField(org.apache.ranger.common.SortField)

Example 15 with SortField

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)));
        }
    }
}
Also used : SortField(org.apache.ranger.common.SortField)

Aggregations

SortField (org.apache.ranger.common.SortField)34 Test (org.junit.Test)30 SearchCriteria (org.apache.ranger.common.SearchCriteria)26 HttpServletRequest (javax.servlet.http.HttpServletRequest)23 ArrayList (java.util.ArrayList)15 VXLong (org.apache.ranger.view.VXLong)12 Date (java.util.Date)3 VXAccessAuditList (org.apache.ranger.view.VXAccessAuditList)3 XXServiceDef (org.apache.ranger.entity.XXServiceDef)2 VXAccessAudit (org.apache.ranger.view.VXAccessAudit)2 VXTrxLogList (org.apache.ranger.view.VXTrxLogList)2 VXUser (org.apache.ranger.view.VXUser)2 VXUserList (org.apache.ranger.view.VXUserList)2 Predicate (org.apache.commons.collections.Predicate)1 KeySearchFilter (org.apache.ranger.plugin.util.KeySearchFilter)1 VXAuditMap (org.apache.ranger.view.VXAuditMap)1 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)1 VXAuthSession (org.apache.ranger.view.VXAuthSession)1 VXAuthSessionList (org.apache.ranger.view.VXAuthSessionList)1 VXCredentialStore (org.apache.ranger.view.VXCredentialStore)1