Search in sources :

Example 1 with VXModuleDefList

use of org.apache.ranger.view.VXModuleDefList in project ranger by apache.

the class XModuleDefServiceBase method searchModuleDef.

/**
 * @param searchCriteria
 * @return
 */
public VXModuleDefList searchModuleDef(SearchCriteria searchCriteria) {
    VXModuleDefList returnList = new VXModuleDefList();
    List<VXModuleDef> vXModuleDefList = new ArrayList<VXModuleDef>();
    searchCriteria.setMaxRows(Integer.MAX_VALUE);
    List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
    Map<Long, T> matchModule = new HashMap<Long, T>();
    for (T moduleDef : resultList) {
        matchModule.put(moduleDef.getId(), moduleDef);
    }
    List<T> moduleDefList = new ArrayList<T>(matchModule.values());
    // Iterate over the result list and create the return list
    for (T gjXModuleDef : moduleDefList) {
        VXModuleDef vXModuleDef = populateViewBean(gjXModuleDef);
        vXModuleDefList.add(vXModuleDef);
    }
    returnList.setTotalCount(vXModuleDefList.size());
    returnList.setvXModuleDef(vXModuleDefList);
    return returnList;
}
Also used : VXModuleDefList(org.apache.ranger.view.VXModuleDefList) HashMap(java.util.HashMap) VXModuleDef(org.apache.ranger.view.VXModuleDef) ArrayList(java.util.ArrayList)

Example 2 with VXModuleDefList

use of org.apache.ranger.view.VXModuleDefList in project ranger by apache.

the class TestXUserREST method test80searchXModuleDef.

@SuppressWarnings("unchecked")
@Test
public void test80searchXModuleDef() {
    VXModuleDefList testVXModuleDefList = new VXModuleDefList();
    VXModuleDef vXModuleDef = createVXModuleDef();
    List<VXModuleDef> VXModuleDefs = new ArrayList<VXModuleDef>();
    VXModuleDefs.add(vXModuleDef);
    testVXModuleDefList.setvXModuleDef(VXModuleDefs);
    testVXModuleDefList.setTotalCount(1);
    testVXModuleDefList.setStartIndex(1);
    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, "module", "modulename", null)).thenReturn("");
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "moduleDefList", "id", null)).thenReturn("");
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "userName", "userName", null)).thenReturn("");
    Mockito.when(searchUtil.extractString(request, testSearchCriteria, "groupName", "groupName", null)).thenReturn("");
    Mockito.when(xUserMgr.searchXModuleDef(testSearchCriteria)).thenReturn(testVXModuleDefList);
    VXModuleDefList outputVXModuleDefList = xUserRest.searchXModuleDef(request);
    assertNotNull(outputVXModuleDefList);
    assertEquals(outputVXModuleDefList.getTotalCount(), testVXModuleDefList.getTotalCount());
    assertEquals(outputVXModuleDefList.getStartIndex(), testVXModuleDefList.getStartIndex());
    Mockito.verify(xUserMgr).searchXModuleDef(testSearchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "module", "modulename", null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "moduleDefList", "id", null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "userName", "userName", null);
    Mockito.verify(searchUtil).extractString(request, testSearchCriteria, "groupName", "groupName", null);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXModuleDefList(org.apache.ranger.view.VXModuleDefList) VXModuleDef(org.apache.ranger.view.VXModuleDef) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 VXModuleDef (org.apache.ranger.view.VXModuleDef)2 VXModuleDefList (org.apache.ranger.view.VXModuleDefList)2 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SearchCriteria (org.apache.ranger.common.SearchCriteria)1 SortField (org.apache.ranger.common.SortField)1 Test (org.junit.Test)1