Search in sources :

Example 1 with VXTrxLogList

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

the class TestAssetREST method testGetTransactionReport.

@Test
public void testGetTransactionReport() {
    List<VXTrxLog> vXTrxLogs = new ArrayList<VXTrxLog>();
    VXTrxLogList vXTrxLogList = new VXTrxLogList();
    vXTrxLogList.setVXTrxLogs(vXTrxLogs);
    String transactionId = "123456";
    Mockito.when(assetMgr.getTransactionReport(transactionId)).thenReturn(vXTrxLogList);
    VXTrxLogList expectedVXTrxLogListt = assetREST.getTransactionReport(request, transactionId);
    Assert.assertEquals(vXTrxLogList, expectedVXTrxLogListt);
    Mockito.verify(assetMgr).getTransactionReport(transactionId);
}
Also used : VXTrxLog(org.apache.ranger.view.VXTrxLog) VXTrxLogList(org.apache.ranger.view.VXTrxLogList) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with VXTrxLogList

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

the class TestAssetREST method testGetReportLogs.

@Test
public void testGetReportLogs() {
    SearchCriteria searchCriteria = new SearchCriteria();
    List<SortField> sortFields = null;
    List<VXTrxLog> vXTrxLogs = new ArrayList<VXTrxLog>();
    VXTrxLogList vXTrxLogList = new VXTrxLogList();
    vXTrxLogList.setVXTrxLogs(vXTrxLogs);
    Mockito.when(searchUtil.extractCommonCriterias(request, sortFields)).thenReturn(searchCriteria);
    Mockito.when(searchUtil.extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn("test");
    Mockito.when(searchUtil.extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Integer) 8);
    Mockito.when(searchUtil.extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(new Date());
    Mockito.when(assetMgr.getReportLogs(searchCriteria)).thenReturn(vXTrxLogList);
    VXTrxLogList expectedVXTrxLogListt = assetREST.getReportLogs(request);
    Assert.assertEquals(vXTrxLogList, expectedVXTrxLogListt);
    Mockito.verify(searchUtil, Mockito.times(4)).extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil).extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil, Mockito.times(2)).extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(assetMgr).getReportLogs(searchCriteria);
    Mockito.verify(searchUtil).extractCommonCriterias(request, sortFields);
}
Also used : VXTrxLog(org.apache.ranger.view.VXTrxLog) VXTrxLogList(org.apache.ranger.view.VXTrxLogList) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) SearchCriteria(org.apache.ranger.common.SearchCriteria) Date(java.util.Date) Test(org.junit.Test)

Example 3 with VXTrxLogList

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

the class TestXAuditREST method Test5searchXTrxLog.

@SuppressWarnings("unchecked")
@Test
public void Test5searchXTrxLog() {
    VXTrxLogList vxExpList = new VXTrxLogList();
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    searchCriteria.addParam("name", name);
    Mockito.when(searchUtil.extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any())).thenReturn(searchCriteria);
    Mockito.when(xAuditMgr.searchXTrxLogs(searchCriteria)).thenReturn(vxExpList);
    VXTrxLogList vxActList = auditREST.searchXTrxLogs(request);
    Assert.assertNotNull(vxActList);
    Assert.assertEquals(vxExpList, vxActList);
    Mockito.verify(searchUtil).extractCommonCriterias((HttpServletRequest) Mockito.any(), (List<SortField>) Mockito.any());
    Mockito.verify(xAuditMgr).searchXTrxLogs(searchCriteria);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXTrxLogList(org.apache.ranger.view.VXTrxLogList) SortField(org.apache.ranger.common.SortField) Test(org.junit.Test)

Example 4 with VXTrxLogList

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

the class XTrxLogService method searchXTrxLogs.

