use of org.apache.ranger.view.VXResourceList in project ranger by apache.
the class TestAssetREST method testSearchXResource.
@Test
public void testSearchXResource() {
List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
List<VXResource> vXResourcesList = new ArrayList<VXResource>();
RangerService rangerService = rangerService(Id);
long i;
for (i = 1; i <= 2; i++) {
RangerPolicy rangerPolicy = rangerPolicy(i);
VXResource vXresource = vxResource(i);
rangerPolicyList.add(rangerPolicy);
vXResourcesList.add(vXresource);
Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vXresource);
}
Mockito.when(serviceREST.getServiceByName(rangerPolicyList.get(0).getService())).thenReturn(rangerService);
VXResourceList expectedVXResourceList = new VXResourceList();
expectedVXResourceList.setVXResources(vXResourcesList);
SearchFilter searchFilter = new SearchFilter();
Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, null)).thenReturn(searchFilter);
Mockito.when(serviceREST.getPolicies(searchFilter)).thenReturn(rangerPolicyList);
VXResourceList actualVXResourceList = assetREST.searchXResources(request);
Assert.assertNotNull(actualVXResourceList);
Assert.assertEquals(expectedVXResourceList.getVXResources(), actualVXResourceList.getVXResources());
Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, null);
Mockito.verify(serviceREST).getPolicies(searchFilter);
for (i = 0; i < 2; i++) {
Mockito.verify(serviceUtil, Mockito.times(1)).toVXResource(rangerPolicyList.get((int) i), rangerService);
}
Mockito.verify(serviceREST, Mockito.times(2)).getServiceByName(rangerPolicyList.get(0).getService());
}
use of org.apache.ranger.view.VXResourceList in project ranger by apache.
the class TestAssetREST method testCountXResource.
@Test
public void testCountXResource() {
List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
List<VXResource> vXResourcesList = new ArrayList<VXResource>();
RangerService rangerService = rangerService(Id);
long i;
for (i = 1; i <= 2; i++) {
RangerPolicy rangerPolicy = rangerPolicy(i);
VXResource vXresource = vxResource(i);
rangerPolicyList.add(rangerPolicy);
vXResourcesList.add(vXresource);
Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vXresource);
}
VXLong expectedXResouce = new VXLong();
expectedXResouce.setValue(2l);
Mockito.when(serviceREST.getServiceByName(rangerPolicyList.get(0).getService())).thenReturn(rangerService);
VXResourceList expectedVXResourceList = new VXResourceList();
expectedVXResourceList.setVXResources(vXResourcesList);
SearchFilter searchFilter = new SearchFilter();
Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, null)).thenReturn(searchFilter);
Mockito.when(serviceREST.getPolicies(searchFilter)).thenReturn(rangerPolicyList);
VXLong actualXResource = assetREST.countXResources(request);
Assert.assertEquals(expectedXResouce.getValue(), actualXResource.getValue());
}
use of org.apache.ranger.view.VXResourceList in project ranger by apache.
the class XResourceServiceBase method searchXResources.
/**
* @param searchCriteria
* @return
*/
public VXResourceList searchXResources(SearchCriteria searchCriteria) {
VXResourceList returnList = new VXResourceList();
List<VXResource> xResourceList = new ArrayList<VXResource>();
List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
// Iterate over the result list and create the return list
for (T gjXResource : resultList) {
VXResource vXResource = populateViewBean(gjXResource);
xResourceList.add(vXResource);
}
returnList.setVXResources(xResourceList);
return returnList;
}
use of org.apache.ranger.view.VXResourceList in project ranger by apache.
the class XResourceService method searchXResources.
@Override
public VXResourceList searchXResources(SearchCriteria searchCriteria) {
VXResourceList returnList;
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
// If user is system admin
if (currentUserSession != null && currentUserSession.isUserAdmin()) {
returnList = super.searchXResources(searchCriteria);
} else {
// need to be optimize
returnList = new VXResourceList();
int startIndex = searchCriteria.getStartIndex();
int pageSize = searchCriteria.getMaxRows();
searchCriteria.setStartIndex(0);
searchCriteria.setMaxRows(Integer.MAX_VALUE);
List<XXResource> resultList = (List<XXResource>) searchResources(searchCriteria, searchFields, sortFields, returnList);
List<XXResource> adminPermResourceList = new ArrayList<XXResource>();
for (XXResource xXResource : resultList) {
VXResponse vXResponse = xaBizUtil.hasPermission(populateViewBean(xXResource), AppConstants.XA_PERM_TYPE_ADMIN);
if (vXResponse.getStatusCode() == VXResponse.STATUS_SUCCESS) {
adminPermResourceList.add(xXResource);
}
}
if (!adminPermResourceList.isEmpty()) {
populatePageList(adminPermResourceList, startIndex, pageSize, returnList);
}
}
if (returnList != null && returnList.getResultSize() > 0) {
for (VXResource vXResource : returnList.getVXResources()) {
populateAuditList(vXResource);
}
}
return returnList;
}
Aggregations