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;
}
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);
}
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;
}
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);
}
Aggregations