@Override
public VXTrxLogList searchXTrxLogs(SearchCriteria searchCriteria) {
    EntityManager em = daoManager.getEntityManager();
    CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
    CriteriaQuery<VXXTrxLog> selectCQ = criteriaBuilder.createQuery(VXXTrxLog.class);
    Root<VXXTrxLog> rootEntityType = selectCQ.from(VXXTrxLog.class);
    Predicate predicate = generatePredicate(searchCriteria, em, criteriaBuilder, rootEntityType);
    selectCQ.where(predicate);
    if ("asc".equalsIgnoreCase(searchCriteria.getSortType())) {
        selectCQ.orderBy(criteriaBuilder.asc(rootEntityType.get("createTime")));
    } else {
        selectCQ.orderBy(criteriaBuilder.desc(rootEntityType.get("createTime")));
    }
    int startIndex = searchCriteria.getStartIndex();
    int pageSize = searchCriteria.getMaxRows();
    List<VXXTrxLog> resultList = em.createQuery(selectCQ).setFirstResult(startIndex).setMaxResults(pageSize).getResultList();
    int maxRowSize = Integer.MAX_VALUE;
    int minRowSize = 0;
    XXServiceDef xxServiceDef = daoManager.getXXServiceDef().findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME);
    UserSessionBase session = ContextUtil.getCurrentUserSession();
    if (session != null && session.isKeyAdmin()) {
        resultList = em.createQuery(selectCQ).setFirstResult(minRowSize).setMaxResults(maxRowSize).getResultList();
    }
    if (session != null && session.isAuditKeyAdmin()) {
        resultList = em.createQuery(selectCQ).setFirstResult(minRowSize).setMaxResults(maxRowSize).getResultList();
    }
    List<VXTrxLog> trxLogList = new ArrayList<VXTrxLog>();
    for (VXXTrxLog xTrxLog : resultList) {
        VXTrxLog trxLog = mapCustomViewToViewObj(xTrxLog);
        if (trxLog.getUpdatedBy() != null) {
            XXPortalUser xXPortalUser = daoManager.getXXPortalUser().getById(Long.parseLong(trxLog.getUpdatedBy()));
            if (xXPortalUser != null) {
                trxLog.setOwner(xXPortalUser.getLoginId());
            }
        }
        trxLogList.add(trxLog);
    }
    List<VXTrxLog> keyAdminTrxLogList = new ArrayList<VXTrxLog>();
    if (session != null && xxServiceDef != null && (session.isKeyAdmin() || session.isAuditKeyAdmin())) {
        List<VXTrxLog> vXTrxLogs = new ArrayList<VXTrxLog>();
        for (VXTrxLog xTrxLog : trxLogList) {
            int parentObjectClassType = xTrxLog.getParentObjectClassType();
            Long parentObjectId = xTrxLog.getParentObjectId();
            if (parentObjectClassType == AppConstants.CLASS_TYPE_XA_SERVICE_DEF && parentObjectId.equals(xxServiceDef.getId())) {
                vXTrxLogs.add(xTrxLog);
            } else if (parentObjectClassType == AppConstants.CLASS_TYPE_XA_SERVICE && !(parentObjectId.equals(xxServiceDef.getId()))) {
                for (VXTrxLog vxTrxLog : trxLogList) {
                    if (parentObjectClassType == vxTrxLog.getObjectClassType() && parentObjectId.equals(vxTrxLog.getObjectId()) && vxTrxLog.getParentObjectId().equals(xxServiceDef.getId())) {
                        vXTrxLogs.add(xTrxLog);
                        break;
                    }
                }
            } else if (xTrxLog.getObjectClassType() == AppConstants.CLASS_TYPE_XA_USER || xTrxLog.getObjectClassType() == AppConstants.CLASS_TYPE_RANGER_POLICY || xTrxLog.getObjectClassType() == AppConstants.HIST_OBJ_STATUS_UPDATED) {
                XXPortalUser xxPortalUser = null;
                if (xTrxLog.getUpdatedBy() != null) {
                    xxPortalUser = daoManager.getXXPortalUser().getById(Long.parseLong(xTrxLog.getUpdatedBy()));
                }
                if (xxPortalUser != null && xxPortalUser.getId() != null) {
                    List<XXPortalUserRole> xxPortalUserRole = daoManager.getXXPortalUserRole().findByUserId(xxPortalUser.getId());
                    if (xxPortalUserRole != null && (xxPortalUserRole.get(0).getUserRole().equalsIgnoreCase("ROLE_KEY_ADMIN") || xxPortalUserRole.get(0).getUserRole().equalsIgnoreCase("ROLE_KEY_ADMIN_AUDITOR"))) {
                        vXTrxLogs.add(xTrxLog);
                    }
                }
            }
        }
        keyadminCount = (long) vXTrxLogs.size();
        if (vXTrxLogs != null && !vXTrxLogs.isEmpty()) {
            for (int k = startIndex; k <= pageSize; k++) {
                if (k < vXTrxLogs.size()) {
                    keyAdminTrxLogList.add(vXTrxLogs.get(k));
                }
            }
        }
    }
    VXTrxLogList vxTrxLogList = new VXTrxLogList();
    vxTrxLogList.setStartIndex(startIndex);
    vxTrxLogList.setPageSize(pageSize);
    if (session != null && (session.isKeyAdmin() || session.isAuditKeyAdmin())) {
        vxTrxLogList.setVXTrxLogs(keyAdminTrxLogList);
    } else {
        vxTrxLogList.setVXTrxLogs(trxLogList);
    }
    return vxTrxLogList;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) EntityManager(javax.persistence.EntityManager) VXTrxLog(org.apache.ranger.view.VXTrxLog) VXTrxLogList(org.apache.ranger.view.VXTrxLogList) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXXTrxLog(org.apache.ranger.entity.view.VXXTrxLog)

Example 5 with VXTrxLogList

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

the class XTrxLogServiceBase method searchXTrxLogs.

/**
 * @param searchCriteria
 * @return
 */
public VXTrxLogList searchXTrxLogs(SearchCriteria searchCriteria) {
    VXTrxLogList returnList = new VXTrxLogList();
    List<VXTrxLog> xTrxLogList = new ArrayList<VXTrxLog>();
    List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
    // Iterate over the result list and create the return list
    for (T gjXTrxLog : resultList) {
        VXTrxLog vXTrxLog = populateViewBean(gjXTrxLog);
        xTrxLogList.add(vXTrxLog);
    }
    returnList.setVXTrxLogs(xTrxLogList);
    return returnList;
}
Also used : VXTrxLog(org.apache.ranger.view.VXTrxLog) VXTrxLogList(org.apache.ranger.view.VXTrxLogList) ArrayList(java.util.ArrayList)

Aggregations

VXTrxLogList (org.apache.ranger.view.VXTrxLogList)5 ArrayList (java.util.ArrayList)4 VXTrxLog (org.apache.ranger.view.VXTrxLog)4 Test (org.junit.Test)3 SortField (org.apache.ranger.common.SortField)2 Date (java.util.Date)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SearchCriteria (org.apache.ranger.common.SearchCriteria)1 UserSessionBase (org.apache.ranger.common.UserSessionBase)1 XXPortalUser (org.apache.ranger.entity.XXPortalUser)1 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)1 XXServiceDef (org.apache.ranger.entity.XXServiceDef)1 VXXTrxLog (org.apache.ranger.entity.view.VXXTrxLog)1