Search in sources :

Example 1 with VXPolicyList

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

the class ServiceUtil method rangerPolicyListToPublic.

public VXPolicyList rangerPolicyListToPublic(List<RangerPolicy> rangerPolicyList, SearchFilter filter) {
    RangerService service = null;
    List<VXPolicy> vXPolicyList = new ArrayList<VXPolicy>();
    VXPolicyList vXPolicyListObj = new VXPolicyList(new ArrayList<VXPolicy>());
    if (CollectionUtils.isNotEmpty(rangerPolicyList)) {
        int totalCount = rangerPolicyList.size();
        int startIndex = filter.getStartIndex();
        int pageSize = filter.getMaxRows();
        int toIndex = Math.min(startIndex + pageSize, totalCount);
        String sortType = filter.getSortType();
        String sortBy = filter.getSortBy();
        for (int i = startIndex; i < toIndex; i++) {
            RangerPolicy policy = rangerPolicyList.get(i);
            try {
                service = svcStore.getServiceByName(policy.getService());
            } catch (Exception excp) {
                throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(), true);
            }
            if (service == null) {
                throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, RangerServiceNotFoundException.buildExceptionMsg(policy.getService()), true);
            }
            VXPolicy vXPolicy = toVXPolicy(policy, service);
            if (vXPolicy != null) {
                vXPolicyList.add(vXPolicy);
            }
        }
        vXPolicyListObj = new VXPolicyList(vXPolicyList);
        vXPolicyListObj.setPageSize(pageSize);
        vXPolicyListObj.setResultSize(vXPolicyList.size());
        vXPolicyListObj.setStartIndex(startIndex);
        vXPolicyListObj.setTotalCount(totalCount);
        vXPolicyListObj.setSortBy(sortBy);
        vXPolicyListObj.setSortType(sortType);
    }
    return vXPolicyListObj;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPolicyList(org.apache.ranger.view.VXPolicyList) VXPolicy(org.apache.ranger.view.VXPolicy) ArrayList(java.util.ArrayList) RangerService(org.apache.ranger.plugin.model.RangerService) RangerServiceNotFoundException(org.apache.ranger.plugin.util.RangerServiceNotFoundException) InvalidNameException(javax.naming.InvalidNameException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 2 with VXPolicyList

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

the class TestPublicAPIs method test12countPolicies.

@Test
public void test12countPolicies() throws Exception {
    VXLong vXLong = new VXLong();
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerService service = rangerService();
    RangerPolicy policy = rangerPolicy();
    List<RangerPolicy> policyList = new ArrayList<RangerPolicy>();
    policyList.add(policy);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    List<VXPolicy> vXPolicies = new ArrayList<VXPolicy>();
    vXPolicies.add(vXPolicy);
    VXPolicyList vXPolicyList = new VXPolicyList(vXPolicies);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    filter.setStartIndex(0);
    filter.setMaxRows(10);
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields)).thenReturn(filter);
    Mockito.when(serviceREST.getPolicies(filter)).thenReturn(policyList);
    Mockito.when(serviceUtil.rangerPolicyListToPublic(policyList, filter)).thenReturn(vXPolicyList);
    VXPolicyList dbVXPolicyList = publicAPIs.searchPolicies(request);
    vXLong.setValue(dbVXPolicyList.getResultSize());
    Assert.assertNotNull(vXLong);
    Assert.assertEquals(vXLong.getValue(), 1);
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, policyService.sortFields);
    Mockito.verify(serviceREST).getPolicies(filter);
    Mockito.verify(serviceUtil).rangerPolicyListToPublic(policyList, filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXLong(org.apache.ranger.view.VXLong) VXPolicyList(org.apache.ranger.view.VXPolicyList) ArrayList(java.util.ArrayList) VXPolicy(org.apache.ranger.view.VXPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 3 with VXPolicyList

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

the class XPolicyService method mapToVXPolicyList.

public VXPolicyList mapToVXPolicyList(VXResourceList vXResourceList) {
    List<VXPolicy> policyList = new ArrayList<VXPolicy>();
    for (VXResource vXAsset : vXResourceList.getVXResources()) {
        VXPolicy vXRepo = mapXAToPublicObject(vXAsset);
        policyList.add(vXRepo);
    }
    VXPolicyList vXPolicyList = new VXPolicyList(policyList);
    return vXPolicyList;
}
Also used : VXPolicyList(org.apache.ranger.view.VXPolicyList) VXPolicy(org.apache.ranger.view.VXPolicy) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource)

Example 4 with VXPolicyList

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

the class TestPublicAPIs method test11searchPolicies.

@Test
public void test11searchPolicies() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerService service = rangerService();
    RangerPolicy policy = rangerPolicy();
    List<RangerPolicy> policyList = new ArrayList<RangerPolicy>();
    policyList.add(policy);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    List<VXPolicy> vXPolicies = new ArrayList<VXPolicy>();
    vXPolicies.add(vXPolicy);
    VXPolicyList vXPolicyList = new VXPolicyList(vXPolicies);
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    filter.setStartIndex(0);
    filter.setMaxRows(10);
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields)).thenReturn(filter);
    Mockito.when(serviceREST.getPolicies(filter)).thenReturn(policyList);
    Mockito.when(serviceUtil.rangerPolicyListToPublic(policyList, filter)).thenReturn(vXPolicyList);
    VXPolicyList dbVXPolicyList = publicAPIs.searchPolicies(request);
    Assert.assertNotNull(dbVXPolicyList);
    Assert.assertEquals(dbVXPolicyList.getResultSize(), vXPolicyList.getResultSize());
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, policyService.sortFields);
    Mockito.verify(serviceREST).getPolicies(filter);
    Mockito.verify(serviceUtil).rangerPolicyListToPublic(policyList, filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXPolicyList(org.apache.ranger.view.VXPolicyList) ArrayList(java.util.ArrayList) VXPolicy(org.apache.ranger.view.VXPolicy) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)4 VXPolicy (org.apache.ranger.view.VXPolicy)4 VXPolicyList (org.apache.ranger.view.VXPolicyList)4 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)3 RangerService (org.apache.ranger.plugin.model.RangerService)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)2 Test (org.junit.Test)2 InvalidNameException (javax.naming.InvalidNameException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 RangerServiceNotFoundException (org.apache.ranger.plugin.util.RangerServiceNotFoundException)1 VXLong (org.apache.ranger.view.VXLong)1 VXResource (org.apache.ranger.view.VXResource)1